Created
May 4, 2020 06:33
-
-
Save ferbass/82540c24f62cb0bd14c4ccd4607c86de to your computer and use it in GitHub Desktop.
Reverse complement of DNA strand using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alt_map = {'ins':'0'} | |
complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'} | |
def reverse_complement(seq): | |
for k,v in alt_map.iteritems(): | |
seq = seq.replace(k,v) | |
bases = list(seq) | |
bases = reversed([complement.get(base,base) for base in bases]) | |
bases = ''.join(bases) | |
for k,v in alt_map.iteritems(): | |
bases = bases.replace(v,k) | |
return bases | |
>>> seq = "TCGGinsGCCC" | |
>>> print "Reverse Complement:" | |
>>> print(reverse_complement(seq)) | |
GGGCinsCCGA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.bioinformatics.org/sms/rev_comp.html