Harvard:Biophysics 101/2007/02/08: Difference between revisions
From OpenWetWare
Jump to navigationJump to search
ShawnDouglas (talk | contribs) (coinflip.py) |
(No difference)
|
Revision as of 10:27, 8 February 2007
Solution to Feb 6 Assignment
- Here's an example
#!/usr/bin/env python import random # create a list to store our results tally = [0 for i in range(11)] for i in range(10000): # generate a random 10-mer coinflip = ''.join([random.choice('HT') for j in range(10)]) # tally k-mers in the 10-mer for k in range(2,11): Hcount = Tcount = 0 H = ''.join(['H' for n in range(k)]) # k-mer of H's pos = coinflip.find(H,0) while not pos == -1: Hcount = Hcount + 1 pos = coinflip.find(H,pos+1) T = ''.join(['T' for n in range(k)]) # k-mer of T's pos = coinflip.find(T,0) while not pos == -1: Tcount = Tcount + 1 pos = coinflip.find(T,pos+1) tally[k] = tally[k] + Hcount + Tcount for i in range(2,11): print '%2s: %5d' % (i, tally[i]) # print the results