Mercurial > repos > galaxyp > msconvert
annotate msconvert_raw_wrapper.py @ 0:ab59b1826345 draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
| author | galaxyp |
|---|---|
| date | Thu, 22 Oct 2015 14:00:58 -0400 |
| parents | |
| children |
| rev | line source |
|---|---|
|
0
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
1 #!/usr/bin/env python |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
2 import optparse |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
3 import os |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
4 import sys |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
5 import tempfile |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
6 import shutil |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
7 import subprocess |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
8 import re |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
9 from os.path import basename |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
10 import logging |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
11 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
12 assert sys.version_info[:2] >= ( 2, 6 ) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
13 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
14 log = logging.getLogger(__name__) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
15 working_directory = os.getcwd() |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
16 tmp_stderr_name = tempfile.NamedTemporaryFile(dir = working_directory, suffix = '.stderr').name |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
17 tmp_stdout_name = tempfile.NamedTemporaryFile(dir = working_directory, suffix = '.stdout').name |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
18 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
19 def stop_err( msg ): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
20 sys.stderr.write( "%s\n" % msg ) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
21 sys.exit() |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
22 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
23 def read_stderr(): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
24 stderr = '' |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
25 if(os.path.exists(tmp_stderr_name)): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
26 with open(tmp_stderr_name, 'rb') as tmp_stderr: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
27 buffsize = 1048576 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
28 try: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
29 while True: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
30 stderr += tmp_stderr.read(buffsize) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
31 if not stderr or len(stderr) % buffsize != 0: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
32 break |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
33 except OverflowError: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
34 pass |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
35 return stderr |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
36 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
37 def execute(command, stdin=None): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
38 with open(tmp_stderr_name, 'wb') as tmp_stderr: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
39 with open(tmp_stdout_name, 'wb') as tmp_stdout: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
40 proc = subprocess.Popen(args=command, shell=True, stderr=tmp_stderr.fileno(), stdout=tmp_stdout.fileno(), stdin=stdin, env=os.environ) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
41 returncode = proc.wait() |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
42 if returncode != 0: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
43 raise Exception("Program returned with non-zero exit code %d. stderr: %s" % (returncode, read_stderr())) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
44 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
45 def delete_file(path): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
46 if os.path.exists(path): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
47 try: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
48 os.remove(path) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
49 except: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
50 pass |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
51 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
52 def delete_directory(directory): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
53 if os.path.exists(directory): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
54 try: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
55 shutil.rmtree(directory) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
56 except: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
57 pass |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
58 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
59 def symlink(source, link_name): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
60 import platform |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
61 if platform.system() == 'Windows': |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
62 import win32file |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
63 win32file.CreateSymbolicLink(source, link_name, 1) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
64 else: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
65 os.symlink(source, link_name) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
66 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
67 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
68 def copy_to_working_directory(data_file, relative_path): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
69 if os.path.abspath(data_file) != os.path.abspath(relative_path): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
70 shutil.copy(data_file, relative_path) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
71 return relative_path |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
72 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
73 def __main__(): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
74 run_script() |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
75 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
76 #ENDTEMPLATE |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
77 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
78 to_extensions = ['mzML', 'mzXML', 'mgf', 'txt', 'ms2', 'cms2'] |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
79 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
80 def str_to_bool(v): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
81 """ From http://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python """ |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
82 return v.lower() in ["yes", "true", "t", "1"] |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
83 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
84 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
85 def run_script(): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
86 parser = optparse.OptionParser() |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
87 parser.add_option('--input', dest='input') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
88 parser.add_option('--output', dest='output') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
89 parser.add_option('--fromextension', dest='fromextension') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
90 parser.add_option('--toextension', dest='toextension', default='mzML', choices=to_extensions) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
91 parser.add_option('--binaryencoding', dest='binaryencoding', choices=['32', '64']) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
92 parser.add_option('--mzencoding', dest='mzencoding', choices=['32', '64']) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
93 parser.add_option('--intensityencoding', dest='intensityencoding', choices=['32', '64']) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
94 parser.add_option('--noindex', dest='noindex') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
95 parser.add_option('--zlib', dest='zlib') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
96 parser.add_option('--filter', dest='filter', action='append', default=[]) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
97 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
98 (options, args) = parser.parse_args() |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
99 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
100 filter_commands = '' |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
101 for filter in options.filter: |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
102 filter_commands = "%s --filter \"%s\"" % (filter_commands, filter) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
103 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
104 input_file = 'input.%s' % options.fromextension |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
105 copy_to_working_directory(options.input, input_file) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
106 os.mkdir('output') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
107 cmd = "msconvert --%s -o output" % (options.toextension) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
108 if str_to_bool(options.noindex): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
109 cmd = "%s %s" % (cmd, "--noindex") |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
110 if str_to_bool(options.zlib): |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
111 cmd = "%s %s" % (cmd, "--zlib") |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
112 cmd = "%s --%s" % (cmd, options.binaryencoding) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
113 cmd = "%s --mz%s" % (cmd, options.mzencoding) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
114 cmd = "%s --inten%s" % (cmd, options.intensityencoding) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
115 cmd = "%s %s" % (cmd, input_file) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
116 cmd = "%s %s" % (cmd, filter_commands) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
117 print(cmd) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
118 execute(cmd) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
119 output_files = os.listdir('output') |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
120 assert len(output_files) == 1 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
121 output_file = output_files[0] |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
122 shutil.copy(os.path.join('output', output_file), options.output) |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
123 |
|
ab59b1826345
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/msconvert commit 815179cfd9754d3859239258fa30c331d5daaa41-dirty
galaxyp
parents:
diff
changeset
|
124 if __name__ == '__main__': __main__() |
