-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse-complement.py
More file actions
51 lines (37 loc) · 1.08 KB
/
reverse-complement.py
File metadata and controls
51 lines (37 loc) · 1.08 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
'''
NAME
reverse-complement.py
VERSION
1.0
AUTHOR
Hely Salgado, Mich Mourra
DESCRIPTION
Make the reverse complement of DNA sequence
CATEGORY
Genomic Sequence
USAGE
% python reverse-complement.py -i filename
example
% python reverse-complement -i sequence.txt
'''
import argparse
# program arguments
parser = argparse.ArgumentParser(description="Make the reverse complement of DNA sequence")
parser.add_argument(
"-i", "--input",
help="genomic sequence file in raw or fastA format",
required=True)
args = vars(parser.parse_args())
# Getting the dna sequence from the file
with open(args['input'],'r') as readFile:
sequence = "";
for line in readFile:
# Ignore comments or FastA head line
if line.startswith('#') or line.startswith('>'):
continue
else:
sequence += line.strip()
sequence = sequence.upper()
# Dictionary containing the complement equivalents
sequence = sequence[::-1].translate(str.maketrans({'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}))
print ('{}'.format(sequence))