diff 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
line wrap: on
line diff
--- a/mqparam.py	Sat Apr 11 11:50:09 2020 -0400
+++ b/mqparam.py	Fri Feb 19 21:25:06 2021 +0000
@@ -6,11 +6,12 @@
 import ntpath
 import os
 import re
-import yaml
 import xml.etree.ElementTree as ET
 from itertools import zip_longest
 from xml.dom import minidom
 
+import yaml
+
 
 def et_add_child(el, name, text, attrib=None):
     "Add a child element to an xml.etree.ElementTree.Element"
@@ -308,6 +309,23 @@
                              .format(key))
         node.text = str(value)
 
+    def set_list_param(self, key, values):
+        """Set a list parameter.
+        Args:
+            key: (string) XML tag of the parameter
+            values: the lit of values of the parameter XML node
+        Returns:
+            None
+        """
+        node = self._root.find(key)
+        if node is None:
+            raise ValueError('Element {} not found in parameter file'
+                             .format(key))
+        node.clear()
+        node.tag = key
+        for e in values:
+            et_add_child(node, name='string', text=e)
+
     def _from_yaml(self, conf):
         """Read a yaml config file.
         Args:
@@ -317,6 +335,7 @@
         """
         with open(conf) as f:
             conf_dict = yaml.safe_load(f.read())
+
         paramGroups = conf_dict.pop('paramGroups')
         self.add_infiles([pg.pop('files') for pg in paramGroups])
         for i, pg in enumerate(paramGroups):
@@ -325,8 +344,8 @@
                 self[i].set_silac(*silac)
             isobaricLabels = pg.pop('isobaricLabels', False)
             if isobaricLabels:
-                for l in isobaricLabels:
-                    self[i].set_isobaric_label(*l)
+                for ibl in isobaricLabels:
+                    self[i].set_isobaric_label(*ibl)
             for el in ['fixedModifications', 'variableModifications', 'enzymes']:
                 lst = pg.pop(el, None)
                 if lst is not None:
@@ -339,7 +358,10 @@
         else:
             raise Exception('No fasta files provided.')
         for key in conf_dict:
-            self.set_simple_param(key, conf_dict[key])
+            if key in ['restrictMods']:
+                self.set_list_param(key, conf_dict[key])
+            else:
+                self.set_simple_param(key, conf_dict[key])
 
     def write(self, mqpar_out):
         """Write pretty formatted xml parameter file.