forked from mtarbit/Rosalind-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e003-revc.py
executable file
·40 lines (30 loc) · 1.69 KB
/
e003-revc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# Reverse Complement
# ==================
#
# In a DNA string, the complement of A is T, and the complement of C is G.
#
# The reverse complement of a DNA string s is the string sc formed by reversing
# the symbols of s, then taking the complement of each symbol (e.g., the reverse
# complement of GTCA is TGAC).
#
# Given: A DNA string s of length at most 1000 bp.
#
# Return: The reverse complement of s.
#
# Sample Dataset
# --------------
# AAAACCCGGT
#
# Sample Output
# -------------
# ACCGGGTTTT
def reverse_complement(s):
complements = {'A':'T', 'C':'G', 'T':'A', 'G':'C'}
sc = reversed(s)
sc = [complements[c] for c in sc]
return ''.join(sc)
if __name__ == "__main__":
small_dataset = "AAAACCCGGT"
large_dataset = "GGTTGTCTTCACGACAACACCGCGCTGGCCAAGGTATTAAATAGGCGCATCACTGCTTCTCCCATGACATTGAAAAGGTTAACTTCCCCCATCCAACGTCAGTCTCCATTCTTTCAGTCGGGGGCAAATATGACCGGAGTTAAAGGACTCGAGCTATTGCAGAGCCACGGACGAGAGCAATTCACCAGAGCATAGCAAAAGTGCCGGCCGGCCTACGACCCGGAGACCGTGAAGTTGCGTCCCATTGCTGTTGCATTACAACCGCTCGCGAACGCATCAGTTGGTATATATATCTAAAAGCGTGGCGTGGCCTTGGTACTATTCGGAGAGATCCTAGTTATGCATGAGCAAGCTCGCCGTACGGGTCTGCCACGGTGGAGTTGAGTTTGTAGGCGATAGCCTAGCCGACGGGCTGACTGCGCCAAGAGACTTTCTCCTGATTGAGCTTATGATTGAAAGGCAACGACACAATCATATCGCCGGCGAGTAGACGTCTACTAAAGTTACAGTATTATTTAGCGGCTGAGGAGTTCACACCCTGTCCCAGGTGCGGACAATACTGCTATCTAGGGGCACATGGGTGATGGCATCGGACCGTATTGGATGGGAGGAAATTGGTTCCTTTAGACTAAAGGGTCGTTTCAGCGACAAATATTCAACGTCCCTCTTTTCGGATTTCATTTGCTCATGCAGATCGTGACTACTTACCTGCGACCCGGTAGACATGTGAAGGCTGTTTGTCTAATATCCTTGCATGAGGGTCGACGTATATTGGTCTACCAGGTTCAAGACAGCGGACTATGTATAATCTTCTGGTGTTCCATTAACTCACCCTCAGACCCGACGAAATCCAGCCAACCCTGGGAACTGATATCCCCACAAAATTTCTC"
print reverse_complement(large_dataset)