9

I have created a workflow within snakemake, I Have a problem when I want to run just one rule. Indeed it runs for me the rules where the output is the input of my rule even if those one are already created before.

Example :

rule A:
 input A
 output A

rule b:
 input b = output A
 output b

rule c:
 input c = output b
 output c

How can I run just the rule C?

Dominique
  • 16,450
  • 15
  • 56
  • 112
BioManil
  • 91
  • 1
  • 1
  • 3
  • What is the command you use to run snakemake? It would be better if you could show us real example instead of pseudocode, as something could be wrong with the code. – Manavalan Gajapathy Apr 24 '19 at 14:37
  • By default snakemake runs only the first rule of a workflow. If its inputs are not available, it will look for other rules to produce them. – rioualen Apr 24 '19 at 16:59
  • 3
    Without a more specific example I can't really help, but you could experiment with `--until`. From the help for snakemake: `--until TARGET [TARGET ...], -U TARGET [TARGET ...] Runs the pipeline until it reaches the specified rules or files. Only runs jobs that are dependencies of the specified rule or files, does not run sibling DAGs.` – Russ Hyde Apr 25 '19 at 12:21
  • @JeeYem snakemake -p my_rule --config run-date=22_01_2019. my_rule take as an input an output of a previous rule(x) but in my case this output is already generated, and when I want to run my_rule he is starting from rule (x). – BioManil Apr 26 '19 at 09:27
  • @rioualen this is my issue, for me the inputs are available that's why I don't understand – BioManil Apr 26 '19 at 09:31
  • 1
    It appears something is wrong with the code. Seeing the actual code would help. – Manavalan Gajapathy Apr 26 '19 at 14:08

4 Answers4

7

You can used the --allowed-rules option.

snakemake --allowed-rules c

Snakemake will try to rerun upstream rules linked by the input/output chain to your downstream rule if the output file(s) of the upstream rule(s) have changed (including if they've been re-created but the content hasn't changed). This behavior makes Snakemake reproducible, but maybe isn't desirable if you're trying to debug a specific part of your pipeline and don't want to run all the intermediate steps.

See this discussion: https://bitbucket.org/snakemake/snakemake/issues/688/execute-specified-rule-only-and-not

vantom
  • 454
  • 4
  • 11
6

If there are dependencies, I have found that only --until works if you want to run rule C just run snakemake -R --until c. If there are assumed dependencies, like shared input or output paths, it will force you to run the upstream rules without the use of --until. Always run first with -n for a dry-run.

jimh
  • 1,651
  • 2
  • 15
  • 28
5

You just run:

snakemake -R b

To see what this will do in advance:

snakemake -R b -n

-R selects the one rule (and all its dependent rules also!), -n does a "dry run", it just prints what it would do without -n.

Freek
  • 1,097
  • 2
  • 12
  • 30
  • 5
    Is there a way to run the rule without running the dependent rules? For example, if I generate the input files outside of snakemake can I run a specific rule that takes these files as input? – helicase Oct 23 '19 at 20:26
  • 1
    I am using snakemake 5.16.0 and there does not seem to be a -R argument. – Phoenix Mu Jul 10 '20 at 18:10
  • 2
    This didn't work for me. I found that --until worked better. – Dan Bolser Sep 09 '20 at 15:05
  • --forcerun, -R: Force the re-execution or creation of the given rules or files. Use this option if you changed a rule and want to have all its output in your workflow updated. (Snakemake doc) – Muhammed Hasan Celik Feb 16 '21 at 07:10
-2

I think "--force" = "-f" is what is asked for here:

snakemake --force c
snakemake -f c

--force, -f Force the execution of the selected target or the first rule regardless of already created output. (default: False)
--forceall, -F Force the execution of the selected (or the first) rule and all rules it is dependent on regardless of already created output. (default: False)
--forcerun [TARGET ...], -R [TARGET ...] Force the re-execution or creation of the given rules or files. Use this option if you changed a rule and want to have all its output in your workflow updated. (default: None) )