Created
November 7, 2011 02:24
-
-
Save mahmoudhossam/1344064 to your computer and use it in GitHub Desktop.
Finds a DNA sequence complement
This file contains hidden or 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
#!/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