samedi 4 avril 2015

How to create multiple random sequences in python?

I'm trying to make 200 random DNA sequences, and I can't figure out how to make 200 of them! Here's what I have so far:



from random import random

def randABCD(n, probA, probT, probC, probG):
# where probA + probT + probC + probG == 1
# n = number of characters in string
# pX = probability of the character
cA = probA
cT = cA + probT
cC = cT + probC
def choose():
r = random()
if r < cA:
return 'A'
elif r < cT:
return 'T'
elif r < cC:
return 'C'
else:
return 'G'
return ''.join([choose() for i in xrange(n)])




Aucun commentaire:

Enregistrer un commentaire