-
Notifications
You must be signed in to change notification settings - Fork 16
/
filter.py
executable file
·39 lines (35 loc) · 1.2 KB
/
filter.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
#!/usr/bin/env python
import csv
import argparse
import sys
parser = argparse.ArgumentParser(description="Take a sorted list of clusters and filter them such that the output contains only cluster bounds of clusters with more than one member.")
parser.add_argument("ifile", metavar="Input", help="Input BED file")
parser.add_argument("type", metavar="Repeat type", help="Repeat type label")
parser.add_argument("ofile", metavar="Output", help="Output BED file")
args = parser.parse_args()
if(args.ifile == None or args.ofile == None or args.type==None) :
parser.print_help()
sys.exit()
of = open(args.ofile, "w")
lastID = None
lastChr = None
lastStart = None
lastStop = None
lastCount = 0
for line in csv.reader(open(args.ifile, "r"), dialect="excel-tab") :
if(line[3] != args.type) :
continue
if(line[4] == lastID) :
lastCount += 1
lastStop = line[2]
else :
if(lastCount > 1) :
of.write("%s\t%s\t%s\n" % (lastChr, lastStart, lastStop))
lastChr = line[0]
lastStart = line[1]
lastStop = line[2]
lastID = line[4]
lastCount = 1
if(lastCount > 1) :
of.write("%s\t%s\t%s\n" % (lastChr, lastStart, lastStop))
of.close()