Python 是否可以在snakemake';什么是规则?

Python 是否可以在snakemake';什么是规则?,python,snakemake,qiime,Python,Snakemake,Qiime,我想使用singularity运行多个名为qc.smk,dada2.smk,picrust2.smk的Snake文件。然后有一个名为longital.smk的蛇文件,我希望有条件地运行。例如,如果纵向数据为 正在使用中 # set vars LONGITUDINAL = config['perform_longitudinal'] rule all: input: # fastqc output before trimming raw_html = expand(&quo

我想使用singularity运行多个名为
qc.smk
dada2.smk
picrust2.smk
的Snake文件。然后有一个名为
longital.smk
的蛇文件,我希望有条件地运行。例如,如果纵向数据为 正在使用中

# set vars

LONGITUDINAL = config['perform_longitudinal']

rule all:
  input:
    # fastqc output before trimming
    raw_html = expand("{scratch}/fastqc/{sample}_{num}_fastqc.html", scratch = SCRATCH, sample=SAMPLE_SET, num=SET_NUMS),
    raw_zip = expand("{scratch}/fastqc/{sample}_{num}_fastqc.zip", scratch = SCRATCH, sample=SAMPLE_SET, num=SET_NUMS),
    raw_multi_html = SCRATCH + "/fastqc/raw_multiqc.html",
    raw_multi_stats = SCRATCH + "/fastqc/raw_multiqc_general_stats.txt"

# there are many more files in rule all

##### setup singularity #####

singularity: "docker://continuumio/miniconda3"

##### load rules #####

include: "rules/qc.smk"
include: "rules/dada2.smk"
include: "rules/phylogeny.smk"
include: "rules/picrust2.smk"

if LONGITUDINAL == 'yes':
    include: 'rules/longitudinal.smk'
    print("Will perform a longitudinal analysis")
else:
    print("no longitudinal analysis")
以上代码仅在运行纵向数据集时有效。但是,当我不运行纵向分析时,snakemake会失败并说:

MissingInputException in line 70 of /mnt/c/Users/noahs/projects/tagseq-qiime2-snakemake-1/Snakefile:
Missing input files for rule all:
我想如果我能够添加一个类似的条件语句,就像我为我的外部蛇形文件snakemake所做的一样,我不会因为不包括纵向蛇形文件而发疯。

你可以在
规则all
之外定义一个你想要的输出列表(或dict),并将其输入,类似这样的工作原理:

myoutput = list()

if condition_1 == True:
    myoutput.append("file_1.txt")
if condition_2 == True:
    myoutput.append("file_2.txt")

rule all:
    input:
        myoutput

编辑:

myoutput
放在规则all的输入中的第一位:

rule all:
    input:
        myoutput,
        raw_html = "raw_html_path",
        raw_zip = "raw_zip_path"
或将其命名,并将其放置在任何地方:

rule all:
    input:
        raw_html = "raw_html_path",
        myoutput = myoutput,
        raw_zip = "raw_zip_path"

在Python(和snakemake)中,命名的位置参数总是位于命名参数之前。

感谢您的回复。我不确定我是否犯了一个错误,因为这个结构不适合我。我的所有输出是否都必须附加列表才能工作?目前,我的所有输出文件都在规则all中正常列出,并在其余输入文件的下方添加了
myoutput
,但出现了以下错误:
SyntaxError位于/mnt/c/Users/noahs/projects/tagseq-qiime2-snakemake-1/Snakefile的第178行/mnt/c/c/Users/noahs/projects/tagseq-qiime2-snakemake-1/Snakefile:positional参数后面的关键字参数
178是我添加
myoutput
myoutput
列表移动到
all:input:
中的第一位,或者执行类似
all:input:optional=myoutput
的操作。像这样打你@Noah\u海鸥,因为我不确定你是否会收到我的其他答案,这对我仍然不起作用。虽然我的命名模式在snakemake中运行良好,但append函数可能不喜欢我的文件的命名方式。下面是一个我正试图按照您的建议通过append函数传递的文件名示例<代码>myout.append(“pw_diff=OUTPUTDIR+”/qiime2/asv/longital/'+PROJ+ANALYSIS+“成对差异.qzv”)非常感谢!你是救命恩人。首先,我能够通过定义规则all之外的位置参数使其工作。因为我需要将一个多输入列表添加到另一个输入列表中,所以我还必须使用extend而不是append。但是如果有你的帮助,我是无法理解的。