Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ferbass
Created May 4, 2020 06:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferbass/82540c24f62cb0bd14c4ccd4607c86de to your computer and use it in GitHub Desktop.
Save ferbass/82540c24f62cb0bd14c4ccd4607c86de to your computer and use it in GitHub Desktop.
Reverse complement of DNA strand using Python
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
@ferbass
Copy link
Author

ferbass commented May 4, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment