我正在关注他们文档页面上的snakemake教程,并真正理解了输入函数https://snakemake.readthedocs.io/en/stable/tutorial/advanced.html#step-3-input-functions的概念
基本上,他们对config.yaml
的定义如下:
samples:
A: data/samples/A.fastq
B: data/samples/B.fastq
和Snakefile
,无任何输入功能:
configfile: "config.yaml"
rule all:
input:
"plots/quals.svg"
rule bwa_map:
input:
"data/genome.fa",
"data/samples/{sample}.fastq"
output:
"mapped_reads/{sample}.bam"
threads: 12
shell:
"bwa mem -t {threads} {input} | samtools view -Sb - > {output}"
rule samtools_sort:
input:
"mapped_reads/{sample}.bam"
output:
"sorted_reads/{sample}.bam"
shell:
"samtools sort -T sorted_reads/{wildcards.sample} -O bam {input} > {output}"
rule samtools_index:
input:
"sorted_reads/{sample}.bam"
output:
"sorted_reads/{sample}.bam.bai"
shell:
"samtools index {input}"
rule bcftools_call:
input:
fa = "data/genome.fa",
bam = expand("sorted_reads/{sample}.bam",sample=config['samples']),
bai = expand("sorted_reads/{sample}.bam.bai",sample=config['samples'])
output:
"calls/all.vcf"
shell:
"bcftools mpileup -f {input.fa} {input.bam} | "
"bcftools call -mv - > {output}"
rule plot_quals:
input:
"calls/all.vcf"
output:
"plots/quals.svg"
script:
"scripts/plot-quals.py"
在本教程中,他们提到此扩展发生在初始化步骤中:
bam = expand("sorted_reads/{sample}.bam",sample=config['samples']),
bai = expand("sorted_reads/{sample}.bam.bai",sample=config['samples'])
在此阶段,无法确定规则bwa_map
的FASTQ路径.然而,如果我们按原样运行,代码会工作,为什么会这样?
然后,他们建议使用输入函数将bwa_map
延迟到下一阶段(DAG阶段),如下所示:
def get_bwa_map_input_fastqs(wildcards):
return config["samples"][wildcards.sample]
rule bwa_map:
input:
"data/genome.fa",
get_bwa_map_input_fastqs
output:
"mapped_reads/{sample}.bam"
threads: 8
shell:
"bwa mem -t {threads} {input} | samtools view -Sb - > {output}"
我真的很困惑,输入函数什么时候有意义,什么时候没有?