comparison init.py @ 0:256cc0e17454 draft

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