comparison mqparam.py @ 4:9cb7dcc07dae draft default tip

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit 5e4f8567c0145de8c6f9344fe4ee4c3bf2a81e59"
author galaxyp
date Fri, 19 Feb 2021 21:25:06 +0000
parents 2d67fb758956
children
comparison
equal deleted inserted replaced
3:2d67fb758956 4:9cb7dcc07dae
4 4
5 import copy 5 import copy
6 import ntpath 6 import ntpath
7 import os 7 import os
8 import re 8 import re
9 import yaml
10 import xml.etree.ElementTree as ET 9 import xml.etree.ElementTree as ET
11 from itertools import zip_longest 10 from itertools import zip_longest
12 from xml.dom import minidom 11 from xml.dom import minidom
12
13 import yaml
13 14
14 15
15 def et_add_child(el, name, text, attrib=None): 16 def et_add_child(el, name, text, attrib=None):
16 "Add a child element to an xml.etree.ElementTree.Element" 17 "Add a child element to an xml.etree.ElementTree.Element"
17 child = ET.SubElement(el, name, attrib=attrib if attrib else {}) 18 child = ET.SubElement(el, name, attrib=attrib if attrib else {})
306 if node is None: 307 if node is None:
307 raise ValueError('Element {} not found in parameter file' 308 raise ValueError('Element {} not found in parameter file'
308 .format(key)) 309 .format(key))
309 node.text = str(value) 310 node.text = str(value)
310 311
312 def set_list_param(self, key, values):
313 """Set a list parameter.
314 Args:
315 key: (string) XML tag of the parameter
316 values: the lit of values of the parameter XML node
317 Returns:
318 None
319 """
320 node = self._root.find(key)
321 if node is None:
322 raise ValueError('Element {} not found in parameter file'
323 .format(key))
324 node.clear()
325 node.tag = key
326 for e in values:
327 et_add_child(node, name='string', text=e)
328
311 def _from_yaml(self, conf): 329 def _from_yaml(self, conf):
312 """Read a yaml config file. 330 """Read a yaml config file.
313 Args: 331 Args:
314 conf: (string) path to the yaml conf file 332 conf: (string) path to the yaml conf file
315 Returns: 333 Returns:
316 None 334 None
317 """ 335 """
318 with open(conf) as f: 336 with open(conf) as f:
319 conf_dict = yaml.safe_load(f.read()) 337 conf_dict = yaml.safe_load(f.read())
338
320 paramGroups = conf_dict.pop('paramGroups') 339 paramGroups = conf_dict.pop('paramGroups')
321 self.add_infiles([pg.pop('files') for pg in paramGroups]) 340 self.add_infiles([pg.pop('files') for pg in paramGroups])
322 for i, pg in enumerate(paramGroups): 341 for i, pg in enumerate(paramGroups):
323 silac = pg.pop('labelMods', False) 342 silac = pg.pop('labelMods', False)
324 if silac: 343 if silac:
325 self[i].set_silac(*silac) 344 self[i].set_silac(*silac)
326 isobaricLabels = pg.pop('isobaricLabels', False) 345 isobaricLabels = pg.pop('isobaricLabels', False)
327 if isobaricLabels: 346 if isobaricLabels:
328 for l in isobaricLabels: 347 for ibl in isobaricLabels:
329 self[i].set_isobaric_label(*l) 348 self[i].set_isobaric_label(*ibl)
330 for el in ['fixedModifications', 'variableModifications', 'enzymes']: 349 for el in ['fixedModifications', 'variableModifications', 'enzymes']:
331 lst = pg.pop(el, None) 350 lst = pg.pop(el, None)
332 if lst is not None: 351 if lst is not None:
333 self[i].set_list_param(el, lst) 352 self[i].set_list_param(el, lst)
334 for key in pg: 353 for key in pg:
337 if fastafiles: 356 if fastafiles:
338 self.add_fasta_files(fastafiles, parse_rules=conf_dict.pop('parseRules', {})) 357 self.add_fasta_files(fastafiles, parse_rules=conf_dict.pop('parseRules', {}))
339 else: 358 else:
340 raise Exception('No fasta files provided.') 359 raise Exception('No fasta files provided.')
341 for key in conf_dict: 360 for key in conf_dict:
342 self.set_simple_param(key, conf_dict[key]) 361 if key in ['restrictMods']:
362 self.set_list_param(key, conf_dict[key])
363 else:
364 self.set_simple_param(key, conf_dict[key])
343 365
344 def write(self, mqpar_out): 366 def write(self, mqpar_out):
345 """Write pretty formatted xml parameter file. 367 """Write pretty formatted xml parameter file.
346 Compose it from global parameters and parameter Groups. 368 Compose it from global parameters and parameter Groups.
347 """ 369 """