Podman容器中Snakemake调用Conda环境执行命令失败求助
解决Podman容器内Snakemake+Conda执行命令失败的问题
问题原因
错误里的source: not found是因为Podman容器默认使用dash作为/bin/sh,而source是Bash的内置命令,dash不支持(dash中对应命令是.)。Snakemake激活Conda环境时默认用source,导致激活失败,进而找不到fasterq-dump命令。
解决方法
方法1:强制Snakemake使用Bash执行shell命令
在Snakefile中为目标rule指定Bash作为执行shell,修改后的rule如下:
rule download: output: "out/SRR12346784.fastq" conda: "/home/keks/app/conda_env.yml" shell: "/bin/bash -c 'fasterq-dump --split-files --outdir out SRR12346784'"
或者全局设置所有rule使用Bash,在Snakefile开头添加:
shell: "/bin/bash"
方法2:直接调用Conda环境内命令的绝对路径
既然已经知道Snakemake生成的Conda环境路径,直接使用该路径下的fasterq-dump:
rule download: output: "out/SRR12346784.fastq" conda: "/home/keks/app/conda_env.yml" shell: """ /home/keks/app/.snakemake/conda/6a57ef84/bin/fasterq-dump --split-files --outdir out SRR12346784 """
注意:该路径是Snakemake根据环境配置生成的哈希路径,若修改conda_env.yml,路径会变化,仅适合临时测试。
方法3:修改Podman容器默认Shell为Bash
启动Podman容器时,指定默认Shell为Bash:
podman run --entrypoint /bin/bash -it [你的镜像名]
这样容器内/bin/sh会指向Bash,Snakemake的source命令就能正常执行。
方法4:升级Snakemake版本
部分旧版本Snakemake在处理非Bash的Shell时存在兼容问题,升级到最新稳定版可能解决该问题:
conda install -c bioconda snakemake --update-all
内容的提问来源于stack exchange,提问作者kEks
相关产品推荐
相关产品推荐

