-
Notifications
You must be signed in to change notification settings - Fork 1
/
coveredByBed
executable file
·53 lines (45 loc) · 1.55 KB
/
coveredByBed
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
#!/usr/bin/env python
from sys import *
import sys
from re import *
if len(argv)==1:
print " Will read bed features from stdin. (small)"
print " Will let pass features that are covered by some feature in the file."
print " (big). So small.start, small,stop have to be inside big.start,big.stop"
print " Make sure that the bed-FILE is much bigger than data from stdin."
print " than the features that come in from stdin. They are kept in memory."
print ""
print " SYNTAX: "
print " coveredByBed <bed-filename>"
exit()
# read features from stdin
lines = sys.stdin.readlines()
# remove header
while lines[0].startswith("track") or lines[0].startswith("browser"):
lines.pop(0)
# parse faturespositions, keep everthing
features = []
for line in lines:
line = line.strip()
fields = line.split(" ", 3)
# [0] = seqname, [1] = startpos, [2] = endpos, [3] = rest crap
features.append([fields[0], int(fields[1]), int(fields[2]), fields[3]])
del lines
#print features
#read bigfile
f = open(argv[1], 'r')
line = f.readline()
while line!="":
if not line.startswith("#") and not line.startswith("track"):
fields = line.split()
seq = fields[0]
start = int(fields[1])
stop = int(fields[2])
for i in reversed(range(0, len(features))):
#print i
#print "fields"+ str(fields)
#print "feautres" + str(features[i])
if features[i][0]==seq and start <= features[i][1] and features[i][2] <= stop:
print features[i][0], features[i][1], features[i][2], features[i][3]
del features[i]
line = f.readline()