annotate create_mqpar.py @ 9:37d669de2828 draft

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