Recent IPAR xml config blocks include the runfolder name
[htsworkflow.git] / htsworkflow / pipelines / ipar.py
index b7d5a54071ad15ec3cfe1e649abbc9291b24b0a9..8203f5e0f29fda173728e3f504522f6cd579520f 100644 (file)
@@ -1,7 +1,7 @@
 """
 Extract information about the IPAR run
 
-IPAR 
+IPAR
     class holding the properties we found
 ipar
     IPAR factory function initalized from a directory name
@@ -19,11 +19,12 @@ import re
 import stat
 import time
 
-from htsworkflow.pipelines.runfolder import \
+from htsworkflow.pipelines import \
    ElementTree, \
    VERSION_RE, \
    EUROPEAN_STRPTIME
 
+LOGGER = logging.getLogger(__name__)
 SOFTWARE_NAMES = ('IPAR_1.01', 'IPAR_1.3', 'Intensities')
 
 class Tiles(object):
@@ -70,10 +71,31 @@ class IPAR(object):
     def __init__(self, xml=None):
         self.tree = None
         self.date = datetime.datetime.today()
-       self._tiles = None
+        self._tiles = None
         if xml is not None:
             self.set_elements(xml)
 
+    def _get_runfolder_name(self):
+        """Return runfolder name"""
+        if self.tree is None:
+            raise ValueError("Can't query an empty run")
+        runfolder = self.tree.xpath('RunParameters/Runfolder')
+        return runfolder
+    runfolder_name = property(_get_runfolder)
+    
+    def _get_software(self):
+        """Return software name"""
+        if self.tree is None:
+            raise ValueError("Can't determine software name, please load a run")
+        software = self.tree.xpath('Software')
+        if len(software) == 0:
+          return None
+        elif len(software) > 1:
+            raise RuntimeError("Too many software tags, please update ipar.py")
+        else:
+            return software[0].attrib['Name']
+    software = property(_get_software)
+
     def _get_time(self):
         return time.mktime(self.date.timetuple())
     def _set_time(self, value):
@@ -163,7 +185,7 @@ class IPAR(object):
             raise ValueError('Expected "IPAR" SubElements')
         xml_version = int(tree.attrib.get('version', 0))
         if xml_version > IPAR.XML_VERSION:
-            logging.warn('IPAR XML tree is a higher version than this class')
+            LOGGER.warn('IPAR XML tree is a higher version than this class')
         for element in list(tree):
             if element.tag == IPAR.RUN:
                 self.tree = element
@@ -184,14 +206,14 @@ def load_ipar_param_tree(paramfile):
     if run.attrib.has_key('Name') and run.attrib['Name'] in SOFTWARE_NAMES:
         return run
     else:
-        logging.info("No run found")
+        LOGGER.info("No run found")
         return None
 
 def ipar(pathname):
     """
     Examine the directory at pathname and initalize a IPAR object
     """
-    logging.info("Searching IPAR directory %s" % (pathname,))
+    LOGGER.info("Searching IPAR directory %s" % (pathname,))
     i = IPAR()
     i.pathname = pathname
 
@@ -212,11 +234,12 @@ def ipar(pathname):
         # its still live.
 
     # look for parameter xml file
-    paramfiles = [os.path.join(pathname, 'config.xml'),
+    paramfiles = [os.path.join(pathname, 'RTAConfig.xml'),
+                  os.path.join(pathname, 'config.xml'),
                   os.path.join(path, '.params')]
     for paramfile in paramfiles:
         if os.path.exists(paramfile):
-            logging.info("Found IPAR Config file at: %s" % ( paramfile, ))
+            LOGGER.info("Found IPAR Config file at: %s" % ( paramfile, ))
             i.tree = load_ipar_param_tree(paramfile)
             mtime_local = os.stat(paramfile)[stat.ST_MTIME]
             i.time = mtime_local