This is a bash
script that automatically computes the diffusion along perivascular spaces (ALPS) metric from diffusion-weighted images (dwi
).
The ALPS index has been described by Taoka et al. (Japanese Journal of Radiology, 2017)
As of 2024-02-03, there is a new option (-f) to specify whether the transformation of the tensors to the template space should be performed with FSL flirt/applywarp (default option) or with the FSL function vecreg
, as suggested in PMIDs 36472803 and 37162692.
The default option remains flirt/applywarp, because according to my data, the ALPS index seems to be more robust this way.
If you use this script, please cite our work AND report the link to this repository:
If you have any question, please contact me: barisano [at] stanford [dot] edu.
This script assumes that FSL and MRtrix3 are in your $PATH.
You must define these elements (except when -s 1
, read Optional arguments):
-a
: 4D NIfTI
file of dwi
(the first volume should be a B0 image)-b
: bval
file-c
: bvec
file-m
: BIDS sidecar json
file including the metadata of the input dwi
(not required, but HIGHLY RECOMMENDED)json
file. The DTI fitting will use the eddy corrected data as input.
If you do not provide this file, then NO eddy correction will be performed, and the DTI fitting will be performed on the raw dwi
input or the preprocessed dwi
input (if preprocessing is enabled).json
files generated from dcm2niix
(https://github.com/rordenlab/dcm2niix)A second dwi
dataset with opposite phase encoding (PE) direction to correct for susceptibility-induced distortions.
To correct for susceptibility-induced distortions, the user must define the following 4 additional inputs:
-i
: 4D NIfTI
file of the second dwi
input (the first volume must be a B0 image and the PE direction must be opposite to the PE of the first dwi
dataset in order to be used)-j
: bval
file of the second dwi
input. If not provided together with the second dwi
input, the first volume of the second dwi
input will be assumed to have b-value equal to that of the first dwi
input.-k
: bvec
file of the second dwi
input. Not needed.-n
: BIDS sidecar json
file of the second dwi
input. If not provided together with the second dwi
input, the PE direction of the second dwi
input will be assumed to be opposite to the PE direction of the first dwi
input.If the user does not specify these options, the script will use the default argument for each of them (see below)
-d
: determines which preprocessing steps need to be performed on the dwi
input(s) [default = 1]
-e
: determines which EDDY program to use [default = 1]
alps.sh
without specifying the json
file with the -m
option, but using only the inputs -a
, -b
, and -c
); ${FSLDIR}/bin/eddy_openmp
(should take 1-to-2 hours to run, for most inputs);${FSLDIR}/bin/eddy
(should take ~7 hours to run, for most inputs);${FSLDIR}/bin/eddy_correct
(does not require a metadata file)eddy_cuda
). The binary file specified by the user must be located in ${FSLDIR}/bin/
(do not include "${FSLDIR}/bin/" in the command, just the name of the binary file).-r
: Region of interest (ROI) analysis [default = 1]
csv
file with ALPS index will NOT be generated)JHU-ICBM-FA-1mm.nii.gz
:
L_SCR.nii.gz
LEFT PROJECTION FIBERS (superior corona radiata)R_SCR.nii.gz
RIGHT PROJECTION FIBERS (superior corona radiata)L_SLF.nii.gz
LEFT ASSOCIATION FIBERS (superior longitudinal fasciculus)R_SLF.nii.gz
RIGHT ASSOCIATION FIBERS (superior longitudinal fasciculus)NIfTI
binary masks), which MUST be in the following order:
LEFT
PROJECTION FIBERS (superior corona radiata)RIGHT
PROJECTION FIBERS (superior corona radiata)LEFT
ASSOCIATION FIBERS (superior longitudinal fasciculus)RIGHT
ASSOCIATION FIBERS (superior longitudinal fasciculus)-t
: template to use for the ROI analysis [default = 1]. Only used if -r
is not equal to 0. The DTI maps will be registered to the template specified by the user.
-r
option. Alternatively, if -r
option is 1 (default), then the default ROIs will be linearly registered from JHU-FA template space into native space.JHU-ICBM-FA-1mm.nii.gz
(if no structural MRI data input), MNI_T1_1mm_brain.nii.gz
(if structural data input is a T1) or JHU-ICBM-T2-1mm.nii.gz
(if structural data input is a T2) in FSLDIR will be used as template.NIfTI
file to be used as a template. The ROIs must be in the same space of this template. The DTI maps will be registered to this template.-v
: VOLUMETRIC structural MRI data (a T1w or T2w NIfTI nii.gz
file) to be used for registration of the FA map to the template-h
: weight of the structural MRI data (1=T1-weighted [default], 2=T2-weighted, no PD, no FLAIR)-w
: WARP, type of registration (option needed only when the analysis is done in the template space AND a structural MRI data is NOT provided; option -w is ignored when a structural MRI is used (-v is not empty).-f
: Define FSL's function to transform the TENSOR to the template. flirt
(if -w = 0) or applywarp
(if -w = 1 or 2 or -v is not empty) to transform the TENSOR file to the template space.vecreg
to transform the TENSOR file to the template space. -o
: name of the output folder. If not specified, the default output folder will be called 'alps' and will be located in the same folder of the (first) input.-s
: Option to skip preprocessing and DTI fitting, i.e. performs ONLY ROI analysis [default = 0]; -s 1
, then -o
MUST BE DEFINED and MUST CORRESPOND TO THE FOLDER WHERE dti_FA.nii.gz
AND dti_tensor.nii.gz
ARE LOCATED.
This option is useful for example when the user wants to perform the ROI analysis in NATIVE space with custom ROIs drawn on the output of the DTI processing steps (dti_FA.nii.gz) (see Example 4). In this case, the user can run the alps
script twice: the first time skipping the ROI analysis (-r 0
option), then draw the ROIs on the dti_FA.nii.gz output, and then re-run the alps
script with the options -s 1
, -r myroi1.nii.gz,myroi2.nii.gz,myroi3.nii.gz,myroi4.nii.gz
and -o outputdirectory
(where "outputdirectory" is the directory where dti_FA.nii.gz and the other tensor files are located).id
name in the output csv file with the ALPS index, include the -a
option with the ID you want to use (e.g., -a myID
; if -a
is a .nii
or .nii.gz
file, then the file extension will be excluded from the ID name: -a mynifti.nii.gz
will result in ID mynifti
).csv
file named alps.csv
located in alps.stat
folder in the output directory. This file includes the id
(based on the -a
input), the scanner manufacturer (based on the -m
input), and the metrics required to compute the ALPS index, separately for the left and right side:
$$ALPS=mean(Dxproj,Dxassoc)/mean(Dyproj,Dzassoc)$$
The last column named alps
is the average of the ALPS index on the left and right side.csv
file named fa+md_alps.csv
located in alps.stat
folder in the output directory is generated. This file includes the same id
header as the main output alps.csv
and the fractional anisotrophy (FA) and mean diffusivity (MD) measured in the same exact ROIs used for the ALPS index, on both sides. The last 2 columns are the average measures of the FA and MD on the left and right side of the projection fibers and the left and right side of the association fibers..nii.gz
files are the outputs from the FSL command dtifit
and their names start with dti_
dxx.nii.gz
,dyy.nii.gz
, and dzz.nii.gz
are the tensor files used for the calculation of the ALPS index. If the analysis is done on a template space, the corresponding files transformed to the template space will be also output.-d
option): dwi1.denoised.nii.gz
,dwi1.unring.nii.gz
,dwi1.denoised.unring.nii.gz
, which represents the denoised dwi image, the unringed dwi image, and the denoised+unringed dwi image, respectively. If 2 dwi inputs are provided, the output will be generated for each input.eddy_corrected_data.
my_hifi_b0.nii.gz
(the new B0 image corrected for susceptibility-induced distortions) and my_topup_results_fieldcoef.nii.gz
(what topup thinks the off-resonance field looks like).IMPORTANT: If Eddy current correction outputs are not present in the output folder, it means that the DTI fitting has been performed EITHER on preprocessed (denoised and/or unringed) input(s) OR on raw dwi input(s) if preprocessed data are not present in the output folder. If TOPUP correction outputs are not present in the output folder, it means that NO TOPUP correction has been applied (see the log for understanding the reason why).
dwi
input.alps.sh -a my_4D_dwi.nii.gz -b my_bval_file -c my_bvec_file -m my_bids_file.json
This command will preprocess my_4D_dwi.nii.gz
(denoising and unringing, i.e. default option -d
), perform eddy current correction on the preprocessed data, and compute the ALPS index using the provided default ROIs on FSL template JHU-ICBM-FA-1mm.nii.gz
. The output folder will be called with the default name "alps" and will be located in the same folder as the input.
dwi
inputs with opposite PE direction and B0 image as first volume in both inputs.alps.sh -a dwi_PA.nii.gz -b id_PA.bval -c id_PA.bvec -m id_PA.json -i dwi_AP.nii.gz -j id_AP.bval -k id_AP.bvec -n id_AP.json
This command will preprocess both dwi_PA.nii.gz
and dwi_AP.nii.gz
(denoising and unringing, i.e. default option -d
), perform TOPUP and eddy current correction on the preprocessed data, and compute the ALPS index using the provided default ROIs on FSL template JHU-ICBM-FA-1mm.nii.gz
. The output folder will be called with the default name "alps" and will be located in the same folder as the FIRST input.
dwi
input, in native space (-t 0
), and customized output folder (-o my_output_folder
).alps.sh -a my_4D_dwi.nii.gz -b my_bval_file -c my_bvec_file -m my_bids_file.json -t 0 -r proj_L.nii.gz,proj_R.nii.gz,assoc_L.nii.gz,assoc_R.nii.gz -o my_output_folder
This command will preprocess my_4D_dwi.nii.gz
(denoising and unringing, i.e. default option -d
), perform eddy current correction on the preprocessed data, and compute the ALPS index in native space (-t 0
) using the ROI files defined by the user, which MUST be in native space. The output folder will be "my_output_folder".
dwi
input in native space (-t 0
) after drawing ROIs on the output dti_FA.nii.gz.This is a 3-step process:
alps.sh -a my_4D_dwi.nii.gz -b my_bval_file -c my_bvec_file -m my_bids_file.json -r0 -o my_output_folder
my_4D_dwi.nii.gz
(denoising and unringing, i.e. default option -d
), perform eddy current correction on the preprocessed data, and output only the DTI fitting files in "my_output_folder".alps.sh -a my_4D_dwi.nii.gz -t 0 -s 1 -o my_output_folder -r myroi1_native.nii.gz,myroi2_native.nii.gz,myroi3_native.nii.gz,myroi4_native.nii.gz
This command will skip all preprocessing steps and the DTI fitting step (-s 1
) and will use the DTI fitting output files previously generated in "my_output_folder" to compute the ALPS index in native space (-t 0
) using the user-defined ROIs (-r myroi1_native.nii.gz,myroi2_native.nii.gz,myroi3_native.nii.gz,myroi4_native.nii.gz
).-a my_4D_dwi.nii.gz
is not required in this latest command, but is only needed to add the ID in the final CSV output file with the ALPS index.alps.sh -a my_4D_dwi.nii.gz -b my_bval_file -c my_bvec_file -m my_bids_file.json -d 0 -r 1 -t 1
This command will perform ONLY eddy current correction on the RAW dwi
input data (not denoised nor unringed), and compute the ALPS index using the provided default ROIs on FSL template JHU-ICBM-FA-1mm.nii.gz
. The output folder will be called with the default name "alps" and will be located in the same folder as the input.
-e 3
option).alps.sh -a my_4D_dwi.nii.gz -b my_bval_file -c my_bvec_file
This command will preprocess my_4D_dwi.nii.gz
(denoising and unringing, i.e. default option -d
) and compute the ALPS index using the provided default ROIs on FSL template JHU-ICBM-FA-1mm.nii.gz
. Eddy current correction will be applied only if the user specifies the option -e 3
(i.e., using ${FSLDIR}/bin/eddy_correct
). If -e 3
is not specified, no eddy current correction will be performed, which is not recommended.