Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created November 7, 2011 02:24
Show Gist options
  • Save mahmoudhossam/1344064 to your computer and use it in GitHub Desktop.
Save mahmoudhossam/1344064 to your computer and use it in GitHub Desktop.
Finds a DNA sequence complement
#!/usr/bin/python2
"""
A DNA sequence is a string made up of the letters A, T, G, and C.
To find the complement of a DNA sequence, As are replaced by Ts,
Ts by As, Gs by Cs, and Cs by Gs. For example, the complement
of AATTGCCGT is TTAACGGCA.
This function finds the complement.
"""
from UserString import MutableString
from sys import argv
def complement(seq):
result = MutableString(seq)
for i in range(len(result)):
if result[i] == 'A':
result[i] = 'T'
elif result[i] == 'T':
result[i] = 'A'
elif result[i] == 'G':
result[i] = 'C'
elif result[i] == 'C':
result[i] = 'G'
return result
def main():
print repr(complement(argv[1]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment