如何编写 Snakemake rule-all,其中 expand 语句可以处理所有特定输入文件的缺失
How to write a Snakemake rule-all, where expand statements can handle the absence of all particular input files
我想写一个 Snakemake-Pipeline 来处理短读或长读测序文件或两种类型,具体取决于输入文件中提供的文件类型。
首先,我的 Snakefile 调用一个 shell 脚本,该脚本创建一个配置文件,其中输入目录中标题 short_reads 下的所有短读文件的名称和标题 long_reads 下的所有长读文件的名称。
接下来是我的所有规则:
rule all:
input:
expand("../qc/id/{sample}/fastqc_raw/{sample}_R1_fastqc.html", sample=config["samples_short"]),
expand("../qc/id/{sample}/nanoplot_raw/NanoPlot-report.html", sample=config["samples_long"])
...
但是,如果未提供其中一种文件类型(长读或短读),Snakemake 将失败并出现 KeyError。
如果我以标题仍然存在但没有示例名称的方式修改配置文件,Snakemake 会尝试使用值 None 调用输入,例如
Missing input files for rule nanoplot_raw:
../raw_reads/None_ont.fastq.gz
我如何设计 rule-all 使其能够处理短读或长读以及两种序列类型作为输入?
感谢您的帮助!
以下是否有效?
if config["samples_short"]:
fastqc_short = expand("../qc/id/{sample}/fastqc_raw/{sample}_R1_fastqc.html", sample=config["samples_short"])
else:
fastqc_short = []
if config["samples_long"]:
nanoplot_long = expand("../qc/id/{sample}/nanoplot_raw/NanoPlot-report.html", sample=config["samples_long"])
else:
nanoplot_long = []
rule all:
input:
fastqc_short,
nanoplot_long,
...
我想写一个 Snakemake-Pipeline 来处理短读或长读测序文件或两种类型,具体取决于输入文件中提供的文件类型。 首先,我的 Snakefile 调用一个 shell 脚本,该脚本创建一个配置文件,其中输入目录中标题 short_reads 下的所有短读文件的名称和标题 long_reads 下的所有长读文件的名称。 接下来是我的所有规则:
rule all:
input:
expand("../qc/id/{sample}/fastqc_raw/{sample}_R1_fastqc.html", sample=config["samples_short"]),
expand("../qc/id/{sample}/nanoplot_raw/NanoPlot-report.html", sample=config["samples_long"])
...
但是,如果未提供其中一种文件类型(长读或短读),Snakemake 将失败并出现 KeyError。 如果我以标题仍然存在但没有示例名称的方式修改配置文件,Snakemake 会尝试使用值 None 调用输入,例如
Missing input files for rule nanoplot_raw: ../raw_reads/None_ont.fastq.gz
我如何设计 rule-all 使其能够处理短读或长读以及两种序列类型作为输入?
感谢您的帮助!
以下是否有效?
if config["samples_short"]:
fastqc_short = expand("../qc/id/{sample}/fastqc_raw/{sample}_R1_fastqc.html", sample=config["samples_short"])
else:
fastqc_short = []
if config["samples_long"]:
nanoplot_long = expand("../qc/id/{sample}/nanoplot_raw/NanoPlot-report.html", sample=config["samples_long"])
else:
nanoplot_long = []
rule all:
input:
fastqc_short,
nanoplot_long,
...