comparison create_mqpar.py @ 4:dcd39bcc7481 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit da342a782ccc391b87fb4fead956b7b3cbd21258"
author galaxyp
date Sat, 11 Apr 2020 11:49:19 -0400
parents
children 37d669de2828
comparison
equal deleted inserted replaced
3:175e062b6a17 4:dcd39bcc7481
1 """Create paramter xml file for a specific MaxQuant version from yaml or command line input
2 and a template parameter file.
3 """
4
5 import argparse
6 import os
7 import yaml
8
9 from mqparam import MQParam
10
11 parser = argparse.ArgumentParser()
12
13 parser.add_argument('--yaml', '-y', help="""Yaml config file. Only those parameters differing
14 from the template need to be specified.""")
15
16 parser.add_argument('--exp_design', '-e', help="Experimental design template as it is created by the MaxQuant GUI.")
17
18 parser.add_argument('template', help="Template Parameter File.")
19
20 parser.add_argument('--mqpar_out', '-o', help="Output file, will be ./mqpar.xml if omitted.")
21
22 parser.add_argument('--substitution_rx', '-s', help="""Regular expression for filename substitution.
23 Necessary for usage in the Galaxy tool. Can usually be ignored.""")
24
25 parser.add_argument('--version', '-v', help="""A version number. Raises exception if it doesn't
26 match the MaxQuant version of the template. For usage in the Galaxy tool.""")
27
28 # in case numThreads is a environment variable, otherwise it can be specified in the yaml file as well
29 parser.add_argument('--num_threads', '-t', help="Number of threads to specify in mqpar.")
30 args = parser.parse_args()
31
32 # edit file names, working dir is unknown at the time of galaxy tool configfile creation
33 if args.yaml:
34 with open(args.yaml) as f:
35 conf_dict = yaml.safe_load(f.read())
36
37 for n, pg in enumerate(conf_dict['paramGroups']):
38 for num, fl in enumerate(pg['files']):
39 if not fl.startswith('/'):
40 conf_dict['paramGroups'][n]['files'][num] = os.path.join(os.getcwd(), fl)
41 with open('yaml', 'w') as f:
42 yaml.safe_dump(conf_dict, stream=f)
43 args.yaml = 'yaml'
44
45 kwargs = dict(yaml=args.yaml)
46 if args.substitution_rx:
47 kwargs['substitution_rx'] = args.substitution_rx
48 mqparam = MQParam(args.template, args.exp_design, **kwargs)
49 if args.version and mqparam.version != args.version:
50 raise Exception('mqpar version is ' + mqparam.version + '. Tool uses version {}.'.format(args.version))
51 mqparam.set_simple_param('numThreads', args.num_threads)
52
53 mqparam.write(args.mqpar_out if args.mqpar_out else 'mqpar.xml')