annotate mytools/fimo2bed.py @ 7:f0dc65e7f6c0

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:59:07 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
1 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
2 #pattern name sequence name start stop score p-value q-value matched sequence
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
3 constitutive-donor mm9_chr1_39533592_39535592_- 1815 1823 12.032 4.26e-06 0.397 CAGGTAAGT
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
4 constitutive-donor mm9_chr1_59313750_59315750_+ 1889 1897 12.032 4.26e-06 0.397 CAGGTAAGT
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
5
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
6 #pattern name sequence name start stop score p-value q-value matched sequence
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
7 constitutive-donor mm9_chr1_172019075_172021075_- 1947 1955 12.032 4.26e-06 0.843 CAGGTAAGT
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
8 constitutive-donor mm9_chr1_15300532_15302532_+ 156 164 12.032 4.26e-06 0.843 CAGGTAAGT
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
9 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
10
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
11 import sys
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
12
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
13 def fimo2bed(filename,rc):
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
14 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
15 parse fimo output to make a bed file
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
16 rc: the sequence have been reverse complemented
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
17 '''
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
18 f = open(filename)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
19 header = f.readline()
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
20 for line in f:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
21 pattern,posi,begin,stop,score,pv,qv,seq = line.strip().split('\t')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
22 flds = posi.split('_')
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
23 start = flds[-3]
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
24 end = flds[-2]
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
25 strand = flds[-1]
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
26 chrom = '_'.join(flds[1:-3]) #'chrX_random'
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
27 if not rc:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
28 if strand == '+':
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
29 start1 = str(int(start) + int(begin)-1)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
30 end1 = str(int(start) + int(stop))
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
31 print '\t'.join([chrom,start1,end1,seq,score,strand])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
32 else:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
33 start1 = str(int(end) - int(stop))
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
34 end1 = str(int(end) - int(begin)+1)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
35 print '\t'.join([chrom,start1,end1,seq,score,strand])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
36 else:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
37 if strand == '-':
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
38 start1 = str(int(start) + int(begin)-1)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
39 end1 = str(int(start) + int(stop))
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
40 print '\t'.join([chrom,start1,end1,seq,score,'+'])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
41 else:
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
42 start1 = str(int(end) - int(stop))
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
43 end1 = str(int(end) - int(begin)+1)
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
44 print '\t'.join([chrom,start1,end1,seq,score,'-'])
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
45
f0dc65e7f6c0 Uploaded
xuebing
parents:
diff changeset
46 fimo2bed(sys.argv[1],sys.argv[2]=='rc')