在Nextflow中执行奇点容器时激活conda环境 [英] Activate conda environment on execution of Singularity container in Nextflow
问题描述
我正在使用奇点容器来运行Nextflow工作流管理系统中的命令。我在Singularity内部有一个conda环境,当我将其装入容器时可以激活它
I am using Singularity containers to run commands from Nextflow workflow management system. I have a conda environment inside Singularity which I can activate when I shell into the container
singularity pull shub://brucemoran/Singularity:pcgr.centos7
singularity shell brucemoran-Singularity-pcgr.centos7.img
#<inside container>
source activate pcgr
执行Nextflow时,我已定义为 source激活pcgr
,我认为应该激活conda env。但是我收到绑定变量HOST
警告。我认为这与非激活以及随后使用的变量有关,这些变量应在激活env(?)时定义。
When Nextflow executes I have defined to source activate pcgr
which I think should activate the conda env. But I get an unbound variable HOST
warning. I think that relates to the non-activation and subsequent use of variables that should be defined if the env was activated(?).
我希望容器激活env(pcgr)每当执行时。我尝试了
I would like the container to activate the env (pcgr) whenever it is executed. I tried with
%run
source activate pcgr
和
%post
source activate pcgr
但这对我不起作用
singularity exec pcgr.img which pcgr.py
which: no pcgr.py in ...
我看不到它是如何完成的,但是假设它很简单,并且我在很大程度上忽略了某些东西!
I cannot see how this is done, but presume it is easy and I am massively overlooking something!
帮助表示赞赏。
推荐答案
以奇异的外壳在特殊环境中运行,因此对 .bashrc的标准conda修改
不起作用。相反,您需要修改 $ SINGULARITY_ENVIRONMENT 变量。奇点定义文件中的以下几行应该可以正常工作:
The shell in singularity runs in a special environment, so the standard conda modifications to the .bashrc
do not work. Instead, you need to modify the $SINGULARITY_ENVIRONMENT variable. Something along these lines in your Singularity definition file should work:
# set to whatever your conda path is, I usually install to /opt
echo "source /opt/conda/etc/profile.d/conda.sh" >> $SINGULARITY_ENVIRONMENT
echo "conda activate pcgr" >> $SINGULARITY_ENVIRONMENT
这种方式将自动激活conda环境。如果您希望在步骤中手动激活它,则可以省去第二行,而在%run
步骤中这样做。
This way the conda environment will automatically be activated. If you prefer to activate it manually in your steps, you can leave out the second line and do so in your %run
steps.
这篇关于在Nextflow中执行奇点容器时激活conda环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!