Skip to content

Freewater Analysis

Jared Tanner edited this page Nov 16, 2023 · 8 revisions

All code used was coded by Ofer Pasternak. If you would like the software to calculate freewater from diffusion imaging, please contact him at [email protected].

Steps to analyze free-water.

  1. Convert dicom files to nifti using your preferred method or by following this guide.
  2. Copy all nifti, bval, and bvec files to a single location (I prefer them all in one directory for one study, although they could also be separated by group, if needed).
  3. Eddy correct and rotate the b vectors (it's best to use Topup and EDDY instead of eddy_correct if you have the correct data. See this guide for an example). This loop also does a linear transformation to a T2 MNI template, which is not necessary. for subj in $(cat subnames.txt) ; do eddy_correct ${subj}_*64dir_dwi.nii.gz ${subj}_dwi_ec.nii.gz 0 ; fslroi ${subj}_dwi_ec.nii.gz ${subj}_b0.nii.gz 0 1 ; bet ${subj}_b0.nii.gz ${subj}_brain -f .3 -g 0 -n -R -m ; ./rotate_bvecs ${subj}_*64dir_dwi.bvec ${subj}_dwi_ec-rot.bvec ${subj}_dwi_ec.ecclog ; mv ${subj}_*.bval ${subj}_dwi_ec.bval ; flirt -in ${subj}_brain.nii.gz -ref mni152_t2w_2mm_brain.nii.gz -out ${subj}_b02MNI -omat ${subj}_b02MNI.mat -bins 256 -cost corratio -searchrx -180 180 -searchry -180 180 -searchrz -180 180 -dof 12 -interp trilinear ; done
  4. Copy all the files to a directory for freewater processing for subj in $(cat subnames.txt) ; do mkdir ../${subj} ; cp ${subj}_dwi_ec.nii.gz ../${subj}/${subj}_ecc.nii.gz ; cp ${subj}_dwi_ec.bval ../${subj}/${subj}.bval ; cp ${subj}_dwi_ec-rot.bvec ../${subj}/${subj}.bvec ; cp ${subj}_brain_mask.nii.gz ../${subj}/${subj}_brain_mask.nii.gz ; done
  5. If you have multi-shell data and ran dwifslpreproc (mrtrix), you can then extract b values <=1000 for freewater estimation using an FSL tool: select_dwi_vols sub-001_ses-04_dwi_den_preproc.nii.gz bvals sub-001_ses-04_dwi_den_preproc_subset 0 -b 101 -b 400 -b 700 -b 1000 -obv bvecs (example)
  6. Run the MatLab script called freewater_nii_ed.m and select the appropriate nifti file: sub-001_ecc.nii.gz and give it an output name like sub-001_FW when prompted.
  7. To calculate DTI metrics controlled for freewater, use niimath (or fslmaths but newer versions of fslmaths give segmentation faults on this step): niimath. The command is run like this: niimath sub-001_FW_TensorCorrected.nii -tensor_decomp sub-001_FWcorrected