Use a logger initialized to the module name much more consistently.
[htsworkflow.git] / htsworkflow / pipelines / genome_mapper.py
index 5ae788e07089fde076d8afe8f56995f42978f7e5..fb16d7ffc60ed70ce11c10b4a204316de9e3f37e 100644 (file)
@@ -8,6 +8,7 @@ import logging
 
 from htsworkflow.util.alphanum import alphanum
 
+LOGGER = logging.getLogger(__name__)
 class DuplicateGenome(Exception): pass
 
 
@@ -22,7 +23,7 @@ def getAvailableGenomes(genome_base_dir):
   """
   raises IOError (on genome_base_dir not found)
   raises DuplicateGenome on duplicate genomes found.
-  
+
   returns a double dictionary (i.e. d[species][build] = path)
   """
 
@@ -52,8 +53,8 @@ def getAvailableGenomes(genome_base_dir):
     try:
       species, build = line.split('|')
     except:
-      logging.warning('Skipping: Invalid metafile (%s) line: %s' \
-                      % (metafile, line))
+      LOGGER.warning('Skipping: Invalid metafile (%s) line: %s' \
+                     % (metafile, line))
       continue
 
     build_dict = d.setdefault(species, {})
@@ -64,12 +65,12 @@ def getAvailableGenomes(genome_base_dir):
     build_dict[build] = genome_dir
 
   return d
-  
+
 
 class constructMapperDict(object):
     """
     Emulate a dictionary to map genome|build names to paths.
-    
+
     It uses the dictionary generated by getAvailableGenomes.
     """
     def __init__(self, genome_dict):
@@ -80,19 +81,19 @@ class constructMapperDict(object):
         Return the best match for key
         """
         elements = re.split("\|", key)
-        
+
         if len(elements) == 1:
           # we just the species name
           # get the set of builds
           builds = self.genome_dict[elements[0]]
-            
+
           # sort build names the way humans would
           keys = builds.keys()
           keys.sort(cmp=alphanum)
-          
+
           # return the path from the 'last' build name
           return builds[keys[-1]]
-                        
+
         elif len(elements) == 2:
           # we have species, and build name
           return self.genome_dict[elements[0]][elements[1]]
@@ -104,21 +105,21 @@ class constructMapperDict(object):
         return self[key]
       except KeyError, e:
         return default
-      
+
     def keys(self):
         keys = []
         for species in self.genome_dict.keys():
             for build in self.genome_dict[species]:
                 keys.append([species+'|'+build])
         return keys
-            
+
     def values(self):
         values = []
         for species in self.genome_dict.keys():
             for build in self.genome_dict[species]:
                 values.append(self.genome_dict[species][build])
         return values
-       
+
     def items(self):
         items = []
         for species in self.genome_dict.keys():
@@ -127,7 +128,7 @@ class constructMapperDict(object):
                 value = self.genome_dict[species][build]
                 items.append((key, value))
         return items
-            
+
 if __name__ == '__main__':
 
   if len(sys.argv) != 2:
@@ -139,5 +140,5 @@ if __name__ == '__main__':
 
   for k,v in d2.items():
     print '%s: %s' % (k,v)
-  
-  
+
+