更新时间:2022-06-25 20:39:18
对于问题的第一部分,将a
作为列表传递:
For the first part of your question, pass a
as a list:
def random_dna_sequence(length):
return ''.join(np.random.choice(list('ACTG')) for _ in range(length))
或将您的碱基定义为列表或元组:
Or define your bases as a list or tuple:
BASES = ('A', 'C', 'T', 'G')
def random_dna_sequence(length):
return ''.join(np.random.choice(BASES) for _ in range(length))
第二部分有一个类似的解决方案:将概率作为列表或元组传递:
The second part has a similar solution: pass the probabilities as a list or tuple:
BASES = ('A', 'C', 'T', 'G')
P = (0.2, 0.2, 0.3, 0.3)
def random_dna_sequence(length):
return ''.join(np.random.choice(BASES, p=P) for _ in range(length))