You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建Snakemake GEO数据集下载工作流时遇R脚本执行错误求助

问题排查与解决

错误现象

执行Snakemake工作流时触发以下错误:

RuleException: CalledProcessError in file /home/sara/sara/Snakefile, line 8: Command 'set -euo pipefail; Rscript --vanilla /home/sara/sara/.snakemake/scripts/tmps2lv_wlb.meta.R' returned non-zero exit status 1.
File "/home/sara/sara/Snakefile", line 8, in __rule_download
File"/home/sara/mambaforge/envs/snakemake/lib/python3.11/concurrent/futures/thread.py", line 58, in run Shutting down, this might take some time. Exiting because a job execution failed. Look above for error message

核心错误点与修复方案

1. R脚本语法与拼写错误

你的R脚本存在两处致命错误:

  • 变量名拼写错误:snakemakege应为snakemake
  • 参数访问方式错误:Snakemake在R环境中通过$访问参数/输出对象,而非[]

修改后的R脚本:

library(GEOquery)
# 遍历所有配置的样本进行下载
for (sample in snakemake@params$sample) {
  getGEOSuppFiles(sample, baseDir = snakemake@output$dir)
}

2. Conda包名拼写错误

config.yml中bioconducor-GEOquery拼写错误,修正为bioconductor-GEOquery:

env:
    - bioconductor-oligo
    - bioconductor-GEOquery
channels:
    - conda-forge
    - bioconda
Samples:
    - "GSE6955"
    - "GSE67311"

3. Snakefile环境配置缺失

当前Snakefile未指定使用Conda环境,导致R脚本无法找到已安装的生物信息学包。需在规则中添加conda配置,确保工作流调用指定环境:

configfile: "config.yml"
rule download:
    output: 
        dir= directory("/home/sara/sara/downloads/")
    params:
        sample=config["Samples"]
    conda:
        config["env"]
    script: 
        "scripts/meta.R"

更规范的做法是将环境定义单独写入environment.yml,再在Snakefile中引用:

environment.yml
name: geo-download
channels:
  - conda-forge
  - bioconda
dependencies:
  - bioconductor-oligo
  - bioconductor-GEOquery
修改后的Snakefile
configfile: "config.yml"
rule download:
    output: 
        dir= directory("/home/sara/sara/downloads/")
    params:
        sample=config["Samples"]
    conda:
        "environment.yml"
    script: 
        "scripts/meta.R"

4. 工作流输出追踪优化(可选)

若需要Snakemake单独追踪每个样本的下载文件,可修改规则为每个样本生成对应输出,避免仅依赖目录:

configfile: "config.yml"
rule all:
    input:
        expand("/home/sara/sara/downloads/{sample}/{sample}_RAW.tar", sample=config["Samples"])

rule download:
    output: 
        "/home/sara/sara/downloads/{sample}/{sample}_RAW.tar"
    params:
        sample="{sample}"
    conda:
        "environment.yml"
    script: 
        "scripts/meta.R"

对应的R脚本调整为:

library(GEOquery)
getGEOSuppFiles(snakemake@params$sample, baseDir = dirname(snakemake@output[[1]]))

验证步骤

  1. 先手动测试R脚本是否能正常运行:
    Rscript --vanilla scripts/meta.R
    
  2. 执行Snakemake时添加--use-conda参数,确保自动创建并使用指定环境:
    snakemake --use-conda --cores 1
    

内容的提问来源于stack exchange,提问作者ADHD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 09:00:41