def gen_sequence(comp, length) :
seq_string = ''
##### Part 3 : Your random sequence generating code goes here
# Assertion is advised
assert abs( sum(comp.values())-1 ) < 0.01 , 'Probabilities do not add up to 1.'
# We generate a sequence of given length
for i in range(length) :
# Get a random number in [0,1)
dice = random()
limit=0
# We divide [0,1) interval according to probabilities of each nucleotide
for nuc in comp :
limit += comp[nuc]
# We add the letter that dice hits
if dice<limit :
seq_string += nuc
limit = 0
# Roll another dice for the next nucleotide
break
#####
sequence = Seq(seq_string)
return SeqRecord(sequence, id='Random Sequence', description=comp.__repr__())
##### ALL MODIFICATIONS GO ABOVE THIS LINE #####
### Part 0 : Argument Parsing
### We want out program to have easy-to-use parameters
### We are using the argparse library for this
评论列表
文章目录