我是一个新的 Snakemake 用户,正在尝试使用一些数据来开发一个管道,以便能够实现我们的真实数据。我有多个文件夹(每位患者一个文件夹),每个文件夹中每个肿瘤和正常样本都有多个文件:这是我的目录结构
`A/
A-T1.fastq
A-N1.fastq
B/
B-T1.fastq
B-N1.fastq
C/
C-T1.fastq
C-N1.fastq`
等等....(总共100多个目录)。
这也是我的蛇文件:
`#!/usr/bin/env snakemake
configfile:
"config.json"
(DIRS,SAMPLES) = glob_wildcards(config['data']+"{dir}/{sample}.fastq")
rule all:
input:
expand("results/mapped/{dir}/{sample}.sorted.bam", dir=DIRS, sample=SAMPLES)
rule symlink:
input:
expand(config['data']+"{dir}/{{sample}}.fastq")
output:
"00-input/{dir}/{sample}.fastq"
shell:
"ln -s {input} {output}"
rule map_reads:
input:
"data/genome.fa",
"00-input/{dir}/{sample}.fastq"
output:
"results/mapped/{dir}/{sample}.bam"
conda:
"envs/samtools.yaml"
shell:
"bwa mem {input} | samtools view -b - > {output}"
rule sort_alignments:
input:
"results/mapped/{dir}/{sample}.bam"
output:
"results/mapped/{dir}/{sample}.sorted.bam"
conda:
"envs/samtools.yaml"
shell:
"samtools sort -o {output} {input}"`
这也是我的配置文件:
`{
"data": "/analysis/Anna/snakemake-demo/data/samples_fastq/"
}`
通过运行此脚本,我收到以下错误消息:
`WildcardError in line 13:
No values given for wildcard 'dir'.
`
我尝试了一种不同的方法,添加修改我的规则符号链接:
` input:
expand(config['data']+"{{dir}}/{{sample}}.fastq")
`
这次我收到了不同的错误消息:
`Missing input files for rule symlink:`
我已经在 Stack 上查看了几个类似的问题,但到目前为止还无法修复我的错误。如果有人可以帮助我了解我的错误在哪里以及如何解决该问题的任何线索,我将不胜感激。谢谢你
我在堆栈上尝试了类似的问题来修复错误,但仍然很挣扎。
通过在我的计算机上运行一个最小的示例,根据您提供的信息,我成功地重现了您的错误。
关于第一个错误,您的解决方案
expand(config['data']+"{{dir}}/{{sample}}.fastq")
也对我有用。
但是,对于第二个错误,完整的错误消息是:
MissingInputException: Missing input files for rule symlink:
output: 00-input/A/A-T1.sorted.fastq
wildcards: dir=A, sample=A-T1.sorted
affected files:
/home/paularthur/Documents/stack_overflow/77107606/data/A/A-T1.sorted.fastq
请注意,示例通配符的值为
A-T1.sorted
,而您期望它为 A-T1
。
我对您版本文件名的理解不明确。 Snakemake 无法自动推断规则
sample
和规则 sort_alignments
之间通配符 map_reads
的值。
在这种情况下,我使用规则依赖关系https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#rule-dependency
重要的是,请注意,此处引用规则 a 要求规则 a 在文件中定义在规则 b 之上,因为该对象必须已经已知。此功能还允许我们解决使用文件名时不明确的依赖关系。
请注意,当您引用的规则定义了多个输出文件,但您只想需要其中的一个子集作为另一个规则的输入时,您应该命名输出文件并专门引用它们:
通过相应地修改您的 Snakefile,我设法在试运行中运行管道:
rule all:
input:
expand("results/mapped/{dir}/{sample}.sorted.bam", dir=DIRS, sample=SAMPLES)
rule symlink:
input:
expand(config['data']+"{{dir}}/{{sample}}.fastq")
output:
"00-input/{dir}/{sample}.fastq"
shell:
"ln -s {input} {output}"
rule map_reads:
input:
fasta="data/genome.fa",
fastq=rules.symlink.output
output:
"results/mapped/{dir}/{sample}.bam"
shell:
"bwa mem {input} | samtools view -b - > {output}"
rule sort_alignments:
input:
rules.map_reads.output
output:
"results/mapped/{dir}/{sample}.sorted.bam"
shell:
"samtools sort -o {output} {input}"