Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop workflow (without error) if an output file is empty #2891

Open
davidecrs opened this issue May 22, 2024 · 1 comment
Open

Stop workflow (without error) if an output file is empty #2891

davidecrs opened this issue May 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@davidecrs
Copy link

Hi,

is it possible to stop the snakemake workflow if an output file is empty? I've tried with the checkpoints but couldn't properly create the rules and make it work.

For example, in the following rule, I'm computing the assembly with metaspades and filtering (with seqkit seq)the produced contigs.fasta to retrieve only the contigs with 1000 min-len (output: "filtered_contigs.fasta"). However, After this last step, the filtering removes all the contigs producing an empty file.

Since many other rules depend on the file "filtered_contigs.fasta", is it possible to stop the execution of snakemake (without errors) ?

run_metaspades:
    input:
        r1=expand("{wdir}/{sample}/{pre_processing}/R1.fastq.gz", pre_processing=config["MODULES"]["pre_processing"], allow_missing=True),
        r2=expand("{wdir}/{sample}/{pre_processing}/R2.fastq.gz", pre_processing=config["MODULES"]["pre_processing"], allow_missing=True),
    output:
        folder = directory("{wdir}/{sample}/metaspades"),
        contigs_fasta = "{wdir}/{sample}/metaspades/contigs.fasta",
        filtered_fasta = "{wdir}/{sample}/metaspades/filtered_contigs.fasta"
    threads: config["threads"]
    conda: config["ENVS"]["metaspades"] 
    shell:
        """
        mkdir -p {output.folder}

        spades.py --meta --only-assembler -t {threads} {params.user_params} -1 {input.r1} -2 {input.r2} -o {output.folder}
        seqkit seq --min-len 1000 {output.contigs_fasta} -o {output.filtered_fasta}
        """

Best regards

@davidecrs davidecrs added the bug Something isn't working label May 22, 2024
@nate-d-olson
Copy link

I believe you want to use filtered_fasta = ensure("{wdir}/{sample}/metaspades/filtered_contigs.fasta", non_empty = True) in your output directive.

https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#ensuring-output-file-properties-like-non-emptyness-or-checksum-compliance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants