Snakemake with R script, error: snakemake object not found

Snakemake with R script, error: snakemake object not found

我在尝试 运行 调用 R 脚本的 snakemake 规则时遇到问题。相关的 snakemake 规则如下所示:

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
        '''

这是我的 R 脚本的顶部,它在 S4 对象调用时失败:

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)

库加载正常,错误消息指出:

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

我试图将我的依赖项组织在一个 conda .yml 文件中,该文件如下所示:

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

为什么 R 无法识别 snakemake 文档中描述的 snakemake 输入?我是 运行ning snakemake 版本 6.5.1.

示例使用 script: 而不是 shell: 所以改为

script:
  "./deseq2.R"

而不是

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

看起来 snakemake 需要 inject R code 到脚本中来定义 snakemake 变量,它不能用任意 shell 命令来做到这一点。仅当脚本文件以“.R”结尾时才执行此操作