annotate getIndelRates_3way.py @ 0:02e619ae15dc draft default tip

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