Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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_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. I would appreciate any help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use itertools.product:

from itertools import product
result = [f'A{n}G{k}' for n, k in product(N, K)]

Result:

['ATGA', 'ATGG', 'ACGA', 'ACGG']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading