-
Notifications
You must be signed in to change notification settings - Fork 1
Home
To process MRI data, it's best to have an understanding of the command line (typically Bash). You also need a computer with the relevant applications you will use. This guide will provide a broad introduction to structural and functional MRI analyses. This is a work in progress so a lot will change over time. This wiki is an outgrowth of my an OS X-specific website I maintain (but don't actively update).
- Beginner's Guide to Command Line Interface
- More about the Command Line Interface
- Introduction to bash scripting for neuroimaging
- Great source of neuroimaging tools and data: NITRC
- Before you begin
- Preprocessing and processing images
- MRI File Formats
- Download example test-retest multi-modal dataset
- Alternative option for test-retest MRI data
- More public datasets
- Convert DICOM to NIfTI
- BIDS and dcm2bids: Structuring your data sets
- Correct intensity nonuniformities (bias field)
- Resample images to isotropic voxel size 1
- Brain Extraction and Tissue Segmentation
Neuroimaging computing is generally done on Linux or macOS. You may need to be logged in as root to install many of these programs, depending on the permissions of the directory on which you are installing. The following are specifics about operating systems I currently use to run neuroimaging analyses:
In order to have access to root user you have to directly enable the option, for instructions refer to this page here. You can also install a number of tools using the command line with superuser access: sudo
. If you are on a university or company managed computer, it's a good idea to talk with your IT administrator before installing any software (if you have administrator access).
Before installing any neuroimaging software, there are some tools you should make sure are on your computer first.
You should install the XCode Command Line Tools before beginning any of these other tasks. Probably the easiest way to install these tools is to run the following command
git --version
If you don't have the command line tools installed it will prompt you to install them (requires admin access). You can also install XCode if you wish. I often use it when I'm writing scripts but there are many other options. The version of XCode will vary, depending on your OS version. Read more about XCode.
You can also install the Xcode command line tools using the following command
xcode-select --install
If you ran the command listed above, you have git installed. You can also visit this link for more instructions, including for other operating systems.
While you can use TextEdit that's built into macOS, it has limitations because it is a pure text editor. It is fast and lightweight though so I use it for most of my quick work. Many people use Vim but it has a steep learning curve and is not user-friendly. I don't recommend it to novices.
One cross-platform option is Atom. Installation instructions for the Mac are here. While this has more features than you'll need for simple Bash scripting (we'll cover that later), it gives you a solid platform to work on.
There are many other options so explore a little to see which editor fits you and your needs. To find options perform a web search for code editor
.
Pip is a package manager for Python.
On macOS you can install it like this in Terminal
easy_install pip
Or, you might need to run it with administrator privileges
sudo easy_install pip
We will use this to install some neuroimaging software.
Homebrew is a general package manager for the command line in macOS. It allows some software to be easily installed and updated (it's essentially a command line version of the App Store).
Install it like this by pasting and running this in Terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then you are ready to install applications/packages you might need.
Don't do this now but here's an example of how it is used to install.
brew install eigen
(this is a dependency if you install MRtrix).
Then later, if you want to make sure applications and packages are up-to-date you can run the following commands.
brew update && brew upgrade
If you want to make sure a particular package does not upgrade (could be important to make neuroimaging reproducible and even valid), you can "pin" it.
brew pin mrtrix3
There are many 'flavors' of Linux. I strongly recommend using Debian or a Debian-based distribution. There are many active ones to choose from. To simplify, I recommend Ubuntu, Mint, or Debian. Ubuntu is quite easy to use and learn. I strongly recommend you stick with versions of Ubuntu that have long-term support (LTS). The current LTS release is 18.04.1 (Bionic Beaver). Some neuroimaging software might not work with newer OS versions (e.g., 18.10; I tried with 18.10 and while some tools worked well, others like FSL had some issues).
CentOS, Red Hat, and others work well but my experience is with Debian-based distributions so all my instructions are Debian(-based) specific.
Similar base tools are recommended for Linux as for macOS. Again these are Ubuntu/Debian specific.
sudo apt update
sudo apt install git
Then make sure it's installed correctly
git --version
You should see output like git version 2.17.1
It's not necessary for our purposes but you can personalize some git environmental variables.
git config --global user.name "Your Name"
(of course, replace "Your Name" and don't include the quotation marks)
git config --global user.email "youremail@domain.com"
(replace "youremail@domain.com" and don't include the quotation marks)
Installing pip is easy on Ubuntu
In Terminal run these commands
sudo apt update
sudo apt install python-pip
Then check if it installed correctly
pip --version
You should see output like this
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
There is a newer version of Python (and pip) but we'll ignore that for now.
To simplify installation of some neuroimaging software in Linux, using the NeuroDebian repositories is helpful. You can enable NeuroDebian on your system by simply copying and pasting the following two commands into a terminal window. This will add the NeuroDebian repository to your native package management system, and you will be able to install neuroscience software the same way as any other package.
wget -O- http://neuro.debian.net/lists/bionic.us-tn.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
sudo apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9
Now you can update the package index and you are ready to install packages. Simply execute the following command in a terminal:
sudo apt-get update
You are ready to go – enjoy NeuroDebian!
For a complete list of packages available now, check this link.
For example, if you wanted to install AFNI (not otherwise covered on this site, although some of its tools are very useful for other purposes), you could enter the following command
sudo apt install afni
Follow the prompts and it will shortly be installed.
With the Windows Subsystem for Linux activated and Ubuntu installed you can use many common MRI applications. If you are using Windows it may be easier to log in as the Administrator for all of these downloads. If you are using a managed computer, you will likely need your IT administrator to install any software.
Some imaging programs (MANGO, dcm2nii, mricron, and some functions of ANTs) can be installed onto Windows easily but you will quickly find barriers between programs. The neuroimaging community likes to run things on Linux or macOS (although SPM runs well on Windows so many people who do only fMRI research use Windows). If you are interested in having these programs on your own computer I suggest a free installation of Linux. If you aren't fully committed to using just Linux you can run it in a Virtual Machine or partition your drive to dual boot, which allows you to run Linux or Windows upon restarting your computer each time. NeuroDebian is a VM that can be installed and run without too much difficulty. I won't reproduce the installation instructions here.
Another option mentioned previously is with Windows 10 and the Windows Subsystem for Linux. Follow those instructions to get this useful tool installed. Once you enable the WSL, you can easily install your Linux distribution of choice. There are some limitations to the WSL relative to a "pure" installation of Linux but it gives access to a number of the tools previously unusable in Windows. Windows Subsystem for Linux Documentation
Now you should be able to follow most/all of the instructions for Ubuntu.