Mercurial > repos > galaxyp > maxquant
comparison mqwrapper.py @ 0:4ce8694766e3 draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
| author | galaxyp |
|---|---|
| date | Fri, 19 Jul 2019 19:13:15 -0400 |
| parents | |
| children | 461ba35a313f |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4ce8694766e3 |
|---|---|
| 1 """ | |
| 2 Run MaxQuant on a modified mqpar.xml. | |
| 3 Use maxquant conda package. | |
| 4 TODO: add support for parameter groups | |
| 5 | |
| 6 Authors: Damian Glaetzer <d.glaetzer@mailbox.org> | |
| 7 | |
| 8 based on the maxquant galaxy tool by John Chilton: | |
| 9 https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant | |
| 10 """ | |
| 11 | |
| 12 import argparse | |
| 13 import os | |
| 14 import shutil | |
| 15 import subprocess | |
| 16 | |
| 17 import mqparam | |
| 18 | |
| 19 # build parser | |
| 20 parser = argparse.ArgumentParser() | |
| 21 | |
| 22 # input, special outputs and others | |
| 23 other_args = ('raw_files', 'mzxml_files', 'fasta_files', | |
| 24 'description_parse_rule', 'identifier_parse_rule', | |
| 25 'exp_design', 'output_all', | |
| 26 'mqpar_out', 'infile_names', 'mzTab', | |
| 27 'version', 'substitution_rx') | |
| 28 | |
| 29 # txt result files | |
| 30 txt_output = ('evidence', 'msms', 'parameters', | |
| 31 'peptides', 'proteinGroups', 'allPeptides', | |
| 32 'libraryMatch', 'matchedFeatures', | |
| 33 'modificationSpecificPeptides', 'ms3Scans', | |
| 34 'msmsScans', 'mzRange', 'peptideSection', | |
| 35 'summary') | |
| 36 | |
| 37 # arguments for mqparam | |
| 38 ## global | |
| 39 global_flags = ('calc_peak_properties', | |
| 40 'write_mztab', | |
| 41 'ibaq', | |
| 42 'ibaq_log_fit', | |
| 43 'separate_lfq', | |
| 44 'lfq_stabilize_large_ratios', | |
| 45 'lfq_require_msms', | |
| 46 'advanced_site_intensities', | |
| 47 'match_between_runs') | |
| 48 | |
| 49 global_simple_args = ('min_unique_pep', | |
| 50 'num_threads', | |
| 51 'min_peptide_len', | |
| 52 'max_peptide_mass') | |
| 53 | |
| 54 ## parameter group specific | |
| 55 param_group_flags = ('lfq_skip_norm',) | |
| 56 | |
| 57 param_group_simple_args = ('missed_cleavages', | |
| 58 'lfq_mode', | |
| 59 'lfq_min_edges_per_node', | |
| 60 'lfq_avg_edges_per_node', | |
| 61 'lfq_min_ratio_count') | |
| 62 | |
| 63 param_group_silac_args = ('light_mods', 'medium_mods', 'heavy_mods') | |
| 64 | |
| 65 list_args = ('fixed_mods', 'var_mods', 'proteases') | |
| 66 | |
| 67 arguments = ['--' + el for el in (txt_output | |
| 68 + global_simple_args | |
| 69 + param_group_simple_args | |
| 70 + list_args | |
| 71 + param_group_silac_args | |
| 72 + other_args)] | |
| 73 | |
| 74 flags = ['--' + el for el in global_flags + param_group_flags] | |
| 75 | |
| 76 for arg in arguments: | |
| 77 parser.add_argument(arg) | |
| 78 for flag in flags: | |
| 79 parser.add_argument(flag, action="store_true") | |
| 80 | |
| 81 args = vars(parser.parse_args()) | |
| 82 | |
| 83 # link infile datasets to names with correct extension | |
| 84 # for maxquant to accept them | |
| 85 files = (args['raw_files'] if args['raw_files'] | |
| 86 else args['mzxml_files']).split(',') | |
| 87 ftype = ".thermo.raw" if args['raw_files'] else ".mzXML" | |
| 88 filenames = args['infile_names'].split(',') | |
| 89 fnames_with_ext = [(a if a.endswith(ftype) | |
| 90 else os.path.splitext(a)[0] + ftype) | |
| 91 for a in filenames] | |
| 92 | |
| 93 for f, l in zip(files, fnames_with_ext): | |
| 94 os.link(f, l) | |
| 95 | |
| 96 # build mqpar.xml | |
| 97 mqpar_in = os.path.join(os.getcwd(), 'mqpar.xml') | |
| 98 subprocess.run(('maxquant', '-c', mqpar_in)) | |
| 99 mqpar_out = args['mqpar_out'] if args['mqpar_out'] != 'None' else mqpar_in | |
| 100 | |
| 101 | |
| 102 exp_design = args['exp_design'] if args['exp_design'] != 'None' else None | |
| 103 m = mqparam.MQParam(mqpar_out, mqpar_in, exp_design, | |
| 104 substitution_rx=args['substitution_rx']) | |
| 105 if m.version != args['version']: | |
| 106 raise Exception('mqpar version is ' + m.version + | |
| 107 '. Tool uses version {}.'.format(args['version'])) | |
| 108 | |
| 109 # modify parameters, interactive mode if no mqpar_in was specified | |
| 110 m.add_infiles([os.path.join(os.getcwd(), name) for name in fnames_with_ext], True) | |
| 111 m.add_fasta_files(args['fasta_files'].split(','), | |
| 112 identifier=args['identifier_parse_rule'], | |
| 113 description=args['description_parse_rule']) | |
| 114 | |
| 115 for e in (global_simple_args | |
| 116 + param_group_simple_args | |
| 117 + global_flags | |
| 118 + param_group_flags): | |
| 119 if args[e]: | |
| 120 m.set_simple_param(e, args[e]) | |
| 121 | |
| 122 for e in list_args: | |
| 123 if args[e]: | |
| 124 m.set_list_params(e, args[e].split(',')) | |
| 125 | |
| 126 if args['light_mods'] or args['medium_mods'] or args['heavy_mods']: | |
| 127 m.set_silac(args['light_mods'].split(',') if args['light_mods'] else None, | |
| 128 args['medium_mods'].split(',') if args['medium_mods'] else None, | |
| 129 args['heavy_mods'].split(',') if args['heavy_mods'] else None) | |
| 130 | |
| 131 m.write() | |
| 132 | |
| 133 # build and run MaxQuant command | |
| 134 cmd = ['maxquant', mqpar_out] | |
| 135 | |
| 136 subprocess.run(cmd, check=True, cwd='./') | |
| 137 | |
| 138 # copy results to galaxy database | |
| 139 for el in txt_output: | |
| 140 destination = args[el] | |
| 141 source = os.path.join(os.getcwd(), "combined", "txt", "{}.txt".format(el)) | |
| 142 if destination != 'None' and os.path.isfile(source): | |
| 143 shutil.copy(source, destination) | |
| 144 | |
| 145 if args['mzTab'] != 'None': | |
| 146 source = os.path.join(os.getcwd(), "combined", "txt", "mzTab.mzTab") | |
| 147 if os.path.isfile(source): | |
| 148 shutil.copy(source, args['mzTab']) |
