Neuroconda - MRC CBU Imaging Wiki

Revision 1 as of 2020-12-01 14:18:29

Clear message
location: Neuroconda

Neuroconda at MRC CBU

Neuroconda is a Conda environment that bundles Python, R and some system binaries and libraries for neuroimaging analysis. For general Neuroconda documentation, please see the project Github page. Here we describe the details of the existing Neuroconda deployment at CBU.

What are environments and why is this useful?

It's worth familiarising yourself with the Conda documentation to get some idea of how environments work. At a high level, when you activate Neuroconda, your system path is modified to add various libraries and packages to the path. So for any analysis code to work, the environment must first be activated. The neat thing about this extra step is that you now have control over exactly which package versions your code is running, instead of implicitly depending on whatever happens to be on your path at the moment.

Each time a new Neuroconda release is made, we create a new environment on the imaging system. You can se all the available Neuroconda versions by doing this in a login node shell session:

conda env list | grep neuroconda

As long as you always activate the same Neuroconda release, code you write should run reproducibly for yourself and even people at other institutions.

Using Neuroconda at CBU

The easiest way to get started is to do something like this on a login node

source /imaging/local/software/neuroconda/v2_0/neuroconda.csh

This works assuming you've kept your shell to the CBU default TCSH shell. If you've wisely switched to bash, zsh or another modern shell, the line you need is

source /imaging/local/software/neuroconda/v2_0/neuroconda.sh

This will add all the neuroconda packages to your path, but also some non-conda neuroimaging packages such as AFNI, FSL and Freesurfer. You can consult the script to see exactly what packages get added. To test that everything worked, try doing

which python; which fsl

You should get something like

/imaging/local/software/miniconda/envs/neuroconda_2_0/bin/python
/imaging/local/software/centos7/fsl/bin/fsl

Just keep in mind that everything is set up specifically in this shell session. If you start another shell or log out and in again, you'll have to run the source command again.

For native python/R code

If you aren't planning to use those non-Conda neuro packages that we added in the source script above, you can just use Neuroconda like any Conda environment by doing

conda activate neuroconda_2_0

For batch / job submission

If you want to use Neuroconda non-interactively, for instance when running a batch script or submitting a job to our SLURM cluster, things get a little bit more complicated. The environment you just activated is specific to the shell you're currently running, as we just saw. And conda environments can only be activated in interactive login shells out of the box, so simply putting the above lines in your shell scripts may not work.

The best way around this is to add the following line to the top of your bash shell scripts:

source $(conda info --base)/etc/profile.d/conda.sh

After which the commands above should work normally inside the script.

A more hacky route is to put the source or conda activate line above in your shell login script, so that every shell you start is in neuroconda. You can then put the -l flag in your shell script she-bang to force scripts to run as login shell. But that may have unintended effects (for example, it may break vncserver). I don't recommend this approach.

Adding and updating packages

The central neuroconda environments we provide are read-only. This is to preserve reproducibility. We're all using the same environments, so if you were able to change things it would have unpredictable effects for everyone else on the imaging system.

If you need something, please get in touch with Johan who will be happy to add it to the next Neuroconda release. But if you need it sooner than that, you can always clone the environment. Once you have your personal version of the Neuroconda environment (which lives in your home directory rather than on the shared imaging drive) you can modify it as you see fit.