确实,如果Snakemake有一个标志可以查找缺失的中间结果并在缺失时重新生成它们(以及所有依赖项),那将是很好的(但目前没有这样的选项)。
注意,m00am和Jon Chung建议使用-R
选项会重新生成所有其他文件,而不管中间文件是否缺失。因此这并不理想。
解决方法1:强制重新创建文件
使用-R
或-f
标志强制重新创建中间文件(下面是帮助信息)。关键在于明确地指定目标文件,而不是规则。
snakemake -s test.sf testA1.txt
snakemake -s test.sf -R testA1.txt
snakemake -s test.sf -f testA1.txt
snakemake -s test.sf -F testA1.txt
请注意,对于后两个,需要重新运行管道以更新依赖项:
snakemake -s test.sf
防止更新相关文件(通过触碰文件)
如果您不希望更新相关文件(即testB1.txt,testC1.txt),也有选项可用。
您可以重新生成testA1.txt,然后“重置”其修改时间,例如设置为源文件的修改时间,这将防止管道更新任何内容:
snakemake -s test.sf -f testA1.txt
touch testA1.txt -r test1.txt
snakemake -s test.sf
现在不会执行任何操作,因为testB1.txt
比testA1.txt
新。
或者您可以使用--touch
标记依赖文件(即testB1.txt,testC1.txt)为“较新”:
snakemake -s test.sf -f testA1.txt
snakemake -s test.sf --touch
解决方法2:创建新规则
可以通过创建新规则来扩展snakefile:
rule A_all:
input: "testA1.txt", "testA2.txt"
然后可以像这样调用:
snakemake A_all -s test.sf
这将只生成
testA1.txt
,类似于上面的工作流中的
-f
,因此需要重新运行管道或更改修改时间。一个技巧是使用
--touch
“更新”中间文件。
snakemake -s test.sf --touch testA1.txt -n
这将“更新”testA1.txt
。重新创建依赖文件需要之后正常运行snakemake:
snakemake -s test.sf
请注意,如果删除了testA1.txt
,这将无法起作用,需要执行以下操作代替删除。
相关参数的帮助信息:
--touch, -t Touch output files (mark them up to date without
really changing them) instead of running their
commands. This is used to pretend that the rules were
executed, in order to fool future invocations of
snakemake. Fails if a file does not yet exist.
--force, -f Force the execution of the selected target or the
first rule regardless of already created output.
--forceall, -F Force the execution of the selected (or the first)
rule and all rules it is dependent on regardless of
already created output.
--forcerun [TARGET [TARGET ...]], -R [TARGET [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.