South Green Logo

South Green Trainings pages

Description Hands On Lab Exercises for HPC
Related-course materials AdvancedHPC
Authors Ndomassi TANDO (
Creation Date 10/05/2019
Last Modified Date 17/05/2022


Practice 1: Install your own packages

1) Prepare your work environment

Create 3 folders:

2) Install bwa

Go to the download page of bwa

Download the 0.7.17 version in your ~/sources folder using wget

Read the instructions in the archive and install it into ~/softs/bwa-0.7.17 folder

Configure your .bashrc to use your version by default with adding the following line to your .bashrc:

export PATH=~/softs/bwa-0.7.17/:$PATH

source ~/.bashrc

Test your installation with the command:

which bwa

3) Install samtools

Go to the download page of samtools

Download the 1.15 version in your ~/sources folder

Read the instruction in the archive and install it into ~/softs/samtools-1.15 folder

Configure your .bashrc to use your version by default with adding the following line to your .bashrc:

export PATH=~/softs/samtools-1.15/bin:$PATH

source ~/.bashrc

Test your installation with the command:

which samtools

Practice 2: Create a module environment

1) Prepare your work environment

Create the folder ~/privatemodules

Modify your .basrc with the following:

module use --append $HOME/privatemodules

Place it after the if loop.

Comment the following lines:

export PATH=~/softs/bwa-0.7.17/:$PATH

export PATH=~/softs/samtools-1.15/bin:$PATH

Retrieve the following modulefile as example and modify it to your needs: /data2/formation/TP-advanced-hpc/modulefile-blast-2.4.0+

2) Create a modulefile for bwa 0.7.17

Create a folder ~/privatemodules/bwa

Into that folder create a modulefile 0.7.17

Don’t forget the conflict line

3) Create a modulefile for samtools-1.15

Create a folder ~/privatemodules/samtools

Into that folder create a modulefile 1.15

Don’t forget the conflict line

4) Check that you can see your modulefiles with module avail

They will appear under a new session /home/<your_login>/privatemodules

5) Load your modules and test them with the commands:

 $ whereis bwa
 $ whereis samtools

6) Try to load the following softwares and notice what happen:

 $ module load bwa/0.7.17
 $ module load samtools/1.15

Practice 3 : Launch a job array

A job array allows you to launch several computations at the same time in one script.

You can imagine launch up to 10000 jobs as the same time.

That is why is very important to launch your job array with %5 to launch it with 5 running jobs at the same time maximum.

In this exercise, we are going to launch a bwa mem on 15 different individuals in one job array script on several nodes at the same time.

At the end, we will receive 15 results files directly into our /home.

1) Have a look of the data you are going to use in /data2/formation/TP-advanced-hpc/bwa/fastqDir

The 2 pairs of read files for individual X are named as follow: CloneX.1.fastq and CloneX.2.fastq

With X for 1 to 15. X will be replaced in our script by SLURM_ARRAY_TASK_ID

2) Using a job array create a script to perform a bwa-mem on the 15 individuals

You can use the template script here: /data2/formation/TP-advanced-hpc/

The script should transfer the /data2/formation/TP-advanced-hpc/bwa/ folder into the /scratch of the node.

The command to use for the transfer is:

scp -r nas:/data2/formation/TP-advanced-hpc/bwa  /scratch/your_directory

Use your own module environment for bwa

The command to launch on every individual is

bwa mem bwa/reference.fasta bwa/fastqDir/CloneX.1.fastq bwa/fastqDir/CloneX.2.fastq > bwa/results/mapping-X.sam

Practice 4: Install Singularity

Install dependencies:

With apt get

$ sudo apt-get update && sudo apt-get install -y  build-essential libssl-dev uuid-dev libgpgme11-dev squashfs-tools libseccomp-dev git pkg-config

With yum

$ sudo yum update -y && \
      sudo yum groupinstall -y 'Development Tools' && sudo yum install -y openssl-devel libuuid-devel libseccomp-devel wget squashfs-tools git

Install The programming language Go:

We are going to install the archive go.1.20.4.linux-amd64.tar.gz

Launch the following commands:

export VERSION=1.20.4 OS=linux ARCH=amd64 
  sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz 
  rm go$VERSION.$OS-$ARCH.tar.gz    

Set up your environment for Go with the following commands:

echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.bashrc
  source ~/.bashrc

Download and install singularity from repo:

Launch the following command to install singularity

# move to the singularity folder
     tar xvfz singularity-ce-3.8.0.tar.gz
     cd singularity-ce-3.8.0
     # launch the mconfig command ( you can add the option --prefix=path to custom the installation directory)
     ./mconfig --prefix=/usr/local/singularity-3.8.0
     # Compile into the build directory
     make -C ./builddir
     # Install the binaries into /usr/local/bin by default as superuser
     sudo make -C ./builddir install

Type the following command to your .bashrc file to locate singularity

 echo 'export PATH=/usr/local/singularity-3.8.0/bin:$PATH' >> ~/.bashrc
    # resource your .bashrc
    source ~/.bashrc

Practice 5 : Create your own Singularity container

In your home user, create 2 folders:

mkdir ~/def

mkdir ~/containers

1) Create a recipe file:

A Singularity Recipe includes specifics about installation software, environment variables, files to add, and container metadata.

Retrieve the singularity.def file /data2/formation/TP-advanced-hpc/singularity.def

Modify it to create a recipe file for bwa 0.7.17 named bwa-0.7.17.def in your ~/def folder

2) On your own PC in your ~/containers folder, Build your singularity image from your recipe file as superuser

 sudo /usr/local/singularity-3.8.0/bin/singularity build ../containers/bwa-0.7.17.simg bwa-0.7.17.def 

It will produce a singularity image called bwa-0.7.17.simg

3) Test your container

 singularity run ../containers/bwa-0.7.17.simg 

4) Transfer your container from your PC to into your /home using filezilla or scp

 scp ../containers/bwa-0.7.17.simg

Then , connect to and run the following commands:

 srun -p short --pty bash -i

cd /scratch

mkdir formationX

cd formationX

scp -r nas:/data2/formation/TP-advanced-hpc/bwa .

scp  ~/bwa-0.7.17.simg .

module load system/singularity/3.6.0

mkdir bwa/results

singularity run ~/bwa-0.7.17.simg mem bwa/reference.fasta bwa/fastqDir/Clone1.1.fastq bwa/fastqDir/Clone1.2.fastq > bwa/results/mapping-1.sam

Check if you get a mapping-1.sam file then erase your folder and go back to master0


rm -rf /scratch/formationX


Practice 6 : Use your own Singularity container with sbatch

You have to add module load system/singularity/3.6.0 in your modulefile and point to the location of your container


The resource material is licensed under the Creative Commons Attribution 4.0 International License (here).