-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetIGSfromGFF
More file actions
executable file
·82 lines (61 loc) · 1.85 KB
/
Copy pathgetIGSfromGFF
File metadata and controls
executable file
·82 lines (61 loc) · 1.85 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/pypy
import sys
import os
import re
from Bio import SeqIO
if len(sys.argv) < 3:
print('USAGE: getIGS GBK GFF')
sys.exit(65)
# rRNA magic regex
regex = '(.*)16[sS]|(.*)23[sS]'
prog = re.compile(regex)
print('Using /%s/ regex search'%regex)
print('')
gbk = sys.argv[1]
gff = sys.argv[2]
# Parsing the gff
print('Reading %s'%gff)
d = {}
for l in open(gff):
if l.lstrip().startswith('#'):
continue
s = l.strip().split('\t')
d[s[0]] = d.get(s[0], [])
d[s[0]].append( (int(s[3]), int(s[4]), s[6], s[8]) )
print('Reading %s'%gbk)
print('')
i = 0
rseqs = []
org = gbk.split('.')[0]
for s in SeqIO.parse(gbk, 'genbank'):
if s.id not in d:continue
rRNA = sorted(d[s.id], key=lambda x: x[0])
for f, f1 in zip(rRNA, rRNA[1:]):
# Are we between 16s and 23s?
if not prog.match(f[3]) or not prog.match(f1[3]):
continue
#print f.qualifiers['product'][0], f1.qualifiers['product'][0]
# We suppose they should be in the same strand, right?
if f[2] != f1[2]:
continue
# Check that the two features are not so distant from each other
dist = f1[0] - f[1]
if dist > 30000:
print('Suspicious long IGS (%d)'%(dist))
i += 1
rid = '%s_%d'%(org, i)
rseq = s[f[1]+1 : f1[0]-1]
if f[2] == '-':
rseq = rseq.reverse_complement()
rseq.description = '(%s, %d, %d, -)'%(s.id,
f[1]+1, f1[0]-1)
else:
rseq.description = '(%s, %d, %d, +)'%(s.id,
f[1]+1, f1[0]-1)
rseq.id = rid
rseqs.append(rseq)
if len(rseqs) == 0:
print ('No IGS found for %s'%org)
else:
print('Found %d IGS in %s'%(len(rseqs), org))
SeqIO.write(rseqs, '%s.rna.fna'%org, 'fasta')