randomSeq-solution.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:FMAB 作者: BrendelGroup 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号