annotate tools/regVariation/getIndelRates_3way.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 #Guruprasad Ananda
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 from galaxy import eggs
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 import pkg_resources
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 pkg_resources.require( "bx-python" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 import sys, os, tempfile
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 import traceback
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 import fileinput
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 from warnings import warn
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 from galaxy.tools.util.galaxyops import *
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 from bx.intervals.io import *
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 from bx.intervals.operations import quicksect
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 def stop_err(msg):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 sys.stderr.write(msg)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 sys.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 def counter(node, start, end, sort_col):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 global full, blk_len, blk_list
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 if node.start < start:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 if node.right:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 counter(node.right, start, end, sort_col)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 elif start <= node.start <= end and start <= node.end <= end:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 full += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 if node.other[0] not in blk_list:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 blk_list.append(node.other[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 blk_len += int(node.other[sort_col+2])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 if node.left and node.left.maxend > start:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 counter(node.left, start, end, sort_col)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 if node.right:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 counter(node.right, start, end, sort_col)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 elif node.start > end:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 if node.left:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 counter(node.left, start, end, sort_col)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 infile = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 fout = open(sys.argv[2],'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 int_file = sys.argv[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 if int_file != "None": #User has specified an interval file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 fint = open(int_file, 'r')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 dbkey_i = sys.argv[4]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 chr_col_i, start_col_i, end_col_i, strand_col_i = parse_cols_arg( sys.argv[5] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 stop_err("Unable to open input Interval file")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 def main():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 for i, line in enumerate( file ( infile )):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 line = line.rstrip('\r\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 if len( line )>0 and not line.startswith( '#' ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 elems = line.split( '\t' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 if i == 30:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 break # Hopefully we'll never get here...
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62 if len( elems ) != 18:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 stop_err( "This tool only works on tabular data output by 'Fetch Indels from 3-way alignments' tool. The data in your input dataset is either missing or not formatted properly." )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 for i, line in enumerate( file ( infile )):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66 line = line.rstrip('\r\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 elems = line.split('\t')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 assert int(elems[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70 assert len(elems) == 18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 if int_file != "None":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72 if dbkey_i not in elems[3] and dbkey_i not in elems[8] and dbkey_i not in elems[13]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 stop_err("The species build corresponding to your interval file is not present in the Indel file.")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 if dbkey_i in elems[3]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75 sort_col = 4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 elif dbkey_i in elems[8]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 sort_col = 9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78 elif dbkey_i in elems[13]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79 sort_col = 14
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
80 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
81 species = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
82 species.append( elems[3].split('.')[0] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
83 species.append( elems[8].split('.')[0] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
84 species.append( elems[13].split('.')[0] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
85 sort_col = 0 #Based on block numbers
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
86 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
87 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
88 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
89
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
90
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
91 fin = open(infile, 'r')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
92 skipped = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
93
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
94 if int_file == "None":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
95 sorted_infile = tempfile.NamedTemporaryFile()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
96 cmdline = "sort -n -k"+str(1)+" -o "+sorted_infile.name+" "+infile
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
97 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
98 os.system(cmdline)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
99 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
100 stop_err("Encountered error while sorting the input file.")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
101 print >>fout, "#Block\t%s_InsRate\t%s_InsRate\t%s_InsRate\t%s_DelRate\t%s_DelRate\t%s_DelRate" %(species[0],species[1],species[2],species[0],species[1],species[2])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
102 prev_bnum = -1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
103 sorted_infile.seek(0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
104 for line in sorted_infile.readlines():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
105 line = line.rstrip('\r\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
106 elems = line.split('\t')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
107 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
108 assert int(elems[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
109 assert len(elems) == 18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
110 new_bnum = int(elems[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
111 if new_bnum != prev_bnum:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
112 if prev_bnum != -1:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
113 irate = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
114 drate = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
115 for i,elem in enumerate(inserts):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
116 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
117 irate.append(str("%.2e" %(inserts[i]/blen[i])))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
118 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
119 irate.append('0')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
120 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
121 drate.append(str("%.2e" %(deletes[i]/blen[i])))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
122 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
123 drate.append('0')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
124 print >>fout, "%s\t%s\t%s" %(prev_bnum, '\t'.join(irate) , '\t'.join(drate))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
125 inserts = [0.0, 0.0, 0.0]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
126 deletes = [0.0, 0.0, 0.0]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
127 blen = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
128 blen.append( int(elems[6]) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
129 blen.append( int(elems[11]) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
130 blen.append( int(elems[16]) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
131 line_sp = elems[1].split('.')[0]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
132 sp_ind = species.index(line_sp)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
133 if elems[1].endswith('insert'):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
134 inserts[sp_ind] += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
135 elif elems[1].endswith('delete'):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
136 deletes[sp_ind] += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
137 prev_bnum = new_bnum
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
138 except Exception, ei:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
139 #print >>sys.stderr, ei
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
140 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
141 irate = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
142 drate = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
143 for i,elem in enumerate(inserts):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
144 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
145 irate.append(str("%.2e" %(inserts[i]/blen[i])))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
146 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
147 irate.append('0')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
148 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
149 drate.append(str("%.2e" %(deletes[i]/blen[i])))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
150 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
151 drate.append('0')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
152 print >>fout, "%s\t%s\t%s" %(prev_bnum, '\t'.join(irate) , '\t'.join(drate))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
153 sys.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
154
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
155
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
156 inf = open(infile, 'r')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
157 start_met = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
158 end_met = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
159 sp_file = tempfile.NamedTemporaryFile()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
160 for n, line in enumerate(inf):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
161 line = line.rstrip('\r\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
162 elems = line.split('\t')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
163 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
164 assert int(elems[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
165 assert len(elems) == 18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
166 if dbkey_i not in elems[1]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
167 if not(start_met):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
168 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
169 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
170 sp_end = n
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
171 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
172 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
173 print >>sp_file, line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
174 if not(start_met):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
175 start_met = True
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
176 sp_start = n
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
177 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
178 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
179
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
180 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
181 assert sp_end
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
182 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
183 sp_end = n+1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
184
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
185 sp_file.seek(0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
186 win = NiceReaderWrapper( fileinput.FileInput( int_file ),
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
187 chrom_col=chr_col_i,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
188 start_col=start_col_i,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
189 end_col=end_col_i,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
190 strand_col=strand_col_i,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
191 fix_strand=True)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
192
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
193 indel = NiceReaderWrapper( fileinput.FileInput( sp_file.name ),
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
194 chrom_col=1,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
195 start_col=sort_col,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
196 end_col=sort_col+1,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
197 strand_col=-1,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
198 fix_strand=True)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
199
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
200 indelTree = quicksect.IntervalTree()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
201 for item in indel:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
202 if type( item ) is GenomicInterval:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
203 indelTree.insert( item, indel.linenum, item.fields )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
204 result=[]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
205
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
206 global full, blk_len, blk_list
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
207 for interval in win:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
208 if type( interval ) is Header:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
209 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
210 if type( interval ) is Comment:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
211 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
212 elif type( interval ) == GenomicInterval:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
213 chrom = interval.chrom
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
214 start = int(interval.start)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
215 end = int(interval.end)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
216 if start > end:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
217 warn( "Interval start after end!" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
218 ins_chr = "%s.%s_insert" %(dbkey_i,chrom)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
219 del_chr = "%s.%s_delete" %(dbkey_i,chrom)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
220 irate = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
221 drate = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
222 if ins_chr not in indelTree.chroms and del_chr not in indelTree.chroms:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
223 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
224 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
225 if ins_chr in indelTree.chroms:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
226 full = 0.0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
227 blk_len = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
228 blk_list = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
229 root = indelTree.chroms[ins_chr] #root node for the chrom insertion tree
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
230 counter(root, start, end, sort_col)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
231 if blk_len:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
232 irate = full/blk_len
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
233
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
234 if del_chr in indelTree.chroms:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
235 full = 0.0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
236 blk_len = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
237 blk_list = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
238 root = indelTree.chroms[del_chr] #root node for the chrom insertion tree
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
239 counter(root, start, end, sort_col)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
240 if blk_len:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
241 drate = full/blk_len
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
242
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
243 interval.fields.append(str("%.2e" %irate))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
244 interval.fields.append(str("%.2e" %drate))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
245 print >>fout, "\t".join(interval.fields)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
246 fout.flush()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
247
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
248 if __name__ == "__main__":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
249 main()