Singularity (Bioperl Example)

We are able to use 'singularity' containers (similar to Docker containers) to run some speciality software which may not compile or run under the regular CentOS/RedHat operating systems on the CSC clusters.

This is an example of how to use a container to run a simple Bioperl script from their example/tutorial.

If you just want to test out a container, you can open it with a shell (note this shouldn't be for long running jobs as you're running it on the login node).  Just once (per login session) you need to set up the environment (with module)

module load singularity 

Then you can start the container (assuming you using one of the prebuilt containers in /sw/csc/SingularityImg - or, of course, you can point to your own in your home directory)

singularity shell  /sw/csc/SingularityImg/ubuntu_bioperl_biopy2.img

then you can run commands within it (e.g. before and after this type  'gcc -v' to see that it's a different (newer) environment - below is an example (with some output removed for clarity)

[pcw@knot ~]$ gcc -v
gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
[pcw@knot ~]$ singularity shell /sw/csc/SingularityImg/ubuntu_bioperl_biopy2.img

gcc -Singularity: Invoking an interactive shell within container...

Singularity ubuntu_bioperl_biopy2.img:~>
Singularity ubuntu_bioperl_biopy2.img:~> gcc -v

gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2)
Singularity ubuntu_bioperl_biopy2.img:~> exit

to run a single command within singularity you can use 'exec' rather than shell.  e.g.singularity exec /sw/csc/SingularityImg/ubuntu_bioperl_biopy2.img gcc -v

and this is how you'll use it in a job script.

Back to Bioperl - if you have a simple perl script named bioseq.pl

use Bio::Seq; use Bio::SeqIO;

$seq_obj = Bio::Seq->new(-seq=>"aaaatgggggggggggccccgtt",
                         -display_id => "#12345",
                         -desc => "example 1",
                         -alphabet => "dna" );

$seqio_obj = Bio::SeqIO->new(-file => '>sequence.fasta', -format => 'fasta' );

$seqio_obj->write_seq($seq_obj);

then you'd just run it from a batch script that looks like this

#!/bin/bash -l
#PBS -l nodes=1:ppn=4

cd $PBS_O_WORKDIR

# gets rid of a warning from perl in singularity
LANG=C

# note you need '-l' after bash at first line to use 'module'...
module load singularity
# now  execute the perl script in the bioperl container 
#  (this should all be on one line)
singularity exec /sw/csc/SingularityImg/ubuntu_bioperl_biopy2.img   perl bioseq.pl

i.e. note that last line that just runs the perl script from within the singularity container!