Commits

Johannes Köster committed 41a7219

Allow to define the jobname.

Comments (0)

Files changed (5)

snakemake/__init__.py

     quiet=False,
     keepgoing=False,
     cluster=None,
+    jobname="snakejob.{rulename}.{jobid}.sh",
     immediate_submit=False,
     standalone=False,
     ignore_ambiguity=False,
                         quiet=quiet,
                         keepgoing=keepgoing,
                         cluster=cluster,
+                        jobname=jobname,
                         immediate_submit=immediate_submit,
                         standalone=standalone,
                         ignore_ambiguity=ignore_ambiguity,
                         prioritytargets=prioritytargets, quiet=quiet,
                         keepgoing=keepgoing, printshellcmds=printshellcmds,
                         printreason=printreason, printrulegraph=printrulegraph,
-                        printdag=printdag, cluster=cluster,
+                        printdag=printdag, cluster=cluster, jobname=jobname,
                         immediate_submit=immediate_submit,
                         ignore_ambiguity=ignore_ambiguity,
                         workdir=workdir, stats=stats,
             "The default script resides as 'jobscript.sh' in the "
             "installation directory.")
     parser.add_argument(
+        "--jobname", "--jn", default="snakejob.{rulename}.{jobid}.sh", metavar="NAME",
+        help="Provide a custom name for the jobscript that is submitted to the cluster (see --cluster)."
+        "NAME is \"snakejob.{rulename}.{jobid}.sh\" per default. The wildcards {rulename} and {jobid} have to be present in the name.")
+    parser.add_argument(
         "--reason", "-r", action = "store_true",
         help="Print the reason for each executed rule.")
     parser.add_argument(
             quiet=args.quiet,
             keepgoing=args.keep_going,
             cluster=args.cluster,
+            jobname=args.jobname,
             immediate_submit=args.immediate_submit,
             standalone=True,
             ignore_ambiguity=args.allow_ambiguity,

snakemake/executors.py

 from snakemake.logging import logger
 from snakemake.stats import Stats
 from snakemake.utils import format, Unformattable
+from snakemake.io import get_wildcard_names
 from snakemake.exceptions import print_exception, get_exception_origin
 from snakemake.exceptions import format_error, RuleException
 from snakemake.exceptions import ClusterJobException, ProtectedOutputException, WorkflowError
 class ClusterExecutor(RealExecutor):
 
     def __init__(
-        self, workflow, dag, cores, submitcmd="qsub",
+        self, workflow, dag, cores, submitcmd="qsub", jobname="snakejob.{rulename}.{jobid}.sh",
         printreason=False, quiet=False, printshellcmds=False, output_wait=3):
         super().__init__(
             workflow, dag, printreason=printreason, quiet=quiet,
         except IOError as e:
             raise WorkflowError(e)
 
+        if not "jobid" in get_wildcard_names(jobname):
+            raise WorkflowError("Defined jobname (\"{}\") has to contain the wildcard {jobid}.")
+
         self.submitcmd = submitcmd
+        self.jobname = jobname
         self.threads = []
         self._tmpdir = None
         self.cores = cores if cores else ""
         return os.path.abspath(self._tmpdir)
 
     def get_jobscript(self, job):
-        return os.path.join(self.tmpdir, "snakejob.{}.{}.sh".format(job.rule.name, self.dag.jobid(job)))
+        return os.path.join(self.tmpdir, self.jobname.format(rulename=job.rule.name, jobid=self.dag.jobid(job)))
 
 
 def run_wrapper(run, input, output, params, wildcards, threads, resources, log, linemaps):
             rule=self.rule)
 
     def get_wildcard_names(self):
-        return set(match.group('name') for match in
-            _wildcard_regex.finditer(self.file))
+        return get_wildcard_names(self.file)
 
     def contains_wildcard(self):
         return contains_wildcard(self.file)
     "\{\s*(?P<name>\w+?)(\s*,\s*(?P<constraint>[^\}]*))?\s*\}")
 
 
+def get_wildcard_names(pattern):
+    return set(match.group('name') for match in
+            _wildcard_regex.finditer(pattern))
+
+
 def contains_wildcard(path):
     return _wildcard_regex.search(path) is not None
 

snakemake/scheduler.py

         dryrun=False,
         touch=False,
         cluster=None,
+        jobname=None,
         immediate_submit=False,
         quiet=False,
         printreason=False,
                 threads=use_threads,
                 output_wait=output_wait)
             self._executor = ClusterExecutor(
-                workflow, dag, None, submitcmd=cluster,
+                workflow, dag, None, submitcmd=cluster, jobname=jobname,
                 printreason=printreason, quiet=quiet,
                 printshellcmds=printshellcmds, output_wait=output_wait)
             if immediate_submit:

snakemake/workflow.py

         forcetargets=False, forceall=False, forcerun=None,
         prioritytargets=None, quiet=False, keepgoing=False,
         printshellcmds=False, printreason=False, printdag=False,
-        cluster=None, immediate_submit=False, ignore_ambiguity=False,
+        cluster=None, jobname=None, immediate_submit=False, ignore_ambiguity=False,
         workdir=None, printrulegraph=False,
         stats=None, force_incomplete=False, ignore_incomplete=False,
         list_version_changes=False, list_code_changes=False,
 
         scheduler = JobScheduler(
             self, dag, cores, dryrun=dryrun, touch=touch, cluster=cluster,
-            immediate_submit=immediate_submit,
+            jobname=jobname, immediate_submit=immediate_submit,
             quiet=quiet, keepgoing=keepgoing,
             printreason=printreason, printshellcmds=printshellcmds,
             output_wait=output_wait)