Don't attempt to save xml for a matrix in firecrest if it wasn't created.
[htsworkflow.git] / htsworkflow / pipelines / firecrest.py
index 4fbde5d517ac661cfecd68ff8ab2fff2472f5d9f..e8d0a2898c0c4d5621732a2fd0abdb5778dcdfd1 100644 (file)
@@ -1,13 +1,17 @@
 """
 Extract information about the Firecrest run
 
-Firecrest - class holding the properties we found
-firecrest - Firecrest factory function initalized from a directory name
-fromxml - Firecrest factory function initalized from an xml dump from
-          the Firecrest object.
+Firecrest 
+  class holding the properties we found
+firecrest 
+  Firecrest factory function initalized from a directory name
+fromxml 
+  Firecrest factory function initalized from an xml dump from
+  the Firecrest object.
 """
 
 from datetime import date
+from glob import glob
 import os
 import re
 import time
@@ -17,6 +21,8 @@ from htsworkflow.pipelines.runfolder import \
    VERSION_RE, \
    EUROPEAN_STRPTIME
 
+__docformat__ = "restructuredtext en"
+
 class Firecrest(object):
     XML_VERSION=1
 
@@ -64,8 +70,9 @@ class Firecrest(object):
         run_date.text = str(self.time)
         user = ElementTree.SubElement(root, Firecrest.USER)
         user.text = self.user
-        matrix = ElementTree.SubElement(root, Firecrest.MATRIX)
-        matrix.text = self.matrix
+        if self.matrix is not None:
+            matrix = ElementTree.SubElement(root, Firecrest.MATRIX)
+            matrix.text = self.matrix
         return root
 
     def set_elements(self, tree):
@@ -112,12 +119,19 @@ def firecrest(pathname):
     # username
     f.user = groups[3]
 
+    bustard_pattern = os.path.join(pathname, 'Bustard*')
     # should I parse this deeper than just stashing the 
     # contents of the matrix file?
     matrix_pathname = os.path.join(pathname, 'Matrix', 's_matrix.txt')
-    if not os.path.exists(matrix_pathname):
+    if os.path.exists(matrix_pathname):
+        # this is for firecrest < 1.3.2
+        f.matrix = open(matrix_pathname, 'r').read()
+    elif glob(bustard_pattern) > 0:
+        f.matrix = None
+        # there are runs here. Bustard should save the matrix.
+    else:
         return None
-    f.matrix = open(matrix_pathname, 'r').read()
+
     return f
 
 def fromxml(tree):