Skip to content

Anatomy preprocessing

Noam Peled edited this page Aug 29, 2017 · 8 revisions

Once you have run the setup script, open the terminal (or command line in Windows):

For running the anatomy preprocessing, you’ll need FreeSurfer, which can be used only on a Linux or Mac OS. If you are using Windows, you’ll need to run this step on another machine, or on a virtual one. You can download an ubuntu virtual machine that already includes FreeSurfer here.

Template Brains

In case you don't need to work on a specific subject's brain, only on a template one (If your subject doesn't have MRI, or for group averaging for example), you can download colin27 files from here

Source the Freesurfer directory

In case you do want to work on a specific subject's brain, you'll need to run the anatomy preprocessing script. Parts of the script are using FreeSurfer commands, so first you'll need to download FreeSurfer, the dev version (look for "Development Version"). To source Freesurfer, you can:

  1. Do it manually every time you open a new terminal: Set the directory where FreeSurfer was installed as an environmental variable typing: export FREESURFER_HOME=/usr/local/freesurfer Then source the setup script typing: source $FREESURFER_HOME/

  2. Edit the .bashrc (if you use a bash shell) and setup an alias Open the .bashrc file (or .cshrc, depends if you are using bash or csh) with a text editor: gedit ~/.bashrc Add these two lines export FREESURFER_HOME=/usr/local/freesurfer alias alias_name="source $FREESURFER_HOME/" Save the changes and start a new terminal. Every time you start a new terminal and type alias_name it will automatically source FreeSurfer.

Running anatomy preprocessing script

cd inside the folder where the mmvt code is (/home/user/code/mmvt for example). Make sure your python is 3.4 and above. You can check that by running the following command: python src/ Part of the anatomy preprocessing is using Matlab (If you don’t have Matlab, we are really sorry, we’ll migrate this code to python ASAP. Meantime, you can contact us and we’ll run this step for you). Before running the script, you need to make sure you can run matlab by running “matlab” in the command line. If you areldy have matlab installed, but you can't run it by calling "matlab" from the command line, you have two options:

  1. Copy the default_args.ini file from the resources folder, under the mmvt code folder. Edit the file and set your matlab_cmd full path command.
  2. On Linux based OS, add a matlab alias to the basrc/cshrc files. To make sure you can run matlab, run the following command: python -m src.run_matlab

Now you can run the anatomy preprocessing. Here we are using ‘subj01’ as the name for the subject, you should replace it with your own subject’s name:

python -m src.preproc.anatomy -s subj01

The default parcellation atlas is the FreeSurfer aparc.DKTatlas40 atlas. If you want to use a different atlas, like the Lausanne250 for example, make sure your local fsaverage has the annotation files. You can download Lausanne250 and Lausanne500 files here.

python -m src.preproc.anatomy -s subj01 -a atlas_name

In the MMVT_DATA folder, you’ll find the atlas.csv file. Make sure the atlas you are using is there. In this file, you’ll find the aparc, aparc2009 and aparc.DKTatlas40 FreeSurfer atlases, and the Lausanne125, Lausanne250 and Lausanne500 atlases. The first column is the atlas friendly name (dkt for aparc.DKTatlas40 for example), the second column is the atlas real name, and the third is the atlas’s description.

If the FreeSurfer recon-all files aren’t placed locally, or you don’t want to write to this folder (in that case you should have chosen a different subject’s folder in the setup), you should add the --remote_subject_dir flag:

python -m src.preproc.anatomy -s subj01 -a atlas_name --remote_subject_dir /home/user/subjects/subj01

If you need to use ftp to reach the recon-all files, you should add the sftp, sftp_username and sftp_domain flags (you’ll be asked for the password in the command line):

python -m src.preproc.anatomy -s subj01 -a atlas_name --remote_subject_dir /home/user/subjects/subj01 --sftp 1 --sftp_username USERNAME --sftp_domain DOMAIN_NAME

You can also process multiple subjects at once by concatenating the subjects names with a comma (no spaces):

python -m src.preproc.anatomy -s subj01,subj02,subj03 -a atlas_name

Warning: If you wish to run the script on more than one subject, you shouldn't run the script in parallel (in more than one terminal). This issue will be fixed in the future.

If you wish to get the recon-all files from a remote directory, for more than one subject you should add the {subject} template to the remote_subject_dir (the apostrophes are needed because of the '{' special character):

python -m src.preproc.anatomy -s subj01,subj02,subj03 -a atlas_name --remote_subject_dir "/home/user/subjects/{subject}"

Of Course, you can also use the sftp flags.

Troubleshoot: If for some reason the connection or the data transfer fails rerun the command by adding the overwrite_fs_files flag to overwrite the files: python -m src.preproc.anatomy -s subj01 -a atlas_name --overwrite_fs_files 1

Creating the blend files

After this step is completed you are now ready to create the subject’s blend file (the file you’ll open in Blender):

python -m src.mmvt_addon.scripts.create_new_subject -s subj01 -a atlas_name

You can use the subjects flag instead of the s flag to create more than one Blend file:

python -m src.mmvt_addon.scripts.create_new_subject --subjects subj01,subj02,subj03 -a atlas_name