0

I am trying to fix a Snakefile. There are two rules (see the code below), each one would work if it's the only one, but only the rule prernaseqc would work when both are kept.

It seems that snakemake totally ignores the other.

I tried to touch file files_to_rnaseqc.txt etc, and it does not help. Why?

Any ideas would be appreciated.

import os
configfile: "run.json"
workpath = config['project']['workpath']

samples=sorted(list(config['project']['units'].keys()))

from snakemake.utils import R
from os.path import join
configfile: "run.json"

from os import listdir

star_dir="STAR_files"
bams_dir="bams"
log_dir="logfiles"
rseqc_dir="RSeQC"
kraken_dir="kraken"
preseq_dir="preseq"
pfamily = 'rnaseq'


rule prernaseqc:
   input: 
    expand(join(workpath,bams_dir,"{name}.star_rg_added.sorted.dmark.bam"), name=samples)
   output:
    out1=join(workpath,bams_dir,"files_to_rnaseqc.txt")
   priority: 2
   params: 
    rname='pl:prernaseqc',batch='--mem=4g --time=04:00:00'
   run:
        with open(output.out1, "w") as out:
            out.write("Sample ID\tBam file\tNotes\n")
            for f in input:
                out.write("%s\t"  % f)
                out.write("%s\t"  % f)
                out.write("%s\n"  % f)
            out.close()

rule rnaseqc:
   input:
    join(workpath,bams_dir,"files_to_rnaseqc.txt")
   output:
    join(workpath,"STAR_QC")
   priority: 2
   params: 
    rname='pl:rnaseqc',
    batch='--mem=24g --time=48:00:00',
    bwaver=config['bin'][pfamily]['tool_versions']['BWAVER'],
    rrnalist=config['references'][pfamily]['RRNALIST'],
    rnaseqcver=config['bin'][pfamily]['RNASEQCJAR'],
    rseqcver=config['bin'][pfamily]['tool_versions']['RSEQCVER'],   
    gtffile=config['references'][pfamily]['GTFFILE'],
    genomefile=config['references'][pfamily]['GENOMEFILE']

   shell: """
module load {params.bwaver}
module load {params.rseqcver}

var="{params.rrnalist}"
if [  $var == "-" ]; then
      java -Xmx48g -jar {params.rnaseqcver} -n 1000 -s {input} -t {params.gtffile} -r {params.genomefile}  -o {output}
else
      java -Xmx48g -jar {params.rnaseqcver} -n 1000 -s {input} -t {params.gtffile} -r {params.genomefile} -rRNA {params.rrnalist}  -o {output}
fi
Manavalan Gajapathy
  • 3,900
  • 2
  • 20
  • 43
coder2019
  • 21
  • 1
  • thank you for edit the question, but "until I touched the file" should be deleted from the question. Touching the file does not help. – coder2019 May 10 '19 at 16:29
  • How are you running Snakemake? Just `snakemake`? You need to edit your question to include this crucial info. – merv May 13 '19 at 00:15

1 Answers1

1

Snakemake, by design, uses output files listed in first rule of the file as target files (i.e. files that need to be created). Hence, in your case, whichever rule happens to be the first gets executed, while the other remains unexecuted.

You need to specify a target rule that lists all output files. It is customary to name it rule all.

rule all:
    input:
        join(workpath,bams_dir,"files_to_rnaseqc.txt"),
        join(workpath,"STAR_QC")
Manavalan Gajapathy
  • 3,900
  • 2
  • 20
  • 43