标签: snakemake

如何避免在输入或中间输出文件更新后运行 Snakemake 规则

即使 Snakemake 构建的输出文件已经存在,Snakemake 也希望重新运行我的整个管道,因为我修改了第一个输入或中间输出文件之一。

我通过做一个 Snakemake 空运行来解决-n这个问题,它为更新的输入文件提供了以下报告:

Reason: Updated input files: input-data.csv
Run Code Online (Sandbox Code Playgroud)

以及此消息用于更新中间文件

reason: Input files updated by another job: intermediary-output.csv
Run Code Online (Sandbox Code Playgroud)

如何强制 Snakemake 忽略文件更新?

workflow caching file build snakemake

13
推荐指数
2
解决办法
1614
查看次数

建议使用shell()执行多个shell命令的方法

在snakemake中,使用shell()函数执行多个命令的推荐方法是什么?

shell snakemake

11
推荐指数
1
解决办法
3641
查看次数

文件丢失时 SnakeMake 是否可以强制重新运行规则

当删除管道中较早创建的文件时,SnakeMake 似乎并不认为这是一个问题,只要后面的文件还在:

rule All:
    input: "testC1.txt", "testC2.txt"

rule A:
    input: "{X}{Y}.txt"
    output: "{X}A{Y}.txt"
    shell: "cp {input} {output}"

rule B:
    input: "{X}A{Y}.txt"
    output: "{X}B{Y}.txt"
    shell: "cp {input} {output}"

rule C:
    input: "{X}B{Y}.txt"
    output: "{X}C{Y}.txt"
    shell: "cp {input} {output}"
Run Code Online (Sandbox Code Playgroud)

将此 SnakeFile 保存在 test.sf 中并执行以下操作:

rm testA*.txt testB*.txt testC*.txt
echo "test1" >test1.txt
echo "test2" >test2.txt
snakemake -s test.sf
# Rerun:
snakemake -s test.sf
# SnakeMake says all is up to date, which it is.
# Remove intermediate results:
rm testA1.txt
# Rerun:
snakemake …
Run Code Online (Sandbox Code Playgroud)

delete-file snakemake

8
推荐指数
2
解决办法
3116
查看次数

Snakemake 在集群(slurm)取消作业时挂起

也许答案对许多人来说是显而易见的,但我很惊讶我找不到关于这个主题的问题,这对我来说是一个主要问题。我将不胜感激提示!

在由 slurm 管理的集群上提交作业时,如果队列管理器取消作业(例如,资源或时间不足),snakemake 似乎没有收到任何信号,并且永远挂起。另一方面,当作业失败时,snakemake 也会失败,正如预期的那样。这种行为是正常的/想要的吗?当工作被取消时,我怎么能让蛇制作失败?我在 3.13.3 版中遇到了这个问题,它仍然更新到 5.3.0。

例如,在这种情况下,我启动了一个简单的管道,但没有足够的资源用于规则 pluto:

$ snakemake -j1 -p --cluster 'sbatch --mem {resources.mem}' pluto.txt
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cluster nodes: 1
Unlimited resources: mem
Job counts:
    count   jobs
    1       pippo
    1       pluto
    2

[Tue Sep 25 16:04:21 2018]
rule pippo:
    output: pippo.txt
    jobid: 1
    resources: mem=1000

seq 1000000 | shuf > pippo.txt
Submitted job 1 with external jobid 'Submitted batch job 4776582'.
[Tue Sep 25 16:04:31 2018]
Finished job 1. …
Run Code Online (Sandbox Code Playgroud)

jobs cancellation slurm snakemake

8
推荐指数
1
解决办法
743
查看次数

Snakemake temp() 导致不必要的规则重新运行

我正在使用 Snakemake v 5.4.0,并且遇到了 temp() 的问题。在假设的场景中:

Rule A --> Rule B1 --> Rule C1
     |
      --> Rule B2 --> Rule C2 

where Rule A generates temp() files used by both pathways 1 (B1 + C1) and 2 (B2 + C2).
Run Code Online (Sandbox Code Playgroud)

如果我运行管道,由 RuleA 生成的 temp() 文件将在两个路径中使用后被删除,这正是我所期望的。但是,如果我随后想要重新运行 Pathway 2,则必须重新创建 RuleA 的 temp() 文件,这会触发整个管道的重新运行,而不仅仅是 Pathway2。对于长管道来说,这在计算上变得非常昂贵。除了不使用 之外,还有什么好方法可以防止这种情况发生吗temp()?在我的情况下,这需要很多 TB 的额外硬盘空间?

snakemake

8
推荐指数
1
解决办法
822
查看次数

在 AWS Batch 中使用 Snakemake 工作流程

我想问 Snakemake 社区是否有人在 AWS Batch 中成功实施了 Snakemake 工作流程。

2018 年 10 月最近发布的第 4 页似乎表明 Snakemake 无法在 AWS 上运行,因为它无法处理资源管理。这是出版物:Tibanna:用于在云上可扩展执行便携式管道的软件- https://www.biorxiv.org/content/early/2019/04/29/440974.full.pdf

是的,同一篇论文确实表明 Snakemake 可以很好地与 Google Cloud Platform (GCP) 配合使用。

但是,Snakemake 文档指出:“Snakemake 4.0 及更高版本支持通过 Kubernetes 在云中执行。这与云提供商无关。” - https://snakemake.readthedocs.io/en/stable/executable.html#cloud-support

因此,我想知道是否有人使用 AWS Batch 实施了 Snakemake。

另外,在这个问题上,有没有人知道任何 github/bitbucket 页面详细说明了 Snakemake 与 GCP 的成功实现。

提前致谢。

snakemake aws-batch

8
推荐指数
1
解决办法
878
查看次数

Snakemake 有没有办法像 GNU Make 中的 `eval` 那样评估动态 Snakefile 结构?

我希望在我的 Snakemake 工作流程中拥有各种动态“快捷方式”(规则名称),而不需要标记文件。我想到的方法与evalGNU Make 中的方法类似,但 Snakemake 似乎无法评估 Snakefile 语法中的变量扩展代码。有办法做到这一点吗?

这是一个简化的示例 Snakefile。我想要一个与每个输出“阶段”相对应的规则名称,现在我必须手动定义它们。想象一下,如果我有更多“阶段”和“步骤”,并且希望有一个规则,如果我添加这些阶段,可以生成所有“b”、“d”或“z”文件。动态定义规则名称比定义每次添加新阶段时更新的每个组合要简洁得多。

stages = ['a', 'b']
steps = [1, 2]

rule all:
    input:
        expand('{stage}{step}_file', stage=stages, step=steps)

rule:
    output:
        touch('{stage}{step}_file')

# Can these two be combined so that I don't have to add more
# rules for each new "stage" above while retaining the shorthand
# rule name corresponding to the stage?
rule a:
    input: expand('a{step}_file', step=steps)

rule b:
    input: expand('b{step}_file', step=steps)
Run Code Online (Sandbox Code Playgroud)

python bash eval gnu-make snakemake

7
推荐指数
1
解决办法
125
查看次数

Snakemake params函数是否在输入文件存在之前进行评估?

考虑一下这个蛇文件:

def rdf(fn):
    f = open(fn, "rt")
    t = f.readlines()
    f.close()
    return t

rule a:
    output: "test.txt"
    input: "test.dat"
    params: X=lambda wildcards, input, output, threads, resources: rdf(input[0])
    message: "X is {params.X}"
    shell: "cp {input} {output}"

rule b:
    output: "test.dat"
    shell: "echo 'hello world' >{output}"
Run Code Online (Sandbox Code Playgroud)

当运行并且test.txt和test.dat都不存在时,会出现此错误:

InputFunctionException in line 7 of /Users/tedtoal/Documents/BioinformaticsConsulting/Mars/Cacao/Pipeline/SnakeMake/t2:
FileNotFoundError: [Errno 2] No such file or directory: 'test.dat'
Run Code Online (Sandbox Code Playgroud)

但是,如果test.dat存在,则可以正常运行。为什么?

我希望在snakemake准备运行规则'a'之前不对参数进行评估。相反,它必须在DAG阶段中在运行规则“ a”之前调用上述params函数rdf()。但是,即使最初不存在test.dat,也可以进行以下操作:

import os

def rdf(fn):
    if not os.path.exists(fn): return ""
    f = open(fn, "rt")
    t = f.readlines()
    f.close() …
Run Code Online (Sandbox Code Playgroud)

parameters snakemake

6
推荐指数
1
解决办法
291
查看次数

Snakemake + docker示例,如何使用卷

让我们有一个简单的蛇文件

rule targets:
    input:
        "plots/dataset1.pdf",
        "plots/dataset2.pdf"

rule plot:
    input:
        "raw/{dataset}.csv"
    output:
        "plots/{dataset}.pdf"
    shell:
        "somecommand {input} {output}"
Run Code Online (Sandbox Code Playgroud)

我想归纳出绘图规则,以便它可以在docker容器中运行,

rule targets:
    input:
        "plots/dataset1.pdf",
        "plots/dataset2.pdf"

rule plot:
    input:
        "raw/{dataset}.csv"
    output:
        "plots/{dataset}.pdf"
    singularity:
        "docker://joseespinosa/docker-r-ggplot2"
    shell:
        "somecommand {input} {output}"
Run Code Online (Sandbox Code Playgroud)

如果我了解得很好,当我运行时,我会在docker容器中snakemake --use-singularity获得该somecommand运行,如果不对容器进行一些卷配置,则无法找到输入的csv文件。

您能否提供一个小的工作示例,说明如何在Snakefile或其他Snakemake文件中配置卷?

docker snakemake singularity-container

6
推荐指数
1
解决办法
663
查看次数

Snakemake using a rule in a loop

I'm trying to use Snakemake rules within a loop so that the rule takes the output of the previous iteration as input. Is that possible and if yes how can I do that?

Here is my example

  1. Setup the test data
mkdir -p test
echo "SampleA" > test/SampleA.txt
echo "SampleB" > test/SampleB.txt
Run Code Online (Sandbox Code Playgroud)
  1. Snakemake
SAMPLES = ["SampleA", "SampleB"]

rule all:
    input:
        # Output of the final loop
        expand("loop3/{sample}.txt", sample = SAMPLES)


#### LOOP ####
for i in list(range(1, 4)):
    # Setup …
Run Code Online (Sandbox Code Playgroud)

python shell snakemake

6
推荐指数
2
解决办法
567
查看次数