-
Notifications
You must be signed in to change notification settings - Fork 0
/
join_bg.py
executable file
·28 lines (24 loc) · 963 Bytes
/
join_bg.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
#!/usr/bin/env python
import sys
inp_files = sys.argv[1:]
for bg in inp_files:
out = bg.replace('.bg', '.gtf')
with open(out, 'w') as ofile:
with open(bg, 'r') as ifile:
starting = None
ending = None
for line in ifile:
content = line.split()
stoffset = int(content[1])
endoffset = int(content[2])
if starting is None:
starting = stoffset
ending = endoffset
if stoffset == ending or stoffset == ending + 1:
ending = endoffset
continue
if stoffset != ending or stoffset != ending + 1:
ofile.write('\t'.join([content[0], str(starting), str(ending)])+ '\n')
starting = stoffset
ending = endoffset
ofile.write('\t'.join([content[0], str(starting), str(ending)]))