Harvard:Biophysics 101/2007/Notebook:HRH/2007-2-8

Assigned on Feb 6, 2007

Script in progress:

import random
 * 1) !/usr/bin/env python
 * 1) Hetmann Hsieh
 * 2) Assignment 2
 * 3) 2/8/07

tally = [0 for i in range(11)]
 * 1) make a list of values for each


 * 1) Generate the random 10-mer of H's and T's

for i in range(10000): coinflip = ''.join([random.choice(['H','T']) for n in range (10)]) # Use this loop to tally up instances of each k-mer (from 2 to 10) for k in range(2,11): # store a k-mer of H's       H = ''.join(['H' for n in range(k)]) Hcount = 0 pos = coinflip.find(H,0) while not pos == -1: Hcount = Hcount + 1 pos = coinflip.find(H,pos+1)

# Update the tally for this k-mer tally[k] = tally[k] + Hcount

# Use this loop to tally up instances of each k-mer (from 2 to 10) for k in range(2,11): # store a k-mer of T's       Tcount = 0 T = ''.join(['T' for n in range(k)]) pos = coinflip.find(T,0) while not pos == -1: Tcount = Tcount + 1 pos = coinflip.find(T,pos+1)

# Update the tally for this k-mer tally[k] = tally[k] + Hcount

for i in range(2,11): print i, tally[i]
 * 1) print out the results

Output:

2 22791 3 10172 4 4412 5 1860 6 792 7 336 8 147 9 66 10 28