Search code examples
slurmsnakemakesbatch

Snakemake and sbatch


I have a Snakefile that has a rule which sends 7 different shell commands. I want to run each of these shell commands in sbatch and I want them to run in different slurm nodes. Right now when I include sbatch inside the shell command in the Snakemake rule I do not get the desired output file because it takes awhile to run and when sbatch returns the command is still running. I think Snakemake thinks that I don't have the required output file because it thinks that the command "finished executing" before the submitted job completed.

What can I do to submit each rule in one slurm node using sbatch command in Snakemake file


Solution

  • I suspect that what you are doing is:

    rule one:
        input:
            ...
        output:
            ...
        shell:
            """
            sbatch [sbatch-options] "some-command-or-script"
            """
    

    What you want maybe is:

    rule one:
        input:
            ...
        output:
            ...
        shell:
            """
            some-command-or-script
            """
    

    To be executed as

    snakemake --cluster "sbatch [sbatch-options]"
    

    In this way every rule will send its jobs to the cluster and snakemake will handle them. If you want a rule to execute its jobs locally (not via sbatch) mark that rule with the directive localrule (check documentation for more detail)