小编ted*_*oal的帖子

建议使用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 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
查看次数

如何使用来自变量的名称将命名元素添加到 R 向量

我想向向量 V 添加一个元素,比如 100,并使用变量 x 的值作为新元素的名称。我知道可以这样做:

V = c(V, 100)
names(V)[length(V)] = x
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一种简单的单线解决方案,如果有的话。我试过:

V = c(V, as.name(x)=100)
Run Code Online (Sandbox Code Playgroud)

V = c(V, eval(x)=100)
Run Code Online (Sandbox Code Playgroud)

但那些不起作用。

好的,发现了最好的方法:

V[x] = 100
Run Code Online (Sandbox Code Playgroud)

r elementname

5
推荐指数
2
解决办法
3862
查看次数

snakemake配置参数值是否可以插入/扩展{<name>}值的字符串?

有没有办法在.yaml文件中定义snakemake配置字符串,以便它可以包含{wildcard}和{param}值,并且当在shell命令中使用该字符串时,{<name>}值将替换为"<name>"的实际值?

例如,假设您希望配置字符串定义要作为参数传递给程序的字符串格式:

RG:"ID:{ID} REP:{REP}"

其中上面是.yaml文件,ID和REP是通配符,shell命令会将展开的字符串作为参数传递给程序.

wildcard-expansion parameter-expansion snakemake

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