Skip to content

Random Tips

Noah Reid edited this page Jan 26, 2024 · 8 revisions

Random HPC and Bioinformatics Tips

  1. Running batch job on the cluster without writing a script
  2. Customizing your prompt

Running batch job on the cluster without writing a script.

Occasionally one might want to execute a simple command like mv cp or anything simple. So without creating a batch script you can run it on the go using --wrap flag.

# e.g to copy a directory from source to destination
sbatch -p general -q general --mem=2G -c 1 -o movestatus.out --wrap "cp -a source destination"

# it can be used in regular analysis and support multiple commands seperated by ";" (e.g indexing a bam file)
sbatch -p general \
       -q general \
       --mem=10G \
       -c 1 \
       -o samtoolsIndex.out \
       -J bamINdex \
       --wrap "module load samtools/1.9; samtools index INPUTBAMFILE.bam"

# -o outfile ( to collect stderr and stdout sepereately use -o, -e flags)
# -J JOBNAME

CONS: There will be no record of the command that is executed, once the job finishes

How to customize your bash prompt

The prompt is where you enter commands in BASH.

By default it will probably look like this:

image

But you can change it to suit your needs, or just for fun. For example, this prompt has the format [ username@hostname ] ~ [ current working directory ]

image

This is particularly useful when you have multiple terminal windows open because it can help keep you oriented to where you're working. In the above case, hpc-ext-2 is one of our five external login nodes and ~ indicates the user's home directory. You will know at a glance that you shouldn't use this terminal for any serious computing.

If you start an interactive session, you'll see something like this:

image

xanadu-22 is one of our compute nodes. Again, at a glance you'll know you can do serious work in this terminal, or that you should close it if you're not using it to free up resources. If utility is not your thing, you can opt for silliness, as the entire set of unicode characters is available:

image

You can accomplish this by making edits to two configuration files that live in your home directory, .bashrc and .bash_profile. Because these files begin with a . they are hidden from the normal directory listing. You can see if you already have them by typing ls -a to list ALL files. If you don't, you can create them by:

touch .bashrc .bash_profile

To create a custom prompt, you simply need to set an environment variable called PS1. This variable is read by the shell as the prompt configuration. To get the prompt above, add the following line to .bashrc:

PS1="\[\033[01;32m\][ \u@\h ]\[\033[37m\] : \[\033[01;36m\][ \W ] \[\033[01;37m\]\$\[\033[00m\] "

This will change the prompt on login shells, but not in interactive sessions, so we also need to add the following lines to .bash_profile

if [ -f $HOME/.bashrc ]; then
        source $HOME/.bashrc
fi

This causes .bashrc to be sourced in interactive sessions.

Once you've created and edited these files, start a new session to make sure your changes have taken effect.

For more details on the available variables and syntax of the prompt format, check this website