OSCR

DTI-ALPS Primarily Reflects White Matter Diffusion Dispersion and Microstructural Heterogeneity in Neurodegeneration: Insights From Multi-Modal MRI.

Code ↔ Paper

3 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 3 matches
  1. [1] § Materials and Methods › T1 and FLAIR Images Preprocessing and T1/FLAIR Ratio Calculation ↔ KUL_T1T2FLAIRMTR_ratio.sh, lines 220 to 276 · score 0.75 · N4 bias field, antsRegistration, rigidly, intensity · Report a mismatch
  2. [2] § Materials and Methods › T1 and FLAIR Images Preprocessing and T1/FLAIR Ratio Calculation ↔ KUL_lesion_fs_recall.sh, lines 684 to 730 · score 0.60 · N4 bias field, ANTs, FLAIR, Preprocessing · Report a mismatch
  3. [3] § Materials and Methods › T1 and FLAIR Images Preprocessing and T1/FLAIR Ratio Calculation ↔ KUL_T1T2FLAIRMTR_ratio.sh, lines 872 to 928 · score 0.56 · brain masks, calibration, nonlin3, nonlinearly, histogram, template · Report a mismatch

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Shell · 998 lines · 44 KB · MPL-2.0 · 2 matches

  1. #!/bin/bash
  2. # Sarah Cappelle & Stefan Sunaert
  3. # 22/12/2020 - v1.0
  4. # 18/02/2021 - v1.1 (adding calibration)
  5. # 24/10/2022 - v1.2 (accepted for publication)
  6. # 17/08/2023 - v1.3 bug fix (using local path)
  7. #
  8. # This script computes a T1/T2, T1/FLAIR and MTC (magnetisation transfer contrast) ratio
  9. #
  10. # This scripts follows the rationales of
  11. # - D. Pareto et al. AJNR 2020
  12. # - Ganzetti et al. Frontiers in human neuroscience 2014
  13. #
  14. # Starting from 3D-T1w, 3D-FLAIR and 2D-T2w scans we compute:
  15. # bias correct the images using N4biascorrect from ANTs
  16. # ANTs rigid coregister and reslice all images to the 3D-T1w (in isotropic 1 mm space)
  17. # create masked brain images using HD-BET
  18. # calibrate the images according to Ganzetti
  19. # compute a T1FLAIR_ratio, a T1T2_ratio and a MTR
  20. version="1.3"
  21. kul_main_dir=$(dirname "$0")
  22. script=$(basename "$0")
  23. source $kul_main_dir/KUL_main_functions.sh
  24. # $cwd & $log_dir is made in main_functions
  25. # FUNCTIONS --------------
  26. # function Usage
  27. function Usage {
  28. cat <<USAGE
  29. `basename $0` computes a T1/T2, T1/FLAIR and MTC (magnetisation transfer contrast) ratio, using BIDS organised data.
  30. Usage:
  31. `basename $0` <OPT_ARGS>
  32. Example:
  33. `basename $0` -p JohnDoe -f 2 -m -v
  34. Required arguments:
  35. -p: participant name
  36. Optional arguments:
  37. -s: session of the participant
  38. -a: automatic mode (just work on all images in the BIDS folder)
  39. -n: number of cpu to use (default 15)
  40. -m: also run MS lesion segmentation using Freesurfer7 SamSeg
  41. -f: also run fastsurfer (1=full, 2=segmentation with CC & stats, 3=fast segmentation without CC)
  42. -d: only perform part of the workflow
  43. levels:
  44. 1 = bias-correction
  45. 2 = rigid registration of the T2w and/or FLAIR to the T1w
  46. 3 = spatially normalise (warp) the T1w to the MNI atlas
  47. 4 = run fastsufer (req option -f)
  48. 5 = run samseg (req option -m)
  49. 6 = hd-bet the images
  50. 7 = calibration
  51. 8 = compute the T1w/T2w and/or T1w/FLAIR ratio
  52. 9 = compute the MTR
  53. 10 = warp the results to MNI
  54. -c: do not run, but output files for the VSC HPC
  55. -v: show output from commands
  56. Documentation:
  57. This script computes a T1/T2, T1/FLAIR and MTC (magnetisation transfer contrast) ratio, using BIDS organised data.
  58. It follows the rationale of Ganzetti et al. Frontiers in human neuroscience 2014 and D. Pareto et al. AJNR 2020.
  59. The full methodology is described in "T1w/FLAIR ratio standardization as a myelin marker in MS patients,
  60. by S Cappelle, D Pareto, S Sunaert, I Smets, A Laenen, B Dubois, Ph Demaerel" - https://pubmed.ncbi.nlm.nih.gov/36451354/
  61. A T1w is mandatory.
  62. A T1w/T2w ratio is computed if a T2w is present.
  63. A T1w/FLAIR ratio is computed if a FLAIR is present.
  64. A MTR is computed if an MTI pair is available.
  65. It also segments (MS or T1w-hypo/FLAIR-hyper) lesions using Freesurfer Samseg if T1w and FLAIR are present and option -m is given.
  66. It also calculates a FastSurfer parcellation if option -f is used.
  67. Dependecies:
  68. general:
  69. - input images must be supplied in Brain Imaging Data Structure (https://bids.neuroimaging.io/) format in the folder "BIDS"
  70. required:
  71. - MRTrix3 - https://www.mrtrix.org/
  72. - ANTs - http://stnava.github.io/ANTs/
  73. - HD-BET - https://github.com/MIC-DKFZ/HD-BET
  74. optional:
  75. - FastSurfer - https://deep-mi.org/research/fastsurfer/
  76. - Freesurfer Samseg - https://surfer.nmr.mgh.harvard.edu/fswiki/Samseg
  77. References:
  78. @ Sarah Cappelle & Stefan Sunaert
  79. USAGE
  80. exit 1
  81. }
  82. # CHECK COMMAND LINE OPTIONS -------------
  83. #
  84. # Set defaults
  85. auto=0 # default if option -s is not given
  86. silent=1 # default if option -v is not given
  87. outputdir="$cwd/T1T2FLAIRMTR_ratio"
  88. ms=0
  89. ncpu=15
  90. fastsurf=0
  91. hpc=0
  92. deel=10
  93. # Set required options
  94. #p_flag=0
  95. if [ "$#" -lt 1 ]; then
  96. Usage >&2
  97. exit 1
  98. else
  99. while getopts "p:s:f:n:d:acmv" OPT; do
  100. case $OPT in
  101. a) #automatic mode
  102. auto=1
  103. ;;
  104. p) #participant
  105. participant=$OPTARG
  106. ;;
  107. s) #session
  108. session=$OPTARG
  109. ;;
  110. n) #ncpu
  111. ncpu=$OPTARG
  112. ;;
  113. f) #fastsurfer
  114. fastsurf=$OPTARG
  115. ;;
  116. d) #new workflow
  117. deel=$OPTARG
  118. ;;
  119. m) #MS lesion segmentation
  120. ms=1
  121. ;;
  122. c) #VSC HPC
  123. hpc=1
  124. ;;
  125. v) #verbose
  126. silent=0
  127. ;;
  128. \?)
  129. echo "Invalid option: -$OPTARG" >&2
  130. echo
  131. Usage >&2
  132. exit 1
  133. ;;
  134. :)
  135. echo "Option -$OPTARG requires an argument." >&2
  136. echo
  137. Usage >&2
  138. exit 1
  139. ;;
  140. esac
  141. done
  142. fi
  143. # check for required options
  144. #if [ $p_flag -eq 0 ] ; then
  145. # echo
  146. # echo "Option -p is required: give the BIDS name of the participant." >&2
  147. # echo
  148. # exit 2
  149. #fi
  150. export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=${ncpu}
  151. ants_verbose=1
  152. fs_silent=""
  153. # verbose or not?
  154. if [ $silent -eq 1 ] ; then
  155. export MRTRIX_QUIET=1
  156. ants_verbose=0
  157. fs_silent=" > /dev/null 2>&1"
  158. fi
  159. d=$(date "+%Y-%m-%d_%H-%M-%S")
  160. log=log/log_${d}.txt
  161. # --- FUNCTIONS ---
  162. function KUL_antsApply_Transform {
  163. antsApplyTransforms -d 3 \
  164. --verbose $ants_verbose \
  165. -i $input \
  166. -o $output \
  167. -r $reference \
  168. -t $transform \
  169. -n Linear
  170. }
  171. function KUL_antsApply_Transform_MNI {
  172. antsApplyTransforms -d 3 \
  173. --verbose $ants_verbose \
  174. -i $input \
  175. -o $output \
  176. -r $reference \
  177. -t $transform1 -t $transform2 \
  178. -n $interpolation_type
  179. }
  180. function KUL_iso_biascorrect {
  181. local input=$1
  182. local output
  183. output=${input##*/}
  184. output=${output%%.*}
  185. bias_output=$outdir/tmp/${output}_iso_biascorrected.nii.gz
  186. if [ ! -f $bias_output ]; then
  187. echo " doing biascorrection on the ${td}"
  188. mrgrid $input regrid -voxel 1 $outdir/tmp/${output}_iso.nii.gz -force
  189. local bias_input=$outdir/tmp/${output}_iso.nii.gz
  190. N4BiasFieldCorrection --verbose $ants_verbose \
  191. -d 3 \
  192. -i $bias_input \
  193. -o $bias_output
  194. else
  195. echo " biascorrection of the ${td} already done"
  196. fi
  197. }
  198. function KUL_MTI_reorient_crop_hdbet_iso {
  199. iso_output=$outdir/tmp/${output}_iso.nii.gz
  200. mrgrid $input regrid -voxel 1 $iso_output -force
  201. }
  202. # Rigidly register the input to the T1w
  203. function KUL_rigid_register {
  204. antsRegistration --verbose $ants_verbose --dimensionality 3 \
  205. --output [$outdir/tmp/${ants_type},$outdir/tmp/${newname}] \
  206. --interpolation BSpline \
  207. --use-histogram-matching 0 --winsorize-image-intensities [0.005,0.995] \
  208. --initial-moving-transform [$outdir/tmp/$ants_template,$outdir/tmp/$ants_source,1] \
  209. --transform Rigid[0.1] \
  210. --metric MI[$outdir/tmp/$ants_template,$outdir/tmp/$ants_source,1,32,Regular,0.25] \
  211. --convergence [1000x500x250x100,1e-6,10] \
  212. --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox
  213. }
  214. # Register and compute the ratio
  215. function KUL_reg2t1 {
  216. local base0=${test_T1w##*/}
  217. local base=${base0%_T1w*}
  218. ants_type="${base}_rigid_${td}_reg2t1_"
  219. ants_template="${base}_T1w_iso_biascorrected.nii.gz"
  220. ants_source="${base}_${td}_iso_biascorrected.nii.gz"
  221. newname="${base}_${td}_iso_biascorrected_reg2T1w.nii.gz"
  222. #finalname="${base}_${td}_reg2T1w.nii.gz"
  223. if [ ! -f $outdir/tmp/${newname} ]; then
  224. echo " rigid registration of the ${td} to the T1w"
  225. KUL_rigid_register
  226. else
  227. echo " skipping rigid registration of the ${td} to the T1w - already done"
  228. fi
  229. }
  230. function KUL_computeratio {
  231. if [ ! -f $outdir/${base}_ratio-T1${td}_calib-nonlin3.nii.gz ];then
  232. echo " computing the ratio T1w/${td}"
  233. #if [[ ${td} == "T2w" ]];then
  234. # factor=42
  235. #else
  236. # factor=1.705
  237. #fi
  238. #mrcalc \
  239. # $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz $factor -div \
  240. # $outdir/tmp/${base}_${td}_iso_biascorrected_reg2T1w.nii.gz -divide \
  241. # $outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz -multiply \
  242. # $outdir/${base}_ratio-T1${td}_calib-none.nii.gz -nthreads $ncpu -force
  243. mrcalc \
  244. $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  245. $outdir/tmp/${base}_${td}_iso_biascorrected_reg2T1w.nii.gz -divide \
  246. $outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz -multiply \
  247. $outdir/${base}_ratio-T1${td}_calib-none.nii.gz -nthreads $ncpu -force
  248. mrcalc \
  249. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-lin.nii.gz \
  250. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-lin_reg2T1w.nii.gz -divide \
  251. $outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz -multiply \
  252. $outdir/${base}_ratio-T1${td}_calib-lin.nii.gz -nthreads $ncpu -force
  253. mrcalc \
  254. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin.nii.gz \
  255. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin_reg2T1w.nii.gz -divide \
  256. $outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz -multiply \
  257. $outdir/${base}_ratio-T1${td}_calib-nonlin.nii.gz -nthreads $ncpu -force
  258. if [ $t2 -eq 1 ]; then #need the T2w to calculate the ventricles
  259. mrcalc \
  260. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin2.nii.gz \
  261. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w.nii.gz -divide \
  262. $outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz -multiply \
  263. $outdir/${base}_ratio-T1${td}_calib-nonlin2.nii.gz -nthreads $ncpu -force
  264. fi
  265. mrcalc \
  266. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin3.nii.gz \
  267. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin3_reg2T1w.nii.gz -divide \
  268. $outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz -multiply \
  269. $outdir/${base}_ratio-T1${td}_calib-nonlin3.nii.gz -nthreads $ncpu -force
  270. else
  271. echo " the ratio T1w/${td} is already computed"
  272. fi
  273. }
  274. function KUL_apply_warp2mni {
  275. echo " warping ${td} results to MNI"
  276. reference=$fix_im
  277. transform1="$outdir/warp2mni/${base}_T1w2MNI_1Warp.nii.gz"
  278. transform2="[$outdir/warp2mni/${base}_T1w2MNI_0GenericAffine.mat,0]"
  279. interpolation_type="LanczosWindowedSinc"
  280. if [[ ${td} == "T1w" ]];then
  281. local ext=""
  282. elif [[ ! ${td} == "MTI" ]];then
  283. local ext="_reg2T1w"
  284. input="$outdir/${base}_ratio-T1${td}_calib-none.nii.gz"
  285. output="$outdir/${base}_space-MNI_ratio-T1${td}_calib-none.nii.gz"
  286. KUL_antsApply_Transform_MNI
  287. input="$outdir/${base}_ratio-T1${td}_calib-lin.nii.gz"
  288. output="$outdir/${base}_space-MNI_ratio-T1${td}_calib-lin.nii.gz"
  289. KUL_antsApply_Transform_MNI
  290. input="$outdir/${base}_ratio-T1${td}_calib-nonlin.nii.gz"
  291. output="$outdir/${base}_space-MNI_ratio-T1${td}_calib-nonlin.nii.gz"
  292. KUL_antsApply_Transform_MNI
  293. if [ $t2 -eq 1 ]; then
  294. input="$outdir/${base}_ratio-T1${td}_calib-nonlin2.nii.gz"
  295. output="$outdir/${base}_space-MNI_ratio-T1${td}_calib-nonlin2.nii.gz"
  296. KUL_antsApply_Transform_MNI
  297. fi
  298. input="$outdir/${base}_ratio-T1${td}_calib-nonlin3.nii.gz"
  299. output="$outdir/${base}_space-MNI_ratio-T1${td}_calib-nonlin3.nii.gz"
  300. KUL_antsApply_Transform_MNI
  301. elif [[ ${td} == "MTI" ]];then
  302. local ext="_reg2T1w"
  303. input="$outdir/${base}_ratio-MTC.nii.gz"
  304. output="$outdir/${base}_space-MNI_ratio-MTC.nii.gz"
  305. KUL_antsApply_Transform_MNI
  306. fi
  307. input="$outdir/${base}_${td}${ext}.nii.gz"
  308. output="$outdir/${base}_space-MNI_${td}${ext}.nii.gz"
  309. KUL_antsApply_Transform_MNI
  310. }
  311. function KUL_MTI_register_computeratio {
  312. base0=${test_T1w##*/}
  313. base=${base0%_T1w*}
  314. # convert the 4D MTI to single 3Ds
  315. input="$outdir/tmp/${base}_${td}_iso.nii.gz"
  316. S0="$outdir/tmp/${base}_${td}_iso_S0.nii.gz"
  317. Smt="$outdir/tmp/${base}_${td}_iso_Smt.nii.gz"
  318. mrconvert $input -coord 3 0 $S0 -force
  319. mrconvert $input -coord 3 1 $Smt -force
  320. # determine the registration
  321. ants_type="${base}_rigid_${td}_reg2t1_"
  322. ants_template="${base}_T1w_iso_biascorrected.nii.gz"
  323. ants_source="${base}_${td}_iso_Smt.nii.gz"
  324. newname="${base}_${td}_iso_Smt_reg2T1w.nii.gz"
  325. finalname="${base}_${td}_reg2T1w.nii.gz"
  326. KUL_rigid_register
  327. Smt="$outdir/tmp/$newname"
  328. # Now apply the coregistration to the 4D MTI
  329. input=$S0
  330. output="$outdir/tmp/${base}_${td}_iso_S0_reg2T1w.nii.gz"
  331. S0=$output
  332. transform="$outdir/tmp/${base}_rigid_${td}_reg2t1_0GenericAffine.mat"
  333. reference="$outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz"
  334. KUL_antsApply_Transform
  335. # make a better mask
  336. mask=$outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz
  337. # MTR formula: (S0 - Smt)/S0
  338. mrcalc $S0 $Smt -subtract $S0 -divide $mask -multiply \
  339. $outdir/${base}_ratio-MTC.nii.gz -nthreads $ncpu -force
  340. # Also warp to MNI space
  341. reference=$ref_im
  342. transform1="$outdir/warp2mni/${base}_T1w2MNI_1Warp.nii.gz"
  343. transform2="[$outdir/warp2mni/${base}_T1w2MNI_0GenericAffine.mat,0]"
  344. interpolation_type="Linear"
  345. input="$outdir/${base}_ratio-MTC.nii.gz"
  346. output="$outdir/${base}_ratio-MTC_MNI.nii.gz"
  347. KUL_antsApply_Transform_MNI
  348. cp $outdir/tmp/$newname $outdir/$finalname
  349. }
  350. # --- MAIN ---
  351. printf "\n\n\n"
  352. # here we give the data
  353. if [ $auto -eq 0 ]; then
  354. if [ -z "$session" ]; then
  355. fullsession1=""
  356. fullsession2=""
  357. else
  358. fullsession1="ses-${session}/"
  359. fullsession2="ses-${session}_"
  360. fi
  361. datadir="$cwd/BIDS/sub-${participant}/${fullsession1}anat"
  362. T1w=("$datadir/sub-${participant}_${fullsession2}T1w.nii.gz")
  363. T2w=("$datadir/sub-${participant}_${fullsession2}T2w.nii.gz")
  364. FLAIR=("$datadir/sub-${participant}_${fullsession2}FLAIR.nii.gz")
  365. MTI=("$datadir/sub-${participant}_${fullsession2}MTI.nii.gz")
  366. else
  367. T1w=($(find $cwd/BIDS -type f -name "*T1w.nii.gz" | sort ))
  368. fi
  369. hpc_counter=0
  370. hpc_task=1
  371. for test_T1w in ${T1w[@]}; do
  372. # defining the basename from the array elements
  373. base0=${test_T1w##*/};base=${base0%_T1w*}
  374. local_participant=${base%_ses*}
  375. local_session="ses-${base##*ses-}"
  376. outdir=$outputdir/$local_participant/$local_session
  377. check_done="$outdir/${base}.done"
  378. # resetting found files
  379. d=0
  380. t2=0
  381. flair=0
  382. mti=0
  383. # read the level of completed workflow
  384. if [ ! -f $check_done ];then
  385. level_done=0
  386. else
  387. level_done=$(cat $check_done)
  388. if [ -z $level_done ];then
  389. #echo "empty"
  390. level_done=10
  391. fi
  392. fi
  393. # only execute if workflow level in not yet reached
  394. if [ $level_done -lt $deel ];then
  395. echo " current level of processing done: $level_done"
  396. # write files for the VSC
  397. if [ $hpc -eq 1 ];then
  398. mkdir -p VSC
  399. if [ $hpc_counter -eq 0 ];then
  400. #echo "#!/bin/bash -e" > VSC/VSC_commands.sh
  401. echo "participant, session" > VSC/pbs_data_${hpc_task}.csv
  402. fi
  403. vsc_participant=${local_participant##*sub-}
  404. vsc_session=${local_session##*ses-}
  405. #vsc_cmd="KUL_T1T2FLAIRMTR_ratio_new.sh -p $vsc_participant -s $vsc_session -m -f 2 -d 3"
  406. #echo $vsc_cmd >> VSC/VSC_commands.sh
  407. echo "${vsc_participant},${vsc_session}" >> VSC/pbs_data_${hpc_task}.csv
  408. hpc_counter=$((hpc_counter+1))
  409. if [ $hpc_counter -ge 34 ];then
  410. hpc_task=$((hpc_task+1))
  411. hpc_counter=0
  412. fi
  413. else
  414. # Test whether T2 and/or FLAIR also exist
  415. test_T2w="${test_T1w%_T1w*}_T2w.nii.gz"
  416. if [ -f $test_T2w ];then
  417. #echo "The T2 exists"
  418. d=$((d+1))
  419. t2=1
  420. fi
  421. test_FLAIR="${test_T1w%_T1w*}_FLAIR.nii.gz"
  422. if [ -f $test_FLAIR ];then
  423. #echo "The FLAIR exists"
  424. d=$((d+1))
  425. flair=1
  426. fi
  427. test_MTI="${test_T1w%_T1w*}_MTI.nii.gz"
  428. if [ -f $test_MTI ];then
  429. #echo "The MTI exists"
  430. d=$((d+1))
  431. mti=1
  432. fi
  433. # If a T1w and a T2w and/or a FLAIR exists
  434. if [ $d -gt 0 ]; then
  435. mkdir -p $outdir/tmp
  436. mkdir -p $outdir/histograms
  437. mkdir -p $outdir/masks
  438. mkdir -p $outdir/rois
  439. mkdir -p $outputdir/log
  440. kul_e2cl "KUL_T1T2FLAIR_ratio is processing $local_participant and session $local_session" ${outputdir}/${log}
  441. # PART 1 - make all images conform and bias-correct
  442. if [ $deel -ge 1 ]; then
  443. # for the T1w
  444. td="T1w"
  445. KUL_iso_biascorrect $test_T1w
  446. cp $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz $outdir/${base}_T1w.nii.gz
  447. if [ $t2 -eq 1 ];then
  448. td="T2w"
  449. KUL_iso_biascorrect $test_T2w
  450. fi
  451. if [ $flair -eq 1 ];then
  452. td="FLAIR"
  453. KUL_iso_biascorrect $test_FLAIR
  454. fi
  455. fi
  456. # PART 2 - register the T2w and/or FLAIR to the T1w
  457. if [ $deel -ge 2 ]; then
  458. if [ $t2 -eq 1 ];then
  459. td="T2w"
  460. KUL_reg2t1
  461. cp $outdir/tmp/${base}_${td}_iso_biascorrected_reg2T1w.nii.gz $outdir/${base}_${td}_reg2T1w.nii.gz
  462. fi
  463. if [ $flair -eq 1 ];then
  464. td="FLAIR"
  465. KUL_reg2t1
  466. cp $outdir/tmp/${base}_${td}_iso_biascorrected_reg2T1w.nii.gz $outdir/${base}_${td}_reg2T1w.nii.gz
  467. fi
  468. fi
  469. # PART 3 - Spatially normalise (warp) the T1w to the MNI atlas
  470. if [ $deel -ge 3 ]; then
  471. fix_im="$kul_main_dir/atlasses/Ganzetti2014/mni_icbm152_t1_tal_nlin_sym_09a.nii"
  472. ref_im="$kul_main_dir/atlasses/Ganzetti2014/mni_icbm152_t1_tal_nlin_sym_09a_with_neck.nii"
  473. #input=${test_T1w##*/}
  474. #input=${input%%.*}
  475. #mov_im=$outdir/tmp/${input}_iso_biascorrected.nii.gz
  476. mov_im=$outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz
  477. output="$outdir/warp2mni/${base}_T1w2MNI_"
  478. mkdir -p $outdir/warp2mni
  479. if [ ! -f $outdir/warp2mni/${base}_T1w2MNI_Warped.nii.gz ]; then
  480. echo " computing the spatial normalisation (warp) of the T1w to MNI (takes about 20 minutes)"
  481. my_cmd="antsRegistrationSyN.sh -d 3 -f ${fix_im} -m ${mov_im} \
  482. -o ${output} -n ${ncpu} -j 1 -t s $fs_silent"
  483. eval $my_cmd
  484. else
  485. echo " skipping MNI spatial normalisation, since it's already computed"
  486. fi
  487. fi
  488. # PART 4 - run fastsurfer (optional)
  489. if [ $deel -ge 4 ] && [ $fastsurf -gt 0 ]; then
  490. mkdir -p $outdir/fs
  491. #export FREESURFER_HOME=/usr/local/KUL_apps/freesurfer6
  492. #source $FREESURFER_HOME/SetUpFreeSurfer.sh
  493. if [ ! -f $outdir/fs/$base/mri/aparc.DKTatlas+aseg.deep.mgz ]; then
  494. if [ $fastsurf -eq 1 ]; then
  495. echo " running full fastsufer"
  496. my_cmd="$FASTSURFER_HOME/run_fastsurfer.sh \
  497. --sid $base --sd $outdir/fs \
  498. --t1 $test_T1w \
  499. --fs_license $FS_LICENSE \
  500. --py python --parallel --ignore_fs_version --threads $ncpu $fs_silent"
  501. elif [ $fastsurf -eq 2 ]; then
  502. echo " running segmentation-with-CC & stats fastsufer"
  503. my_cmd="$FASTSURFER_HOME/run_fastsurfer.sh \
  504. --sid $base --sd $outdir/fs \
  505. --t1 $test_T1w \
  506. --fs_license $FS_LICENSE \
  507. --seg_with_cc_only --py python --ignore_fs_version --threads $ncpu $fs_silent"
  508. elif [ $fastsurf -eq 3 ]; then
  509. echo " running segmentation-only fastsufer"
  510. my_cmd="$FASTSURFER_HOME/run_fastsurfer.sh \
  511. --sid $base --sd $outdir/fs \
  512. --t1 $test_T1w \
  513. --seg_only --py python --ignore_fs_version --threads $ncpu $fs_silent"
  514. fi
  515. eval $my_cmd
  516. else
  517. echo " fastsurfer seems to have run already"
  518. fi
  519. fi
  520. # PART 5 - MS lesion segmentation (optional)
  521. MSlesion="$outdir/rois/${base}_MSLesion.nii.gz"
  522. if [ $deel -ge 5 ] && [ $ms -eq 1 ];then
  523. if [ $flair -eq 1 ];then
  524. if [ ! -f $MSlesion ];then
  525. echo " running samseg (takes about 20 minutes)"
  526. T1w_iso="$outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz"
  527. FLAIR_reg2T1w="$outdir/tmp/${base}_FLAIR_iso_biascorrected_reg2T1w.nii.gz"
  528. my_cmd="run_samseg --input $T1w_iso $FLAIR_reg2T1w --pallidum-separate \
  529. --lesion --lesion-mask-pattern 0 1 --output $outdir/samseg \
  530. --threads $ncpu $fs_silent"
  531. eval $my_cmd
  532. SamSeg="$outdir/samseg/seg.mgz"
  533. mrcalc $SamSeg 99 -eq $MSlesion -force -nthreads $ncpu
  534. else
  535. echo " already ran samseg"
  536. fi
  537. else
  538. echo " Warning! No Flair available to do lesion MS segmentation"
  539. fi
  540. fi
  541. # PART 6 - hd-bet and background search
  542. if [ $deel -ge 6 ];then
  543. # hd-bet brain extraction of the T1w
  544. if [ ! -f $outdir/tmp/${base}_T1w_iso_biascorrected_brain.nii.gz ]; then
  545. echo " doing hd-bet on ${base}_T1w_iso_biascorrected.nii.gz"
  546. my_cmd="hd-bet -i $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  547. -o $outdir/tmp/${base}_T1w_iso_biascorrected_brain.nii.gz $fs_silent"
  548. eval $my_cmd
  549. mv $outdir/tmp/${base}_T1w_iso_biascorrected_brain_mask.nii.gz $outdir/masks
  550. else
  551. echo " skipping hd-bet on ${base}_T1w_iso_biascorrected.nii.gz - already done"
  552. fi
  553. # find the background by thresholding the T1w
  554. background="$outdir/masks/${base}_T1w_iso_biascorrected_background.nii.gz"
  555. if [ ! -f $background ]; then
  556. max_T1w=$(mrstats $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz -output max)
  557. echo " thresholding background using 0.5% of max signal of the T1w - $max_T1w"
  558. mrcalc $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz $max_T1w 0.005 -mul -lt \
  559. $background -force -nthreads $ncpu
  560. else
  561. echo " thresholding background already done"
  562. fi
  563. fi
  564. # PART 7 - Calibration
  565. check7="$outdir/histograms/${base}_T1w_iso_biascorrected_calib-nonlin3_histogram.csv"
  566. if [ $deel -ge 7 ] && [ ! -f $check7 ];then
  567. # -----------------------------------------------------------------------------------------------------------------------------
  568. # METHOD 1 - LINEAR histogram matching using eye/muscle tissue
  569. echo " performing linear histogram matching"
  570. M1_template_T1w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_T1w.nii.gz"
  571. M1_template_T2w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_T2w.nii.gz"
  572. M1_template_FLAIR="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_T2w.nii.gz"
  573. M1_template_mask_eye="$kul_main_dir/atlasses/Ganzetti2014/eyemask.nii"
  574. M1_template_mask_tempmuscle="$kul_main_dir/atlasses/Ganzetti2014/tempmask.nii"
  575. # Warp the eye and muscle back to subject space
  576. echo " warping eye/muscle and skull/air back to subject space"
  577. reference=$mov_im
  578. # REVIEW SARAH: There was a bug here in the order of transforms
  579. transform2="$outdir/warp2mni/${base}_T1w2MNI_1InverseWarp.nii.gz"
  580. transform1="[$outdir/warp2mni/${base}_T1w2MNI_0GenericAffine.mat,1]"
  581. interpolation_type="NearestNeighbor"
  582. input=$M1_template_mask_eye
  583. output="$outdir/masks/${base}_method1_eye.nii.gz"
  584. KUL_antsApply_Transform_MNI
  585. input=$M1_template_mask_tempmuscle
  586. output="$outdir/masks/${base}_method1_tempmuscle.nii.gz"
  587. KUL_antsApply_Transform_MNI
  588. # sum the masks
  589. mrcalc $outdir/masks/${base}_method1_eye.nii.gz $outdir/masks/${base}_method1_tempmuscle.nii.gz -add \
  590. $outdir/masks/${base}_method1_eye_and_muscle.nii.gz -nthreads $ncpu -force
  591. mrcalc $M1_template_mask_eye $M1_template_mask_tempmuscle -add \
  592. $outdir/masks/${base}_method1_mni_eye_and_muscle.nii.gz -nthreads $ncpu -force
  593. # do the LINEAR histogram matching using eye/muscle tissue
  594. mrhistmatch \
  595. -mask_input $outdir/masks/${base}_method1_eye_and_muscle.nii.gz \
  596. -mask_target $outdir/masks/${base}_method1_mni_eye_and_muscle.nii.gz \
  597. linear \
  598. $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  599. $M1_template_T1w \
  600. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-lin.nii.gz -nthreads $ncpu -force
  601. mrhistogram -bin 100 -ignorezero \
  602. $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  603. $outdir/histograms/${base}_T1w_iso_biascorrected_histogram.csv -force
  604. mrhistogram -bin 100 -ignorezero \
  605. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-lin.nii.gz \
  606. $outdir/histograms/${base}_T1w_iso_biascorrected_calib-lin_histogram.csv -nthreads $ncpu -force
  607. if [ $t2 -eq 1 ];then
  608. mrhistmatch \
  609. -mask_input $outdir/masks/${base}_method1_eye_and_muscle.nii.gz \
  610. -mask_target $outdir/masks/${base}_method1_mni_eye_and_muscle.nii.gz \
  611. linear \
  612. $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz \
  613. $M1_template_T2w \
  614. $outdir/tmp/${base}_T2w_iso_biascorrected_calib-lin_reg2T1w.nii.gz -nthreads $ncpu -force
  615. mrhistogram -bin 100 -ignorezero \
  616. $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz \
  617. $outdir/histograms/${base}_T2w_iso_biascorrected_reg2T1w_histogram.csv -force
  618. mrhistogram -bin 100 -ignorezero \
  619. $outdir/tmp/${base}_T2w_iso_biascorrected_calib-lin_reg2T1w.nii.gz \
  620. $outdir/histograms/${base}_T2w_iso_biascorrected_calib-lin_reg2T1w_histogram.csv -nthreads $ncpu -force
  621. fi
  622. if [ $flair -eq 1 ];then
  623. # Note: this is probably not a good calibration, since Ganzetti did not have a MNI-FLAIR
  624. mrhistmatch \
  625. -mask_input $outdir/masks/${base}_method1_eye_and_muscle.nii.gz \
  626. -mask_target $outdir/masks/${base}_method1_mni_eye_and_muscle.nii.gz \
  627. linear \
  628. $outdir/tmp/${base}_FLAIR_iso_biascorrected_reg2T1w.nii.gz \
  629. $M1_template_FLAIR \
  630. $outdir/tmp/${base}_FLAIR_iso_biascorrected_calib-lin_reg2T1w.nii.gz -nthreads $ncpu -force
  631. mrhistogram -bin 100 -ignorezero \
  632. $outdir/tmp/${base}_FLAIR_iso_biascorrected_reg2T1w.nii.gz \
  633. $outdir/histograms/${base}_FLAIR_iso_biascorrected_reg2T1w_histogram.csv -force
  634. mrhistogram -bin 100 -ignorezero \
  635. $outdir/tmp/${base}_FLAIR_iso_biascorrected_calib-lin_reg2T1w.nii.gz \
  636. $outdir/histograms/${base}_FLAIR_iso_biascorrected_calib-lin_reg2T1w_histogram.csv -nthreads $ncpu -force
  637. fi
  638. # -----------------------------------------------------------------------------------------------------------------------------
  639. # METHOD 2 - the NON-LINEAR histogram matching using non-brain tissue
  640. echo " performing nonlinear histogram matching"
  641. # Warp the brain_mask and its inverse to subject space
  642. M2_template_T1w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_T1w.nii.gz"
  643. M2_template_T2w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_T2w.nii.gz"
  644. M2_template_FLAIR="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_T2w.nii.gz"
  645. input="$kul_main_dir/atlasses/Ganzetti2014/brainmask_mni_dilated.nii"
  646. output="$outdir/masks/${base}_method2_MNI2subj_brainmask_mni_dilated.nii.gz"
  647. KUL_antsApply_Transform_MNI
  648. input="$kul_main_dir/atlasses/Ganzetti2014/brainmask_mni_dilated_inverse.nii"
  649. output="$outdir/masks/${base}_method2_MNI2subj_brainmask_mni_dilated_inverse.nii.gz"
  650. KUL_antsApply_Transform_MNI
  651. mrhistmatch \
  652. -mask_input $outdir/masks/${base}_method2_MNI2subj_brainmask_mni_dilated_inverse.nii.gz \
  653. -mask_target $kul_main_dir/atlasses/Ganzetti2014/brainmask_mni_dilated_inverse.nii \
  654. nonlinear \
  655. $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  656. $M2_template_T1w \
  657. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin.nii.gz -nthreads $ncpu -force
  658. mrhistogram -bin 100 -ignorezero \
  659. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin.nii.gz \
  660. $outdir/histograms/${base}_T1w_iso_biascorrected_calib-nonlin_histogram.csv -nthreads $ncpu -force
  661. if [ $t2 -eq 1 ];then
  662. mrhistmatch \
  663. -mask_input $outdir/masks/${base}_method2_MNI2subj_brainmask_mni_dilated_inverse.nii.gz \
  664. -mask_target $kul_main_dir/atlasses/Ganzetti2014/brainmask_mni_dilated_inverse.nii \
  665. nonlinear \
  666. $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz \
  667. $M2_template_T2w \
  668. $outdir/tmp/${base}_T2w_iso_biascorrected_calib-nonlin_reg2T1w.nii.gz -nthreads $ncpu -force
  669. mrhistogram -bin 100 -ignorezero \
  670. $outdir/tmp/${base}_T2w_iso_biascorrected_calib-nonlin_reg2T1w.nii.gz \
  671. $outdir/histograms/${base}_T2w_iso_biascorrected_calib-nonlin_reg2T1w_histogram.csv -nthreads $ncpu -force
  672. fi
  673. if [ $flair -eq 1 ];then
  674. mrhistmatch \
  675. -mask_input $outdir/masks/${base}_method2_MNI2subj_brainmask_mni_dilated_inverse.nii.gz \
  676. -mask_target $kul_main_dir/atlasses/Ganzetti2014/brainmask_mni_dilated_inverse.nii \
  677. nonlinear \
  678. $outdir/tmp/${base}_FLAIR_iso_biascorrected_reg2T1w.nii.gz \
  679. $M2_template_FLAIR \
  680. $outdir/tmp/${base}_FLAIR_iso_biascorrected_calib-nonlin_reg2T1w.nii.gz -nthreads $ncpu -force
  681. mrhistogram -bin 100 -ignorezero \
  682. $outdir/tmp/${base}_FLAIR_iso_biascorrected_calib-nonlin_reg2T1w.nii.gz \
  683. $outdir/histograms/${base}_FLAIR_iso_biascorrected_calib-nonlin_reg2T1w_histogram.csv -nthreads $ncpu -force
  684. fi
  685. # Method 3 - Cappelle & Sunaert
  686. echo " performing second (Cappelle) nonlinear histogram matching"
  687. M3_template_T1w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_Cappelle2021_T1w.nii.gz"
  688. M3_template_T2w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_Cappelle2021_T2w.nii.gz"
  689. M3_template_FLAIR="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_Cappelle2021_FLAIR.nii.gz"
  690. M3_template_mask_4_T1w="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_Cappelle2021_mask_4_T1w.nii.gz"
  691. M3_template_mask_4_T2w_and_FLAIR="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_Cappelle2021_mask_4_T2w_and_FLAIR.nii.gz"
  692. mask1="$outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz"
  693. mask2="$outdir/masks/${base}_T1w_iso_biascorrected_brain_inverted_mask.nii.gz"
  694. mrcalc $mask1 0.1 -lt $mask2 -nthreads $ncpu -force
  695. mask3="$outdir/masks/${base}_T1w_iso_biascorrected_brain_inverted_mask_nobackground.nii.gz"
  696. mrcalc $mask1 0.1 -lt $background -sub 0.1 -gt $mask3 -nthreads $ncpu -force
  697. # do the scond NON-LINEAR histogram matching using non-brain tissue
  698. mrhistmatch \
  699. -mask_input $mask3 \
  700. -mask_target $M3_template_mask_4_T1w \
  701. nonlinear \
  702. $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  703. $M3_template_T1w \
  704. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin2.nii.gz -nthreads $ncpu -force
  705. mrhistogram -bin 100 -ignorezero \
  706. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin2.nii.gz \
  707. $outdir/histograms/${base}_T1w_iso_biascorrected_calib-nonlin2_histogram.csv -nthreads $ncpu -force
  708. if [ $t2 -eq 1 ];then
  709. td="T2w"
  710. # find the ventricles by thresholding the T2w
  711. max_T2w=$(mrstats $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz -output max)
  712. echo " max signal of the T2w is $max_T2w"
  713. ventricles="$outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w_ventricules.nii.gz"
  714. mrcalc $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz $max_T2w 0.75 -mul -gt \
  715. $ventricles -nthreads $ncpu -force
  716. skull_and_ventricules="$outdir/masks/${base}_T2w_iso_biascorrected_reg2T1w_skull_and_ventricules.nii.gz"
  717. mrcalc $mask3 $ventricles -add 0.1 -gt $skull_and_ventricules -nthreads $ncpu -force
  718. # do the scond NON-LINEAR histogram matching using non-brain tissue
  719. mrhistmatch \
  720. -mask_input $skull_and_ventricules \
  721. -mask_target $M3_template_mask_4_T2w_and_FLAIR \
  722. nonlinear \
  723. $outdir/tmp/${base}_${td}_iso_biascorrected_reg2T1w.nii.gz \
  724. $M3_template_T2w \
  725. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w.nii.gz -nthreads $ncpu -force
  726. mrhistogram -bin 100 -ignorezero \
  727. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w.nii.gz \
  728. $outdir/histograms/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w_histogram.csv -nthreads $ncpu -force
  729. fi
  730. if [ $flair -eq 1 ] && [ $t2 -eq 1 ];then
  731. td="FLAIR"
  732. # find the ventricles by thresholding the T2w
  733. max_T2w=$(mrstats $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz -output max)
  734. echo " max signal of the T2w is $max_T2w"
  735. ventricles="$outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w_ventricules.nii.gz"
  736. mrcalc $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz $max_T2w 0.75 -mul -gt \
  737. $ventricles -nthreads $ncpu -force
  738. skull_and_ventricules="$outdir/masks/${base}_FLAIR_iso_biascorrected_reg2T1w_skull_and_ventricules.nii.gz"
  739. mrcalc $mask3 $ventricles -add 0.1 -gt $skull_and_ventricules -nthreads $ncpu -force
  740. # do the scond NON-LINEAR histogram matching using non-brain tissue
  741. mrhistmatch \
  742. -mask_input $skull_and_ventricules \
  743. -mask_target $M3_template_mask_4_T2w_and_FLAIR \
  744. nonlinear \
  745. $outdir/tmp/${base}_${td}_iso_biascorrected_reg2T1w.nii.gz \
  746. $M3_template_FLAIR \
  747. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w.nii.gz -nthreads $ncpu -force
  748. mrhistogram -bin 100 -ignorezero \
  749. $outdir/tmp/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w.nii.gz \
  750. $outdir/histograms/${base}_${td}_iso_biascorrected_calib-nonlin2_reg2T1w_histogram.csv -nthreads $ncpu -force
  751. fi
  752. # Last method of calibration
  753. # do it in the whole image except for the MS lesions
  754. M4_template_T1w=$M3_template_T1w
  755. M4_template_T2w=$M3_template_T2w
  756. M4_template_FLAIR=$M3_template_FLAIR
  757. M4_template_mask="$kul_main_dir/atlasses/Local/Cappelle2021/tpl-MNI152NLin2009aSym_res-1_Cappelle2021_T1w_mask_brain_mask.nii.gz"
  758. mask1="$outdir/masks/${base}_T1w_iso_biascorrected_brain_mask.nii.gz"
  759. mask_subj="$outdir/masks/${base}_method4_brain_mask_without_lesions.nii.gz"
  760. MSlesion_dilated="$outdir/masks/${base}_method4_MSlesion_dilated.nii.gz"
  761. maskfilter $MSlesion dilate $MSlesion_dilated -force
  762. mrcalc $mask1 $MSlesion_dilated -subtract $mask_subj -nthreads $ncpu -force
  763. mrhistmatch \
  764. -mask_input $mask_subj \
  765. -mask_target $M4_template_mask \
  766. nonlinear \
  767. $outdir/tmp/${base}_T1w_iso_biascorrected.nii.gz \
  768. $M4_template_T1w \
  769. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin3.nii.gz -nthreads $ncpu -force
  770. mrhistogram -bin 100 -ignorezero \
  771. $outdir/tmp/${base}_T1w_iso_biascorrected_calib-nonlin3.nii.gz \
  772. $outdir/histograms/${base}_T1w_iso_biascorrected_calib-nonlin3_histogram.csv -nthreads $ncpu -force
  773. if [ $t2 -eq 1 ];then
  774. mrhistmatch \
  775. -mask_input $mask_subj \
  776. -mask_target $M4_template_mask \
  777. nonlinear \
  778. $outdir/tmp/${base}_T2w_iso_biascorrected_reg2T1w.nii.gz \
  779. $M4_template_T2w \
  780. $outdir/tmp/${base}_T2w_iso_biascorrected_calib-nonlin3_reg2T1w.nii.gz -nthreads $ncpu -force
  781. mrhistogram -bin 100 -ignorezero \
  782. $outdir/tmp/${base}_T2w_iso_biascorrected_calib-nonlin3_reg2T1w.nii.gz \
  783. $outdir/histograms/${base}_T2w_iso_biascorrected_calib-nonlin3_histogram.csv -nthreads $ncpu -force
  784. fi
  785. if [ $flair -eq 1 ];then
  786. mrhistmatch \
  787. -mask_input $mask_subj \
  788. -mask_target $M4_template_mask \
  789. nonlinear \
  790. $outdir/tmp/${base}_FLAIR_iso_biascorrected_reg2T1w.nii.gz \
  791. $M4_template_FLAIR \
  792. $outdir/tmp/${base}_FLAIR_iso_biascorrected_calib-nonlin3_reg2T1w.nii.gz -nthreads $ncpu -force
  793. mrhistogram -bin 100 -ignorezero \
  794. $outdir/tmp/${base}_FLAIR_iso_biascorrected_calib-nonlin3_reg2T1w.nii.gz \
  795. $outdir/histograms/${base}_FLAIR_iso_biascorrected_calib-nonlin3_histogram.csv -nthreads $ncpu -force
  796. fi
  797. fi
  798. # PART 8 - compute the ratio
  799. if [ $deel -ge 8 ];then
  800. if [ $t2 -eq 1 ];then
  801. td="T2w"
  802. KUL_computeratio
  803. fi
  804. if [ $flair -eq 1 ];then
  805. td="FLAIR"
  806. KUL_computeratio
  807. fi
  808. fi
  809. # PART 9 - MTI and MTR
  810. test_done_MTI="$outdir/${base}_ratio-MTC_MNI.nii.gz"
  811. if [ $deel -ge 9 ] && [ $mti -eq 1 ] && [ ! -f $test_done_MTI ];then
  812. input=$test_MTI
  813. output=${test_MTI##*/}
  814. output=${output%%.*}
  815. echo " doing hd-bet of the MTI"
  816. KUL_MTI_reorient_crop_hdbet_iso
  817. td="MTI"
  818. echo " coregistering MTI to T1 and computing the MTC ratio"
  819. KUL_MTI_register_computeratio
  820. fi
  821. # PART 10 - warping results to mni too
  822. if [ $deel -ge 10 ];then
  823. td="T1w"
  824. KUL_apply_warp2mni
  825. if [ $t2 -eq 1 ];then
  826. td="T2w"
  827. KUL_apply_warp2mni
  828. fi
  829. if [ $flair -eq 1 ];then
  830. td="FLAIR"
  831. KUL_apply_warp2mni
  832. fi
  833. if [ $mti -eq 1 ];then
  834. td="MTI"
  835. KUL_apply_warp2mni
  836. fi
  837. fi
  838. #rm -fr $outdir/tmp/${base}*.gz
  839. #cd T1T2FLAIRMTR_ratio/tmp/
  840. #rm -fr *std.nii.gz *iso.nii.gz *ted.nii.gz *reg2T1w.nii.gz *mask.nii.gz *eye.nii.gz *muscle.nii.gz *.csv *MTI* *MNI.nii.gz *verse.nii.gz *inv.nii.gz *brain.nii.gz
  841. #rm -fr *std.nii.gz *iso.nii.gz *ted.nii.gz *reg2T1w.nii.gz *eye.nii.gz *muscle.nii.gz *.csv *MTI* *MNI.nii.gz *verse.nii.gz *inv.nii.gz *brain.nii.gz
  842. #cd ../..
  843. echo ${deel} > $check_done
  844. echo " done"
  845. else
  846. echo " Nothing to do here"
  847. fi
  848. fi
  849. else
  850. echo " $base already done"
  851. fi
  852. done

KUL_T1T2FLAIRMTR_ratio.sh at commit 2c11248, under MPL-2.0 · at the source

Overview

Authors: Luca Sacchi1,2, Giovanni Farruggio2, Giorgio Bocca2,3, Tiziana Carandini2, Milena De Riz2, Laura Ghezzi1,2, Manuela Pintus2, Anna Pietroboni2, Giacomo Boffa4,5, Elisa Scola6, Fabio Triulzi6,7, Marco Bozzali8, Daniela Galimberti1,2, Mara Cercignani9, Andrea Arighi2
  1. Department of Biomedical, Surgical and Dental Sciences, University of Milan, Milan, Italy
  2. Neurodegenerative Diseases Unit, Fondazione IRCCS Ca' Granda, Ospedale Maggiore Policlinico, Milan, Italy
  3. Department of Biomedical Sciences for Health, University of Milan, Milan, Italy
  4. Department of Neuroscience, Rehabilitation, Ophthalmology, Genetics, Maternal and Child Health (DiNOGMI), University of Genoa, Genoa, Italy
  5. IRCCS Ospedale Policlinico San Martino, Genoa, Italy
  6. Neuroradiology Unit, Fondazione IRCCS Ca’ Granda, Ospedale Maggiore Policlinico, Milan, Italy
  7. Department of Pathophysiology and Transplantation, University of Milan, Milan, Italy
  8. Department of Neurosciences “Rita Levi Montalcini”, University of Turin, Turin, Italy
  9. Cardiff University Brain Research Imaging Centre, School of Psychology, Cardiff University, Cardiff, UK
Journal: Human brain mapping, volume 47, issue 14, article e70603
Dates: received 19 November 2025; accepted 30 June 2026; published online 24 September 2026; in print October 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1002/hbm.70603 · PMID 42786724 · PMCID PMC13612971 · OpenAlex W4416247825
Open access: gold, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: structural MRI / diffusion (modality), human (organism), other condition (population), Alzheimer's / dementia (population)
Methods: Statistics, Spectral & time-frequency, Connectivity, fMRI & imaging, Physiology & signal measures
Keywords: Alzheimer's disease, DTI‐ALPS, glymphatic system, NODDI, quantitative susceptibility mapping
MeSH: Brain*, Diffusion Tensor Imaging*, Glymphatic System*, Neurodegenerative Diseases*, White Matter*, Aged, Aged, 80 and over, Anisotropy, Diffusion Magnetic Resonance Imaging, Female, Humans, Magnetic Resonance Imaging, Male, Middle Aged, Multimodal Imaging (* major topic)
Topic: Cerebrospinal fluid and hydrocephalus (Clinical Neurology, Medicine), according to OpenAlex
Funding: Ministero della Salute (PNRR-POC-2023-12377354); Associazione 'Centro Dino Ferrari' ETS; Fondazione BCC Milano; Fondazione Regionale per la Ricerca Biomedica (3430931)
Citations: not cited yet (Europe PMC); 96 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.

treanus/KUL_NIS

License: MPL-2.0
State: the link answers, verified on 1 November 2026
Evidence: files inventoried
Commit: 2c11248436041bffa0a63ae7f819317b03efb3ad, 18 August 2023
Languages: Shell (42), MATLAB (8), Python (7)
Size: 171 files, 57 scripts
Software Heritage: not archived
Found in: the text, “T1 and FLAIR Images Preprocessing and T1/FLAIR R”
Holds: README, license file, documentation
Not found: CITATION.cff, environment file, tests, continuous integration
Tools: MRtrix3 (29 files), ANTs (14 files), FSL (9 files), FreeSurfer (7 files), SPM (6 files), BIDS Validator (4 files), NumPy (4 files), Dcm2Bids (2 files), NiBabel (2 files), SciPy (2 files), fMRIPrep (1 file), Statistics and Machine Learning Toolbox (1 file), MRIQC (1 file), pandas (1 file), SimpleITK (1 file)
Availability: 2 checks, the latest on 1 November 2026: the link answers
  • 1 November 2026: the link answers
  • 29 September 2026: the link answers
59 files

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 57 scripts, each with its path and the digest of its content;
  • 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

  • it says that the data are available on request

Read it in the paper: doi.org/10.1002/hbm.70603.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 1 October 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 15 authors, 5 keywords, 15 MeSH terms, 4 funders, 96 references.

Cite

This paper

Sacchi, L., Farruggio, G., Bocca, G., Carandini, T., De Riz, M., Ghezzi, L., Pintus, M., Pietroboni, A., Boffa, G., Scola, E., Triulzi, F., Bozzali, M., Galimberti, D., Cercignani, M., & Arighi, A. (2026). DTI-ALPS Primarily Reflects White Matter Diffusion Dispersion and Microstructural Heterogeneity in Neurodegeneration: Insights From Multi-Modal MRI. Human brain mapping, 47(14), e70603. https://doi.org/10.1002/hbm.70603

BibTeX

@article{sacchi2026dti,
author = {Sacchi, Luca and Farruggio, Giovanni and Bocca, Giorgio and Carandini, Tiziana and De Riz, Milena and Ghezzi, Laura and Pintus, Manuela and Pietroboni, Anna and Boffa, Giacomo and Scola, Elisa and Triulzi, Fabio and Bozzali, Marco and Galimberti, Daniela and Cercignani, Mara and Arighi, Andrea},
title = {{DTI-ALPS Primarily Reflects White Matter Diffusion Dispersion and Microstructural Heterogeneity in Neurodegeneration: Insights From Multi-Modal MRI}},
journal = {Human brain mapping},
year = {2026},
month = oct,
volume = {47},
number = {14},
pages = {e70603},
publisher = {Wiley},
issn = {1065-9471},
doi = {10.1002/hbm.70603},
url = {https://doi.org/10.1002/hbm.70603},
pmid = {42786724},
pmcid = {PMC13612971}
}

RIS

TY - JOUR
AU - Sacchi, Luca
AU - Farruggio, Giovanni
AU - Bocca, Giorgio
AU - Carandini, Tiziana
AU - De Riz, Milena
AU - Ghezzi, Laura
AU - Pintus, Manuela
AU - Pietroboni, Anna
AU - Boffa, Giacomo
AU - Scola, Elisa
AU - Triulzi, Fabio
AU - Bozzali, Marco
AU - Galimberti, Daniela
AU - Cercignani, Mara
AU - Arighi, Andrea
TI - DTI-ALPS Primarily Reflects White Matter Diffusion Dispersion and Microstructural Heterogeneity in Neurodegeneration: Insights From Multi-Modal MRI
T2 - Human brain mapping
J2 - Hum Brain Mapp
PY - 2026
DA - 2026/10/01
VL - 47
IS - 14
SP - e70603
SN - 1065-9471
PB - Wiley
DO - 10.1002/hbm.70603
UR - https://doi.org/10.1002/hbm.70603
LA - en
ER -

CSL-JSON

{
"id": "10.1002/hbm.70603",
"type": "article-journal",
"title": "DTI-ALPS Primarily Reflects White Matter Diffusion Dispersion and Microstructural Heterogeneity in Neurodegeneration: Insights From Multi-Modal MRI",
"container-title": "Human brain mapping",
"author": [
{
"family": "Sacchi",
"given": "Luca"
},
{
"family": "Farruggio",
"given": "Giovanni"
},
{
"family": "Bocca",
"given": "Giorgio"
},
{
"family": "Carandini",
"given": "Tiziana"
},
{
"family": "De Riz",
"given": "Milena"
},
{
"family": "Ghezzi",
"given": "Laura"
},
{
"family": "Pintus",
"given": "Manuela"
},
{
"family": "Pietroboni",
"given": "Anna"
},
{
"family": "Boffa",
"given": "Giacomo"
},
{
"family": "Scola",
"given": "Elisa"
},
{
"family": "Triulzi",
"given": "Fabio"
},
{
"family": "Bozzali",
"given": "Marco"
},
{
"family": "Galimberti",
"given": "Daniela"
},
{
"family": "Cercignani",
"given": "Mara"
},
{
"family": "Arighi",
"given": "Andrea"
}
],
"container-title-short": "Hum Brain Mapp",
"volume": "47",
"issue": "14",
"page": "e70603",
"DOI": "10.1002/hbm.70603",
"PMID": "42786724",
"PMCID": "PMC13612971",
"ISSN": "1065-9471",
"publisher": "Wiley",
"URL": "https://doi.org/10.1002/hbm.70603",
"language": "en",
"issued": {
"date-parts": [
[
2026,
10,
1
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1007/s00234-025-03875-9 [code]
Evaluating the T1w/FLAIR ratio as a proxy for myelin: Associations with myelin water Imaging, diffusion metrics, and cognition.
Journal: Neuroradiology
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, structural MRI / diffusion, 8 references
[2] doi:10.1016/j.nicl.2022.103248 [code]
T1w/FLAIR ratio standardization as a myelin marker in MS patients.
Journal: NeuroImage. Clinical
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, structural MRI / diffusion, 6 references
[3] doi:10.1162/imag.a.122 [code]
Neural micro and macrostructural correlates of visual outcomes in children with unilateral cerebral palsy: A fixel-based study.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, structural MRI / diffusion, other condition, 4 references
[4] doi:10.1093/braincomms/fcag129 [code]
Longitudinal changes of choroid plexus volumes and MRI ratios in multiple sclerosis.
Journal: Brain communications
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, structural MRI / diffusion, 2 references
[5] doi:10.1007/s00221-023-06545-5 [code]
Longitudinal changes in global structural brain connectivity and cognitive performance in former hospitalized COVID-19 survivors: an exploratory study.
Journal: Experimental brain research
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, structural MRI / diffusion, other condition, 1 reference
[6] doi:10.1017/s0033291724003362 [code]
Gray and white matter differences in the medial temporal lobe in late-life depression: a multimodal PET-MRI investigation.
Journal: Psychological medicine
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, structural MRI / diffusion
[7] doi:10.1038/s41598-023-42429-y [code]
A cross-sectional case-control study on the structural connectome in recovered hospitalized COVID-19 patients.
Journal: Scientific reports
In common: Dcm2Bids, MRIQC, BIDS Validator, 12 other tools, other condition
[8] doi:10.1002/mds.30325 [code]
Impaired Glymphatic Clearance, Measured Using Diffusion Tensor Image Analysis Along the Perivascular Space (DTI-ALPS), is Linked to Poor Cognitive Outcomes in Parkinson's Disease.
Journal: Movement disorders : official journal of the Movement Disorder Society
In common: Alzheimer's / dementia, structural MRI / diffusion, 14 references
[9] doi:10.1038/s41531-025-01257-9 [code]
Alterations of cerebrospinal fluid flow dynamics in Parkinson's disease.
Journal: NPJ Parkinson's disease
In common: ANTs, FreeSurfer, FSL, 4 other tools, structural MRI / diffusion, 8 references
[10] doi:10.1162/netn_a_00330 [code]
The human brain connectome weighted by the myelin content and total intra-axonal cross-sectional area of white matter tracts.
Journal: Network neuroscience (Cambridge, Mass.)
In common: MRtrix3, ANTs, FreeSurfer, 7 other tools, structural MRI / diffusion, 7 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1002/hbm.70603.svg)](https://openscicode.org/badge/doi/10.1002/hbm.70603)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1002/hbm.70603.svg
   :target: https://openscicode.org/badge/doi/10.1002/hbm.70603
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1002/hbm.70603"><img src="https://openscicode.org/badge/doi/10.1002/hbm.70603.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.