[Python] Two config files (same variables but different values) for one Snakemake file

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have one yaml file called config_T11H.yaml with the following content:

    # the configuration for workflow of T11H

    BASE_EDITOR: T11H
    INDIR: data/alignment
    OUTDIR: output/output_T11H

    # start and end positions of editing window
    START: 3
    END: 9


    and I have another yaml file named config_T11L.yaml with the following content:

    # the configuration for workflow of T11L

    BASE_EDITOR: T11L
    INDIR: data/alignment
    OUTDIR: output/output_T11L

    # start and end positions of editing window
    START: 3
    END: 15


    I have written a snakemake file base_editing.smk that will run a pipeline with the two sets of parameters in the two yaml files above.

    Currently what I am doing is to manually modify the variable configfile in the snakemake file:

    Firstly I write configfile: "config_T11H.yaml" at the beginning of the snakemake file, and run the snakemake file snakemake -c 1 -s base_editing.smk;

    After it finishes, I then modify the snakemake file configfile: "config_T11L.yaml" and run the snakemake file again snakemake -c 1 -s base_editing.smk.

    A toy snakemake file is as followed:

    configfile: "config/config_T11H.yaml"
    # configfile: "config/config_T11L.yaml"

    base_editor = config["BASE_EDITOR"]
    input_dir = config["INDIR"]
    output_dir = config["OUTDIR"]

    # editing window
    start = config["START"]
    end = config["END"]

    rule all:
    input:
    head = output_dir + "/temp_head.txt"

    rule files:
    input:
    files = input_dir
    output:
    txt = output_dir + "/temp.txt"
    params:
    editor = base_editor
    shell:
    """
    ls {input.files} | grep {params.editor} > {output.txt}
    """

    rule head:
    input:
    txt = output_dir + "/temp.txt"
    output:
    head = output_dir + "/temp_head.txt"
    params:
    end = int(end)
    shell:
    """
    head -{params.end} {input.txt} > {output.head}
    """


    Is there an easier way to run the snakemake file on the two yaml files with only one-go?

    One failed try:

    # configfile: "config/config_T11H.yaml"
    # configfile: "config/config_T11L.yaml"

    configfiles = ["config/config_T11H.yaml", "config/config_T11L.yaml"]

    for fn_config in configfiles:
    configfile: fn_config
    base_editor = config["BASE_EDITOR"]
    input_dir = config["INDIR"]
    output_dir = config["OUTDIR"]

    # editing window
    start = config["START"]
    end = config["END"]

    print(end)

    rule all:
    input:
    head = output_dir + "/temp_head.txt"

    rule files:
    input:
    files = input_dir
    output:
    txt = output_dir + "/temp.txt"
    params:
    editor = base_editor
    shell:
    """
    ls {input.files} | grep {params.editor} > {output.txt}
    """

    rule head:
    input:
    txt = output_dir + "/temp.txt"
    output:
    head = output_dir + "/temp_head.txt"
    params:
    end = int(end)
    shell:
    """
    head -{params.end} {input.txt} > {output.head}
    """


    With the error message:

    CreateRuleException in file workflow/base_editing.smk, line 19:
    The name all is already used by another rule
    File "workflow/base_editing.smk", line 19, in <module>

    Continue reading...

Compartilhe esta Página