Contents
How To Set Up
How To Extract The Raw Data From Scanner
How To Inflate Brains Automatically
How To Inflate Brains Manually
How To Make Block Design Comparisons
How To DO Retinotopy
How To Draw Your Results
How To Manipulate ROIs and Annotations

How To Set Up

run nmrenv, and set $SUBJECTS_DIR and $SUBJECT correctly.
(or in my case, run my script called nmrdaniel)

My script nmrdaniel is a script that has the following lines:
---cut here--
#If you want the FS-Fast software etc, use this:
source ~inverse/freesurfer_alpha/nmr-std-env
setenv SUBJECTS_DIR /space/doodles/1/users/MTstudy/fMRI/subjects
setenv SUBJECT subj011
echo "All ready now. Subject value is:"
echo $SUBJECT
--cut here--

You must run either nmrenv or a script like nmrdaniel before running any freesurfer or FS-FAST command.

generate the subject directory structure:
mksubjdirs <subjname>
This command must be run for every subject.


How To Extract The Raw Data From Scanner

Unpack the data from bourget:
browse-sessions

find the correct subject, possibly by searching.

Ask it to start, and you will find that instead it will tell you the path for unpacking.
unpacksdcmdir -src <source> -targ <target> -scanonly

This outputs the type of scans used. Now use a file at $FREESURFER_HOME/numaris4-protocols.unpackcfg to correctly make a config file. The format is:

num folder format fileprefix
Here is an example config file.
1 scout bshort f
3 bold bshort f
4 bold bshort f
5 bold bshort f
6 bold bshort f
7 bold bshort f
8 bold bshort f
The number is acquisition number.
The folder is where that acquisition is stored (bold directory, scout directory etc)
The format is the form of the data files.
The fileprefix is how the filenames start.

Next run it again with your config file.

unpacksdcmdir -src <source> -targ <target> -cfg<configfile> -fsfast

Note: I have come across old data which was *.ima format. This can be unpacked using
unpackimadir2
which works just like unpacksdcmdir.

*** There is always a problem after unpacking that the TR is not set correctly. Please fix it.

pico $SUBJECTS_DIR/$SUBJECT/bold/seq.info

Goto the 3danat/ dir

Copy contents to mri/orig. For example...
cp 3danal/* mri/orig



How To Inflate Brains Automatically

From the subject's directory, run the following
recon-all -subjid <subjname> -all [-waitfor <filetowaitfor>] -notify <filetonotifydone>
(many ways to run this function. See recon-all -help)

Or, do the faster technique, of running each step of recon all separately.
I have a script called "reconSTEPS" in my fMRI Tools section of my website which will help you do this.
To run it properly, you must make at least 2 copies of it, one for each hemisphere, and edit them appropriately.
If you do it right, you can reconstruct the entire brain in less time, since the hemispheres can be run in parallel.
Also, if you have more than one computer available, you can speed this process up.
If you have more than one subject, you can reconstruct more than one of them at a time using this technique.
The advantage of using reconSTEPS is that if anything fails you can simply re-run the remaining steps instead of the
entire thing all over again. You can also go into manual reconstruction, which is explained below.

To check results:

check_subject <subjname>

At this point, it should be good. But if not, the following steps may help.


How To Inflate Brains Manually


A. Try a different structural.
cp 3danal/003/* mri/orig

B. If there is a filling error, you may be missing a good seed point in corpus collusum, right or left hemisphere or pons. Find them, then fill them based on your findings.

tkmedit <subjname> T1

Click on the points, and you can find x,y,z.

mri_fill -C <x> <y> <z>-rh <x> <y> <z> -lh <x> <y> <z> -P <x> <y> <z> $SUBJECTS_DIR/$SUBJECT/mri/wm/ $SUBJECTS_DIR/$SUBJECT/mri/filled

In the filled/ directory, make sure a &ldquo;surf&rdquo; directory exists. If not, make one.

In that same directory, if mri_tesselate is there. If not, run:
mri_tesselate_filled 255 ../surf/lh.orig
mri_tesselate_filled 127 ../surf/rh.orig
inflate_subject-rh<subjectname>
inflate_subject-lh<subjectname>
fix_subject<subjectname>
morph_subject<subjectname>
make_final_surfaces<subjectname>
parcellate_subject<subjectname>
map_all_labels <subjectname>

C. Try using csurf:

Goto subject's directory.
csurf

Choose subject.

Subject-tools->Edit Segmentation.
Click on a region where two parts of brain are connected that should not be.
In tksurfer, TOOLS->save point.
In mkedit window, TOOLS-> goto point.
Edit->voxels.
Middle mouse adds, right mouse deletes. Check slice before and after as well. Remove the unwanted connection.
File-> save main volume as->save as default
Surfer window, Subject-tools->Process volume
Subject-tools->Create surface
Subject-tools->Fix surface topology
Subject-tools->Make final surface
Subject-tools->Create surface
Subject-tools->register surfaces

After all this...

To check results:

check_subject <subjname>



How To Make Block Design Comparisons


You will need paradigm files. They list each TR based time point, tab, and then a condition number. For instance:

0 0
2 0
4 1
6 1
8 0
...

This file is then saved as whatever you feel like, but the same file name is used for all functional runs. Tradition has "mtstudy.par". It is then placed in bold/003 where 003 is an example functional run. All runs get one.

You need to generate a file that lists the subject name in the subject directory. Redundant here, but other directory structures might care. This file must be called subjectname.

pico $SUBJECTS_DIR/$SUBJECT/subjectname

And it simply contains the name of your subject, for instance

bert

This file is stored in the subject dir.

You need a totally separate study directory, from where you will make all your commands. In there, you need the session dir and session id files.

This file can be called anything, but by my custom use

sessdir

This file has one line, which is the complete path of the session directory, meaning the directory right underneath the one that has the name of the subject.

The session id file has the name of the subject on one line. The file is called
sessid.

Now you can start. From your study directory, run commands.

Make talairach xform files for later registration

mktalxfm-sess -sf sessid -df sessdir

Motion correct

mc-sess -fstem f -fmcstem fmc -sf sessid -df sessdir [-rlf runlistfile]

Spatial smooth and intensity normalize: (note that 8 is arbitrary)

spatialsmooth-sess -i fmc -o fmcsm8 -fwhm 8 -sf sessid -df sessdir

Motion correction:

plot-twf-sess -ymax 5.0 -mc -funcstem fmcsm8 -sf sessid -df sessdir
If motion > 2.5mm, time points can be disregarded. If excessive, drop that file.

Now make an tpexclude.txt file on the subject's functional raw directories.

It contains one column of return delimited numbers which represent each TR time point that should be excluded.
emacs tpexclude.txt &

Make the analysis here. You can ignore the tpexclude if all your motion is ok. You can add the -runlistfile option if you want to.

mkanalysis-sess -analysis mtstudy -paradigm mtstudy.par -tpexclude tpexclude.txt -blocked -motioncor -inorm -sf sessid -df sessdir
OR
mkanalysis-sess.new -analysis mtstudy -TR 2.5 -paradigm mtstudy.par -designtype blocked -funcstem fmcsm8 -nskip 4 -polyfit 2 -gammafit 2.25 1.25 -timewindow 53 -nconditions 4 -runlistfile <runlistfilename> -sf sessid -df sessdir

Edit the analysis setup file from the studyDir:

emacs mtstudy/analysis.cfg &

Make average session level data...

selxavg-sess -analysis mtstudy -sf sessid -df sessdir

Make contrasts...

mkcontrast-sess -analysis mtstudy -contrast <contrastname>-a <#> -a<#> -c <#>-c <#> -sf sessid -df sessdir

Now calculate them...

stxgrinder-sess -analysis mtstudy -contrast <contrastname> -sf sessid -df sessdir

This can be simplified if there are more than one contrast, they can be run all at once:

stxgrinder-sess -analysis mtstudy -all-sf sessid -df sessdir -space tal
stxgrinder-sess -analysis mtstudy -all-sf sessid -df sessdir -space native
stxgrinder-sess -analysis mtstudy -all-sf sessid -df sessdir -space sph

Now autoregister:

autoreg-sess -sf sessid -df sessdir

manual register after

tkregister-sess -sf sessid -df sessdir
(there is also a thing called tkregister2)

Resample (res is size of pixel: 1,2,4,8mm):

func2tal-sess -analysis mtstudy -res 2 -sf sessid -df sessdir
func2sph-sess -analysis mtstudy -sf sessid -df sessdir

To make group averages (fixed effects), first set up a group with
isxavg-fe-sess -analysis mtstudy -group <groupname> -sf sessid -df sessdir -space <tal or sph or native>

Then run the averaging with:

stxgrinder2-sess -analysis mtstudy -s <groupname> -space <tal or sph or native> -contrast <contrastname>[-all] -sf sessid -df sessdir

To compare thresholded contrasts together, use this guy...
mergecontrasts-sess -mergecontrast <new_contrast_name> -conjunction <and,or,andor> -analysis mtstudy -contrast <contrast1> <thresh> <pos,neg,abs> <1 if complement, 0 else> [-contrast <contrast2> <thresh> <pos,neg,abs> <1 if complement, 0 else> ] [-contrast <contrast3> <thresh> <pos,neg,abs> <1 if complement, 0 else>] [ ...] -map <t,minsig,iminsig,sig> -space <tal,sph,native> -sf sessid -df sessdir


How To DO Retinotopy


For each session, create retinotopy paradigm files in each of the the
run directories. These paradigm files are different than an
event-related or block paradigm (which list which stimulus was
presented when). A retinotopy paradigm file has information about
whether the run was an eccentricy or polar stimulus and in what
direction the stimulus was presented.

For polar, the direction is indicates whether the spoke was traveling
clockwise or counter-clockwise.  For eccen, the direction is indicates
whether the ring was expanding or contracting. The definition of
what's positive and what's negative is arbitrary, though it must be
consistent. If you don't have both directions, just use positive.

For example, if there were four runs (001, 002, 003, 004), two eccen
and two polar, both in the positive and negative directions. Create
a file (eg, rtopy.par) in each run. Assuming run 001 was eccen in the
negative direction, then the rtopy.par for run 001 would look like:

--------cut here --------
stimtype  eccen
direction neg
--------cut here --------

or
-------cut here------
stimtype polar
direction pos
--------cut here----

If needed, create a run-list file with the all retinotopy runs
(regardless of whether it was eccen or polar).

You need to generate a file that lists the subject name in the subject directory. Redundant here, but other directory structures might care. This file must be called subjectname.

pico $SUBJECTS_DIR/$SUBJECT/subjectname

And it simply contains the name of your subject, for instance

bert

This file is stored in the subject dir.

You need a totally separate study directory, from where you will make all your commands. In there, you need the session dir and session id files.

This file can be called anything, but by my custom use

sessdir

This file has one line, which is the complete path of the session directory, meaning the directory right underneath the one that has the name of the subject.

The session id file has the name of the subject on one line. The file is called
sessid.

Now you can start. From your study directory, run commands.

Make talairach xform files for later registration

mktalxfm-sess -sf sessid -df sessdir

Motion correct

mc-sess -fstem f -fmcstem fmc -sf sessid -df sessdir [-rlf runlistfile]

Spatial smooth and intensity normalize: (note that 5 is arbitrary)

spatialsmooth-sess -i fmc -o fmcsm5 -fwhm 5 -sf sessid -df sessdir

Motion correction:

plot-twf-sess -ymax 5.0 -mc -funcstem fmcsm8 -sf sessid -df sessdir
If motion > 2.5mm, time points can be disregarded. If excessive, drop that file.

Now make an tpexclude.txt file on the subject's functional raw directories.

It contains one column of return delimited numbers which represent each TR time point that should be excluded.
emacs tpexclude.txt &

Create the analysis:
mkanalysis-sess.new  -analysis <analysis_name> -TR <TRvalue> -designtype retinotopy -paradigm rtopy.par -funcstem fmcsm5 -ncylcles <number of cycles> [-runlistfile <filename>]

Run the analysis:
sfa-sess -sf sessid -df sessdir -analysis <analysis_name>

This will create <subjectname>/bold/<analysis_name> in which will be:
  1. volume h-offset (the mean function intensity)
  2. eccen - eccentricity folder (with h volume)
  3. polar - polar folder (with h volume)

The task-related activation can be viewed as with any other contrast
in a non-retinotopy application. Just use eccen or polar as the
contrast and specify h as the map.

The task-related activation for eccen can be viewed with:
  sliceview-sess -sf sessid -analysis <analysis_name> -c eccen -map h -slice mos
The task-related activation for polar can be viewed with:
  sliceview-sess -sf sessid -analysis <analysis_name> -c polar -map h -slice mos

Run paint:
  paint-sess -analysis <analysis_name> -sf sessid

This will create map-imag-lh.w (the imaginary or sine part muliplied
by the log10(sig)), map-real-lh.w (the real or cosine part muliplied
by the log10(sig)), and sig-0-lh.w (the task related activation) for
both the polar and eccen.  It will also create a directory called
fieldsign in bold/<analysis_name> in which fieldsign-lh (or -rh) along with
fieldsignmask-lh will be found.

To view the field-sign on the flattend patch (occip.patch.flat):
  surf-sess -sf sessid -analysis <analysis_name> -retinotopy fieldsign -flat

To view the eccen on the flattend patch (occip.patch.flat):
  surf-sess -sf sessid -analysis <analysis_name> -retinotopy eccen -flat

To view the polar on the flattend patch (occip.patch.flat):
  surf-sess -sf sessid -analysis <analysis_name> -retinotopy polar -flat

To view the task-related polar activation on the flattend patch
  surf-sess -sf sessid -analysis <analysis_name> -c polar -flat



How To Draw Your Results

Paint (for surfing)
paint-sess-new -analysis mtstudy -contrast <contrastname>-map <type> -sf sessid -df sessdir

View individual with... (map types are t,sig,minsig and iminsig)

sliceview-sess -slice <#> -analysis mtstudy -contrast <contrastname>-map <type> -sf sessid -df sessdir [-space tal]
surf-sess-new -analysis mtstudy -contrast <contrastname>-map t-sf sessid -df sessdir -hemi lh
surf-sess-new -analysis mtstudy -contrast<contrastname>-map t-sf sessid -df sessdir -hemi rh

To view volumes:

tkmedit-sess -analysis mtstudy -contrast <contrastname> -map t -sf sessid -df sessdir [-space tal]

View group data in surface form using these (note you pick a subject's brain surface to draw upon...:
paint-sess-new -analysis mtstudy -s <groupname> -contrast <contrastname>-map <sig,t,minsig,iminsig> -d . -space <sph,tal,native> -isxavg <fixed, random> -subject <subjectname>
surf-sess-new -analysis mtstudy -s <groupname> -contrast <contrastname> -map <sig,t,minsig,iminsig>-d . -space sph -isxavg <fixed or random> -subject <subjectname> -hemi <lh or rh> -fthresh <num> -fmid <num>

The simplest command for drawing freesurfer surfaces is:
tksurfer

But lets say you have a functional overlay? No problem. Use:
qsurfer




How To Manipulate ROIs and Annotations

To make a set of annotations for the entire brain, use this command.
parcellate_subject <subjname>

To convert the annotations into labels:

mri_annotation2label --subject <subjname> --hemi <hemi> --outdir <dir, starting from subjdir> --table $FREESURFER_HOME/Simple_surface_labels2002.txt --surf <which surface you want>

To copy labels from one brain to another:

($lab=label name, $sub=subject number
mri_label2label --srclabel ~/MTstudy/fMRI/subjects/subj008/label/$lab \
--srcsubject subj008 --trgsubject subj0$sub \
--trglabel ~/MTstudy/fMRI/subjects/subj0$sub/label/$lab \
--regmethod surface --hemi rh --trghemi rh --srchemi rh
 
Also, there is an optional flag --annotation aparc.a2005s to use the new annotation type.

Matti's tool for batch label2label (includes a smoothing step to make sure the entire brain is covered):

mne_morph_labels