【发布时间】:2018-10-09 17:57:32
【问题描述】:
我正在尝试构建一个 Snakemake 管道,但我很困惑为什么文件名通配符适用于 input 和 output,但不适用于 shell。例如,以下工作正常:
samplelist=[ "aa_S1", "bb_S2"]
rule all:
input: expand("{sample}.out", sample=samplelist)
rule align:
input: "{sample}.txt"
output: "{sample}.out"
shell: "touch {output}"
但是假设我用于shell 的命令实际上是从我给它的字符串派生的,所以我不能直接在shell 命令中命名输出文件。那么如何在shell 命令中使用我的文件名通配符(此处为{sample})?
例如,以下行不通:
samplelist=[ "aa_S1", "bb_S2"]
rule all:
input: expand("{sample}.out", sample=samplelist)
rule align:
input: "{sample}.txt"
output: "{sample}.out"
shell: "touch {sample}.out"
它给了我以下错误:
RuleException in line 6 of Snakefile:
NameError: The name 'sample' is unknown in this context. Please make sure
that you defined that variable. Also note that braces not used for variable
access have to be escaped by repeating them, i.e. {{print $1}}
我该如何解决这个问题?
(或者如果你真的想看一些现实生活中的代码,这就是我正在使用的):
samplelist=[ "aa_S1", "bb_S2"]
rule all:
input: expand("{sample}_aligned.sam", sample=samplelist)
rule align:
input: "{sample}_R1_001.trimmed.fastq.gz",
"{sample}_R2_001.trimmed.fastq.gz"
output: "{sample}_aligned.sam"
threads: 4
shell: "STAR --outFileNamePrefix {sample}_aligned --readFilesIn {input[0]} {input[1]} --readFilesCommand zcat --runMode alignReads --runThreadN {threads} --genomeDir /path/to/StarIndex"
但是报错信息基本一样。对于shell,我可以使用{input}、{output}和{threads},但不能使用{sample}。
我确实看过Snakemake: How do I use a function that takes in a wildcard and returns a value?,但它似乎专注于生成输入文件名。我的问题涉及将文件名通配符插入shell 命令。
【问题讨论】:
标签: snakemake