- 论坛徽章:
- 0
|
利用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)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/33851/showart_1890307.html |
|