annotate collapseBed2.py @ 11:b7f1d9f8f3bc

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