/
BioInf00.py
58 lines (41 loc) · 1.41 KB
/
BioInf00.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python3
import os, sys, re
def reverse(seq):
"""Return the sequence string in reverse order."""
# make a list of letters from string
seq = list(seq.upper())
# reverse the list
seq = reversed(seq)
# join the letters of the list into string and return
return ''.join(seq)
def complement(seq):
"""Return the complementary sequence string."""
# dictionary setup for complement
subst = {'A': 'T', 'T': 'A', 'G':'C', 'C':'G'}
# make a list of letters from string
seq = list(seq.upper())
# for loop of the letters and call the base_complementary dictionary
compl_str = []
for i in range(len(seq)):
compl_str.append(subst[seq[i]])
# join the letters of the list into string and return
return ''.join(compl_str)
def main():
# get input sequence
dna_seq = input('Type your DNA sequence : ')
# check DNA letter (only ACGTacgt)
for i in range(len(dna_seq)):
if dna_seq[i].upper() not in ['A', 'T', 'C', 'G']:
print("Character: " + dna_seq[i] + ' not in DNA Alphabet')
sys.exit()
# change it to upper case
# call reverse function
dna_seq = reverse(dna_seq)
# call complement function
dna_seq = complement(dna_seq)
# print output
print("Reverse complement DNA :", dna_seq)
# exit the program
sys.exit()
if __name__ == '__main__':
main()