comparison hardklor.py @ 0:d796e6613d19 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/hardklor commit f37e6d0357de4d9b1cd743ca291a7d4df2cc7a5f-dirty
author galaxyp
date Mon, 23 May 2016 11:12:40 -0400
parents
children 73fc27617b2e
comparison
equal deleted inserted replaced
-1:000000000000 0:d796e6613d19
1 """
2 Usage:
3 python hardklor.py ms1extenstion ms2extension ms1file
4 ms2file outputfile
5 """
6 import sys
7 import os
8 import subprocess
9
10
11 CONFIG_FILE = 'hk.conf'
12 extension_lookup = {
13 'mzml' : 'mzML',
14 'mzxml' : 'mzXML',
15 'ms1' : 'MS1',
16 }
17
18 # input:
19 ms1_ext = sys.argv[1]
20 ms1_file = sys.argv[2]
21 output_file = sys.argv[3]
22 config_load = os.path.join(os.path.split(sys.argv[0])[0], 'hardklor.conf')
23
24 # parse options
25 options = {}
26 for arg in [x.split('=') for x in sys.argv[4:]]:
27 if arg[1] != '':
28 options[arg[0].replace('-', '')] = arg[1]
29
30
31 # create softlinks since hardklor needs "proper" extensions for input files
32 if ms1_ext in extension_lookup:
33 ms1_ext = extension_lookup[ms1_ext]
34 linkname = 'ms1_dsetlink.{0}'.format(ms1_ext)
35 os.symlink(ms1_file, linkname)
36 ms1_file = linkname
37
38 # load template and dump to config file
39 with open(config_load) as fp:
40 config_str = fp.read()
41 config_to_dump = config_str.format(
42 instrument=options['instrument'],
43 resolution=options['resolution'],
44 centroided=options['centroided'],
45 mslvl=options['mslvl'],
46 depth=options['depth'],
47 algorithm=options['algorithm'],
48 charge_algo=options['charge_algo'],
49 mincharge=options['mincharge'],
50 maxcharge=options['maxcharge'],
51 correlation=options['correlation'],
52 sensitivity=options['sensitivity'],
53 maxfeat=options['maxfeat'],
54 inputfile=ms1_file,
55 outputfile=output_file,
56 )
57 with open(CONFIG_FILE, 'w') as fp:
58 fp.write(config_to_dump)
59
60 # Run hardklor
61 err = subprocess.call(['hardklor', CONFIG_FILE])
62 sys.exit(err)