手动创建 snakemake 通配符
Manually create snakemake wildcards
我正在努力将我的示例 sheet (TSV) 集成到我的管道中。具体来说,我想手动定义样本通配符,而不是从补丁中读取它。原因是并非路径中的所有样本都应该被分析。相反,我制作了一个样本 sheet,其中包含样本列表、查找路径、参考基因组等
sheet 看起来像这样:
name path reference
sample1 path/to/fastq/files mm9
sample2 path/to/fastq/files mm9
我在 snakefile
中加载 sheet:
table_samples = pd.read_table(config["samples"], index_col="name")
SAMPLES = table_samples.index.values.tolist()
第一条规则应该合并里面的 FASTQ 文件,所以做这样的事情会很好:
rule merge_fastq:
output: "{sample}/{sample}.fastq.gz"
params: path = table_samples['path'][{sample}]
shell: """
cat {params.path}/*.fastq.gz > {output}
"""
但是如上所述,它不起作用,因为示例通配符未定义。有没有一种方法可以说我在上面定义的示例列表 (SAMPLES) 包含应执行规则的所有示例?
老实说,问这个问题我觉得很愚蠢,但我已经花了几个小时 finding/searching 一个解决方案,在这一点上我需要更省时 :D
谢谢!
您只需要一个目标规则,在您的规则之后列出您想要的所有具体文件 "merge_fastq":
rule all:
input: expand("{sample}/{sample}.fastq.gz",sample=SAMPLES)
此规则必须放在其他规则的顶部。仅当您在工作流结束时定义了所需的具体文件时,才能使用通配符。
我正在努力将我的示例 sheet (TSV) 集成到我的管道中。具体来说,我想手动定义样本通配符,而不是从补丁中读取它。原因是并非路径中的所有样本都应该被分析。相反,我制作了一个样本 sheet,其中包含样本列表、查找路径、参考基因组等
sheet 看起来像这样:
name path reference
sample1 path/to/fastq/files mm9
sample2 path/to/fastq/files mm9
我在 snakefile
中加载 sheet:
table_samples = pd.read_table(config["samples"], index_col="name")
SAMPLES = table_samples.index.values.tolist()
第一条规则应该合并里面的 FASTQ 文件,所以做这样的事情会很好:
rule merge_fastq:
output: "{sample}/{sample}.fastq.gz"
params: path = table_samples['path'][{sample}]
shell: """
cat {params.path}/*.fastq.gz > {output}
"""
但是如上所述,它不起作用,因为示例通配符未定义。有没有一种方法可以说我在上面定义的示例列表 (SAMPLES) 包含应执行规则的所有示例?
老实说,问这个问题我觉得很愚蠢,但我已经花了几个小时 finding/searching 一个解决方案,在这一点上我需要更省时 :D
谢谢!
您只需要一个目标规则,在您的规则之后列出您想要的所有具体文件 "merge_fastq":
rule all:
input: expand("{sample}/{sample}.fastq.gz",sample=SAMPLES)
此规则必须放在其他规则的顶部。仅当您在工作流结束时定义了所需的具体文件时,才能使用通配符。