Commits

Johannes Köster committed 75d4677 Merge with conflicts

Merge branch 'ruledeps'

Conflicts:
snakemake/workflow.py

Comments (0)

Files changed (5)

             if file in job.subworkflow_input:
                 continue
             try:
-                jobs = self.file2jobs(file)
+                if file in job.dependencies:
+                    jobs = [Job(job.dependencies[file], self, targetfile=file)]
+                else:
+                    jobs = self.file2jobs(file)
                 dependencies[file].extend(jobs)
             except MissingRuleException as ex:
                 pass

snakemake/jobs.py

             else Wildcards(fromdict=format_wildcards))
 
         (self.input, self.output, self.params,
-            self.log, self.ruleio) = rule.expand_wildcards(
+            self.log, self.ruleio, self.dependencies) = rule.expand_wildcards(
             self.wildcards_dict)
 
         self.resources = {

snakemake/rules.py

             self._input = InputFiles()
             self._output = OutputFiles()
             self._params = Params()
+            self.dependencies = dict()
             self.dynamic_output = set()
             self.dynamic_input = set()
             self.temp_output = set()
             self._input = other._input
             self._output = other._output
             self._params = other._params
+            self.dependencies = other.dependencies
             self.dynamic_output = other.dynamic_output
             self.dynamic_input = other.dynamic_input
             self.temp_output = other.temp_output
             non_dynamic_wildcards = dict(
                 (name, values[0])
                 for name, values in wildcards.items() if len(set(values)) == 1)
+            # TODO have a look into how to concretize dependencies here
             (
             branch._input,
             branch._output,
             branch._params,
             branch._log,
-            _) = branch.expand_wildcards(wildcards=non_dynamic_wildcards)
+            _, branch.dependencies) = branch.expand_wildcards(wildcards=non_dynamic_wildcards)
             return branch, non_dynamic_wildcards
         return branch
 
         """
         inoutput = self.output if output else self.input
         if isinstance(item, str):
+            # add the rule to the dependencies
+            if isinstance(item, _IOFile):
+                self.dependencies[item] = item.rule
             _item = IOFile(item, rule=self)
             if is_flagged(item, "temp"):
                 if not output:
                     inoutput.set_name(name, start, end=len(inoutput))
             except TypeError:
                 raise SyntaxError(
-                    "Input and output files have to be specified as strings.")
+                    "Input and output files have to be specified as strings or lists of strings.")
 
     @property
     def params(self):
             output = OutputFiles(
                 o.apply_wildcards(wildcards) for o in self.output)
             output.take_names(self.output.get_names())
+            
+            dependencies = {None if f is None else f.apply_wildcards(wildcards): rule for f, rule in self.dependencies.items()}
 
             ruleio.update(dict((f, f_) for f, f_ in zip(output, self.output)))
 
             log = self.log.apply_wildcards(wildcards) if self.log else None
-            return input, output, params, log, ruleio
+            return input, output, params, log, ruleio, dependencies
         except WildcardError as ex:
             # this can only happen if an input contains an unresolved wildcard.
             raise RuleException(

snakemake/scheduler.py

 
     def schedule(self):
         """ Schedule jobs that are ready, maximizing cpu usage. """
+        
         while True:
             try:
                 self._open_jobs.wait()
             except:
                 # this will be caused because of SIGTERM or SIGINT
+                logger.warning("Terminating processes on user request.")
                 self._executor.shutdown()
                 return False
             self._open_jobs.clear()

snakemake/workflow.py

         Include a snakefile.
         """
         global workflow
+        global rules
         workflow = self
+        rules = Rules()
         first_rule = self.first_rule
         if workdir:
             os.chdir(workdir)
             rule.shellcmd = ruleinfo.shellcmd
             ruleinfo.func.__name__ = "__{}".format(name)
             self.globals[ruleinfo.func.__name__] = ruleinfo.func
+            setattr(rules, name, rule)
             return ruleinfo.func
         return decorate
 
         self.log = None
         self.docstring = None
 
+
 class Subworkflow:
 
     def __init__(self, workflow, name, snakefile, workdir):
 
     def targets(self, dag):
         return [f for job in dag.jobs for f in job.subworkflow_input if job.subworkflow_input[f] is self]
+
+
+class Rules:
+    """ A namespace for rules so that they can be accessed via dot notation. """
+    pass