Example #1
0
def register_task_handler(obj, handler_obj, default_handler=None):
    """Register a module function represented as string in
    to a task handler.
    
    :param obj: the object to which the handler is registered
    :param handler_obj: the handler object to register
    :param default_handler: the default handler to fall back on

    :return: None
    """
    if not handler_obj:
        logging.warn("No handler object provided; skipping")
        return
    if not isinstance(handler_obj, IHandler):
        raise ValueError, "handler object must implement the IHandler interface"
    hdl = _load(handler_obj)
    if not hdl:
        return
    if handler_obj.label() in obj._handlers:
        old_hdl = obj._handlers[handler_obj.label()]
        if fullclassname(old_hdl) == fullclassname(hdl):
            logging.info("Handler object '{}' already registered in {}; skipping".format(fullclassname(hdl), obj))
            return
        else:
            logging.warn("Trying to reset already registered '{}' which is not supported".format(handler_obj.label()))
            return
    else:
        obj._handlers[handler_obj.label()] = hdl
Example #2
0
def register_task_handler(obj, handler_obj, default_handler=None):
    """Register a module function represented as string in
    to a task handler.
    
    :param obj: the object to which the handler is registered
    :param handler_obj: the handler object to register
    :param default_handler: the default handler to fall back on

    :return: None
    """
    if not handler_obj:
        logging.warn("No handler object provided; skipping")
        return
    if not isinstance(handler_obj, IHandler):
        raise ValueError, "handler object must implement the IHandler interface"
    hdl = _load(handler_obj)
    if not hdl:
        return
    if handler_obj.label() in obj._handlers:
        old_hdl = obj._handlers[handler_obj.label()]
        if fullclassname(old_hdl) == fullclassname(hdl):
            logging.info(
                "Handler object '{}' already registered in {}; skipping".
                format(fullclassname(hdl), obj))
            return
        else:
            logging.warn(
                "Trying to reset already registered '{}' which is not supported"
                .format(handler_obj.label()))
            return
    else:
        obj._handlers[handler_obj.label()] = hdl
Example #3
0
 def test_register_task_handler(self):
     obj = MergeSamFiles()
     obj._handlers = {}
     target_handler = RatatoskHandler(label="target_generator_handler", mod="test.test_handler.local_target_generator")
     self.assertEqual(obj._handlers, {})
     register_task_handler(obj, target_handler)
     self.assertEqual(fullclassname(obj._handlers['target_generator_handler']), "test.test_handler.local_target_generator")
Example #4
0
 def test_register_handler(self):
     backend.__handlers__ = {}
     target_handler = RatatoskHandler(
         label="target_generator_handler",
         mod="test.test_handler.local_target_generator")
     self.assertEqual(backend.__handlers__, {})
     register(target_handler)
     self.assertEqual(
         fullclassname(backend.__handlers__['target_generator_handler']),
         "test.test_handler.local_target_generator")
Example #5
0
 def test_register_task_handler(self):
     obj = MergeSamFiles()
     obj._handlers = {}
     target_handler = RatatoskHandler(
         label="target_generator_handler",
         mod="test.test_handler.local_target_generator")
     self.assertEqual(obj._handlers, {})
     register_task_handler(obj, target_handler)
     self.assertEqual(
         fullclassname(obj._handlers['target_generator_handler']),
         "test.test_handler.local_target_generator")
Example #6
0
 def requires(self):
     vcfcls = self.parent()[0]
     indexcls = ratatosk.lib.variation.tabix.Tabix
     return [
         cls(target=source)
         for cls, source in izip(self.parent(), self.source())
     ] + [
         indexcls(target=rreplace(self.source()[0],
                                  vcfcls().suffix,
                                  indexcls().suffix, 1),
                  parent_task=fullclassname(vcfcls))
     ]
Example #7
0
 def requires(self):
     """Task requirements. In many cases this is a single source
     whose name can be generated following the code below, and
     therefore doesn't need reimplementation in the subclasses."""
     bamcls = self.parent()[0]
     indexcls = ratatosk.lib.tools.samtools.Index
     return [bamcls(target=self.source()[0])] + [
         CombineVariants(
             target=os.path.join(self.outdir, "CombinedVariants.vcf"))
     ] + [
         indexcls(target=rreplace(self.source()[0],
                                  bamcls().sfx(),
                                  indexcls().sfx(), 1),
                  parent_task=fullclassname(bamcls))
     ]
Example #8
0
 def requires(self):
     """Task requirements. In many cases this is a single source
     whose name can be generated following the code below, and
     therefore doesn't need reimplementation in the subclasses."""
     bamcls = self.parent()[0]
     indexcls = ratatosk.lib.tools.samtools.Index
     return [
         cls(target=source)
         for cls, source in izip(self.parent(), self.source())
     ] + [
         indexcls(target=rreplace(self.source()[0],
                                  bamcls().sfx(),
                                  indexcls().sfx(), 1),
                  parent_task=fullclassname(bamcls))
     ]
Example #9
0
 def requires(self):
     cls = self.set_parent_task()
     source = self._make_source_file_name()
     # Ugly hack for 1 -> 2 dependency: works but should be dealt with otherwise
     if str(fullclassname(cls)) in ["ratatosk.lib.utils.misc.ResyncMatesJobTask"]:
         if re.search(self.read1_suffix, source):
             self.is_read1 = True
             fq1 = source
             fq2 = rreplace(source, self.read1_suffix, self.read2_suffix, 1)
         else:
             self.is_read1 = False
             fq1 = rreplace(source, self.read2_suffix, self.read1_suffix, 1)
             fq2 = source
         return cls(target=[fq1, fq2])
     else:
         return cls(target=source)
Example #10
0
 def requires(self):
     cls = self.parent()[0]
     source = self.source()[0]
     # Ugly hack for 1 -> 2 dependency: works but should be dealt with otherwise
     if str(fullclassname(cls)) in ["ratatosk.lib.utils.misc.ResyncMates"]:
         rt = determine_read_type(source, self.read1_suffix, self.read2_suffix)
         if rt == 1:
             self.is_read1 = True
             fq1 = source
             fq2 = rreplace(source, self.read1_suffix, self.read2_suffix, 1)
         elif rt == 2:
             self.is_read1 = False
             fq1 = rreplace(source, self.read2_suffix, self.read1_suffix, 1)
             fq2 = source
         retval = [cls(target=[fq1, fq2])]
     else:
         retval = [cls(target=source)]
     if len(self.parent()) > 1:
         retval += [cls(target=source) for cls, source in izip(self.parent()[1:], self.source()[1:])]
     return retval
Example #11
0
 def requires(self):
     """Task requirements. In many cases this is a single source
     whose name can be generated following the code below, and
     therefore doesn't need reimplementation in the subclasses."""
     bamcls = self.parent()[0]
     indexcls = ratatosk.lib.tools.samtools.Index
     return [bamcls(target=self.source()[0])]  + [CombineVariants(target=os.path.join(self.outdir, "CombinedVariants.vcf"))] + [indexcls(target=rreplace(self.source()[0], bamcls().sfx(), indexcls().sfx(), 1), parent_task=fullclassname(bamcls))]
Example #12
0
 def test_register_handler(self):
     backend.__handlers__ = {}
     target_handler = RatatoskHandler(label="target_generator_handler", mod="test.test_handler.local_target_generator")
     self.assertEqual(backend.__handlers__, {})
     register(target_handler)
     self.assertEqual(fullclassname(backend.__handlers__['target_generator_handler']), "test.test_handler.local_target_generator")
Example #13
0
 def requires(self):
     """Task requirements. In many cases this is a single source
     whose name can be generated following the code below, and
     therefore doesn't need reimplementation in the subclasses."""
     bamcls = self.parent()[0]
     indexcls = ratatosk.lib.tools.samtools.Index
     return [cls(target=source) for cls, source in izip(self.parent(), self.source())] + [indexcls(target=rreplace(self.source()[0], bamcls().sfx(), indexcls().sfx(), 1), parent_task=fullclassname(bamcls))]
Example #14
0
 def requires(self):
     cls = self.set_parent_task()
     source = self._make_source_file_name()
     return [cls(target=source), ratatosk.lib.tools.samtools.IndexBam(target=rreplace(source, self.source_suffix, ".bai", 1), parent_task=fullclassname(cls))]
Example #15
0
 def requires(self):
     vcfcls = self.parent()[0]
     indexcls = ratatosk.lib.variation.tabix.Tabix
     return [cls(target=source) for cls, source in izip(self.parent(), self.source())] + [indexcls(target=rreplace(self.source()[0], vcfcls().suffix, indexcls().suffix, 1), parent_task=fullclassname(vcfcls))]
Example #16
0
 def requires(self):
     zipcls = ratatosk.lib.variation.tabix.Bgzip
     indexcls = ratatosk.lib.variation.tabix.Tabix
     return [zipcls(target=self.source()[0]), 
                    indexcls(target=rreplace(self.source()[0], zipcls().sfx(), indexcls().sfx(), 1),
                             parent_task=fullclassname(zipcls))]