snakemake rule error. How can I select rule order?

Viewed 29

I run the snakemake for RNA-seq analysis. I made snakefile for running, and some error occurred in terminal. I set rule salmon quant reads at last order but it is running at first. So snakemake showed the error in rule salmon quant reads. salmon quant reads must run after salmon index finished.

Error in rule salmon_quant_reads:
    jobid: 173
    output: salmon/WT_Veh_11/quant.sf, salmon/WT_Veh_11/lib_format_counts.json
    log: logs/salmon/WT_Veh_11.log (check log file(s) for error message)
    conda-env: /home/baelab2/LEEJUNEYOUNG/7.Colesevelam/RNA-seq/.snakemake/conda/ff908de630224c1a4118f5dc69c8a761

RuleException:
CalledProcessError in line 111 of /home/baelab2/LEEJUNEYOUNG/7.Colesevelam/RNA-seq/Snakefile_2:
Command 'source /home/baelab2/miniconda3/bin/activate '/home/baelab2/LEEJUNEYOUNG/7.Colesevelam/RNA-seq/.snakemake/conda/ff908de630224c1a4118f5dc69c8a761'; set -euo pipefail;  /home/baelab2/miniconda3/envs/snakemake/bin/python3.10 /home/baelab2/LEEJUNEYOUNG/7.Colesevelam/RNA-seq/.snakemake/scripts/tmpr6r8ryk9.wrapper.py' returned non-zero exit status 1.
  File "/home/baelab2/LEEJUNEYOUNG/7.Colesevelam/RNA-seq/Snakefile_2", line 111, in __rule_salmon_quant_reads
  File "/home/baelab2/miniconda3/envs/snakemake/lib/python3.10/concurrent/futures/thread.py", line 58, in run

How can I fix it?

Here is the my snakefile info.

SAMPLES = ["KO_Col_5", "KO_Col_6", "KO_Col_7", "KO_Col_8", "KO_Col_9", "KO_Col_10", "KO_Col_11", "KO_Col_15", "KO_Veh_3", "KO_Veh_4", "KO_Veh_5", "KO_Veh_9", "KO_Veh_11", "KO_Veh_13", "KO_Veh_14", "WT_Col_1", "WT_Col_2", "WT_Col_3", "WT_Col_6", "WT_Col_8", "WT_Col_10", "WT_Col_12", "WT_Veh_1", "WT_Veh_2", "WT_Veh_4", "WT_Veh_7", "WT_Veh_8", "WT_Veh_11", "WT_Veh_14"]

rule all:
    input:
        expand("raw/{sample}_1.fastq.gz", sample=SAMPLES),
        expand("raw/{sample}_2.fastq.gz", sample=SAMPLES),
        expand("qc/fastqc/{sample}_1.before.trim_fastqc.zip", sample=SAMPLES),
        expand("qc/fastqc/{sample}_2.before.trim_fastqc.zip", sample=SAMPLES),
        expand("trimmed/{sample}_1.fastq.gz", sample=SAMPLES),
        expand("trimmed/{sample}_2.fastq.gz", sample=SAMPLES),
        expand("qc/fastqc/{sample}_1.after.trim_fastqc.zip", sample=SAMPLES),
        expand("qc/fastqc/{sample}_2.after.trim_fastqc.zip", sample=SAMPLES),
        expand("salmon/{sample}/quant.sf", sample=SAMPLES),
        expand("salmon/{sample}/lib_format_counts.json", sample=SAMPLES)

rule fastqc_before_trim_1:
    input:
        "raw/{sample}.fastq.gz",
    output:
        html="qc/fastqc/{sample}.before.trim.html",
        zip="qc/fastqc/{sample}.before.trim_fastqc.zip",
    log:
        "logs/fastqc/{sample}.before.log"
    threads: 10    
    priority: 1
    wrapper:
        "v1.7.0/bio/fastqc"

rule cutadapt:
    input:
        r1 = "raw/{sample}_1.fastq.gz",
        r2 = "raw/{sample}_2.fastq.gz"
    output:
        fastq1="trimmed/{sample}_1.fastq.gz",
        fastq2="trimmed/{sample}_2.fastq.gz",
        qc="trimmed/{sample}.qc.txt"
    params:
        adapters = "-a AGATCGGAAGAGCACACGTCTGAACTCCAGTCA -A AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT",
        extra = "--minimum-length 1 -q 20"    
    log:
        "logs/cutadapt/{sample}.log"
    threads: 10    
    priority: 2
    wrapper:
        "v1.7.0/bio/cutadapt/pe"

rule fastqc_after_trim_2:
    input:
        "trimmed/{sample}.fastq.gz"
    output:
        html="qc/fastqc/{sample}.after.trim.html",
        zip="qc/fastqc/{sample}.after.trim_fastqc.zip"
    log:
        "logs/fastqc/{sample}.after.log"
    threads: 10
    priority: 3
    wrapper:
        "v1.7.0/bio/fastqc"

rule salmon_index:
    input:
        sequences="raw/Mus_musculus.GRCm39.cdna.all.fasta"
    output:
        multiext(
            "salmon/transcriptome_index/",
            "complete_ref_lens.bin",
            "ctable.bin",
            "ctg_offsets.bin",
            "duplicate_clusters.tsv",
            "info.json",
            "mphf.bin",
            "pos.bin",
            "pre_indexing.log",
            "rank.bin",
            "refAccumLengths.bin",
            "ref_indexing.log",
            "reflengths.bin",
            "refseq.bin",
            "seq.bin",
            "versionInfo.json",
        ),
    log:
        "logs/salmon/transcriptome_index.log",
    threads: 10
    priority: 10
    params:
        # optional parameters
        extra="",
    wrapper:
        "v1.7.0/bio/salmon/index"

rule salmon_quant_reads:
    input:
        # If you have multiple fastq files for a single sample (e.g. technical replicates)
        # use a list for r1 and r2.
        r1 = "trimmed/{sample}_1.fastq.gz",
        r2 = "trimmed/{sample}_2.fastq.gz",
        index = "salmon/transcriptome_index"
    output:
        quant = "salmon/{sample}/quant.sf",
        lib = "salmon/{sample}/lib_format_counts.json"
    log:
        "logs/salmon/{sample}.log"
    params:
        # optional parameters
        libtype ="A",
        extra="--validateMappings"
    threads: 10
    priority: 20
    wrapper:
        "v1.7.0/bio/salmon/quant"
1 Answers

The only link between salmon_quant_reads and salmon_index is directory salmon/transcriptome_index. However, the directory creation is not a sufficient signal that all work in salmon_index has been completed. So, a quick way to fix this is to include an explicit file:

rule salmon_quant_reads:
    input:
        # If you have multiple fastq files for a single sample (e.g. technical replicates)
        # use a list for r1 and r2.
        r1 = "trimmed/{sample}_1.fastq.gz",
        r2 = "trimmed/{sample}_2.fastq.gz",
        index = "salmon/transcriptome_index",
        _temp_dependency = "salmon/transcriptome_index/info.json",
Related