简体   繁体   中英

Snakemake with R script, error: snakemake object not found

I'm having issues trying to run a snakemake rule that invokes an R script. The relevant snakemake rule looks like this:

rule summarize_transcripts:
    input:
        lineages = expand("../final/{seq_run}/{exp}_transcript_lineages.csv", exp=EXP, seq_run=SEQ_RUN),
        salmon_dir = expand("../salmon_quant_results/{experiment_id}", experiment_id=EXP),
    output:
        species_counts = expand("../final/{seq_run}/{exp}_sp_counts.csv", exp=EXP, seq_run=SEQ_RUN),
        family_counts = expand("../final/{seq_run}/{exp}_family_counts.csv", exp=EXP, seq_run=SEQ_RUN)        
    shell:
        '''
        Rscript ./deseq2.R
        '''

Here's the top of my R script, which fails at the S4 object call:

library('DESeq2')
library('tximport')

#Read in dataframe that contains the trinity ID's linked to lineage information
df <- read.csv(snakemake@input[["lineages"]], header=TRUE)

The libraries load fine, the error message states:

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  object 'snakemake' not found
Calls: read.csv -> read.table
Execution halted

I'm trying to keep my dependencies organized within a conda .yml file, which looks like this:

name: test_env

channels:
  - conda-forge
  - bioconda
  - r
  - default

dependencies:
  - star =2.7.1a
  - trinity =2.12.0
  - samtools =1.12
  - salmon =1.4.0
  - snakemake
  - pandas
  - r=4.1.0
  - r-essentials
  - bioconductor-deseq2
  - bioconductor-tximport

Why is R not recognizing the snakemake inputs as described in the snakemake docs? I am running snakemake version 6.5.1.

The examples use script: rather than shell: So change to

script:
  "./deseq2.R"

rather than

shell:
    '''
    Rscript ./deseq2.R
    '''

It looks like snakemake needs to inject R code into the script to define the snakemake variable and it cannot do that with arbitrary shell commands. This is only done when the script file ends with ".R"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM