OSCR

Longitudinal changes of choroid plexus volumes and MRI ratios in multiple sclerosis.

Code ↔ Paper

1 match 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 1 match
  1. [1] § Materials and methods › Image processing ↔ KUL_T1T2FLAIRMTR_ratio.sh, lines 733–787 · score 0.65 · linear histogram matching, brain tissue, transformation, template, ratios, masks

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Shell · 998 lines · 44 KB · MPL-2.0 · 1 match

  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

  1. Ruhr University Bochum, St. Josef Hospital, Institute of Neuroradiology, 44791 Bochum, Germany
  2. Ruhr University Bochum, St. Josef Hospital, Department of Neurology, 44791 Bochum, Germany
Institutions: St. Josef-Hospital (Germany); Ruhr University Bochum (Germany)
Journal: Brain communications, volume 8, issue 3, article fcag129
Dates: received 1 September 2025; accepted 17 April 2026; published online 18 April 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1093/braincomms/fcag129 · PMID 42158849 · PMCID PMC13180650 · OpenAlex W7154861551
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: structural MRI / diffusion (modality), human (organism), multiple sclerosis (population), clinical / translational (subfield)
Methods: Statistics
Keywords: multiple sclerosis, brain MRI, choroid plexus, longitudinal, lesions
Topic: Multiple Sclerosis Research Studies (Pathology and Forensic Medicine, Medicine), according to OpenAlex
Citations: not cited yet (Europe PMC); 46 references in the paper

Abstract

This longitudinal study aimed to identify the predictive role of choroid plexus enlargement for disability progression and its association with tissue damage in early multiple sclerosis patients. Forty patients with clinically isolated syndrome or early relapsing–remitting multiple sclerosis underwent brain MRI scanning at baseline, after 2 and after 6–8 years. FreeSurfer segmentation was used for brain volume estimation, and the choroid plexus was segmented by use of an independent automated segmentation tool. MRI ratios (T1 weighted through fluid attenuated inversion recovery image values) were calculated after calibration and subtracting lesion masks. Lesion masks were eroded to obtain both lesion rims and centres, for which mean ratios were extracted in addition to normal-appearing white matter. Expanded Disability Status Scale and disease duration were collected from neurological examination. Between baseline and last follow-up, choroid plexus volumes increased, and MRI ratios in lesions decreased significantly, which was dominated by the decrease in clinically isolated syndrome rather than relapsing–remitting patients and more pronounced in lesion rims than in their centre. Choroid plexus volumes were significantly related to MRI ratios within rims of lesions at baseline and within lesion centres after 6–8 years, but not within normal-appearing white matter. No associations between choroid plexus volumes or ratios and disability were found. We observed longitudinal changes of both choroid plexus enlargement and MRI ratios over 6–8 years in early multiple sclerosis patients. Choroid plexus enlargement seemed involved in the dynamic development of lesion destructivity.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

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

treanus/KUL_NIS

License: MPL-2.0
State: the link answers, verified on 29 September 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: “Data availability”
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: 1 check, the latest on 29 September 2026: the link answers
  • 29 September 2026: the link answers
59 files

Center-of-Imaging-Biomarker-Development/chp_seg

License: none: the authors keep all their rights
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Commit: c00eaa243d7a2e749a254489d3b8c48197f70f5c, 2 June 2025
Size: 1 file, 0 scripts
Software Heritage: not archived
Found in: “Data availability”
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 29 September 2026: the link answers
  • 29 September 2026: the link answers
1 file

The paper's code and data availability statement is in the Data section.

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:

  • 2 repositories 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;
  • 1 match 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

Raw MRI and clinical data cannot be made available due to data protection regulations. The pipeline used for the creation of T1w/FLAIR ratio maps is publicly available at https://github.com/treanus/KUL_NIS. For choroid plexus segmentation, we used a publicly available toolbox (https://github.com/Center-of-Imaging-Biomarker-Development/chp_seg).

Reproduced under the paper's license (CC BY), from the paper cited above.

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, 29 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 9 authors, 5 keywords, 43 references.

Cite

This paper

Krieger, B., Bellenberg, B., Müller, D., Sbaihat, H., Roenneke, A. K., Ladopoulos, T., Schneider, R., Gold, R., & Lukas, C. (2026). Longitudinal changes of choroid plexus volumes and MRI ratios in multiple sclerosis. Brain communications, 8(3), fcag129. https://doi.org/10.1093/braincomms/fcag129

BibTeX

@article{krieger2026longitudinal,
author = {Krieger, Britta and Bellenberg, Barbara and Müller, Dajana and Sbaihat, Hasan and Roenneke, Anna Katharina and Ladopoulos, Theodoros and Schneider, Ruth and Gold, Ralf and Lukas, Carsten},
title = {{Longitudinal changes of choroid plexus volumes and MRI ratios in multiple sclerosis}},
journal = {Brain communications},
year = {2026},
month = apr,
volume = {8},
number = {3},
pages = {fcag129},
publisher = {Oxford University Press},
issn = {2632-1297},
doi = {10.1093/braincomms/fcag129},
url = {https://doi.org/10.1093/braincomms/fcag129},
pmid = {42158849},
pmcid = {PMC13180650}
}

RIS

TY - JOUR
AU - Krieger, Britta
AU - Bellenberg, Barbara
AU - Müller, Dajana
AU - Sbaihat, Hasan
AU - Roenneke, Anna Katharina
AU - Ladopoulos, Theodoros
AU - Schneider, Ruth
AU - Gold, Ralf
AU - Lukas, Carsten
TI - Longitudinal changes of choroid plexus volumes and MRI ratios in multiple sclerosis
T2 - Brain communications
J2 - Brain Commun
PY - 2026
DA - 2026/04/18
VL - 8
IS - 3
SP - fcag129
SN - 2632-1297
PB - Oxford University Press
DO - 10.1093/braincomms/fcag129
UR - https://doi.org/10.1093/braincomms/fcag129
LA - en
ER -

CSL-JSON

{
"id": "10.1093/braincomms/fcag129",
"type": "article-journal",
"title": "Longitudinal changes of choroid plexus volumes and MRI ratios in multiple sclerosis",
"container-title": "Brain communications",
"author": [
{
"family": "Krieger",
"given": "Britta"
},
{
"family": "Bellenberg",
"given": "Barbara"
},
{
"family": "Müller",
"given": "Dajana"
},
{
"family": "Sbaihat",
"given": "Hasan"
},
{
"family": "Roenneke",
"given": "Anna Katharina"
},
{
"family": "Ladopoulos",
"given": "Theodoros"
},
{
"family": "Schneider",
"given": "Ruth"
},
{
"family": "Gold",
"given": "Ralf"
},
{
"family": "Lukas",
"given": "Carsten"
}
],
"container-title-short": "Brain Commun",
"volume": "8",
"issue": "3",
"page": "fcag129",
"DOI": "10.1093/braincomms/fcag129",
"PMID": "42158849",
"PMCID": "PMC13180650",
"ISSN": "2632-1297",
"publisher": "Oxford University Press",
"URL": "https://doi.org/10.1093/braincomms/fcag129",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
18
]
]
}
}

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.1162/imag.a.1252 [code]
Does the brain's E:I balance really shape long-range temporal correlations? Lessons learned from 3T MRI.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: MRIQC, Dcm2Bids, fMRIPrep, 7 other tools, structural MRI / diffusion
[2] doi:10.1162/imag.a.1347 [code]
Neural and behavioural correlates of theory of mind reasoning in five-year-old children born preterm.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: MRIQC, Dcm2Bids, fMRIPrep, 7 other tools
[3] doi:10.1016/j.dcn.2026.101765 [code]
Fusiform face area development correlates with development in higher-order social brain regions.
Journal: Developmental cognitive neuroscience
In common: MRIQC, Dcm2Bids, fMRIPrep, 7 other tools
[4] doi:10.1038/s41467-026-71568-9 [code]
Convergent and selective representations of pain, appetitive processes, aversive processes, and cognitive control in the insula.
Journal: Nature communications
In common: fMRIPrep, MRtrix3, ANTs, 8 other tools
[5] doi:10.1038/s41467-026-71151-2 [code]
Common and distinct neural correlates of social interaction processing and theory of mind in narratives.
Journal: Nature communications
In common: fMRIPrep, MRtrix3, ANTs, 8 other tools
[6] doi:10.1038/s41467-026-71719-y [code]
Brain functional-structural gradient coupling reflects development, behavior and genetic influences.
Journal: Nature communications
In common: Dcm2Bids, MRtrix3, ANTs, 7 other tools
[7] doi:10.1038/s41597-026-07676-4 [code]
A neuroimaging dataset combining movie-watching, eye-tracking, sensorimotor mapping, and cognitive tasks.
Journal: Scientific data
In common: BIDS Validator, FreeSurfer, FSL, 6 other tools, structural MRI / diffusion, 1 reference
[8] doi:10.1038/s41467-026-73668-y [code]
Convergent and divergent brain-cognition development in early adolescence.
Journal: Nature communications
In common: MRtrix3, ANTs, FreeSurfer, 7 other tools
[9] doi:10.1371/journal.pbio.3003856 [code]
Aging and metabolism contribute separately to brain-body health.
Journal: PLoS biology
In common: ANTs, FreeSurfer, FSL, 6 other tools, structural MRI / diffusion, clinical / translational, 1 reference
[10] doi:10.1038/s41467-026-71918-7 [code]
Developmental disinhibition gates language lateralization in childhood.
Journal: Nature communications
In common: MRtrix3, ANTs, FreeSurfer, 6 other tools, 1 reference

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.

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: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

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