Using scratch on Crunchomics

Basics

Crunchomics has one login node (omics-h0) and 5 compute nodes (omics-cn001 to omics-cn005). Each of these has its own local scratch storage, which you reach with cd /scratch. The scratch of a compute node has around 8 TB of fast storage space, shared with everyone.

The scratch of a node is only accessible from that node. Files that you write to the scratch on omics-cn002 are not visible from omics-cn003 or from the login node. So either you copy the data to each node that needs it, or you send your jobs to one particular node with the -w option. More information can be found below and in the Crunchomics documentation.

Important

Scratch is temporary storage space. Files are automatically deleted after one month of inactivity. Scratch is also shared by all Crunchomics users, so remove your files when your analysis is done.

For the basics of srun and sbatch, see Start working on an HPC.

Working on a compute node interactively

We can log in to a compute node to work interactively as follows:

srun --cpus-per-task=1 --mem=50G --time=00:30:00 -w omics-cn002 --pty bash -i

Here, we request 1 CPU (--cpus-per-task=1) and 50 GB of memory (--mem=50G) for 30 minutes (--time=00:30:00). --pty bash -i opens an interactive bash shell, and -w omics-cn002 sends the job to compute node omics-cn002. After running this, the prompt shows omics-cn002 instead of omics-h0, which confirms that we are now on compute node omics-cn002.

First, we check whether the scratch still has enough free space for our analysis. df shows the size, used space and free space of each file system:

df -h

In the list, search for scratch or ssdstorage. This is a mount point to the scratch and we need to look for this term to find out how much space we have available. We should see something like this telling us that 28% of space is in use and that we still have 5.2T available:

ssdstorage 7.2T  2.0T  5.2T  28% /ssdstorage

This is enough for our analysis, so we now make a project folder on the scratch. $USER stands for your user name.

# Make a project folder (-p also makes the parent folder /scratch/$USER)
mkdir -p /scratch/$USER/climate

# Move into the project folder
cd /scratch/$USER/climate

# Run your analysis, here: download some data
# This runs on the compute node, with the resources we requested
mkdir data
wget https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/027/325/GCF_000027325.1_ASM2732v1/GCF_000027325.1_ASM2732v1_genomic.fna.gz -P data

# Check that the data is on the scratch of compute node omics-cn002
ls -lh data

Moving data around

To the personal folder

Each scratch can only be accessed from its own node. But your personal folder is accessible from all nodes, so you can copy the downloaded data there:

# Make the target folder in your personal folder
mkdir -p /zfs/omics/personal/$USER/climate/data

# Copy the data
cp data/*gz /zfs/omics/personal/$USER/climate/data/

# Check that the data arrived
ls -lh /zfs/omics/personal/$USER/climate/data/

Move data between scratches

If you don’t have enough space left in your personal folder, there is a slightly complicated way to copy data between the scratch of a compute node and the scratch of the login node:

# Leave the compute node, if you are still logged in to it
exit

# Go to your folder on the scratch of the login node
mkdir -p /scratch/$USER
cd /scratch/$USER

# Copy files from omics-cn002 to the login node
# This command packs the files with tar on omics-cn002, sends them to the login node and unpacks them there
srun -N1 -w omics-cn002 bash -c 'cd /scratch/$USER/climate/data && tar -cf - *fna.gz' | tar -xf - -C /scratch/$USER/

# The other way around: copy a file from the scratch of the login node to omics-cn002
touch test.txt # make an empty test file
tar -cf - test.txt | srun -N1 -w omics-cn002 bash -c 'mkdir -p /scratch/$USER/climate && cd /scratch/$USER/climate && tar -xf -'

# Check that the file is there
srun -w omics-cn002 ls -lh /scratch/$USER/climate

Running a job script on a specific node

For longer running jobs that contain multiple steps, a job script is better than srun. Copy the example below into a new job script with nano scripts/align.sh and save it with Ctrl+X, y and Enter. In the same way, you could for example run an R script with Rscript my_code.R inside a job script.

#!/bin/bash
#SBATCH --job-name=align_Mycoplasma
#SBATCH --output=logs/align_%j.out
#SBATCH --error=logs/align_%j.err
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem-per-cpu=2G
#SBATCH --time=00:10:00

# Prepare a working folder on the scratch
WD="/scratch/$USER/alignment"
mkdir -p $WD
cd $WD

# Download the Mycoplasma genome and build the index
# This and all following steps download and process the data in /scratch/$USER/alignment
wget https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/027/325/GCF_000027325.1_ASM2732v1/GCF_000027325.1_ASM2732v1_genomic.fna.gz -P ./
bowtie2-build GCF_000027325.1_ASM2732v1_genomic.fna.gz MG37

# Download the 2 Illumina files
wget ftp://ftp.sra.ebi.ac.uk/vol1/fastq/ERR486/ERR486828/ERR486828_1.fastq.gz -P ./
wget ftp://ftp.sra.ebi.ac.uk/vol1/fastq/ERR486/ERR486828/ERR486828_2.fastq.gz -P ./

# Run the alignment
bowtie2 -x MG37 -1 ERR486828_1.fastq.gz -2 ERR486828_2.fastq.gz --very-fast -p $SLURM_CPUS_PER_TASK -S result_ERR486828.sam

# Copy the result to the personal folder, which you can reach from every node
mkdir -p /zfs/omics/personal/$USER/alignment
cp result_ERR486828.sam /zfs/omics/personal/$USER/alignment/

Submit the job to a specific node with -w. The job script is a file in your personal folder, so you submit it from there:

# Make the logs folder first: SLURM does not create it
mkdir -p logs

sbatch -w omics-cn002 scripts/align.sh

# Check if the job is still running
squeue -u $USER

# Check that files are created on the scratch of omics-cn002
srun -w omics-cn002 ls -lh /scratch/$USER/alignment

# After the job finished: check that the result was copied to your personal folder
ls -lh /zfs/omics/personal/$USER/alignment/

Cleaning up

When your analysis is done and you checked that the results are in your personal folder, remove your files from the scratch. Look at what is there first, then remove it:

# Check what is in your scratch folder on omics-cn002
srun -w omics-cn002 ls -lh /scratch/$USER/

# Remove the alignment folder from the scratch of omics-cn002
srun -w omics-cn002 rm -r /scratch/$USER/alignment