annotate init.py @ 3:175e062b6a17 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit 74b5aa29e49deaaebe19ce2355a70d4f570f4951"
author galaxyp
date Thu, 15 Aug 2019 08:09:00 -0400
parents 8bac3cc5c5de
children dcd39bcc7481
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python3
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
2 """Initialize MaxQuant tool for use with a new version of
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
3 modifications/enzymes.xml.
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
4
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
5 TODO: Append function: only add modifications that are not
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
6 already present, add modification entries to conda maxquant
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
7
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
8 Authors: Damian Glaetzer <d.glaetzer@mailbox.org>
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
9
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
10 Usage: init.py [-a] [-m MODS_FILE] [-e ENZYMES_FILE]
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
11 FILES are the modifications/enzymes.xml of MaxQuant, located at
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
12 <ANACONDA_DIR>/pkgs/maxquant-<VERSION>/bin/conf/.
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
13 (for conda installations)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
14
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
15 Updates modification parameters in macros.xml.
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
16 """
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
17
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
18 import argparse
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
19 import re
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
20 import xml.etree.ElementTree as ET
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
21 from xml.dom import minidom
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
22
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
23
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
24 def build_list(node, name, mod_list, append=False):
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
25 """Build the modifications list in macros.xml"""
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
26 node.clear()
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
27 node.tag = 'xml'
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
28 node.set('name', name)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
29 for m in mod_list:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
30 ET.SubElement(node, 'expand', attrib={'macro': 'mod_option',
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
31 'value': m})
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
32
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
33
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
34 parser = argparse.ArgumentParser()
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
35 parser.add_argument("-m", "--modifications",
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
36 help="modifications.xml of maxquant")
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
37 parser.add_argument("-e", "--enzymes",
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
38 help="enzymes.xml of maxquant")
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
39 args = parser.parse_args()
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
40
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
41 if args.modifications:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
42 mods_root = ET.parse(args.modifications).getroot()
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
43
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
44 mods = mods_root.findall('modification')
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
45 standard_mods = []
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
46 label_mods = []
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
47 for m in mods:
3
175e062b6a17 "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit 74b5aa29e49deaaebe19ce2355a70d4f570f4951"
galaxyp
parents: 1
diff changeset
48 if (m.findtext('type') == 'Standard' or m.findtext('type') == 'AaSubstitution'):
1
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
49 standard_mods.append(m.get('title'))
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
50 elif m.findtext('type') == 'Label':
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
51 label_mods.append(m.get('title'))
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
52
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
53 if args.enzymes:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
54 enzymes_root = ET.parse(args.enzymes).getroot()
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
55
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
56 enzymes = enzymes_root.findall('enzyme')
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
57 enzymes_list = [e.get('title') for e in enzymes]
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
58
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
59 macros_root = ET.parse('./macros.xml').getroot()
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
60 for child in macros_root:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
61 if child.get('name') == 'modification' and args.modifications:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
62 build_list(child, 'modification', standard_mods)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
63 elif child.get('name') == 'label' and args.modifications:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
64 build_list(child, 'label', label_mods)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
65 elif child.get('name') == 'proteases' and args.enzymes:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
66 build_list(child, 'proteases', enzymes_list)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
67
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
68 rough_string = ET.tostring(macros_root, 'utf-8')
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
69 reparsed = minidom.parseString(rough_string)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
70 pretty = reparsed.toprettyxml(indent=" ")
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
71 even_prettier = re.sub(r"\n\s+\n", r"\n", pretty)
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
72 with open('./macros.xml', 'w') as f:
8bac3cc5c5de planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit ab4e4f1817080cbe8a031a82cb180610ff140847
galaxyp
parents:
diff changeset
73 print(even_prettier, file=f)