文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>构建DNA,RNA或PROTEIN随机序列

构建DNA,RNA或PROTEIN随机序列

时间:2009-04-04  来源:blackjimmy

利用python的random模块,随机生成DNA,RNA或PROTEIN序列,长度为20.    

# generate random sequences
# type: DNA, RNA, PROTEIN
# length is length

import random
def randomseq(type='DNA',length=20):
    seq = ''
    for i in xrange(length):
        if type == 'DNA':
            dicts = list('ATCG')
            seq += dicts[random.randrange(4)]
        if type == 'RNA':
            dicts = list('AUCG')
            seq += dicts[random.randrange(4)]
        if type == 'PROTEIN':
            dicts = list('ACDEFGHIKLMNPQRSTVWY')
            seq += dicts[random.randrange(4)]
    return seq

# another choice
def randomseq2(type='DNA',length=20):
    seq = []
    for i in xrange(length):
        if type == 'DNA':
            dicts = list('ATCG')
            seq.append(dicts[random.randrange(4)])
        if type == 'RNA':
            dicts = list('AUCG')
            seq.append(dicts[random.randrange(4)])
        if type == 'PROTEIN':
            dicts = list('ACDEFGHIKLMNPQRSTVWY')
            seq.append(dicts[random.randrange(4)])
    return ''.join(seq)
        

if __name__ == '__main__':
    print 'RNA: ',randomseq('RNA',20)
    print 'RNA: ',randomseq2('RNA',20)
    print 'DNA: ',randomseq2('DNA',20)
    print 'PROTEIN: ',randomseq('PROTEIN',20)

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载