annotate mytools/fimo2bed.py @ 9:8cec2078632a

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