forked from kyclark/biofx_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution1_for_loop.py
More file actions
executable file
·64 lines (47 loc) · 1.38 KB
/
solution1_for_loop.py
File metadata and controls
executable file
·64 lines (47 loc) · 1.38 KB
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
58
59
60
61
62
63
64
#!/usr/bin/env python3
""" Reverse complement """
import argparse
import os
from typing import NamedTuple
class Args(NamedTuple):
""" Command-line arguments """
dna: str
# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """
parser = argparse.ArgumentParser(
description='Print the reverse complement of DNA',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('dna', metavar='DNA', help='Input sequence or file')
args = parser.parse_args()
if os.path.isfile(args.dna):
args.dna = open(args.dna).read().rstrip()
return Args(args.dna)
# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """
args = get_args()
revc = ''
for base in reversed(args.dna):
if base == 'A':
revc += 'T'
elif base == 'T':
revc += 'A'
elif base == 'G':
revc += 'C'
elif base == 'C':
revc += 'G'
elif base == 'a':
revc += 't'
elif base == 't':
revc += 'a'
elif base == 'g':
revc += 'c'
elif base == 'c':
revc += 'g'
else:
revc += base
print(revc)
# --------------------------------------------------
if __name__ == '__main__':
main()