Installing and running MIRACL
We provide instructions on how to install and run MIRACL using either of the following methods:
Important
Docker is our recommended method for running MIRACL on local machines and servers. We recommend Apptainer to run MIRACL in a cluster environment (e.g. Compute Canada).
Attention
Support for installing MIRACL locally (i.e. on your host system directly without using Docker or Apptainer) has been deprecated. Please use Docker or Apptainer instead.
Important
MIRACL has been tested on:
Docker (version 27.3.1, build ce12230):
Ubuntu:
20.04(Focal Fossa),22.04(Jammy Jellyfish),24.04(Noble Numbat)Debian:
13(trixie)
Apptainer (version 1.3.5):
Ubuntu:
20.04(Focal Fossa),22.04(Jammy Jellyfish),24.04(Noble Numbat)Gentoo:
2.14
We strongly recommend that you use one of the above Linux versions but MIRACL will most likely work on other versions of Linux as long as Docker or Apptainer are installed and working.
Note
Hardware requirements for MIRACL are heavily dependent on the
type/size of your data as well as the analyses you are running. While
some modules and datasets can be less computationally expensive, others
require a lot of resources. As a point of reference, the least powerful
system that we are testing MIRACL on, uses a 24-Core Threadripper
with 128GB RAM and two NVIDIA RTX A6000 GPUs.
We provide a installation script to automatically create a Docker image for you that can be run using Docker Compose. This method does not require a manual installation of MIRACL and works on Linux and in the WSL2 on Windows. Theoretically, MIRACL should also work on MacOS but we do not officially support it.
Tip
Docker is our recommended method for running MIRACL on local machines and servers
Docker is well suited if you want to run MIRACL on a local machine or local server. If you need to run MIRACL on a cluster, see our instructions for installing Apptainer. If you don’t have Docker installed on your computer, do that first. Make sure your installation includes Docker Compose as it is required to run the installation script we provide. Note that Docker Compose is included as part of the Docker Desktop installation by default.
Getting started
First, it is important to understand how the container is built. There
is a base image in the docker folder that installs Python
and dependencies. Then the Dockerfile in the base of the repository
builds the Docker image from that base. When the build
happens, it cats the version.txt file in the repository to save a
versioned base, but then the build uses the tag revised-base-latest that
is always the latest base. The base container is built from this folder
and pushed manually, while the main container is built and pushed
automatically via the CircleCI Recipe. Thus, if you want to
update the base, you will need to see the README.md in that folder
and push new images.
Build MIRACL from scratch
This will build a Docker image of MIRACL based on
its latest version using our default naming scheme. For custom names and
specific versions see below for our Additional build options section.
Clone the MIRACL repo to your machine:
$ git clone https://www.github.com/mgoubran/MIRACL
Change into the newly created directory where you cloned MIRACL to:
$ cd MIRACL
Build the latest MIRACL image using the installation script we provide:
$ ./install.sh
Attention
In order for the ./install.sh script to work, Docker
should NOT be used with sudo. Our script checks and exits if
it is being run with sudo priviledges. The reason for this behavior
is that the installation script creates a user in the Docker container
that matches the uid and gid of the host user which is required
correct X11 forwarding. This user should NOT be root which is
the case when Docker commands are executed with sudo.
For more information on how to add a docker user to use
Docker without sudo visit the official Docker
documentation.
Error
Make sure that the script can be executed. If it can’t and you are
the owner of the file, use chmod u+x install.sh to make it
executable. Prefix the chmod command with sudo if you are not
the owner of the file or change permissions for g and/or o.
Running the script without any flags will start an interactive installation process that will run you through an abbreviated version of the installation.
$ ./install.sh
No flags provided, starting interactive prompt...
Enter Docker image name (default: 'miracl_mgoubran_kirk_4918_img'):
Enter Docker container name (default: 'miracl_mgoubran_kirk_4918'):
Enable GPU in Docker container (required for ACE) (y/N): y
Enter the location of your data on your host system (default: None). If you choose a location, your data will be mounted at '/data' in your container: /data5/projects/
Press enter for the image and container prompts to choose the default names
or enter your preferred names. GPU forwarding will be disabled by default
so enter y, Y, Yes, or YES at the prompt to enable it.
Lastly, you will be prompted for the location of your data on the host
system. Provide the full path to your location. It will be mounted under
/data in the container. Once you entered all prompts, MIRACL
will be installed automatically.
Note
This installation method should be sufficient for 90% of users. However,
If you require more fine grained control see our Additional build
options section further below.
Once the image has successfully been built, run the container using Docker Compose:
$ docker compose up -d
Note
Note that the Docker Compose syntax is different if
you installed it using the standalone method. Compose
standalone uses the -compose syntax instead of the current standard
syntax compose. The above command would thus be docker-compose up -d
when using Compose standalone.
The container is now running and ready to be used.
Using the container
Interactively shell inside:
$ docker exec -it miracl bash
Stopping the container
Exit your container and navigate to your MIRACL folder. Use Docker Compose to stop the container:
$ docker compose down
Note
Note that the Docker Compose syntax is different if
you installed it using the standalone method. Compose
standalone uses the -compose syntax instead of the current standard
syntax compose. The above command would thus be docker-compose up -d
when using Compose standalone.
Mounting additional drives
Files that are saved while using MIRACL should be saved to
volumes mounted into the container in order to make them persistent. You
might have already mounted at least one data location when you used the
interactive installation menu or several if you used the flags outlined
in the Additional build options sections below. However, if you need
to mount additional volumes, you can easily do that by adding them to the
docker-compose.yml in the base directory under the volumes section.
Example:
volumes:
- '/home/mgoubran/.Xauthority:/home/mgoubran/.Xauthority'
- '/home/mgoubran/mydata:/home/mgoubran/mydata' # This is the additional volume
Danger
Do not delete the .Xauthority volume that is already mounted. It
mounts your .Xauthority file which is important for X11 to work
correctly.
The format of mounting volumes is </host/path>:</container/path> (note
that the delimiter is : but that there are no trailing /). In the
above example, the host path /home/mgoubran/mydata is mounted to the
container path /home/mgoubran/mydata. The names for the paths on the
host system do not need to match the names for the locations inside the
container. The above example could therefore also be /home/mgoubran/mydata:/data.
Additional build options
The interactive installation method described above should be sufficient 90% of users. However, if you need more finegrained control or advanced options, use the flags described in this section.
To start, use ./install.sh -h to see all optional flags:
Usage: ./install.sh [-n service_name] [-i image_name] [-c container_name] [-t {auto, x.x.x}] [-g] [-e] [-v vol:vol] [-l] [-s] [-m] [-h]
Automatically build MIRACL Docker image with pseudo host user
Options:
-n, name of the Docker service (randomized default: 'miracl_mgrouban_hughes_11707')
-i, specify image name (randomized default: 'miracl_mgrouban_hughes_11707_img')
-c, specify container name (default: 'miracl')
-t, set when using specific MIRACL tag/version. Use 'auto' to parse from 'miracl/version.txt' or specify version as floating point value in format 'x.x.x' (default: 'latest')
-g, enable Nvidia GPU passthrough mode for Docker container which is required for some of MIRACL's scripts e.g. ACE segmentation (default: false)
-e, disable mounting MIRACL's script directory into Docker container. Mounting is useful if you want host changes to propagate to the container directly (default: false; set flag to disable)
-d, set shared memory (shm) size (e.g. '1024mb', '16gb' or '512gb') which is important for e.g ACE (default: int(MemTotal/1024)*0.85 of host machine)
-v, mount volumes for MIRACL in docker-compose.yml, using a separate flag for each additional volume (format: '/path/on/host:/path/in/container'; default: none)
-l, write logfile of build process to 'build.log' in MIRACL root directory (default: false)
-s, print version of build script and exit
-m, print version of MIRACL on current Git branch and exit
-h, print this help menu and exit
Script version: 2.0.1-beta
MIRACL version: 2.4.2
Let’s have a closer look at the most important flags.
Image and container naming
By default, the installation script will choose names for the image and container randomly, using the following syntax:
<miracl>_<usernamehostuser>_<randomname>_<randomdigitsbetween0and99999>
The image name will also be appended with <_img> do distinguish it
from the container name. We do this to avoid conflicts with previous
or dangling installations of MIRACL. Is you are confident that
you will not duplicate your image or container names, set the -i and
-c flags to choose your preferred names:
$ ./install.sh -i <image_name> -c <container_name>
Example:
$ ./install.sh -i josmann/miracl_dev_img -c miracl_dev
GPU forwarding
If you want to add GPU (Nvidia/CUDA) support to your MIRACL
container, you can do so by running the installation script with the -g
flag:
$ ./install.sh -g
This is required for MIRACL modules like ACE.
Disable script directory mounting
Our installation script mounts the miracl folder from inside your
cloned MIRACL Git folder by default. The miracl folder
contains all of MIRACL's modules and workflow code. This
behavior is useful when you want to make real-time changes to e.g. a module for
fit your specific needs on the fly as the changes will persist across
restarts. In case this behavior is not desired, e.g. when testing changes
that you don’t want to be permanent, use the -e flag to disable
automatic mounting.
Set shared memory size
It is not always desirable to let your host system share all of its available memory with the MIRACL container. By default, the memory that will be shared by MIRACL is calculated as follows:
int(MemTotal/1024)*0.85 of host machine
If you want to increase or limit the memory availabe to MIRACL,
set it manually using the -d flag. Example sizes are 1024mb,
16gb, or 512gb.
Example:
$ ./install.sh -d 512gb
This will set the shared memory size to 512gb.
Mount additional volumes
Use the -v flag if you need to mount several volumes or files from
your host system to your MIRACL Docker container.
Use a separate flag for each additional volume with this format:
-v '/path/on/host:/path/in/container'. Make sure that you use a
separate -v flag for each separate volume!
Example:
$ ./install -v /data5:/data5 -v /configfile:/configfile -v /data4:/additional_data
This will automatically add the volumes to your docker-compose.yml
configuration under the volumes section where you can further edit
or remove them as needed.
Hint
Combine any of the above flags if you want to use several of them together e.g.:
$ ./miracl -i josmann/miracl_dev_img -c miracl_dev -g -v /data:/data -v /config:/config
MIRACL versions
By default, Docker images will be built using the latest version of MIRACL. If you need to build a Docker image based on a specific version of MIRACL, do the following:
Clone the MIRACL repository and navigate to the MIRACL folder:
$ git clone https://www.github.com/mgoubran/MIRACL
$ cd MIRACL
Cloning the repository will download all tags/versions. List them with:
$ git tag -l
Example output:
v1.1.1
v2.2.1
v2.2.2
v2.2.3
v2.2.4
v2.2.5
Decide which tag/version of MIRACL you want to use and check it out as a new branch:
$ git checkout tags/<tag_name> -b <branch_name>
Example:
$ git checkout tags/v2.2.4 -b miracl_v2.2.4
If you are reverting to a version of MIRACL >=
2.2.4, you can build the image for your chosen version by running the installation script with the-tflag:
$ ./install.sh -t
Note
If you want to build an image for a version of MIRACL <= 2.2.4
either follow the build instructions of the particular version or
download the latest installation script using e.g.
wget https://raw.githubusercontent.com/AICONSlab/MIRACL/master/install.sh
(overwrites current installation script if present) and run it with
the -t flag.
From here you can follow our instructions for building MIRACL from scratch starting with
docker compose up -d. Our script will automatically detect the version of the branch you checked out and tag the image accordingly.
Unlike Docker, Apptainer is well suited to run in a cluster environment (like Sherlock at Stanford or Compute Canada). We provide the latest version of MIRACL as a Apptainer container that can be conveniently build from our Docker image on Dockerhub or downloaded from HuggingFace.
Tip
Apptainer is our recommended method for running MIRACL in a SLURM cluster environment such as Compute Canada or Sherlock @ Stanford
Build from Docker
First, log in to the cluster:
$ ssh -Y <username>@<cluster>
<cluster> could be sherlock.stanford.edu or
cedar.computecanada.ca for example
Once logged in, make sure that the Apptainer binary is available. On SLURM cluster you might have to load it as a module. Once you confirmed, that Apptainer is installed and working, navigate to the folder you want to create the Apptainer container in. On a SLURM cluster that could be your scratch folder:
$ cd $SCRATCH
Once there use the following command to create the container off of the MIRACL image hosted on DockerHub:
$ apptainer build miracl.sif docker://mgoubran/miracl:latest
The building process should start and the container will be available once the process has finished.
Download container
If, for some reason, the Apptainer image cannot be built using our DockerHub image, you can directly download a pre-compiled image of MIRACL that we host on HuggingFace.
To do so, log in to your cluster as described above and navigate to the folder you want to save the Apptainer binary in. Like in the example above that could be your scratch folder. Once in the target folder, run either of the the following commands to start the download:
$ wget https://huggingface.co/datasets/AICONSlab/MIRACL/resolve/dev/apptainer/versions/miracl_v251.sif
or
$ curl -L -O https://huggingface.co/datasets/AICONSlab/MIRACL/resolve/dev/apptainer/versions/miracl_v251.sif
Note
Replace the version number with the version of MIRACL you want to download.
Interaction
To shell into the container use:
$ apptainer shell miracl_latest.sif bash
Use the -B flag to bind a data directory to the container:
$ apptainer shell -B /data:/data miracl_latest.sif bash
Use the --nv flag to forward your Nvidia GPU into the container.
$ apptainer shell --nv -B /data:/data miracl_latest.sif bash
See also
For running functions on clusters please check our Apptainer tutorials for Compute Canada and Sherlock
Warning
Support for installing MIRACL locally in the
WSL has been deprecated in version 2.2.6 of
MIRACL. The recommended way to install MIRACL
on Windows is to use Docker in the WSL.
The Windows Subsystem for Linux (WSL) creates an environment that allows users to run versions of Linux without having to set up a virtual machine or a different computer.
Important
Docker Desktop requires WSL version 1.1.3.0
or later to be installed and turned on. To check open a command prompt
in Windows (cmd) and type: wsl --status.
To install WSL, users can follow the instructions from Microsoft. More comprehensive instructions can be found here. Upgrading from WSL1 to WSL2 is recommended, due to WSL2’s benefits.
Once the WSL has been installed you can proceed to install Docker.
Note
You may ignore the next step if you have a preferred, Docker enabled Linux distribution that is already installed in your WSL2.
Installing Docker on Windows
Download the Docker Desktop installer for Windows from here or from the release notes.
Double-click Docker Desktop Installer.exe to run the installer. By default, Docker Desktop is installed at
C:\Program Files\Docker\Docker.
Attention
By default, WSL2 should be used with Docker Desktop. However, if your Windows system supports WSL2 and Hyper-V, make sure to select the WSL2 option on the Configuration page when prompted.
Follow the instructions on the installation wizard to authorize the installer and proceed with the install.
When the installation is successful, select
Closeto complete the installation process.
Tip
Technically, Docker can be run on the Windows command prompt. However, it is recommended to use Docker in a Linux distro installed in the WSL.
Open the WSL2 on Windows in a command prompt (
cmd). Check the drop down menu next to the tab for installed Linux versions or typewsl -l -v.`Ubuntu` is already installed: Select it from the drop down. An Ubuntu terminal will open in a new tab.
`Ubuntu` is not yet installed: Open the Microsoft Store and search for Ubuntu. Choose the version you want to install and click the
Getbutton to automatically install it on the WSL. Select the version you installed from the drop down next to the command prompt tab. An Ubuntu terminal will open in a new tab.
Open Docker Desktop and navigate to
Settings. In theGeneraltab check ifUse the WSL 2 based enginecheckbox is checked. Check it if it isn’t yet.Still in the
Settingsnavigate toResources>WSL integration. Enable the Ubuntu distribution that you want to use Docker with.Go back to the command prompt and open the Docker enabled Ubuntu distro in a new tab.
In the Linux terminal, type
docker run helloto check if Docker is working correctly.
Install MIRACL in the WSL2
Just follow our installation instructions for Docker to install MIRACL as a Docker container in the WSL2.
Hint
Follow the below steps if you want to install MIRACL in your WSL instance locally. If you prefer to use Docker to run MIRACL on Windows follow our installation instructions for Docker instead.
Warning
Support for this installation method has been discontinued starting
with version of 2.2.6 of MIRACL. Please use Docker
or Apptainer instead.
Warning
THIS INSTALLATION METHOD HAS BEEN DEPRECATED!
Steps to setup/run MIRACL on a Linux/macOS machine:
$ git clone https://github.com/mgoubran/MIRACL.git miracl
Tip
Alternatively, you can download the zip file containg the repo and uncompress it
Next, change directories into the newly created miracl folder:
$ cd miracl
Create your virtual MIRACL environment and activate it:
Attention
To setup a virtual environment you need Anaconda for Python 2.7. It can be downloaded from their official website
$ conda create --name miracl python=3.7.4 pip
$ conda activate miracl
Install dependencies:
$ pip install -e .
ANTS & c3d
Next, download the depends folder from our
Dropbox link
and place it either inside the linux_depends or
mac_depends folder:
$ mv ~/Downloads/depends.zip miracl/.
$ cd miracl
$ unzip depends.zip
$ rm depends.zip
This folder contains compiled versions of ANTS and c3d for Linux or Mac OS. Before continuing, make sure to change the permissions.
This can be done by running:
$ chmod -R 755 <path/to/depends>/*
In order to run the pipeline, some symbolic links must be added to
access certain commands. Inside the miracl folder, run:
$ sudo ln -s <path/to/depends>/ants/antsRegistrationMIRACL.sh /usr/bin/ants_miracl_clar && chmod +x /usr/bin/ants_miracl_clar
$ sudo ln -s <path/to/depends>/ants/antsRegistrationMIRACL_MRI.sh /usr/bin/ants_miracl_mr && chmod +x /usr/bin/ants_miracl_mr
Make sure <path/to/depends> is replaced with the directory path
that leads to the depends directory.
Allen atlas
Place the atlases folder (which got downloaded together with the
depends folder) inside the miracl folder:
$ mv ~/Downloads/atlases.zip miracl/.
$ cd miracl
$ unzip atlases.zip
$ rm atlases.zip
This folder contains the Allen Atlas data needed for registration and connectivity analysis.
Fiji & FSL
Install Fiji & FSL
First, download Fiji/ImageJ from their offical website.
Then do:
$ cd depends
$ wget https://downloads.imagej.net/fiji/latest/fiji-linux64.zip
$ unzip fiji-linux64.zip
$ rm fiji-linux64.zip
Next, install additional plugins by going to Help -> Update and
clicking on the Manage update sites button.
Choose the following update sites:
3D ImageJ Suite: http://sites.imagej.net/Tboudier
Biomedgroup: https://sites.imagej.net/Biomedgroup
IJPB-plugins: http://sites.imagej.net/IJPB-plugins
Download FSL and install it:
$ wget https://fsl.fmrib.ox.ac.uk/fsldownloads/fslinstaller.py
$ sudo python fslinstaller.py
Visualization
For the visualization of nifti files and labels we recommend ITKSNAP or the nifti plugin for Fiji/ImageJ.
Diffusion Data
If you have diffusion MRI data download and install MRtrix3:
$ sudo apt-get install git g++ python python-numpy libeigen3-dev zlib1g-dev libqt4-opengl-dev libgl1-mesa-dev libfftw3-dev libtiff5-dev
$ git clone https://github.com/MRtrix3/mrtrix3.git
$ cd mrtrix3
$ ./configure
$ ./build
$ ./set_path
Deactivate
To end a MIRACL session, deactivate your virtual environment:
$ conda deactivate
Update MIRACL
To update MIRACL, navigate into your MIRACL base
folder (e.g. $ cd miracl) and run:
$ git pull
You should be good to go!