-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_position_from_genbank.py
33 lines (24 loc) · 1.61 KB
/
extract_position_from_genbank.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
import sys
from Bio import SeqIO
from argparse import (ArgumentParser, FileType)
def parse_args():
"Parse the input arguments, use '-h' for help"
commands = ArgumentParser(description='Detect phage, repeat and variation regions in genome using a genbank file.')
commands.add_argument('--genbank', type=str, required=True,
help='Genome in Genbank format (Required).')
return commands.parse_args()
args = parse_args()
key1 = 'bacteriophage'
key2 = 'phage'
for rec in SeqIO.parse(open(args.genbank,"r"), 'genbank'):
feat = len(rec.features)
for x in range(0, feat):
if rec.features[x].type == 'repeat_region' or rec.features[x].type == 'variation':
print str(rec.features[x].location).replace(':',',').replace('[','').replace('](+)','').replace('](-)','') +'\t'+str(rec.features[x].type)
if (rec.features[x].type == 'CDS'):
try:
if ((key1 in str(rec.features[x].qualifiers['product'])) or (key1 in str(rec.features[x].qualifiers['note'])) or (key2 in str(rec.features[x].qualifiers['product'])) or (key2 in str(rec.features[x].qualifiers['note']))):
print str(rec.features[x].location).replace(':',',').replace('[','').replace('](+)','').replace('](-)','')+'\t'+str(rec.features[x].type)+'\t'+str(rec.features[x].qualifiers['product'])+'\t'+str(rec.features[x].qualifiers['note'])
except KeyError:
if ((key1 in str(rec.features[x].qualifiers['product'])) or (key2 in str(rec.features[x].qualifiers['product']))):
print str(rec.features[x].location).replace(':',',').replace('[','').replace('](+)','').replace('](-)','')+'\t'+str(rec.features[x].type)+'\t'+str(rec.features[x].qualifiers['product'])