Monday, 2 December 2013

VBM two-sample T-test

Make  a directory to put all of the analysis information into (e.g. mkdir HC_PAT)


This example is for a GM comparison between healthy controls and patients.

- Select 'Basic Models' and choose the directory that you wish the save the analysis into (e.g. HC_PAT)
- Under 'Design' select 'Two sample t-test'
- Then select group 1 and group 2 scans (smwc1* files)
- Click 'covariates' and add 'new: covariate' - call this covariate 'Total Grey Matter Volume' and for the vector click 'edit value' and type in 'spm_load()' which will allow you to select a file to upload. Select the Grey matter volume text file that was created earlier.
- Scroll down to 'Threshold masking', select 'Absolute' (you can choose according to which results you would like to see). Click on 'Threshold' and 'edit value' change the threshold from 100 to 0.05.
- Save this batch so that you can run it again with different groups if you need.
- Run the batch.
- When this is finished click on the 'Estimate' button and select the 'SPM.mat' file within the directory for the analysis (HC_PAT), click done.
- When estimation is complete click the 'Results' button, again select the 'SPM.mat' file and then define new contrast. The first contrast would be named 'HC > PAT' with the vector '1 -1 0', and the second would be PAT > HC' with the vector '-1 1 0'. Select done.
- A series of requests will appear on the left of the screen click 'none' for apply masking, none for p-value, say yes to p<0.001 (this can be changed later) and set the extent threshold to 0.
- To view a stats table, select 'whole brain'.

- If you wanted to add a covariate for age for example, you can repeat this process including another covariate and create a text file with ages (in the exact same order). To account for this in the analysis but without looking for correlations include an extra 0 in the contrast.

Voxel-based morphometry preprocessing for group comparison

Preparations

- Data needs to be in nifti (.nii) format before running anything in SPM.
- Save the script (.m file) that will save total grey matter volumes to your system

Open spm

% spm-8-4290

- it is useful to save each batch as you make it so that you can repeat on a different data set in the same way if necessary.


Step 1: Spatial normalisation

- Select 'Estimate and Write' on the spm buttons panel.
- Upload each subjects file into the 'Source Image' and 'Images to Write' options
- Select T1.nii as 'Template Image'
- Run
- These files save with a 'w' prefix

Step 2: Segmentation

- Under 'Output files' are grey matter, white matter and cerebrospinal fluid - for each select 'Native + Modulated and Unmodulated'
- Under clean up any partitions select 'Thorough Clean'
- This will save files with different prefixes (c1, c2, c3 - grey, white, CSF) and w - normalised, m-modulated -- use the 'wm' prefix for step 3.
- Before moving on to the smoothing step, you will need to write the GM volumes (for grey matter analysis) of each subject into a text file. To do this click the 'utils' tab and select all mwc1* files and then select 'save to txt file'. The files need to be selected in the same order as the design matrix to ensure the volumes correspond to the correct subject. (you may then want to edit the text file and delete everything except the volume measures).

Step 3: Smoothing

- Click the smoothing button, and select files with mwc1 (modulated, normalised grey matter) prefix.
- Keep default settings (i.e. 8mm FWHM)
- Press play button

Finally, you may also like to create a txt file with the vector for groups, e.g. 1 for patients, 0 for controls - ensure the same order as GM volume file and subject selection.

Monday, 4 November 2013

Three group surface-based analysis

1. Create a directory for the group analysis

e.g.

mkdir FSGD

2. Create a simple text file (.fsgd) containing subject information and with the following headers

e.g.
      
        GroupDescriptorFile 1
        Title    MyGroups
        Class   Control
        Class   Patient
        Class   Recovered
        Input   Subject1      Control
        Input   Subject2      Patient
        Input   Subject3      Recovered

3. Create simple text files (.mtx) for each contrast and a group contrast.

e.g.

       Control-Patient.mtx
       1 -1 0

       Control-Recovered.mtx
       1 0 -1

       Patient-Recovered.mtx
       0 1 -1

       group.effect.mtx
       1 -1 0
       1 0 -1

4. Assemble the data (resample each subjects data into a common space, concatenate subjects into a single file (y.mgh), spatial smoothing).

For data that has already been cached (smoothed) use the following command:

   mris_preproc --fsgd mydata.fsgd \
   --cache-in thickness.fwhm10.fsaverage \
   --target fsaverage --hemi lh \
   --out lh.mydata.thickness.10.mgh

For data that has not previously had the -qcache command run on it:

    mris_preproc --fsgd mydata.fsgd \
    --target fsaverage -hemi lh \
    --meas thickness \
    --out lh.mydata.thickness.00.mgh


   mri_surf2surf --hemi lh \
   --s fsaverage \
   --sval lh.mydata.thickness.00.mgh \
   --fwhm 10 \
   --cortex \
   --tval lh.mydata.thickness.10B.mgh

5. GLM analysis: the following command will perform whole-brain cortical thickness analysis.

   mri_glmfit \
   --y lh.mydata.thickness.10.mgh \
   --fsgd mydata.fsgd dods\
   --C  Control-Patient.mtx \
   --C  Control-Recovered.mtx \
   --C  Patient-Recovered.mtx \
   --C  group.effect.mtx \
   --surf fsaverage lh \
   --cortex \
   --glmdir lh.mydata.glmdir

Notes
  • Thickness is the chosen measure in this example, but this can be substituted for any other measures e.g. area or volume.
  •  You can choose between DODS or DOSS depending on your experiment, see http://freesurfer.net/fswiki/DodsDoss)
  • All of the contrasts have been included in this example, as freesurfer uses these contrasts to measure the group effect.

6. View the uncorrected significance map with tksurfer. For this you will need to be in the FSGD directory but not in any of the contrast directories.

e.g.

      tksurfer fsaverage lh inflated \
      -annot aparc.annot -fthresh 2 \
      -overlay lh.mydata.gmldir/Control-Patient/sig.mgh


7. Clusterwise correction for multiple comparisons (Monte Carlo Null-Z  Simulation)

e.g.

       mri_glmfit-sim \
       --glmdir lh.mydata.glmdir \
       --sim mc-z 5 4 mc-z.negative \
       --sim-sign neg --cwpvalthresh 0.4 \
       --overwrite

Notes
  • 5 in the above example is the number of iterations. In this case 5 is used as an example to practice with, it is recommended to run this first before going to a higher number of iterations (up to 50,000). The more iterations run the more accurate the results will be.
  • 4 in the above example is the vertex-wise threshold which corresponds to the p-value (see below).
  • 0.4 in the above example is a request that all clusters that have a cluster-wise p-value threshold of <0.4 are kept. This can be altered, or set to 0.999 to see all of the clusters regardless of p-value.
  • By specifying negative/neg, the results will only display negative changes e.g. cortical thinning. This can be set to positive, to view positive results or absolute to view both.
Voxel-wise thresholds
 
1.3 = p < 0.05
2 = p < 0.01
2.3 = p < 0.005
3 = p < 0.001
3.3 = p < 0.0005
4 = p < 0.0001

8. View the corrected results in the terminal. You will need to be in the directory of the contrast that you wish to view results for.

e.g.

      cd Control-Patient
      less mc-z.negative.sig.cluster.summary

9. Load corrected results in tksurfer

e.g.

     tksurfer fsaverage lh inlfated \
     -annot lh.mydata.glmdir/Control-Patients/mc-z.negative.sig.ocn.annot \
     -fthresh 2 -curv -gray










QDEC Group Analysis

This post will take you through all of the steps needed to be able to run surface-based group analysis using the Query, Design, Execute, Contrast (QDEC) interface.

1. Create a qdec directory within the directory where all of your subject files are stored.

e.g.

% mkdir qdec

4. For display purposes you will need to have an average subject in your subjects_dir. There is an fsaverage already stored in freesurfer which has been made in MNI space.

e.g. cd $SUBJECTS_DIR
     if (! -e fsaverage) ln -s $FREESURFER_HOME/subjects/fsaverage

3. Create a text file containing all of the subject/demographic information that is required to carry out the analysis (e.g. subject ID, Group membership, age, gender etc). It is important to keep in mind that QDEC can normally handle two additional covariates, so try not to include unnecessary information in this text file.
It is likely that you will need to de-mean the ages, depending on whether you use DODS or DOSS.
You should name this file ending in .table.dat :

e.g.

% nedit mydata.table.dat

SubjectID  Group  Age  Gender
Subject1    HC       50     Female 
Subject2    Patient 48     Male
etc..

Remember:
  • Ensure that all subjects are named with the exact same ID as the original image folders.
  • There should be no empty lines between subjects.
  • keep the information stored in this file to a minimum/only include necessary information that will be used in the analysis.
  • If you have more than one table.dat file, containing different categorical information (e.g. controls and patients/ controls and recovered patients) be sure to change the categories in the Group.levels file when running qdec.

4. Any categorical factors (i.e. Group, Gender) will need a separate text file containing the different levels:

e.g.

% nedit Group.levels

HC
Patient

Continuous factors do not need a separate file to define them.

5. If the FreeSurfer environment has been set up properly (as described in previous blog post) you should be able to type in 'qdec' to the terminal and the qdec interface will start to load.

6. When the qdec interface opens up, you can select the table.data file that you have created.

e.g.

File- Load data table

You will also need to go into the 'Design' tab and give the design a name, this will create a directory within your qdec directory, containing all of the output from the analysis you are about to run.

See http://freesurfer.net/fswiki/FsTutorial/QdecGroupAnalysis_freeview for more qdec information.



Thursday, 31 October 2013

Data processing steps for surface-based analysis using FreeSurfer

Notes
- Any words that are in red font need to substituted for your own data set i.e. directory or file names.

1. Make a directory where you will navigate to each time you run any analysis, this could be a 'FreeSurfer' directory or the directory where your data is stored.

e.g.

 % mkdir /home/mydata_dir

2. The following steps will set up FreeSurfer and instruct it to navigate all information to your subjects directory. You will need to set up your subjects directory into the directory that you have just created to ensure that information is all kept together.

e.g.

% setenv FREESURFER_HOME /software/system/freesurfer/freesurfer-5.1.0
% source $FREESURFER_HOME/SetUpFreeSurfer.csh
% setenv SUBJECTS_DIR /home/mydata_dir

These steps will need to be followed each time a new terminal is opened and you wish to run FreeSurfer; if you are running FreeSurfer often it may be beneficial to set up an alias to run these commands.

3. The next step performs automated cortical surface reconstruction, which prepares the data for surface-based analysis. In addition, to process data with the QDEC module of FreeSurfer each subjects needs to have pre-computed smoothed data for the target surface, 'fsaverage' is the default for this. Reconstruction can take many hours, it may be best to run this command overnight. The following command can be used to perform reconstruction and smoothing for all of the data in a set:

e.g.

% foreach file (mydata*)
     recon-all -s $file -qcache
end

To perform reconstruction on one subject at a time:

e.g.

% recon-all -autorecon-all -subjid subject_name


For information on the reconstruction workflow see http://freesurfer.net/fswiki/BasicReconstruction

For more information on how FreeSurfer performs cortical reconstruction see http://freesurfer.net/fswiki/FreeSurferAnalysisPipelineOverview