import random
def getRandomSeq(seq_len):
random_seq = ""
for i in range(seq_len):
random_int = random.randint(1,4)
if random_int == 1:
nucleotide = "A"
if random_int == 2:
nucleotide = "C"
if random_int == 3:
nucleotide = "G"
if random_int == 4:
nucleotide = "T"
random_seq = random_seq + nucleotide
return random_seq
def mutateBase(base):
random_int = random.randint(1,4)
if random_int == 1:
nucleotide = "A"
if random_int == 2:
nucleotide = "C"
if random_int == 3:
nucleotide = "G"
if random_int == 4:
nucleotide = "T"
#Don't change a base to itself.
if nucleotide == base:
return mutateBase(base) #Fancy recursive loop.
else:
return nucleotide
print(mutateBase('A'))
#seed = 2
#random.seed(seed)
print(getRandomSeq(10))
random_seq = ""
for i in range(10):
random_seq += random.choice(["A","T","G","C"])
print(random_seq)
random_seq_lst = random.choices(["A","T","G","C"], k=10)
separator = '' # 定义分隔符
random_seq = separator.join(random_seq_lst)
#random_seq = ''.join(random_seq_lst)
print(random_seq)
python生成随机DNA序列代码
最新推荐文章于 2024-06-12 14:42:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)