annotate tools/stats/aggregate_scores_in_intervals.py @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -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 #!/usr/bin/env python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 # Greg Von Kuster
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 usage: %prog score_file interval_file chrom start stop [out_file] [options]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 -b, --binned: 'score_file' is actually a directory of binned array files
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 -m, --mask=FILE: bed file containing regions not to consider valid
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 -c, --chrom_buffer=INT: number of chromosomes (default is 3) to keep in memory when using a user supplied score file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 from __future__ import division
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 from galaxy import eggs
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 import pkg_resources
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 pkg_resources.require( "bx-python" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 pkg_resources.require( "lrucache" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 pkg_resources.require( "python-lzo" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 import psyco_full
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 import sys
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 import os, os.path
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 from UserDict import DictMixin
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 import bx.wiggle
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 from bx.binned_array import BinnedArray, FileBinnedArray
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 from bx.bitset import *
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 from bx.bitset_builders import *
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 from fpconst import isNaN
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 from bx.cookbook import doc_optparse
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 from galaxy.tools.exception_handling import *
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 assert sys.version_info[:2] >= ( 2, 4 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 import tempfile, struct
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 class PositionalScoresOnDisk:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 fmt = 'f'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 fmt_size = struct.calcsize( fmt )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 default_value = float( 'nan' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 def __init__( self ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 self.file = tempfile.TemporaryFile( 'w+b' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 self.length = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 def __getitem__( self, i ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 if i < 0: i = self.length + i
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 if i < 0 or i >= self.length: return self.default_value
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 self.file.seek( i * self.fmt_size )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 return struct.unpack( self.fmt, self.file.read( self.fmt_size ) )[0]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 except Exception, e:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 raise IndexError, e
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 def __setitem__( self, i, value ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 if i < 0: i = self.length + i
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 if i < 0: raise IndexError, 'Negative assignment index out of range'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 if i >= self.length:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 self.file.seek( self.length * self.fmt_size )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 self.file.write( struct.pack( self.fmt, self.default_value ) * ( i - self.length ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 self.length = i + 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 self.file.seek( i * self.fmt_size )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 self.file.write( struct.pack( self.fmt, value ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 def __len__( self ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 return self.length
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62 def __repr__( self ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 i = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64 repr = "[ "
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 for i in xrange( self.length ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66 repr = "%s %s," % ( repr, self[i] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 return "%s ]" % ( repr )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 class FileBinnedArrayDir( DictMixin ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 Adapter that makes a directory of FileBinnedArray files look like
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72 a regular dict of BinnedArray objects.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 def __init__( self, dir ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75 self.dir = dir
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 self.cache = dict()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 def __getitem__( self, key ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78 value = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79 if key in self.cache:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
80 value = self.cache[key]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
81 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
82 fname = os.path.join( self.dir, "%s.ba" % key )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
83 if os.path.exists( fname ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
84 value = FileBinnedArray( open( fname ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
85 self.cache[key] = value
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
86 if value is None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
87 raise KeyError( "File does not exist: " + fname )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
88 return value
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
89
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
90 def stop_err(msg):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
91 sys.stderr.write(msg)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
92 sys.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
93
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
94 def load_scores_wiggle( fname, chrom_buffer_size = 3 ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
95 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
96 Read a wiggle file and return a dict of BinnedArray objects keyed
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
97 by chromosome.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
98 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
99 scores_by_chrom = dict()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
100 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
101 for chrom, pos, val in bx.wiggle.Reader( UCSCOutWrapper( open( fname ) ) ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
102 if chrom not in scores_by_chrom:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
103 if chrom_buffer_size:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
104 scores_by_chrom[chrom] = BinnedArray()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
105 chrom_buffer_size -= 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
106 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
107 scores_by_chrom[chrom] = PositionalScoresOnDisk()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
108 scores_by_chrom[chrom][pos] = val
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
109 except UCSCLimitException:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
110 # Wiggle data was truncated, at the very least need to warn the user.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
111 print 'Encountered message from UCSC: "Reached output limit of 100000 data values", so be aware your data was truncated.'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
112 except IndexError:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
113 stop_err('Data error: one or more column data values is missing in "%s"' %fname)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
114 except ValueError:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
115 stop_err('Data error: invalid data type for one or more values in "%s".' %fname)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
116 return scores_by_chrom
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
117
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
118 def load_scores_ba_dir( dir ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
119 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
120 Return a dict-like object (keyed by chromosome) that returns
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
121 FileBinnedArray objects created from "key.ba" files in `dir`
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
122 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
123 return FileBinnedArrayDir( dir )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
124
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
125 def main():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
126
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
127 # Parse command line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
128 options, args = doc_optparse.parse( __doc__ )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
129
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
130 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
131 score_fname = args[0]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
132 interval_fname = args[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
133 chrom_col = args[2]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
134 start_col = args[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
135 stop_col = args[4]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
136 if len( args ) > 5:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
137 out_file = open( args[5], 'w' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
138 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
139 out_file = sys.stdout
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
140 binned = bool( options.binned )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
141 mask_fname = options.mask
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
142 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
143 doc_optparse.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
144
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
145 if score_fname == 'None':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
146 stop_err( 'This tool works with data from genome builds hg16, hg17 or hg18. Click the pencil icon in your history item to set the genome build if appropriate.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
147
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
148 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
149 chrom_col = int(chrom_col) - 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
150 start_col = int(start_col) - 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
151 stop_col = int(stop_col) - 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
152 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
153 stop_err( 'Chrom, start & end column not properly set, click the pencil icon in your history item to set these values.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
154
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
155 if chrom_col < 0 or start_col < 0 or stop_col < 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
156 stop_err( 'Chrom, start & end column not properly set, click the pencil icon in your history item to set these values.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
157
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
158 if binned:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
159 scores_by_chrom = load_scores_ba_dir( score_fname )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
160 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
161 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
162 chrom_buffer = int( options.chrom_buffer )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
163 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
164 chrom_buffer = 3
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
165 scores_by_chrom = load_scores_wiggle( score_fname, chrom_buffer )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
166
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
167 if mask_fname:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
168 masks = binned_bitsets_from_file( open( mask_fname ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
169 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
170 masks = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
171
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
172 skipped_lines = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
173 first_invalid_line = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
174 invalid_line = ''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
175
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
176 for i, line in enumerate( open( interval_fname )):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
177 valid = True
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
178 line = line.rstrip('\r\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
179 if line and not line.startswith( '#' ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
180 fields = line.split()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
181
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
182 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
183 chrom, start, stop = fields[chrom_col], int( fields[start_col] ), int( fields[stop_col] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
184 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
185 valid = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
186 skipped_lines += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
187 if not invalid_line:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
188 first_invalid_line = i + 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
189 invalid_line = line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
190 if valid:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
191 total = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
192 count = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
193 min_score = 100000000
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
194 max_score = -100000000
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
195 for j in range( start, stop ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
196 if chrom in scores_by_chrom:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
197 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
198 # Skip if base is masked
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
199 if masks and chrom in masks:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
200 if masks[chrom][j]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
201 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
202 # Get the score, only count if not 'nan'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
203 score = scores_by_chrom[chrom][j]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
204 if not isNaN( score ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
205 total += score
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
206 count += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
207 max_score = max( score, max_score )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
208 min_score = min( score, min_score )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
209 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
210 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
211 if count > 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
212 avg = total/count
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
213 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
214 avg = "nan"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
215 min_score = "nan"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
216 max_score = "nan"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
217
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
218 # Build the resulting line of data
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
219 out_line = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
220 for k in range(0, len(fields)):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
221 out_line.append(fields[k])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
222 out_line.append(avg)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
223 out_line.append(min_score)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
224 out_line.append(max_score)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
225
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
226 print >> out_file, "\t".join( map( str, out_line ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
227 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
228 skipped_lines += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
229 if not invalid_line:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
230 first_invalid_line = i + 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
231 invalid_line = line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
232 elif line.startswith( '#' ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
233 # We'll save the original comments
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
234 print >> out_file, line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
235
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
236 out_file.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
237
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
238 if skipped_lines > 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
239 print 'Data issue: skipped %d invalid lines starting at line #%d which is "%s"' % ( skipped_lines, first_invalid_line, invalid_line )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
240 if skipped_lines == i:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
241 print 'Consider changing the metadata for the input dataset by clicking on the pencil icon in the history item.'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
242
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
243 if __name__ == "__main__": main()