annotate tools/mytools/fimo2bed.py @ 1:cdcb0ce84a1b

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