Genomic Data Science
Introduction: The workshop session will provide a quick tour covering high-level concepts, commands and processes for using Linux and HPC on our MedicineBow cluster. It will cover enough to allow an attendee to access the cluster and to perform analysis associated with this workshop.
Goals:
Introduce ARCC and what types of services we provide including “what is HPC?”
Define “what is a cluster”, and how is it made of partitions and compute nodes.
How to access and start using ARCC’s MedicineBow cluster - using our OnDemand service.
How to start an interactive desktop and open a terminal to use Linux commands within.
Introduce the basics of Linux, the command-line, and how its File System looks on MedicineBow.
Introduce Linux commands to allow navigation and file/folder manipulation.
Introduce Linux commands to allow text files to be searched and manipulated.
Introduce using a command-line text-editor and an alternative GUI based application.
How to setup a Linux environment to use R(/Python) and start RStudio, by loading modules.
How to start interactive sessions to run on a compute node, to allow computation, requesting appropriate resources.
How to put elements together to construct a workflow that can be submitted as a job to the cluster, which can then be monitored.
We will not be covering:
We will not covering, but workshops are available, on:
Using a terminal to SSH onto the Cluster - see Intro to Accessing the Cluster.
Data Management nor Data Transfer (such as using Globus).
Using / Creating Conda Environments - one method for installing your own software.
Using the Jupyter Service via OnDemand.
Sections
- 1 Sections
- 2 *** Class 01 ***
- 3 00 Introduction and Setting the Scope:
- 4 01 About UW ARCC and HPC
- 5 02 Using OnDemand to access the MedicineBow HPC Cluster
- 6 03 Using Linux and the Command Line
- 7 04 Text Editors
- 8 *** Class 02 ***
- 9 05 Using Linux to Search/Parse Text Files
- 10 06 Lets start using R(/Python) and RStudio
- 11 07 Create a basic workflow and submitting jobs.
- 12 08 Summary and Next Steps
*** Class 01 ***
00 Introduction and Setting the Scope:
HPC Skills to Learn: The roadmap to becoming a proficient HPC user can be long, complicated, and varies depending on the user.
Typically what we’re going to cover over the next two classes we’d use two full days.
So bear in mind that we’ll be introducing key high-level concepts, with not as much time for questions/exercises that we’d normally provide.
The classes will be more hands-on demonstrations for you to listen to, follow along where you can - but you’ll need to and be expected to work through these in your own time.
More extensive and in-depth information and walkthroughs are available on our wiki and under workshops/tutorials. You are welcome to dive into those in your own time. Content within them will provide you with a lot more detail and examples of the foundational concepts you would need to be familiar with to become a proficient HPC user.
01 About UW ARCC and HPC
Goals:
Describe ARCC’s role at UW.
Provide resources for ARCC Researchers to seek help.
Introduce staff members, including those available throughout the workshop.
Introduce the concept of an HPC cluster, it’s architecture and when to use one.
Introduce the MedicineBow HPC architecture, hardware, and partitions.
About ARCC and how to reach us
In short, we maintain internally housed scientific resources including more than one HPC Cluster, data storage, and several research computing servers and resources.
We are here to assist UW researchers like yourself with your research computing needs.
Exercise: Navigate to our Service Portal and submit a General Research Computing Support question.
Under the Please further describe your issue section make sure to enter the work “Test”.
What is HPC
HPC stands for High Performance Computing and is one of UW ARCC’s core services. HPC is the practice of aggregating computing power in a way that delivers a much higher performance than one could get out of a typical desktop or workstation. HPC is commonly used to solve large problems, and has some common use cases:
Performing computation-intensive analyses on large datasets: MB/GB/TB in a single or many files, computations requiring RAM in excess of what is available on a single workstation, or analysis performed across multiple CPUs (cores) or GPUs.
Performing long, large-scale simulations: Hours, days, weeks, spread across multiple nodes each using multiple cores.
Running repetitive tasks in parallel: 10s/100s/1000s of small short tasks.
|
---|
What is a Compute Node?
We typically have multiple users independently running jobs concurrently across compute nodes - multi-tentancy.
Resources are shared, but do not interfere with any one else’s resources.
i.e. you have your own cores, your own block of memory.
If someone else’s job fails it does NOT affect yours.
Homogeneous vs Heterogeneous HPCs
There are 2 types of HPC systems:
Homogeneous: All compute nodes in the system share the same architecture. CPU, memory, and storage are the same across the system. (Ex: NWSC’s Derecho)
Heterogeneous: The compute nodes in the system can vary architecturally with respect to CPU, memory, even storage, and whether they have GPUs or not. Usually, the nodes are grouped in partitions. MedicineBow is a heterogeneous cluster.
Cluster: Heterogeneous: Partitions
MedicineBow Hardware Summary Table: Understand what resources are available.
02 Using OnDemand to access the MedicineBow HPC Cluster
Goals:
Demonstrate how users log into OnDemand.
Demonstrate requesting and using a XFCE Desktop Session
Introduce the Linux File System and how it compares to common workstation environments
Introduce HPC specific directories and how they’re used
Introduce MedicineBow specific directories and how they’re used
Demonstrate how to access files using the MedicineBow File Browsing Application
Demonstrate the use of emacs, available as a GUI based text-editor
Log in and Access the Cluster
Open OnDemand Dashboard: This service allows users to access MedicineBow cluster over a web-based portal, via a browser.
Exercise: Open an Interactive Desktop:
Structure of the Linux File System and HPC Directories
From within the Interactive Desktop:
Linux File Structure: Double click on the Home icon, and then File System.
This is specific to the MedicineBow HPC but most Linux environments will look very similar:
Linux Operating Systems (Generally)
Compare and Contrast: Linux, HPC Specific, MedicineBow Specific
Based on: MedicineBow Filesystem
The project name for this class is: genomicdatasci
Exercise: File Browsing in OnDemand GUI: The Files Category and App
03 Using Linux and the Command Line
Goals:
Introduce the shell terminal and command line interface
Demonstrate starting a MedicineBow SSH shell using OnDemand
Demonstrate information provided in a command prompt
Introduce Policy for HPC Login Nodes
Demonstrate how to navigate the file system to create and remove files and folders using command line interface (CLI)
mkdir
,cd
,ls
,mv
,cp
Demonstrate the use of
man
,--help
and identify when these should be usedDemonstrate using a command-line text editor,
vi
Based on Workshop: Intro to Linux Command-Line: The File System
Exercise: Shell Terminal Introducing Command Line
Getting Started: Using the OnDemand service: Using the Terminal:
What am I Using?
Remember:
The MedicineBow Shell Access opens up a new browser tab that is running on a login node. Do not run any computation on these.
[<username>@mblog1/2 ~]$
The OnDemand Interactive Desktop (terminal) is already running on a compute node.
[<username>@mbcpu-001 ~]$
Login Node Policy
As a courtesy to your colleagues, please do not run the following on any login nodes:
Anything compute-intensive (tasks using significant computational/hardware resources - Ex: using 100% cluster CPU)
Any collection of a large # of tasks resulting in a similar hardware footprint to actions mentioned previously.
Either start an Interactive Desktop, an interactive session (
salloc
) or submit a job (sbatch
) These will be covered later.See more on our ARCC HPC Policies.
Demonstrating how to get help in CLI
| [<username>@mblog1 ~]$ man pwd
NAME
pwd - print name of current/working directory
SYNOPSIS
pwd [OPTION]...
DESCRIPTION
Print the full filename of the current working directory.
-L, --logical
use PWD from environment, even if it contains symlinks
-P, --physical
avoid all symlinks
--help display this help and exit
--version
output version information and exit
If no option is specified, -P is assumed.
NOTE: your shell may have its own version of pwd, which usually supersedes the version described here. Please refer to your shell's documentation
for details about the options it supports. |
| [<username>@mblog1 ~]$ cp --help
Usage: cp [OPTION]... [-T] SOURCE DEST
or: cp [OPTION]... SOURCE... DIRECTORY
or: cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. |
Demonstrating file navigation in CLI
File Navigation demonstrating the use of:
| [<username>@mblog1 ~]$ pwd
/home/<username>
[<username>@mblog1 ~]$ ls
Desktop Documents Downloads ondemand R
[<username>@mblog1 ~]$ cd /project/genomicdatasci
[<username>@mblog1 genomicdatasci]$ pwd
/project/genomicdatasci
[<username>@mblog1 genomicdatasci]$ cd <username>
[<username>@mblog1 <username>]$ ls -la
total 2.0K
drwxr-sr-x 2 <username> genomicdatasci 4.0K May 23 11:05 .
drwxrws--- 80 root genomicdatasci 4.0K Jun 4 14:39 ..
[<username>@mblog1 <username>]$ pwd
/project/genomicdatasci/<username>
[<username>@mblog1 <username>]$ cd ..
[<username>@mblog1 genomicdatasci]$ pwd
/project/genomicdatasci |
Demonstrating how to create and remove files and folders using CLI
Creating, moving and copying files and folders:
| [<username>@mblog1 genomicdatasci]$ cd <username>
[<username>@mblog1 <username>]$ touch testfile
[<username>@mblog1 <username>]$ mkdir testdirectory
[<username>@mblog1 <username>]$ ls
testdirectory testfile
[<username>@mblog1 <username>]$ mv testfile testdirectory
[<username>@mblog1 <username>]$ ls
testdirectory
[<username>@mblog1 <username>]$ cd testdirectory
[<username>@mblog1 testdirectory]$ ls
testfile
[<username>@mblog1 testdirectory]$ cd ..
[<username>@mblog1 <username>]$ cp -r testdirectory ~
[<username>@mblog1 <username>]$ cd ~
[<username>@mblog1 ~]$ pwd
/home/<username>
[<username>@mblog1 ~]$ ls
Desktop Documents Downloads ondemand R testdirectory
[<username>@mblog1 ~]$ cd testdirectory
[<username>@mblog1 ~]$ ls
testfile
[<username>@mblog1 ~]$ rm testfile
[<username>@mblog1 ~]$ ls
[<username>@mblog1 ~]$ |
04 Text Editors
See Workshop: Intro to Text Editors in Linux
You can use Text Editors from:
from the command-line.
via GUI, from an Interactive Desktop, using emacs: Applications > Accessories > Emacs
*** Class 02 ***
05 Using Linux to Search/Parse Text Files
Goals:
Using the command-line, demonstrate how to search and parse text files.
Show how
export
can be used to setup environment variables andecho
to see what values they store.Linux Commands:
find
cat
/head
/tail
/grep
sort
/uniq
Pipe
|
output from one command to the input of another, and redirect to a file using>
,>>
.
Based on Workshop: Intro to Linux Command-Line: View Find and Search Files
Your Environment: Echo and Export
# View the settings configured within your environment.
[~]$ env
# View a particular environment variable
# PATH: Where you environment will look for execuatables/commands.
[~]$ echo $PATH
# Create an environment variable that points to the workshop data folder.
[~] export TEST_DATA=/project/genomicdatasci/software/test_data
# Check it has been correctly set.
[~]$ echo $TEST_DATA
/project/genomicdatasci/software/test_data
Use Our Environment Variable
# Lets use it.
# Navigate to your home.
[~]$ cd
# Navigate to the workshop data folder.
[~]$ cd $TEST_DATA
[test_data]$ pwd
/project/genomicdatasci/software/test_data
These are only available within this particular terminal/session.
Once you close this terminal, they are gone.
They are not available across other terminals.
Advanced: To make 'permanent' you can update your
~/.bashrc
Search for a File
Based on: Search for a File
Linux is case-sensitive.
[test_data]$ cd /project/genomicdatasci/software/test_data
# Find a file using its full name.
[test_data]$ find . -name "epithelial_overrep_gene_list.tsv"
./scRNASeq_Results/epithelial_overrep_gene_list.tsv
# Remember, Linux is case sensitive
# Returned to command prompt with no output.
[test_data]$ find . -name "Epithelial_overrep_gene_list.tsv"
[test_data]$
# Use case-insensitive option:
[test_data]$ find . -iname "Epithelial_overrep_gene_list.tsv"
./scRNASeq_Results/epithelial_overrep_gene_list.tsv
Use Wildcards *
# Use Wildcards:
[test_data]$ find . -name "epithelial*"
./scRNASeq_Results/epithelial_overrep_gene_list.tsv
./scRNASeq_Results/epithelial_de_gsea.tsv
[test_data]$ find . -name "*.tsv"
./Grch38/Hisat2/exons.tsv
./Grch38/Hisat2/splicesites.tsv
./DE_Results/DE_sig_genes_DESeq2.tsv
./DE_Results/DE_all_genes_DESeq2.tsv
./scRNASeq_Results/epithelial_overrep_gene_list.tsv
./scRNASeq_Results/epithelial_de_gsea.tsv
./Pathway_Results/fc.go.cc.p.down.tsv
./Pathway_Results/fc.go.cc.p.up.tsv
./BatchCorrection_Results/DE_genes_uhr_vs_hbr_corrected.tsv
View the Contents of a File
Based on: View/Search a File
[]$ cd /project/genomicdatasci/software/test_data/scRNASeq_Results
# View the contents of a TEXT based file:
# Prints everything.
[scRNASeq_Results]$ cat epithelial_overrep_gene_list.tsv
# View 'page-by-page'
# Press 'q' to exit and return to the command-line prompt.
[scRNASeq_Results]$ more epithelial_overrep_gene_list.tsv
View the Start and End of a File
# View the first 10 items.
[]$ head epithelial_overrep_gene_list.tsv
# View the first 15 items.
[]$ head -n 15 epithelial_overrep_gene_list.tsv
# View the last 10 items.
[]$ tail epithelial_overrep_gene_list.tsv
# View the last 5 items.
[]$ tail -n 5 epithelial_overrep_gene_list.tsv
# On a login node, remember you can use 'man head'
# or tail --help to look up all the options for a command.
Search the Contents of a Text File
[]$ cd /project/genomicdatasci/software/test_data/scRNASeq_Results
# Find rows containing "Zfp1"
# Remember: Linux is case-sensitive
# Searching for all lower case: zfp1
[]$ grep zfp1 epithelial_overrep_gene_list.tsv
[]$
# Searching with correct upper/lower case combination: Zfp1
# Returns all the lines that contain this piece of text.
[]$ grep Zfp1 epithelial_overrep_gene_list.tsv
Zfp106
Zfp146
Zfp185
Zfp1
Grep-ing with Case-Insensitive and Line Numbers
# Grep ignoring case.
[]$ grep -i zfp1 epithelial_overrep_gene_list.tsv
Zfp106
Zfp146
Zfp185
Zfp1
# What line numbers are the elements on?
[]$ grep -n -i zfp1 epithelial_overrep_gene_list.tsv
696:Zfp106
1998:Zfp146
2041:Zfp185
2113:Zfp1
Pipe: Count, Sort
Based on: Output Redirection and Pipes
[]$ cd /project/genomicdatasci/software/test_data/scRNASeq_Results
# Pipe: direct the output of one command to the input of another.
# Count how many lines/rows are in a file.
[]$ cat epithelial_overrep_gene_list.tsv | wc -l
2254
# Alphabetically soft a file:
[] sort epithelial_overrep_gene_list.tsv
...
Zswim4
Zyx
Zzz3
Zzz3
# Count lines after sorting.
[]$ sort epithelial_overrep_gene_list.tsv | wc -l
2254
Uniq
# Find and list the unique elements within a file.
# You need to sort your elements first.
[] sort epithelial_overrep_gene_list.tsv | uniq
...
Zswim4
Zyx
Zzz3
# You can pipe multiple commands together.
# Find, list and count the unique elements within a file:
[] sort epithelial_overrep_gene_list.tsv | uniq | wc -l
2253
Redirect Output into a File
# Redirect an output into a file.
# > : Over writes a file
# >> : Appends to a file.
[] sort epithelial_overrep_gene_list.tsv > sorted.tsv
# This will fail for anyone else.
-bash: sorted.tsv: Permission denied
# You do not have write permission within this folder.
[]$ cd ..
[]$ ls -al
drwxr-sr-x 2 <username> genomicdatasci 4096 May 31 13:50 scRNASeq_Results
# Redirect to a location where you do have write permission - you home folder.
[]$ cd scRNASeq_Results/
[]$ sort epithelial_overrep_gene_list.tsv > ~/sorted.tsv
[]$ ls ~
... sorted.tsv ...
[]$ head ~/sorted.tsv
For further details on permissions, read through File Ownership and Permissions.
06 Lets start using R(/Python) and RStudio
Goals:
Using a terminal (via an Interactive Desktop), demonstrate how to load modules to setup an environment that uses R/RStudio and how to start the GUI.
Mention how the module system will be used, in later workshops, to load other software applications.
(Indicate how this relates to setting up environment variables behind the scenes.)
Further explain the differences between using a login node that requires an
salloc
to access a compute node, and that you're already running on a compute node (with limited resources) via an interactive desktop.Confirm arguments for
partition
,gres/gpu
.Note that can confirm a GPU device is available by running
nvidia-smi -L
from the command-line.
Show how the resources from the Interactive Desktop configuration start mapping to those used by
salloc
.
Based on Workshops:
Open a Terminal
You can access a Linux terminal from OnDemand by:
Opening up an Interactive Desktop and opening a terminal.
Running on a compute node: Command prompt:
[<username>@t402 ~]$
Only select what you require:
How many hours? Your session will NOT run any longer that the amount of hours you requested.
Some Desktop Configurations will NOT work with some GPU Types.
Do you actually need a GPU?
Unless you software/library/package has been developed to utilize a GPU, simply selected one will NOT make any difference - this won’t make you code magically run faster.
Selecting a MedicineBow Shell Access which opens up a new browser tab.
Running on the login node:
[<username>@mblog1/2 ~]$
To run any GUI application, you must use OnDemand and an Interactive Desktop.
Setting Up a Session Environment
Across the class, you’ll be using a number of different environments.
Running specific software applications.
Programming with R and using various R libraries.
Programming with Python and using various Python packages.
Environments build with Miniconda - a package/environment manager.
Since the cluster has to cater for everyone we can not provide a simple desktop environment that provides everything.
Instead we provide modules that a user will load that configures their environment for their particular needs within a session.
Loading a module configures various environment variables within that Session.
What is Available?
We have environments available based on compilers, Singularity containers, Conda, Linux Binaries
[]$ module avail
[]$ gcc --version
gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
[]$ which gcc
/usr/bin/gcc
[]$ echo $PATH
/home/<username>/.local/bin:/home/<username>/bin:/apps/s/arcc/1.0/bin:/apps/s/slurm/latest/bin:
/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
Is Python and/or R available?
# An old version of Python is available on the System.
# Systems are updated! Do NOT rely on them for you environment regards versions/reproducability.
[]$ which python
/usr/bin/python
[]$ python --version
Python 3.9.18
# R is NOT available.
[]$ which R
/usr/bin/which: no R in (/home/<username>/.local/bin:/home/<username>/bin:
/apps/s/arcc/1.0/bin:/apps/s/slurm/latest/bin:/usr/share/Modules/bin:
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin)
# Nothing returned.
[]$ echo $R_HOME
[]$
Load a Compiler
# What's avail for a compiler?
[]$ module load gcc/14.2.0
[]$ module avail
# Notice there are a lot more applications available under this loaded compiler.
[]$ gcc --version
gcc (Spack GCC) 14.2.0
[]$ which gcc
/apps/u/spack/gcc/11.4.1/gcc/14.2.0-vzbrz6i/bin/gcc
# Notice that the environment variables have been extended.
[]$ echo $PATH
/apps/u/spack/gcc/11.4.1/gcc/14.2.0-vzbrz6i/bin:/apps/u/spack/gcc/14.2.0/zstd/1.5.5-4jnrrl7/bin:
/home/<username>/.local/bin:/home/<username>/bin:/apps/s/arcc/1.0/bin:
/apps/s/slurm/latest/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
# Notice R is now available and newer versions of Python are available under gcc/14.2.0
Note: For this class, for R, until you hear otherwise, we will actually be using R using the gcc/13.2.0
compiler.
20240926: Update: ARCC has been updating compilers and libraries over the last few weeks, and we are nlow recommending to use the gcc/14.2.0
version of r/4.4.0
.
All this means is that r/4.4.0
has been built with a newer compiler. The core functionality and language remains exactly the same, and you will not see any difference running R scripts.
Load a Newer Version of Python
[]$ module load python/3.10.6
[]$ which python
/apps/u/spack/gcc/14.2.0/python/3.10.6-6lvrsdd/bin/python
[]$ python --version
Python 3.10.6
Typically Loading R
[]$ module load r/4.4.0
# Notice the environment variable has now been set.
[]$ echo $R_HOME
/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R
[]$ which R
/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/bin/R
# Notice ALL the dependencies:
[] module list
Currently Loaded Modules:
1) slurm/latest (S) 42) libxau/1.0.8
2) arcc/1.0 (S) 43) libxdmcp/1.1.4
...
40) libpthread-stubs/0.4 81) r/4.4.0
41) xproto/7.0.31
[]$ R --version
R version 4.4.0 (2024-04-24) -- "Puppy Cup"
You then perform: install.packages
and manage these yourself.
Same with Python: You perform the pip install
to install which ever Python packages you require.
Using module purge to reset you session/environment
[]$ module purge
The following modules were not unloaded:
(Use "module --force purge" to unload all):
1) slurm/latest 2) arcc/1.0
# ml is a shortcut for module list
[salexan5@mblog2 testdirectory]$ ml
Currently Loaded Modules:
1) slurm/latest (S) 2) arcc/1.0 (S)
Where:
S: Module is Sticky, requires --force to unload or purge
Modules Specific for this Class
We have created two modules specifically for this class:
R/4.4.0 + Library of 477 R Packages (this is the original gcc/13.2.0
built library)
[]$ ls /project/genomicdatasci/software/r/libraries/
abind DBI ggnewscale libcoin RcppAnnoy sourcetools
alabaster.base dbplyr ggplot2 lifecycle RcppArmadillo sp
alabaster.matrix DelayedArray ggplotify limma RcppEigen spam
...
The new gcc/14.2.0
version can be found under: /project/genomicdatasci/software/r/libraries_gcc14/
R/4.3.3 and R Package Pigengene
Due to dependency hell issues, we could not install Pigengene within the R library collection.
There are two separate environments.
With different versions of R.
Using R/4.4.0 + Library
[]$ module purge
[]$ module use /project/genomicdatasci/software/modules/
[]$ module avail
...
------------------- /project/genomicdatasci/software/modules -------------------
pigengene/3.18 r/4.4.0-genomic r/4.4.0-genomic-gcc14
...
If you do not call the .libPaths()
command from within R (or an R script) you will not get access to the packages.
Version: r/4.4.0-genomic
(deprecated)
This original library was built use gcc/13.2.0
and covered at the start of the class- I would recommend NOT using this one.
[]$ module purge
[]$ module load r/4.4.0-genomic
-------------------------------------------------------------------------------
The following dependent module(s) are not currently loaded: zlib-ng/2.1.4_zen4 (required by: gcc/13.2.0), zstd/1.5.5_zen4__programs_True (required by: gcc/13.2.0)
-------------------------------------------------------------------------------
[]$ R
R version 4.4.0 (2024-04-24) -- "Puppy Cup"
...
> .libPaths(c('/project/genomicdatasci/software/r/libraries', '/apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R/library'))
Version: r/4.4.0-genomic-gcc14
This later version has been built using gcc/14.2.0
- I would recommend using this version.
[]$ module purge
[]$ module load r/4.4.0-genomic-gcc14
[]$ R
R version 4.4.0 (2024-04-24) -- "Puppy Cup"
...
> .libPaths(c('/project/genomicdatasci/software/r/libraries_gcc14', '/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library'))
R/4.3.3 and R Package Pigengene
[salexan5@mblog2 testdirectory]$ module purge
[salexan5@mblog2 testdirectory]$ module use /project/genomicdatasci/software/modules/
[salexan5@mblog2 testdirectory]$ module load pigengene/3.18
[salexan5@mblog2 testdirectory]$ R --version
R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
...
# Start R
[salexan5@mblog2 testdirectory]$ R
R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
...
> library(Pigengene)
Loading required package: graph
Loading required package: BiocGenerics
...
Due to dependency hell issues, we could not install Pigengene within the R library collection.
There are two separate environments.
With different versions of R.
Using RStudio with R/Library of Packages for this Class
Since we are using RStudio, which is an IDE for R, i.e. a GUI, you need to perform this from an Interactive Desktop, via OnDemand.
From the Interactive Desktop, open a terminal:
[]$ module use /project/genomicdatasci/software/modules/
[]$ module avail
...
------------------- /project/genomicdatasci/software/modules -------------------
pigengene/3.18 r/4.4.0-genomic r/4.4.0-genomic-gcc14
...
[]$ module load r/4.4.0-genomic-gcc14
[]$ module spider rstudio
----------------------------------------------------------------------------
rstudio:
----------------------------------------------------------------------------
Versions:
rstudio/2024.04.1
rstudio/2024.04.2
----------------------------------------------------------------------------
For detailed information about a specific "rstudio" package (including how to load the modules) use the module's full name.
Note that names that have a trailing (E) are extensions provided by other modules.
For example:
$ module spider rstudio/2024.04.2
----------------------------------------------------------------------------
[]$ module load rstudio/2024.04.1
[]$ rstudio
# From within R Studio:
> .libPaths(c('/project/genomicdatasci/software/r/libraries_gcc14', '/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library'))
# Notice how the list of Packages updates.
Remember: If you do not call the .libPaths()
command from within R (or an R script) you will not get access to the packages.
Using RStudio and R/Pigengene for this Class
Remember: Since we are using RStudio, which is an IDE for R, i.e. a GUI, you need to perform this from an Interactive Desktop, via OnDemand.
From the Interactive Desktop, open a terminal:
[]$ module use /project/genomicdatasci/software/modules/
[]$ module load pigengene/3.18
[]$ export PATH=$PATH:/project/genomicdatasci/software/pigengene/3.18/bin/
[]$ export RSTUDIO_WHICH_R=/project/genomicdatasci/software/pigengene/3.18/lib/R/bin/R
[]$ module load rstudio/2024.04.1
[]$ rstudio
If you do not export the detailed environment variables, RStudio will not pick up the version of R.
Other Class Modules
Using the module use
command will also group and show other applications relating to this class:
[]$ module use /project/genomicdatasci/software/modules/
[]$ module avail
...
------------------- /project/genomicdatasci/software/modules -------------------
bam-readcount/0.8.0 kentutils/1.04.0 regtools/1.0.0
bedops/2.4.41 multiqc/1.24.1 rseqc/5.0.3
fastp/0.23.4 picard/3.2.0 samtools/1.20 (D)
fastqc/0.12.1 pigengene/3.18 sratoolkit/3.1.1
hisat-genotype/1.3.3 r/4.4.0-genomic-gcc14 subread/2.0.6
hisat2/2.2.1 r/4.4.0-genomic tophat/2.1.1
...
Request Interactive Session (Compute Node) from a Login Node
Based on Workshop: Intro to job Scheduling
| # Short form:
# Notice we can request more memory.
[@mblog1 ~]$ salloc -A genomicdatasci -t 4:00:00 --mem=4G -c 1
# Long form
# MUST define account/A and time/t
[@mblog1 ~]$ salloc --account=genomicdatasci --time=4:00:00 --mem=4G --cpus-per-task=1
salloc: Granted job allocation 3735901
salloc: Waiting for resource configuration
salloc: Nodes mbcpu-024 are ready for job
[@mbcpu-024 ~]$
[@mbcpu-024 ~]$ exit
exit
salloc: Relinquishing job allocation 3735901
[@mblog1 ~]$ salloc --help |
---|
Request Interactive Session (Compute Node) with a GPU
| [@mblog2]$ salloc -A genomicdatasci -t 8:00:00 --mem=8G -c 2 -p mb-a30 --gres=gpu:1
salloc: Granted job allocation 3735902
salloc: Nodes mba30-002 are ready for job
[@mba30-002]$ nvidia-smi -L
GPU 0: NVIDIA A30 (UUID: GPU-769d8459-cfc2-0a41-0b61-ba5ab798662b)
[@mba30-002]$ exit
exit
salloc: Relinquishing job allocation 3735902
[@mblog2]%
# If you don't ask, you don't get:
[@mblog2]$ salloc -A genomicdatasci -t 8:00:00 --mem=8G -c 2 -p mb-a30
salloc: Granted job allocation 3735903
salloc: Nodes mba30-002 are ready for job
[@mba30-002]$ nvidia-smi -L
No devices found.
[@mba30-002]$ exit
[@mblog2]$ |
---|
Request what you Need!
# You're telling this command to use 4 threads - 4 cores
[]$ hisat2-build -p 4 ...
# Create an interactive session with only 1 core.
[]$ salloc --account=genomicdatasci --time=30:00
# Setup the Environment
[@mbcpu-001]$ hisat2-build -p 4 --ss $INDEX/splicesites.tsv --exon $INDEX/exons.tsv $REFERENCE/chr22_with_ERCC92.fa $INDEX/chr22
...
Total time for call to driver() for forward index: 00:01:09
# Create an interactive session with 4 cores.
[@mblog1]$ salloc --account=genomicdatasci --time=30:00 -c 4
# Setup the Environment
[@mbcpu-001]$ hisat2-build -p 4 --ss $INDEX/splicesites.tsv --exon $INDEX/exons.tsv $REFERENCE/chr22_with_ERCC92.fa $INDEX/chr22
...
Total time for call to driver() for forward index: 00:00:43
The first instance only request one core and ran slower than when we correctly requested 4 cores.
07 Create a basic workflow and submitting jobs.
Goals:
Since RStudio is a GUI, demonstrate moving from running a script within RStudio to running using Rscript from the command-line.
Put the various elements of loading modules, moving into a folder, running an R file, that make up a basic workflow, into a script that can be submitted using
sbatch
to Slurm.Map the
salloc
arguments to#SBATCH
.Show how to monitor a jobs using
squeue
as well as using the email related Slurm options.Show how to request GPU compute nodes and defining
gres
to specifically request a GPU.Provide a basic template.
Based on Workshop: Intro to Job Scheduling
General Wiki: Slurm Workload Manager
Why Submit a Job
A single computation can take, minutes, hours, days, weeks, months. An interactive session quickly becomes impractical.
Submit a job to the Slurm queue - Slurm manages everything for you.
Everything you do on the command-line, working out your workflow, is put into a script.
Workflow:
What resources you require? (Interactive desktop configuration,
salloc
options)What modules are loaded.
Which folder you’re running you computation within. Where the data is stored. Where you want the results.
Command-line calls being called.
Software applications being run.
Submit a Job to the Cluster
Convert salloc
command-line options to an sbatch
related script.
Options have defaults if not defined.
# salloc
[@mblog1 ~]$ salloc -A genomicdatasci -t 8:00:00 --mem=8G -c 2 -p mb-a30 --gres=gpu:1
# sbatch
# Options within your bash script.
#SBATCH --account=genomicdatasci # Account. MUST be defined.
#SBATCH --time=8:00:00 # Time. MUST be defined.
#SBATCH --mem=8G # Memory.
#SBATCH --mem-per-cpu=1G # Alternaitve: Commented out. Default is 1G if no memory values defined.
#SBATCH --cpus-per-task=2 # CPUs per Task - default is 1 if not defined.
#SBATCH --partition=mb-a30 # Partition - If not defined, Slurm will select.
#SBATCH --gres=gpu:1 # Generic Resources
Additional sbatch
Options
#SBATCH --job-name=<job-name>
#SBATCH --nodes=<#nodes> # Default is 1 if not defined.
#SBATCH --ntasks-per-node=<#tasks/node> # Default is 1 if not defined.
#SBATCH --mail-type=ALL
#SBATCH --mail-user=<email-addr>
#SBATCH --output=<filename>_%A.out # Postfix the job id to <filename>
# If not defined: slurm-<job-id>.out
Example Script: What Goes into It?
The bash script can contain:
Linux/bash commands and script.
Module loads.
Application command-line calls.
Lets consider our R workflow. I have:
R scripts copied into my
/gscratch
folder.R related modules to load.
R scripts to run.
to track the time the job starts and ends.
Example Script: Running R Script
#!/bin/bash
# Comment: The first line 'shebang' is followed by the interpreter or the command that should be used to execute the script.
#SBATCH --job-name=r_job
#SBATCH --account=genomicdatasci
#SBATCH --time=10:00
#SBATCH --mail-type=ALL
#SBATCH --mail-user=<email-addr>
#SBATCH --output=r_%A.out
export R_FILES=/gscratch/$USER
echo "R Workflow Example"
START=$(date +'%D %T')
echo "Start:" $START
echo "SLURM_JOB_ID:" $SLURM_JOB_ID
echo "SLURM_JOB_NAME:" $SLURM_JOB_NAME
echo "SLURM_JOB_NODELIST:" $SLURM_JOB_NODELIST
module use /project/genomicdatasci/software/modules
module purge
module load r/4.4.0-genomic-gcc14
cd $R_FILES
Rscript test_r_libraries_gcc14.R
END=$(date +'%D %T')
echo "End:" $END
Submit your Job
# From your Working Directory - the folder you are currently in.
[@mblog1]$ ls
run_r.sh test_data
# You can submit the job from the login node.
# Make a note of the job id.
[@mblog1]$ sbatch run_r.sh
Submitted batch job 16054193
# ST Column: Status of P means Pending / R means Running.
[@mblog1]$ squeue -u <username>
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
16054193 teton r_job <username> R 0:06 1 t402
# Once the job is running, the defined output file will be generated.
[@mblog1]$ ls
r_16054193.out run_r.sh test_data
Monitor your Job
# You can view the contents of your output file:
[@mblog1]$ cat r_16054193.out
R Workflow Example
Start: 06/05/24 14:02:01
SLURM_JOB_ID: 16054193
SLURM_JOB_NAME: r_job
SLURM_JOB_NODELIST: m221
Sleeping...
[@mblog1]$ squeue -u <username>
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
16054193 teton r_job <username> R 0:18 1 t402
# If the job id is nolonger in the queue then it means the job is no longer running.
# It might have completed, or failed and exited.
[@mblog1]$ squeue -u <username>
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
Why is my Job Not Running?
Typically because the resources you are requesting are not currently available.
Slurm will add your job to the queue, but it will be PENDING (P) while it waits for the necessary resources to become available.
As soon as they are, your job will start, and it’s status will update to RUNNING (R).
Slurm manages this for you.
Monitor your Job: Continued…
# You can monitor the queue and/or log file to check if running.
[<username>@mblog1 <username>]$ cat r_16054193.out
R Workflow Example
Start: 06/05/24 14:02:01
SLURM_JOB_ID: 16054193
SLURM_JOB_NAME: r_job
SLURM_JOB_NODELIST: t402
Sleeping...
Loading required package: SeuratObject
Loading required package: sp
Attaching package: ‘SeuratObject’
The following objects are masked from ‘package:base’:
intersect, t
End: 06/05/24 14:02:29
# OR...
Alternative Monitoring of Job via Email: Job Efficiency
# Monitor your email:
Email 1:
Subject: medicinebow Slurm Job_id=16054193 Name=r_job Began, Queued time 00:00:01
Email 2: Job Efficieny:
Subject: medicinebow Slurm Job_id=16054193 Name=r_job Ended, Run time 00:00:28, COMPLETED, ExitCode 0
Job ID: 16054193
Cluster: medicinebow
User/Group: <username>/<username>
State: COMPLETED (exit code 0)
Cores: 1
CPU Utilized: 00:00:07
CPU Efficiency: 25.00% of 00:00:28 core-walltime
Job Wall-clock time: 00:00:28
Memory Utilized: 0.00 MB (estimated maximum)
Memory Efficiency: 0.00% of 1000.00 MB (1000.00 MB/core)
Example Script 2
This might look like something your cover in later sessions:
#!/bin/bash
#SBATCH --job-name=hisat2
#SBATCH --account=genomicdatasci
#SBATCH --time=8:00:00
#SBATCH --cpus-per-task=4
#SBATCH --mem=8G
#SBATCH --mail-type=ALL
#SBATCH --mail-user=<email-addr>
#SBATCH --output=hisat2_%A.out
START=$(date +'%D %T')
echo "Start:" $START
echo "SLURM_JOB_ID:" $SLURM_JOB_ID
echo "SLURM_JOB_NAME:" $SLURM_JOB_NAME
echo "SLURM_JOB_NODELIST:" $SLURM_JOB_NODELIST
module load gcc/12.2.0 hisat2/2.2.1
export REFERENCE=/project/genomicdatasci/software/test_data/Grch38/fasta
export INDEX=/project/genomicdatasci/software/test_data/Grch38/Hisat2
# Comment: Location of the splicesites.tsv file.
cd /gscratch/$USER
hisat2-build -p 4 --ss $INDEX/splicesites.tsv --exon $INDEX/exons.tsv $REFERENCE/chr22_with_ERCC92.fa $INDEX/chr22
END=$(date +'%D %T')
echo "End:" $END
Being a Good Cluster Citizen
Based on: Slurm: Workflows and Best Practices:
Specifically the topic: How can I be a good cluster citizen:
08 Summary and Next Steps
Examples and cheat sheets can be found under: /project/genomicdatasci/arcc_notes
We’ve covered the following high-level concepts, commands and processes:
What is HPC and what is a cluster - focusing on ARC’s MedicineBow cluster.
An introduction to Linux and its File System, and how to navigate around using an Interactive Desktop and/or using the command-line.
Linux command-line commands to view, search, parse, sort text files.
How to pipe the output of one command to the input of another, and how to redirect output to a file.
Using vim as a command-line text editor and/or emacs as a GUI within an Interactive Desktop.
Setting up your environment (using modules) to provide R/Python environments, and other software applications.
Accessing compute nodes via a OnDemand Interactive Desktop, and requesting different resources (cores, memory, GPUs).
Requesting interactive sessions (from a login node) using
salloc
.Setting up a workflow, within a script, that can then be submitted to the Slurm queue using
sbatch
, and how to monitor jobs.