annotate msconvert_wrapper.py @ 1:7016f1f10f42 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit d56659dd48f8c554a832787e71aca6ae65c90848
author galaxyp
date Tue, 14 Mar 2017 16:45:30 -0400
parents baa6c072fccc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
2 import optparse
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
3 import os
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
4 import sys
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
5 import tempfile
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
6 import shutil
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
7 import subprocess
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
8 import re
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
9 import logging
1
7016f1f10f42 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit d56659dd48f8c554a832787e71aca6ae65c90848
galaxyp
parents: 0
diff changeset
10 import shlex
0
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
11
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
12 assert sys.version_info[:2] >= (2, 6)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
13
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
14 log = logging.getLogger(__name__)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
15 working_directory = os.getcwd()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
16 tmp_stderr_name = tempfile.NamedTemporaryFile(dir=working_directory, suffix='.stderr').name
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
17 tmp_stdout_name = tempfile.NamedTemporaryFile(dir=working_directory, suffix='.stdout').name
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
18
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
19
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
20 def stop_err(msg):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
21 sys.stderr.write("%s\n" % msg)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
22 sys.exit()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
23
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
24
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
25 def read_stderr():
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
26 stderr = ''
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
27 if(os.path.exists(tmp_stderr_name)):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
28 with open(tmp_stderr_name, 'rb') as tmp_stderr:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
29 buffsize = 1048576
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
30 try:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
31 while True:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
32 stderr += tmp_stderr.read(buffsize)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
33 if not stderr or len(stderr) % buffsize != 0:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
34 break
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
35 except OverflowError:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
36 pass
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
37 return stderr
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
38
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
39
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
40 def execute(command, stdin=None):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
41 try:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
42 with open(tmp_stderr_name, 'wb') as tmp_stderr:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
43 with open(tmp_stdout_name, 'wb') as tmp_stdout:
1
7016f1f10f42 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit d56659dd48f8c554a832787e71aca6ae65c90848
galaxyp
parents: 0
diff changeset
44 args = shlex.split(command) # handle proper splitting of quoted args
7016f1f10f42 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit d56659dd48f8c554a832787e71aca6ae65c90848
galaxyp
parents: 0
diff changeset
45 proc = subprocess.Popen(args=args, shell=False, stderr=tmp_stderr.fileno(), stdout=tmp_stdout.fileno(), stdin=stdin, env=os.environ)
0
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
46 returncode = proc.wait()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
47 if returncode != 0:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
48 raise Exception("Program returned with non-zero exit code %d. stderr: %s" % (returncode, read_stderr()))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
49 finally:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
50 print(( open(tmp_stderr_name, "r").read() ))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
51 print(( open(tmp_stdout_name, "r").read() ))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
52
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
53
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
54 def delete_file(path):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
55 if os.path.exists(path):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
56 try:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
57 os.remove(path)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
58 except:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
59 pass
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
60
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
61
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
62 def delete_directory(directory):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
63 if os.path.exists(directory):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
64 try:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
65 shutil.rmtree(directory)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
66 except:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
67 pass
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
68
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
69
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
70 def symlink(source, link_name):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
71 import platform
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
72 if platform.system() == 'Windows':
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
73 try:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
74 import win32file
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
75 win32file.CreateSymbolicLink(source, link_name, 1)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
76 except:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
77 shutil.copy(source, link_name)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
78 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
79 os.symlink(source, link_name)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
80
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
81
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
82 def copy_to_working_directory(data_file, relative_path):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
83 if os.path.abspath(data_file) != os.path.abspath(relative_path):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
84 symlink(data_file, relative_path)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
85 return relative_path
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
86
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
87
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
88 def __main__():
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
89 run_script()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
90
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
91 #ENDTEMPLATE
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
92
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
93 to_extensions = ['mzML', 'mzXML', 'unindexed_mzML', 'unindexed_mzXML', 'mgf', 'mz5', 'txt', 'ms2', 'cms2']
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
94
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
95
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
96 def str_to_bool(v):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
97 """ From http://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python """
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
98 return v.lower() in ["yes", "true", "t", "1"]
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
99
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
100
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
101 def _add_filter(filters_file, contents):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
102 filters_file.write("filter=%s\n" % contents)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
103
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
104
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
105 def _skip_line(options, file_num, line_parts):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
106 file_num_column = options.filter_table_file_column
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
107 if not file_num_column:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
108 return False
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
109 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
110 target_file_num_val = str(file_num).strip()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
111 query_file_num_val = line_parts[int(file_num_column) - 1].strip()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
112 #print "target %s, query %s" % (target_file_num_val, query_file_num_val)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
113 return target_file_num_val != query_file_num_val
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
114
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
115
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
116 def _read_table_numbers(path, options, file_num=None):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
117 unique_numbers = set([])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
118 column_num = options.filter_table_column
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
119 input = open(path, "r")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
120 first_line = True
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
121 for line in input:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
122 if not line:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
123 continue
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
124 line = line.strip()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
125 if line.startswith("#"):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
126 first_line = False
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
127 continue
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
128 if column_num == None:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
129 column = line
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
130 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
131 line_parts = line.split("\t")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
132 if _skip_line(options, file_num, line_parts):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
133 continue
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
134 column = line_parts[int(column_num) - 1]
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
135 match = re.match("\d+", column)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
136 if match:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
137 unique_numbers.add(int(match.group()))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
138 first_line = False
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
139 return unique_numbers
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
140
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
141
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
142 def shellquote(s):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
143 return '"' + s.replace('"', '\\"') + '"'
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
144
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
145
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
146 def _add_filter_line_from_file(filter_file, options, file_num=None):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
147 file = options.filter_table
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
148 if not file:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
149 return
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
150 numbers = _read_table_numbers(file, options, file_num)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
151 msconvert_int_set = " ".join([str(number) for number in numbers])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
152 filter_type = options.filter_table_type
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
153 if filter_type == 'number':
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
154 filter_prefix = 'scanNumber'
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
155 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
156 filter_prefix = 'index'
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
157 _add_filter(filter_file, "%s %s" % (filter_prefix, msconvert_int_set))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
158
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
159
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
160 def _create_filters_file(options, file_num=None, debug=False):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
161 suffix = "" if not file_num else str(file_num)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
162 filters_file_path = "filters%s" % suffix
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
163 filters_file = open(filters_file_path, "w")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
164 if options.filters_file:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
165 filters_file.write(open(options.filters_file, "r").read())
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
166 for filter in options.filter:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
167 _add_filter(filters_file, filter)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
168 _add_filter_line_from_file(filters_file, options, file_num=file_num)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
169
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
170 filters_file.close()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
171 if debug:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
172 print(( open(filters_file_path, "r").read() ))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
173 return filters_file_path
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
174
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
175
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
176 def _build_base_cmd(options,args=None):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
177 to_extension = options.toextension
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
178 if to_extension.startswith("unindexed_"):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
179 to_extension = to_extension[len("unindexed_"):]
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
180 to_params = "--noindex"
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
181 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
182 to_params = ""
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
183 cmd = "msconvert --%s %s" % (to_extension, to_params)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
184 if args:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
185 cmd = "%s %s" % (cmd, ' '.join(args))
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
186 if str_to_bool(options.zlib):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
187 cmd = "%s %s" % (cmd, "--zlib")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
188 if options.binaryencoding:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
189 cmd = "%s --%s" % (cmd, options.binaryencoding)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
190 if options.mzencoding:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
191 cmd = "%s --mz%s" % (cmd, options.mzencoding)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
192 if options.intensityencoding:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
193 cmd = "%s --inten%s" % (cmd, options.intensityencoding)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
194 return cmd
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
195
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
196
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
197 def _run(base_cmd, output_dir='output', inputs=[], debug=False):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
198 inputs_as_str = " ".join(['%s' % shellquote(input) for input in inputs])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
199 os.mkdir(output_dir)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
200 cmd = "%s -o %s %s" % (base_cmd, shellquote(output_dir), inputs_as_str)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
201 if debug:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
202 print(cmd)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
203 execute(cmd)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
204 output_files = os.listdir(output_dir)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
205 assert len(output_files) == 1
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
206 output_file = output_files[0]
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
207 return os.path.join(output_dir, output_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
208
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
209
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
210 def run_script():
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
211 parser = optparse.OptionParser()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
212 parser.add_option('--input', dest='inputs', action='append', default=[])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
213 parser.add_option('--input_name', dest='input_names', action='append', default=[])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
214 parser.add_option('--implicit', dest='implicits', action='append', default=[], help='input files that should NOT be on the msconvert command line.')
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
215 parser.add_option('--ident', dest='idents', action='append', default=[])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
216 parser.add_option('--ident_name', dest='ident_names', action='append', default=[])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
217 parser.add_option('--output', dest='output')
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
218 parser.add_option('--refinement', dest='refinement')
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
219 parser.add_option('--fromextension', dest='fromextension')
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
220 parser.add_option('--toextension', dest='toextension', default='mzML', choices=to_extensions)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
221 parser.add_option('--binaryencoding', dest='binaryencoding', choices=['32', '64'])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
222 parser.add_option('--mzencoding', dest='mzencoding', choices=['32', '64'])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
223 parser.add_option('--intensityencoding', dest='intensityencoding', choices=['32', '64'])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
224 parser.add_option('--zlib', dest='zlib', default="false")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
225 parser.add_option('--filter', dest='filter', action='append', default=[])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
226 parser.add_option('--filters_file', dest='filters_file', default=None)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
227 parser.add_option('--filter_table', default=None)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
228 parser.add_option('--filter_table_type', default='index', choices=['index', 'number'])
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
229 parser.add_option('--filter_table_column', default=None)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
230 parser.add_option('--filter_table_file_column', default=None)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
231 parser.add_option('--debug', dest='debug', action='store_true', default=False)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
232
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
233 (options, args) = parser.parse_args()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
234 if len(options.inputs) < 1:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
235 stop_err("No input files to msconvert specified")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
236 if len(options.input_names) > 0 and len(options.input_names) != len(options.inputs):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
237 stop_err("Number(s) of supplied input names and input files do not match")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
238 if not options.output:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
239 stop_err("Must specify output location")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
240 input_files = []
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
241 for i, input in enumerate(options.inputs):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
242 input_base = None
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
243 if len(options.input_names) > i:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
244 input_base = options.input_names[i]
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
245 input_base = input_base.replace("'", "").replace("\"", "")
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
246 print("1- input_base: %s" % input_base)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
247 if not input_base:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
248 input_base = 'input%s' % i
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
249 print("2- input_base: %s" % input_base)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
250 if not input_base.lower().endswith('.%s' % options.fromextension.lower()) and input not in options.implicits:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
251 input_file = '%s.%s' % (input_base, options.fromextension)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
252 print("3- input_base: %s" % input_base)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
253 print("3- input_file: %s" % input_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
254 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
255 input_file = input_base
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
256 print("4- input_base: %s" % input_base)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
257 print("4- input_file: %s" % input_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
258 input_file = input_file
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
259 copy_to_working_directory(input, input_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
260 if input in options.implicits:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
261 continue
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
262 input_files.append(input_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
263 for i, ident in enumerate(options.idents):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
264 ident_file = options.ident_names[i]
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
265 copy_to_working_directory(ident, ident_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
266
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
267 cmd = _build_base_cmd(options,args=args)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
268 file_column = options.filter_table_file_column
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
269 if not file_column:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
270 # Apply same filters to all files, just create a unviersal filter files
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
271 # and run msconvert once.
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
272 filters_file_path = _create_filters_file(options, debug=options.debug)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
273 cmd = "%s -c %s" % (cmd, filters_file_path)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
274 else:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
275 # Dispatching on a column to filter different files differently, need to filter
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
276 # each input once with msconvert and then merge once.
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
277 filtered_files = []
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
278 for index, input_file in enumerate(input_files):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
279 filters_file_path = _create_filters_file(options, index + 1, debug=options.debug)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
280 filter_cmd = "%s -c %s" % (cmd, filters_file_path)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
281 filtered_output_file = _run(filter_cmd, output_dir='output%d' % index, inputs=[input_file], debug=options.debug)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
282 filtered_files.append(filtered_output_file)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
283 input_files = filtered_files
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
284 if len(input_files) > 1:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
285 cmd = "%s --merge" % cmd
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
286 output_file = _run(cmd, output_dir='output', inputs=input_files, debug=options.debug)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
287 shutil.copy(output_file, options.output)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
288 if options.refinement:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
289 # .mzRefinement.tsv
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
290 files = os.listdir(os.getcwd())
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
291 for fname in files:
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
292 if fname.endswith('.mzRefinement.tsv'):
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
293 shutil.copy(fname, options.refinement)
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
294 break
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
295
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
296 def __main__():
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
297 run_script()
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
298
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
299 if __name__ == '__main__':
baa6c072fccc planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msconvert commit 4fa5bf9c62e4bba06c4d6e7de962c85959b61579-dirty
galaxyp
parents:
diff changeset
300 __main__()