-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgffSubsetLTRdigest.py
executable file
·52 lines (46 loc) · 1.41 KB
/
gffSubsetLTRdigest.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
#!/usr/bin/env python3
import sys
from gff3line import GFF3_line
def help():
print('''
Usage:
------------
gffSubset -list <path> -gff <path>
Description:
------------
Takes a list of LTR_retrotransposon IDs and a GFF3 file and outputs
feature blocks for the elements in the list. Assumes the GFF3 is
properly sorted with parent-child relationships preserved.
''', file=sys.stderr)
sys.exit(0)
args = sys.argv
# output help information if missing command line arguments
if ('-list' not in args
or '-gff' not in args
or len(args) < 5):
help()
# read command line arguments
gff = args[args.index('-gff') + 1]
lst = args[args.index('-list') + 1]
# read list contents into a set
lstSet = set()
with open(lst) as fl:
for line in fl:
lstSet.add(line.strip().lstrip('LTR_retrotransposon'))
# read gff lines and output lines belonging to each block whose
# repeat_region feature number is in lstSet
with open(gff) as fl:
output = None
for line in fl:
# skip commented lines
if line.startswith('#'):
continue
GFF = GFF3_line(line)
if GFF.type == 'repeat_region':
output = False
if GFF.attributes['ID'].lstrip('repeat_region') in lstSet:
output = True
print('###')
print(line.strip())
elif output == True:
print(line.strip())