简体   繁体   中英

Python Iterate through characters

I have been trying to pull of median string search for a sequence in the ACGT genome. The problem I have is going to say AAAAAAAA to AAAAAAAC and so forth until I have tried every possible combination.

I've been essentially going brute force at it by creating two lists, one containg A,C,G,T and the other the 8 character sequence, and after each search iterating and swapping characters. The problem is that I don't test all combinations because when two iterate at the same time it jumps a letter.

Is there any way to go AAAAAAAA - AAAAAAAC - AAAAAAAG - AAAAAAAT - AAAAAACA and so forth easily?

使用itertools

itertools.product("ACGT", repeat=8)

如上所述使用itertools,

itertools.product("ACGT", repeat=8) # will work in your case.

Using the regex inverter from the pyparsing wiki Examples page, invert this regex: [ACGT]{8} . You can also try the online inverter at the UtilityMill , but this server will timeout when generating 8-character strings, but I have successfully gotten up to 6 characters within the allowed time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM