ncbi / vadr

Viral Annotation DefineR: classification and annotation of viral sequences based on RefSeq annotation
Other
99 stars 23 forks source link

v-annotate.pl cannot be run with apptainer exec using the VADR Biocontainers Apptainer/Singularity image #87

Open peterk87 opened 2 months ago

peterk87 commented 2 months ago

Hello,

I'm not sure if it's appropriate to post this issue here since it's an issue with the VADR Biocontainer image created from the Bioconda recipe. This issue only arises when running VADR using the Biocontainers Apptainer/Singularity image with Nextflow. There's no issue when running VADR with Nextflow using Conda/Mamba or Docker.

Pulling the VADR Biocontainers Docker image and creating the Apptainer image:

$ apptainer pull docker://quay.io/biocontainers/vadr:1.6.4--pl5321h031d066_0 quay.io-biocontainers-vadr-1.6.4--pl5321h031d066_0.img

Apptainer exec does not have the vadr module in the PERL5LIB env var:

$ apptainer exec quay.io-biocontainers-vadr-1.6.4--pl5321h031d066_0.img v-annotate.pl --help

Can't locate vadr.pm in @INC (you may need to install the vadr module) (@INC contains: /usr/local/lib/perl5/5.32/site_perl /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.32/vendor_perl /usr/local/lib/perl5/vendor_perl /usr/local/lib/perl5/5.32/core_perl /usr/local/lib/perl5/core_perl .) at /usr/local/bin/v-annotate.pl line 13.

Apptainer run works fine since the activation script that sets the PERL5LIB path is sourced:

$ apptainer run quay.io-biocontainers-vadr-1.6.4--pl5321h031d066_0.img v-annotate.pl --help

# v-annotate.pl :: classify and annotate sequences using a model library
# VADR 1.6.4 (Jun 2024)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# date:    Fri Sep 20 15:36:33 2024
#
Usage: v-annotate.pl [-options] <fasta file to annotate> <output directory to create>
...

With $ apptainer exec $IMG bash:

Apptainer> echo $PERL5LIB
# empty/not set

With $ apptainer run $IMG:

Apptainer> echo $PERL5LIB
/usr/local/share/vadr-1.6.4/vadr::/usr/local/share/sequip-0.10/lib

The VADR Bioconda build.sh script creates an activation script:

https://github.com/bioconda/bioconda-recipes/blob/dc96225686dbc772fc733265d51a934ac0f050f2/recipes/vadr/build.sh#L57

But it looks like the script is only sourced when running with Conda, Docker or apptainer run.

Maybe a wrapper script that explicitly sets the necessary env vars would help?

cat > $PREFIX/bin/v-annotate <<EOF
#!/bin/bash
source "${PREFIX}/etc/conda/activate.d/vadr.sh"
$PREFIX/bin/v-annotate.pl "\$@"
EOF

chmod +x $PREFIX/bin/v-annotate