annotate tools/mytools/collapseBed2.py @ 3:33c067c3ae34

Deleted selected files
author xuebing
date Fri, 09 Mar 2012 19:47:53 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 '''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 collapse intervals
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 '''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 def collapseInterval_strand(filename,c_strand,c_score):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 # keeping max column c
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 uniqintv = {}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 data = {}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 f = open(filename)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 header = f.readline()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 if 'chr' in header:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 flds = header.strip().split('\t')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 key = '\t'.join([flds[0],flds[1],flds[2],flds[c_strand]])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 uniqintv[key] = float(flds[c_score])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 data[key] = flds
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 for line in f:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 flds = line.strip().split('\t')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 key = '\t'.join([flds[0],flds[1],flds[2],flds[c_strand]])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 if not uniqintv.has_key(key):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 uniqintv[key] = float(flds[c_score])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 data[key] = flds
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 elif uniqintv[key] < float(flds[c_score]):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 uniqintv[key] = float(flds[c_score])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 data[key] = flds
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 f.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 for key in uniqintv.keys():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 print '\t'.join(data[key])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 import sys
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 if sys.argv[2] == '0':#ignore strand
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 sys.argv[2] = 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 if sys.argv[3] == '0':# ignore score
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 sys.argv[3] = 2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 collapseInterval_strand(sys.argv[1],int(sys.argv[2])-1,int(sys.argv[3])-1)