Mercurial > repos > galaxyp > msconvert
comparison msconvert_wrapper.py @ 5:637e309295cf draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit d70aeb6f0e03a354fb8732f04dce8453b03477ea
author | galaxyp |
---|---|
date | Mon, 12 Dec 2016 17:07:11 -0500 |
parents | 158a71ee5733 |
children | 6b6bba73eadb |
comparison
equal
deleted
inserted
replaced
4:158a71ee5733 | 5:637e309295cf |
---|---|
86 def __main__(): | 86 def __main__(): |
87 run_script() | 87 run_script() |
88 | 88 |
89 #ENDTEMPLATE | 89 #ENDTEMPLATE |
90 | 90 |
91 to_extensions = ['mzML', 'mzXML', 'unindexed_mzML', 'unindexed_mzXML', 'mgf', 'mz5', 'txt', 'ms2', 'cms2'] | 91 to_extensions = ['mzML', 'mzXML', 'unindexed_mzML', 'unindexed_mzXML', 'mgf', 'txt', 'ms2', 'cms2'] |
92 | 92 |
93 | 93 |
94 def str_to_bool(v): | 94 def str_to_bool(v): |
95 """ From http://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python """ | 95 """ From http://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python """ |
96 return v.lower() in ["yes", "true", "t", "1"] | 96 return v.lower() in ["yes", "true", "t", "1"] |
169 if debug: | 169 if debug: |
170 print(( open(filters_file_path, "r").read() )) | 170 print(( open(filters_file_path, "r").read() )) |
171 return filters_file_path | 171 return filters_file_path |
172 | 172 |
173 | 173 |
174 def _build_base_cmd(options,args=None): | 174 def _build_base_cmd(options): |
175 to_extension = options.toextension | 175 to_extension = options.toextension |
176 if to_extension.startswith("unindexed_"): | 176 if to_extension.startswith("unindexed_"): |
177 to_extension = to_extension[len("unindexed_"):] | 177 to_extension = to_extension[len("unindexed_"):] |
178 to_params = "--noindex" | 178 to_params = "--noindex" |
179 else: | 179 else: |
180 to_params = "" | 180 to_params = "" |
181 cmd = "msconvert --%s %s" % (to_extension, to_params) | 181 cmd = "msconvert --%s %s" % (to_extension, to_params) |
182 if args: | |
183 cmd = "%s %s" % (cmd, ' '.join(args)) | |
184 if str_to_bool(options.zlib): | 182 if str_to_bool(options.zlib): |
185 cmd = "%s %s" % (cmd, "--zlib") | 183 cmd = "%s %s" % (cmd, "--zlib") |
186 if options.binaryencoding: | 184 if options.binaryencoding: |
187 cmd = "%s --%s" % (cmd, options.binaryencoding) | 185 cmd = "%s --%s" % (cmd, options.binaryencoding) |
188 if options.mzencoding: | 186 if options.mzencoding: |
208 def run_script(): | 206 def run_script(): |
209 parser = optparse.OptionParser() | 207 parser = optparse.OptionParser() |
210 parser.add_option('--input', dest='inputs', action='append', default=[]) | 208 parser.add_option('--input', dest='inputs', action='append', default=[]) |
211 parser.add_option('--input_name', dest='input_names', action='append', default=[]) | 209 parser.add_option('--input_name', dest='input_names', action='append', default=[]) |
212 parser.add_option('--implicit', dest='implicits', action='append', default=[], help='input files that should NOT be on the msconvert command line.') | 210 parser.add_option('--implicit', dest='implicits', action='append', default=[], help='input files that should NOT be on the msconvert command line.') |
213 parser.add_option('--ident', dest='idents', action='append', default=[]) | |
214 parser.add_option('--ident_name', dest='ident_names', action='append', default=[]) | |
215 parser.add_option('--output', dest='output') | 211 parser.add_option('--output', dest='output') |
216 parser.add_option('--refinement', dest='refinement') | |
217 parser.add_option('--fromextension', dest='fromextension') | 212 parser.add_option('--fromextension', dest='fromextension') |
218 parser.add_option('--toextension', dest='toextension', default='mzML', choices=to_extensions) | 213 parser.add_option('--toextension', dest='toextension', default='mzML', choices=to_extensions) |
219 parser.add_option('--binaryencoding', dest='binaryencoding', choices=['32', '64']) | 214 parser.add_option('--binaryencoding', dest='binaryencoding', choices=['32', '64']) |
220 parser.add_option('--mzencoding', dest='mzencoding', choices=['32', '64']) | 215 parser.add_option('--mzencoding', dest='mzencoding', choices=['32', '64']) |
221 parser.add_option('--intensityencoding', dest='intensityencoding', choices=['32', '64']) | 216 parser.add_option('--intensityencoding', dest='intensityencoding', choices=['32', '64']) |
256 input_file = input_file | 251 input_file = input_file |
257 copy_to_working_directory(input, input_file) | 252 copy_to_working_directory(input, input_file) |
258 if input in options.implicits: | 253 if input in options.implicits: |
259 continue | 254 continue |
260 input_files.append(input_file) | 255 input_files.append(input_file) |
261 for i, ident in enumerate(options.idents): | 256 |
262 ident_file = options.ident_names[i] | 257 cmd = _build_base_cmd(options) |
263 copy_to_working_directory(ident, ident_file) | |
264 | |
265 cmd = _build_base_cmd(options,args=args) | |
266 file_column = options.filter_table_file_column | 258 file_column = options.filter_table_file_column |
267 if not file_column: | 259 if not file_column: |
268 # Apply same filters to all files, just create a unviersal filter files | 260 # Apply same filters to all files, just create a unviersal filter files |
269 # and run msconvert once. | 261 # and run msconvert once. |
270 filters_file_path = _create_filters_file(options, debug=options.debug) | 262 filters_file_path = _create_filters_file(options, debug=options.debug) |
281 input_files = filtered_files | 273 input_files = filtered_files |
282 if len(input_files) > 1: | 274 if len(input_files) > 1: |
283 cmd = "%s --merge" % cmd | 275 cmd = "%s --merge" % cmd |
284 output_file = _run(cmd, output_dir='output', inputs=input_files, debug=options.debug) | 276 output_file = _run(cmd, output_dir='output', inputs=input_files, debug=options.debug) |
285 shutil.copy(output_file, options.output) | 277 shutil.copy(output_file, options.output) |
286 if options.refinement: | 278 |
287 # .mzRefinement.tsv | |
288 files = os.listdir(os.getcwd()) | |
289 for fname in files: | |
290 if fname.endswith('.mzRefinement.tsv'): | |
291 shutil.copy(fname, options.refinement) | |
292 break | |
293 | |
294 def __main__(): | |
295 run_script() | |
296 | 279 |
297 if __name__ == '__main__': | 280 if __name__ == '__main__': |
298 __main__() | 281 __main__() |