[Python] Snakemake WorkflowError: "Target rules may not contain wildcards" when using...

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

  1. Stack

    Stack Membro Participativo

    I’m trying to build a Snakemake pipeline that uses a checkpoint to dynamically determine {sequence} wildcards after processing patient data. My workflow structure is roughly:

    A checkpoint dicom_to_nifti converts raw DICOM files for each {patient} into NIfTI files.

    Then, for every {sequence} discovered inside each patient’s output folder, a downstream rule dummy_process_sequence processes that sequence.

    Finally, I have a rule all that collects all final processed files via a Python function that inspects the checkpoint output.


    import os

    PATIENTS = [d for d in os.listdir("dataset/raw")]
    print(f"Found {len(PATIENTS)} patients")

    checkpoint dicom_to_nifti:
    input: "raw/{patient}/"
    output: directory("nifti/{patient}/")
    conda: "envs/dicom_nifti_env.yaml"
    shell: "python scripts/dicom_to_nifti.py {input} {output}"

    rule dummy_process_sequence:
    input: "nifti/{patient}/{sequence}.nii.gz"
    output: "processed/{patient}/{sequence}.nii.gz"
    shell:
    """
    mkdir -p $(dirname {output})
    echo "Processed {input}" > {output}
    """

    def collect_outputs(wildcards):
    files = []
    for patient in PATIENTS:
    ckpt_outdir = checkpoints.dicom_to_nifti.get(patient=patient).output[0]
    for f in os.listdir(ckpt_outdir):
    if f.endswith(".nii.gz"):
    seq = f[:-7] # strip ".nii.gz"
    files.append(f"processed/{patient}/{seq}.nii.gz")
    return files

    rule all:
    input:
    collect_outputs





    When I run

    snakemake --cores 1 -p

    , I get the error:


    WorkflowError:
    Target rules may not contain wildcards. Please specify concrete files or a rule without wildcards at the command line, or have a rule without wildcards at the very top of your workflow (e.g. the typical "rule all" which just collects all results you want to generate in the end).
    ​

    Continue reading...

Compartilhe esta Página