Skip to content

Environment Modules on H4H🔗

To prevent repeated installations of software commonly used across the cluster,

  • The Environment Modules system is used to provide a standard set of precompiled programming languages, software tools and libraries accessible to all users on H4H.
  • For many common tasks these modules will be sufficient to complete your analysis.

For cases where a software dependency is unavailable you have two courses of action:

  1. Contact the cluster administrators and request they install it
  2. Install the software locally in your H4H home directory (see Installing Packages)

Basic module Commands🔗

The user interface for the Modules package is accessible via the module command. In general, loading a module will modify environment variables such as your PATH or MANPATH to provide access to the requested software. To view an overview of available subcommands for module, run module -t. Note that module is generally only available during job execution and thus cannot be loaded from the Login or Data nodes.

To view a short list of available subcommands, simply type module into the terminal.

module avail

  • Opens a list of all available modules using the less command, allowing you to browse the pages with arrow keys
  • You can pass a pattern string to the command to only show modules matching the pattern
  • If you pass a specific module name (case sensitive), the utility will show you a list of available versions and a description of that module

module spider

  • Similar to avail, but specifically lists all available versions
  • Also supports passing module names or patterns

module whatis

  • Get the description text for a module using its name

module load

  • Load the module into your current environment
  • This works by modifying your PATH environment variable

module list

  • Lists all loaded modules
  • Accepts patterns, which can be useful if you have a lot of modules loaded

module unload

  • Removes a loaded module from your current environment

Try it yourself🔗

  1. Allocate an interactive so you have access to the module command

    Solution
    salloc -c 2 --mem=4G -t 0:30:0
    
  2. Use module avail or module spider to find the module for the most recent R version available on the cluster

    Solution
    module spider R  # Most recent version at time of writing is 4.2.1
    
  3. Get a description of the most recent R module

    Solution
    module whatis R/4.2.1
    
  4. Load the most recent R module, inspecting the $PATH variable before and after loading

    Solution
    echo $PATH
    module load R/4.2.1
    echo $PATH  # Note that loading a module changes your current PATH
    
  5. Get the version of R and confirm it matches the module you loaded

    Solution
    R --version
    
  6. Unload the R module

    Solution
    module unload R/4.2.1
    

Module Collections🔗

If your analysis requires many modules it can be tedious to load all of them in your scripts. To get around this, the module system provides a mechanism to save the state of your currently loaded modules into a collection. This collection can then be restored from the collection file in your job script or interative session.

Try it yourself:

  1. Allocate an interative job on the cluster, if you don't already have one

    Solution
    salloc -c 2 --mem=4G -t 0:30:0
    
  2. View the documentation for the module command and note the options for the save and restore sub-commands

    Solution
    module # could also do module help, module --help or man module
    
  3. Use module spider to find the most recent versions of samtools and picard

    Solution
    module spider samtools  # Most recent at time of writing is 1.14
    module spider picard  # Most recent at time of writing is 2.10.9
    
  4. Load the samtools and picard modules from step 3.

    Solution
    module load samtools/1.14
    module load picard/2.10.9
    
  5. Save your currently loaded packages to a collection called test_collection

    Solution
    module save test_collection  # If you don't specify a collection name it saves to your default collection
    
  6. Open the module help pages and find the command to view available collections

    Solution
    module
    module savelist
    
  7. Open the module help pages and find the command to unload all modules and then run it

    Solution
    module purge
    
  8. List loaded modules to confirm the command worked

    Solution
    module list
    
  9. Restore your module collection

    Solution
    module restore test_collection
    
  10. List loaded modules again to confirm that your command worked

    Solution
    module list  # Should see samtools and picard
    
  11. Use the module documentation to find the command to list the contents of a module collection then run it on test_collection

    Solution
    module -t
    module savelist test_collection
    
  12. Use the module documentation to find the command to delete a collection then remove test_collection and unload all packages

    Solution
    module -t
    module saverm test_collection
    module purge
    

Customizing Defaults🔗

There are many options available to customize the default behavior of modules. These can be by creating a .modulerc file in your $HOME directory.

Alternatively, there are a number of enviromental variables which can be set to modify how module commands and sub-commands behave. Please refer to the Environment Modules documentation for more details.

References🔗

  1. Environment Modules