[英]Find all permutations of a string that is variable only at specific positions in Python
I have a DNA sequence which is variable only at specific locations and need to find all possible scenarios:我有一个仅在特定位置可变的 DNA 序列,需要找到所有可能的情况:
DNA_seq='ANGK' #N can be T or C and K can be A or G
N=['T','C']
K=['A','G']
Results:结果:
['ATGA','ATGG','ACGA','ACGG']
Searching online, It seems permutations
method from itertools
can be used for this purpose but not sure how it can be implemented.在线搜索,似乎
itertools
的permutations
方法可以用于此目的,但不确定如何实现。 I would appreciate any help.我将不胜感激任何帮助。
Use itertools.product
:使用
itertools.product
:
from itertools import product
result = [f'A{n}G{k}' for n, k in product(N, K)]
Result:结果:
['ATGA', 'ATGG', 'ACGA', 'ACGG']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.