Advanced fMRI analyses have the potential to answer questions that mainstream methods cannot. BrainIAK aims to integrate these cutting-edge techniques into a single, accessible Python environment. To help users get started, we have created the following set of tutorials based on courses taught at Princeton and Yale Universities.
The tutorials below are designed to be consumed in sequence, but are modular and can be approached in any order (for more details, see the tutorials preprint). We provide recommendations to scaffold on users’ knowledge and skills, though even advanced users have reported benefiting from the full sequence. All of the notebooks are paired with data that have been preprocessed and are ready for use. Our resources page has helpful links on learning the basics of fMRI preprocessing.
If you have any questions or problems, you can ask the folks in our Gitter chat or file an issue on GitHub.
To only run the tutorials, you can use Google Colaboratory. You only need a web browser. No other installation is necessary. Follow the Colab instructions below. A few notes:
If you want to save your code, you can save a copy of the notebook to Google Drive (accessible from the File menu in Colab).
Instructions
02-data-handling.ipynb
)Shift-Enter
to run. NOTE: you may need to click RUN ANYWAY
when Google Colab presents a warning.
!pip install deepdish ipython matplotlib nilearn notebook pandas seaborn watchdog
!pip install pip\<10
!pip install -U git+https://github.com/brainiak/brainiak
!git clone https://github.com/brainiak/brainiak-tutorials.git
!cd brainiak-tutorials/tutorials/; cp -r 07-searchlight 09-fcma 13-real-time utils.py setup_environment.sh /content/
!mkdir /root/brainiak_datasets
Copy the relevant cell in the setup notebook for the data you want to download and paste and run in a new cell in your tutorial notebook:
- You don’t need to copy all cells in this section, just the cells for the data you need (e.g. only data for 02
if you are running 02-data-handling.ipynb
).
Resize memory for Docker. click: Docker on Menu Bar -> Preferences -> Advanced
The more memory and swap space you can assign, the better. We have tested with 5GB of memory. The default setting of 2GB is too little to load large datasets. Also, increase the swap space to approximately 4-5GB. If your available space is less than 4GB, set the swap space to whatever you have available.
brainiak_datasets
brainiak_datasets
docker run -it -p 8899:8899 -v ~/Downloads/brainiak_datasets:/root/brainiak_datasets --name tutorials brainiak/tutorials
Note the port that you need to connect to the browser: 8899
Running Tutorials
-p
above. Ignore any other port info)Copy the token as shown below
Open tutorials and run.
Run Docker after replacing USERNAME
with your Windows user name:
docker run -it -p 8899:8899 -v C:/Users/USERNAME/downloads/brainiak_datasets:/root/brainiak_datasets --name tutorials brainiak/tutorials
Running Tutorials
-p
above. Ignore any other port info)Copy the token as shown below
Open tutorials and run.
This option is supported for OSX and Linux. For Windows, please use Colab or Docker.
conda
in your terminalInstall brainiak-tutorial conda package:
conda create --name mybrainiak python=3.6
conda activate mybrainiak
or source activate mybrainiak
mv ~/.condarc ~/.condarc.bak
conda install -c pni -c defaults -c conda-forge brainiak_tutorials
In any folder (e.g., cd my_code
) that you would like to store the tutorials run:
git clone https://github.com/brainiak/brainiak-tutorials.git
~/Downloads/brainiak_datasets
The screen shot shows a sample of the data directories for different tutorials
Running Tutorials
cd my_code/brainiak_tutorials/tutorials
setup_environment.sh
for CONDA_ENV=mybrainiak
configuration='local'
./run_jupyter.sh
utils.py
data_path
to ~/Downloads/brainiak_datasets/
Change
data_path = os.path.join(os.path.expanduser('~'), 'brainiak_datasets')
to
data_path = os.path.join(os.path.expanduser('~'), 'Downloads', 'brainiak_datasets')
Install Miniconda with Python 3
Example install commands:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
or run the following command to load pre-installed anaconda:
Here is an example: module load anacondapy/5.3.1
Create a Conda environment
conda create -n mybrainiak
source activate mybrainiak
or conda activate mybrainiak
Ensure that your .condarc is not interfering:
mv ~/.condarc ~/.condarc.bak
Install brainiak-tutorial conda package
conda install -c pni -c defaults -c conda-forge brainiak_tutorials
Download data for the tutorial
wget --no-check-certificate -r -O 'datasets.zip' 'https://docs.google.com/uc?export=download&id=1ZglrmkYw8isBAfsL53n9JgHEucmrnm4E'
unzip datasets.zip
Move data to ~/brainiak_datasets/
In the terminal clone the tutorial repo:
git clone https://github.com/brainiak/brainiak-tutorials.git
Running Tutorials
cd brainiak_tutorials/tutorials
setup_environment.sh
for CONDA_ENV=mybrainiak
configuration='server'
Launch Jupyter on server (steps and screen shots here for Jupyter on server)
./run_jupyter_remote_server.sh
Enter token printed by script when asked for token/password on the jupyter web page
Install brainiak-tutorial conda package
conda install -c pni -c defaults -c conda-forge brainiak_tutorials
~/brainiak_datasets/
git clone https://github.com/brainiak/brainiak-tutorials.git
utils.py
data_path
in utils.py
setup_environment.sh
for CONDA_ENV=mybrainiak
configuration='cluster'
Running Tutorials
setup_environment.sh
for CONDA_ENV=mybrainiak
configuration='cluster'
Launch Jupyter on cluster (steps and screen shots here for Jupyter on server)
cd brainiak-tutorials/tutorials
./run_jupyter_remote_server.sh
(Verify all SLURM parameters for your cluster)
This installation is typically performed by cluster administrators. As a user, you only need to update the modules used, and the path to the data directory. You are expected to have knowledge of SLURM parameters, for your cluster, to launch the Jupyter notebooks and run batch jobs. Your cluster administrator can help you with setting the SLURM parameters.
Administrator tasks
Install brainiak-tutorial conda package
conda install -c pni -c defaults -c conda-forge brainiak_tutorials
Download tutorial data brainiak_datasets.zip
wget --no-check-certificate -r -O 'datasets.zip' 'https://docs.google.com/uc?export=download&id=1ZglrmkYw8isBAfsL53n9JgHEucmrnm4E'
unzip datasets.zip
User tasks
https://github.com/brainiak/brainiak-tutorials.git
In the terminal, clone the tutorial repo:
git clone https://github.com/brainiak/brainiak-tutorials.git
cd brainiak-tutorials/tutorials/
Run tutorials
Edit file setup_environment.sh
and add the correct module. Your cluster administrator should provide the names of the module(s) (e.g., module load pyger/0.8) to load.
CONDA_NAME=mybrainiak
configuration='cluster’
Make the run_jupyter_remote_server.sh
script executable
chmod 711 run_jupyter_remote_server.sh
./run_jupyter_remote_server.sh
utils.py
data_path
in utils.py
to the path location of the brainiak_datasets
folder.You will need to update this line:
data_path = os.path.join(os.path.expanduser('~'), 'brainiak_datasets')
with the correct path.
These datasets are pre-processed and ready to use. They have been condensed to keep the file size small, by reducing the number of subjects from the original studies. Each tutorial is paired with a dataset as listed below. The file brainiak_datasets.zip contains the data for all the tutorials, and in unzipped form uses 18GB of space. If you wish to download data for specific tutorials, use the list below to find the correct dataset to download and use. Note that Colab has its own data download mechanism (see Colab install instructions).
The above data urls point to google drive for faster downloads. The doi reference for these tutorial datasets is https://doi.org/10.5281/zenodo.2598755.
We have compiled a list of useful resources that cover the basics of GitHUB, Python, fMRI, and Machine Learning here.
Like BrainIAK itself, these tutorials are open-sourced as a service to the field and can be freely used, modified, and shared. They are licensed under the Apache License, Version 2.0. If you find them helpful in your research or re-use code they contain, you might consider citing:
Manoj Kumar, Michael J. Anderson, James W. Antony, Christopher Baldassano, Paula P. Brooks, Ming Bo Cai, Po-Hsuan Cameron Chen, Cameron T. Ellis, Gregory Henselman-Petrusek, David Huberdeau, J. Benjamin Hutchinson, Y. Peeta Li, Qihong Lu, Jeremy R. Manning, Anne C. Mennen, Samuel A. Nastase, Hugo Richard, Anna C. Schapiro, Nicolas W. Schuck, Michael Shvartsman, Narayanan Sundaram, Daniel Suo, Javier S. Turek, David Turner, Vy A. Vo, Grant Wallace, Yida Wang, Jamal A. Williams, Hejia Zhang, Xia Zhu, Mihai Capota, Jonathan D. Cohen, Uri Hasson, Kai Li, Peter J. Ramadge, Nicholas B. Turk-Browne, Theodore L. Willke, Kenneth A. Norman, 2020. BrainIAK: The Brain Imaging Analysis Kit. Aperture Neuro, 1(4), 19. https://apertureneuropub.cloud68.co/articles/42/index.html
Kumar, M., Ellis, C.T., Lu, Q., Zhang, H., Capotă, M., Willke, T.L., Ramadge, P.J., Turk-Browne, N.B. and Norman, K.A., 2020. BrainIAK tutorials: User-friendly learning materials for advanced fMRI analysis. PLoS Computational Biology, 16(1), e1007549. https://doi.org/10.1371/journal.pcbi.1007549