pabster212
pabster212

Reputation: 117

Snakemake Checkpoint Throws (exited with non-zero exit code) even after correct completion

I'm currently running a snakemake checkpoint that appears to be throwing a non-zero exit code even after correct completion of the command, and am unsure how to resolve the problem.

The purpose of the below script is to parse a file of coordinates, the bed_file, extract all regions from a bam file rna_file and eventually assemble these regions. The code is below, and my snakemake version is 5.6.0.

#Pull coordinates from a BAM file, and use the command samtools view to extract the corresponding #data, naming the output as the coordinate file, here named "6:25274434-25278245.bam". There are #an unknown number of output files

checkpoint pull_reads_for_BAM:
    input:
    ¦   bed_file = get_lncRNA_file,
    ¦   rna_file = get_RNA_file
    conda:
    ¦   "envs/pydev_1.yml"
    params:
    ¦   "01.pulled_reads"
    output:
    ¦   directory("01.pulled_reads/{tissue}")
    shell:"""

    mkdir 01.pulled_reads/{wildcards.tissue}

    store_regions=$(cat {input.bed_file} | awk -F'\t' '{{ print $1 ":" $2 "-" $3 }}')

    for i in $store_regions ; do
    ¦   samtools view -b -h {input.rna_file} ${{i}} > 01.pulled_reads/{wildcards.tissue}/${{i}}.bam ;
    done

    echo "This completed fine"

    """

rule samtools_sort:
    input:
    ¦   "01.pulled_reads/{tissue}/{i}.bam"
    params:
    ¦   "{i}"
    output:
    ¦   "01.pulled_reads/{tissue}/{i}.sorted.bam"
    shell:
    ¦   "samtools sort -T sorted_reads/{params}.tmp {input} > {output}"

rule samtools_index:
    input:
    ¦   "01.pulled_reads/{tissue}/{i}.sorted.bam"
    output:
    ¦   "01.pulled_reads/{tissue}/{i}.sorted.bam.bai"
    shell:
        "samtools index {input}"

rule string_tie_assembly:
    input:
    ¦   "01.pulled_reads/{tissue}/{i}.sorted.bam"
    output:
    ¦   "02.string_tie_assembly/{tissue}/{i}_assembly.gtf"
    shell:
        "stringtie {input} -f 0.0 -a 0 -m 50 -c 3.0 -f 0.0 -o {output}"


def trigger_aggregate(wildcards):
    checkpoint_output = checkpoints.pull_reads_for_BAM.get(**wildcards).output[0]

    x = expand("02.string_tie_assembly/{tissue}/{i}_assembly.merged.gtf",
    ¦   tissue = wildcards.tissue,
    ¦   i=glob_wildcards(os.path.join(checkpoint_output, "{i}.bam")).i)
    return x


#Aggregate function that triggers rule 
rule combine_all_gtf_things:
    input:
    ¦   trigger_aggregate
    output:
    ¦   "03.final_stuff/{tissue}.merged.gtf"
    shell:"""
    cat {input} > {output}
    """

After the command has run to completion, snakemake returns (exited with non-zero exit code) for some mysterious reason. I can watch the output be generated in the file and it appears to be correct, so I'm unsure why it's throwing this error.

The checkpoint I have generated is modeled after this: https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html

Related Questions that have gone unanswered: Snakemake checkpoint (exited with non-zero exit code)

Upvotes: 1

Views: 606

Answers (2)

pabster212
pabster212

Reputation: 117

It appears that this issue was somehow caused by the wildcards in {tissue} being set as a directory. As to why this throws a non-zero exit status I am unsure. This was fixed by simply appending {tissue}_dir onto the path above.

More on the issue can be found here: https://bitbucket.org/snakemake/snakemake/issues/1303/snakemake-checkpoint-throws-exited-with

Upvotes: 1

dariober
dariober

Reputation: 9062

Not sure if this is a problem but mkdir 01.pulled_reads/{wildcards.tissue} will fail if the directory exists or 01.pulled_reads does not exist before mkdir is executed.

Try adding the -p option to mkidr, i.e. mkdir -p 01.pulled_reads/{wildcards.tissue}

Upvotes: 0

Related Questions