annotate fimo_to_bed.py @ 1:e84f946fd52c default tip

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