Initial port to python3
[htsworkflow.git] / htsworkflow / pipelines / sequences.py
index acd100575744c94984d7b4b1ab5074188145844e..0a3c2fd61e856f04c9872600bc8f4025cc4ba6f4 100644 (file)
@@ -7,7 +7,7 @@ import os
 import types
 import re
 import sys
-from urlparse import urljoin, urlparse
+from urllib.parse import urljoin, urlparse
 
 import RDF
 from htsworkflow.util.rdfhelp import libraryOntology as libNS
@@ -84,7 +84,7 @@ class SequenceFile(object):
         return (self.flowcell, self.lane, self.read, self.project, self.split)
 
     def __unicode__(self):
-        return unicode(self.path)
+        return str(self.path)
 
     def __eq__(self, other):
         """
@@ -109,7 +109,7 @@ class SequenceFile(object):
         return not self == other
 
     def __repr__(self):
-        return u"<%s %s %s %s>" % (self.filetype, self.flowcell, self.lane, self.path)
+        return "<%s %s %s %s>" % (self.filetype, self.flowcell, self.lane, self.path)
 
     def make_target_name(self, root):
         """
@@ -206,8 +206,8 @@ class SequenceFile(object):
         def get_one(s, p):
             values = get(s, p)
             if len(values) > 1:
-                errmsg = u"To many values for %s %s"
-                raise ValueError(errmsg % (unicode(s), unicode(p)))
+                errmsg = "To many values for %s %s"
+                raise ValueError(errmsg % (str(s), str(p)))
             elif len(values) == 1:
                 return values[0]
             else:
@@ -219,7 +219,7 @@ class SequenceFile(object):
                                          rdfNS['type'],
                                          libNS['IlluminaResult'])
         if not model.contains_statement(result_statement):
-            raise KeyError(u"%s not found" % (unicode(seq_id),))
+            raise KeyError("%s not found" % (str(seq_id),))
 
         seq_type_node = model.get_target(seq_id, libNS['file_type'])
         seq_type = stripNamespace(libNS, seq_type_node)
@@ -376,7 +376,7 @@ def scan_for_sequences(dirs):
     Scan through a list of directories for sequence like files
     """
     sequences = []
-    if type(dirs) in types.StringTypes:
+    if type(dirs) in str:
         raise ValueError("You probably want a list or set, not a string")
 
     for d in dirs:
@@ -453,6 +453,10 @@ def update_model_sequence_library(model, base_url):
                 library = guess_library_from_model(model, base_url,
                                                    flowcell,
                                                    lane_id)
+                if library is None:
+                    LOGGER.error("Unable to decypher: %s %s",
+                                 str(flowcell), str(lane_id))
+                    continue
                 library_id = toTypedNode(simplify_uri(library))
                 LOGGER.debug("Adding file (%s) to library (%s) link",
                              str(filenode),
@@ -478,11 +482,13 @@ def guess_library_from_model(model, base_url, flowcell, lane_id):
     where {{
       <{flowcell}> libns:has_lane ?lane ;
                    a libns:IlluminaFlowcell .
-      ?lane libns:lane_number "{lane_id}" ;
+      ?lane libns:lane_number ?lane_id ;
             libns:library ?library .
+      FILTER(str(?lane_id) = "{lane_id}")
     }}
     """
     lane_body = lane_body.format(flowcell=flowcell, lane_id=lane_id)
+    LOGGER.debug("guess_library_from_model: %s", lane_body)
     lanes = []
     tries = 3
     while len(lanes) == 0 and tries > 0:
@@ -503,5 +509,3 @@ def guess_library_from_model(model, base_url, flowcell, lane_id):
         else:
             # try grabbing data
             model.load(flowcellNode.uri, name="rdfa")
-
-