Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix-3.1.2' into main
- Loading branch information
Showing
82 changed files
with
11,318 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Unless otherwise specified by LICENSE(.txt) files in individual | ||
directories, or within individual files or functions, all code is distributed under the MIT License: | ||
|
||
Copyright (c) 2020, CATO developers, All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CATO 3.1.2 | ||
Operating system: macos (MACI64) | ||
Compiled on: 17-May-2021 16:43:35 | ||
Compiled using: MATLAB Compiler 6.5 (R2017b) |
Binary file not shown.
159 changes: 159 additions & 0 deletions
159
bin/macos/3.1.2/functional_preprocessing/preprocess_default.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#!/bin/bash | ||
# | ||
# (Example) preprocessing script for functional MRI data: | ||
# 1. Performs slice timing correction using FSL tool slicetimer if variable | ||
# sliceTimingCorrection is TRUE. | ||
# 2. Performs motion correction using FSL tool MCFLIRT. | ||
# 3. Computes a rs-fMRI reference image by averaging all (motion corrected) | ||
# rs-fMRI frames (using FSL). | ||
# 4. Computes the registration matrix between the rs-fMRI reference image and | ||
# the T1 image (using Freesurfer). | ||
# 5. Registers the T1 parcellation to the reference rs-fMRI image (using | ||
# Freesurfer). | ||
|
||
# https://google.github.io/styleguide/shellguide.html | ||
|
||
# set -x | ||
set -e | ||
|
||
####################################### | ||
# Error handling | ||
####################################### | ||
error() { | ||
if [ -n "$1" ]; then | ||
echo -e "error: $1\n" >&2 | ||
else | ||
read line file <<<$(caller) | ||
echo "An error occurred in line $line of file $file:" >&2 | ||
sed "${line}q;d" "$file" >&2 | ||
fi | ||
exit 1 | ||
|
||
} | ||
|
||
####################################### | ||
# Usage | ||
####################################### | ||
usage() | ||
{ | ||
cat << EOF | ||
(Example) preprocessing script for functional MRI data: | ||
1. Performs slice timing correction using FSL tool slicetimer if | ||
variable sliceTimingCorrection is TRUE. | ||
2. Performs motion correction using FSL tool MCFLIRT. | ||
3. Computes a rs-fMRI reference image by averaging all (motion | ||
corrected) rs-fMRI frames (using FSL). | ||
4. Computes the registration matrix between the rs-fMRI reference | ||
image and the T1 image (using Freesurfer). | ||
5. Registers the T1 parcellation to the reference rs-fMRI image | ||
(using Freesurfer). | ||
EOF | ||
} | ||
|
||
####################################### | ||
# Parse input | ||
####################################### | ||
parse_input() | ||
{ | ||
[[ $# -eq 0 ]] && set -- "--help" | ||
while [ -n "$1" ]; do | ||
shopt -s nocasematch | ||
case "$1" in | ||
--fmriFile=*) | ||
fmriFile=${1#*=} | ||
shift | ||
;; | ||
--fmriProcessedFile=*) | ||
fmriProcessedFile=${1#*=} | ||
shift | ||
;; | ||
--slicetimerOptions=*) | ||
slicetimerOptions=${1#*=} | ||
shift | ||
;; | ||
--sliceTimingCorrection=*) | ||
sliceTimingCorrection=${1#*=} | ||
shift | ||
;; | ||
--fmriReferenceFile=*) | ||
fmriReferenceFile=${1#*=} | ||
shift | ||
;; | ||
--freesurferDir=*) | ||
freesurferDir=${1#*=} | ||
shift | ||
;; | ||
--registrationMatrixFile=*) | ||
registrationMatrixFile=${1#*=} | ||
shift | ||
;; | ||
--motionParametersFile=*) | ||
motionParametersFile=${1#*=} | ||
shift | ||
;; | ||
--freesurferDir=*) | ||
freesurferDir=${1#*=} | ||
shift | ||
;; | ||
--segmentationFile=*) | ||
segmentationFile=${1#*=} | ||
shift | ||
;; | ||
-? | -h | -help | --help) | ||
usage && exit | ||
;; | ||
--*=*) | ||
inputParam=${1:2}; | ||
# echo Not used: $inputParam | ||
shift | ||
;; | ||
*) | ||
error "Unkown input argument '$1'" | ||
shift | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
####################################### | ||
# Main function | ||
####################################### | ||
trap error ERR | ||
|
||
parse_input "$@" | ||
|
||
# TODO: convert MNC to NIFTI | ||
cp "$fmriFile" "$fmriProcessedFile" | ||
|
||
# perform slice timing correction | ||
if [ "$sliceTimingCorrection" = true ] ; then | ||
slicetimer -i "$fmriProcessedFile" -o "${fmriProcessedFile/.nii.gz/_stc.nii.gz}" \ | ||
$slicetimerOptions | ||
mv "${fmriProcessedFile/.nii.gz/_stc.nii.gz}" "$fmriProcessedFile" | ||
fi | ||
|
||
# perform motion correction | ||
mcflirt -in "$fmriProcessedFile" -plots | ||
mv "${fmriProcessedFile/.nii.gz/_mcf.nii.gz}" "$fmriProcessedFile" | ||
mv "${fmriProcessedFile/.nii.gz/_mcf.par}" "$motionParametersFile" | ||
|
||
# create reference volume | ||
fslmaths "$fmriProcessedFile" -Tmean "$fmriReferenceFile" | ||
|
||
# compute registration matrix | ||
if [[ "$freesurferDir" =~ \ |\' ]] || [[ "$fmriReferenceFile" =~ \ |\' ]] || [[ "$registrationMatrixFile" =~ \ |\' ]]; then | ||
echo "bbregister cannot handle filenames with spaces. Variable freesurferDir, fmriReferenceFile or registrationMatrixFile contains spaces." >&2 | ||
exit 1 | ||
fi | ||
|
||
bbregister --s "$freesurferDir" --mov "$fmriReferenceFile" --reg "$registrationMatrixFile" \ | ||
--bold --init-fsl | ||
rm "$registrationMatrixFile".{mincost,param,sum,log} | ||
|
||
# register freesurfer segmentation to reference volume | ||
mri_label2vol --seg "${freesurferDir}/mri/aseg.mgz" --temp "$fmriReferenceFile" \ | ||
--reg "$registrationMatrixFile" --o "$segmentationFile" | ||
|
||
# TODO add registration of MTR weighted image | ||
|
||
exit 0 |
Binary file not shown.
197 changes: 197 additions & 0 deletions
197
bin/macos/3.1.2/structural_preprocessing/preprocess_eddy.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
#!/bin/bash | ||
# | ||
# (Example) preprocessing script that: | ||
# 1. Runs FSL eddy to correct for eddy current distortions and motion artifacts in the DWI data. | ||
# 2. Updates the b-vectors to adjust for the DWI corrections. | ||
# 3. Computes a DWI reference image based on the corrected diffusion-unweighted (b0) volumes. | ||
# 4. Computes the registration matrix between DWI reference image and the T1 image using bbregister. | ||
# 5. Registers the Freesurfer segmentation to the DWI reference image. | ||
|
||
# https://google.github.io/styleguide/shellguide.html | ||
|
||
# set -x | ||
set -e | ||
|
||
####################################### | ||
# Error handling | ||
####################################### | ||
error() { | ||
if [ -n "$1" ]; then | ||
echo -e "error: $1\n" >&2 | ||
else | ||
read line file <<<$(caller) | ||
echo "An error occurred in line $line of file $file:" >&2 | ||
sed "${line}q;d" "$file" >&2 | ||
fi | ||
exit 1 | ||
|
||
} | ||
|
||
####################################### | ||
# Usage | ||
####################################### | ||
usage() | ||
{ | ||
echo "(Example) preprocessing script that:" | ||
echo "1. Runs FSL eddy to correct for eddy current distortions and motion artifacts in the DWI data." | ||
echo "2. Updates the b-vectors to adjust for the DWI corrections." | ||
echo "3. Computes a DWI reference image based on the corrected diffusion-unweighted (b0) volumes." | ||
echo "4. Computes the registration matrix between DWI reference image and the T1 image using bbregister." | ||
echo "5. Registers the Freesurfer segmentation to the DWI reference image." | ||
} | ||
|
||
####################################### | ||
# Parse input | ||
####################################### | ||
parse_input() | ||
{ | ||
[[ $# -eq 0 ]] && set -- "--help" | ||
while [ -n "$1" ]; do | ||
shopt -s nocasematch | ||
case "$1" in | ||
--b0Scans=*) | ||
b0Scans=${1#*=} | ||
shift | ||
;; | ||
--dwiProcessedFile=*) | ||
dwiProcessedFile=${1#*=} | ||
shift | ||
;; | ||
--dwiFile=*) | ||
dwiFile=${1#*=} | ||
shift | ||
;; | ||
--dwiReferenceFile=*) | ||
dwiReferenceFile=${1#*=} | ||
shift | ||
;; | ||
--freesurferDir=*) | ||
freesurferDir=${1#*=} | ||
shift | ||
;; | ||
--registrationMatrixFile=*) | ||
registrationMatrixFile=${1#*=} | ||
shift | ||
;; | ||
--segmentationFile=*) | ||
segmentationFile=${1#*=} | ||
shift | ||
;; | ||
--processedBvecsFile=*) | ||
processedBvecsFile=${1#*=} | ||
shift | ||
;; | ||
--processedBvalsFile=*) | ||
processedBvalsFile=${1#*=} | ||
shift | ||
;; | ||
--acqpFile=*) | ||
acqpFile=${1#*=} | ||
shift | ||
;; | ||
--indexFile=*) | ||
indexFile=${1#*=} | ||
shift | ||
;; | ||
--eddyVersion=*) | ||
eddyVersion=${1#*=} | ||
shift | ||
;; | ||
-? | -h | -help | --help) | ||
usage && exit | ||
;; | ||
--*=*) | ||
inputParam=${1:2}; | ||
# echo Not used: $inputParam | ||
shift | ||
;; | ||
*) | ||
error "Unkown input argument '$1'" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
} | ||
|
||
computeReferenceB0(){ | ||
|
||
# use b0 scan(s) to create reference volume | ||
for i in ${b0Scans[@]}; do | ||
fslroi "$dwiProcessedFile" "${dwiReferenceFile/.nii.gz/_indv_$i.nii.gz}" $((i- 1)) 1 | ||
done | ||
|
||
fslmerge -t "$dwiReferenceFile" "${dwiReferenceFile/.nii.gz/_indv_}"*.nii.gz | ||
fslmaths "$dwiReferenceFile" -Tmean "$dwiReferenceFile" | ||
rm "${dwiReferenceFile/.nii.gz/_indv_}"*.nii.gz | ||
|
||
|
||
} | ||
|
||
####################################### | ||
# Run Eddy | ||
####################################### | ||
runEddy() { | ||
|
||
# Create index file for eddy | ||
nScans=$(mri_info --nframes "$dwiProcessedFile" | tail -n1) | ||
for i in $(eval echo {1..$nScans}); do | ||
echo -n "1 "; | ||
done > "$indexFile" | ||
|
||
$eddyVersion -v --imain="$dwiProcessedFile" \ | ||
--mask="$brainMaskFile" \ | ||
--acqp="$acqpFile" \ | ||
--index="$indexFile" \ | ||
--bvecs="$processedBvecsFile" --bvals="$processedBvalsFile" \ | ||
--out="$dwiProcessedFile" | ||
|
||
# replace bvecs by their rotated counterparts | ||
[ ! -f "${dwiProcessedFile}.eddy_rotated_bvecs" ] && | ||
error "could not find rotated bvecs (use FSL 5.0.9 or higher)" | ||
mv "${dwiProcessedFile}.eddy_rotated_bvecs" "$processedBvecsFile" | ||
|
||
# Clean eddy output | ||
rm "$brainMaskFile" | ||
|
||
} | ||
|
||
####################################### | ||
# Main function. | ||
####################################### | ||
trap error ERR | ||
|
||
parse_input "$@" | ||
|
||
# TODO: check FSL version | ||
|
||
# TODO: convert MNC to NIFTI | ||
cp "$dwiFile" "$dwiProcessedFile" | ||
|
||
# Load b0-scans list and parse them into an array | ||
b0Scans=(${b0Scans//,/ }) | ||
|
||
# Create a mask of the brain based on the b0-reference | ||
computeReferenceB0 | ||
|
||
bet "$dwiReferenceFile" "$dwiProcessedFile" -m -n # creates ${dwiProcessedFile/.nii.gz/_mask.nii.gz} | ||
brainMaskFile=${dwiProcessedFile/.nii.gz/_mask.nii.gz} | ||
rm "$dwiReferenceFile" # we will create a new reference b0 after eddy correction | ||
|
||
runEddy | ||
|
||
# Create new eddy current and movement corrected reference b0-scan | ||
computeReferenceB0 | ||
|
||
# Compute registration matrix from FS to subject space | ||
bbregister --s "$freesurferDir" --mov "$dwiReferenceFile" --reg "$registrationMatrixFile" \ | ||
--dti --init-fsl | ||
rm "$registrationMatrixFile".{mincost,param,sum,log} | ||
|
||
# Register freesurfer segmentation to reference volume | ||
mri_label2vol --seg "${freesurferDir}/mri/aseg.mgz" --temp "$dwiReferenceFile" \ | ||
--reg "$registrationMatrixFile" --o "$segmentationFile" | ||
|
||
# TODO: add registration of MTR weighted image | ||
|
||
exit 0 |
Oops, something went wrong.