# 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)
|