[osotolongo@brick03 f5cehbi]$ singularity run --cleanenv -B /nas:/nas -B /old_nas/f5cehbi/output:/output -B /old_nas/f5cehbi/input:/input /nas/usr/local/opt/singularity/pgs.simg sh /WMHs_segmentation_PGS.sh sub-0020_T1w.nii.gz sub-0020_T2w.nii.gz sub-0020_WMH.nii.gz Step 1 of 9: reading in images...Done! It took roughly 1 seconds Step 2 of 9: registration... 2a) Similarity transform... 2b) Affine transform... 2c) Resampling volume... Registration done! It took roughly 6 seconds Step 3 of 9: rough bias field correction...Done! It took roughly 6 seconds Step 4 of 9: calculating features...Done! It took roughly 28 seconds Step 5 of 9: voxel classification...Done! It took roughly 17 seconds Step 6 of 9: fitting the shape model...Done! It took roughly 6 seconds Step 7 of 9: free deformation...Done! It took roughly 1 seconds Step 8 of 9: building volume from mesh...Done! It took roughly 3 seconds Step 9 of 9: warping back to original space...Done! It took roughly 0 seconds Output ready The whole process took roughly 68 seconds Freeing memory and deleting temporary files... Traceback (most recent call last): File "/WMHs_segmentation_PGS.py", line 89, in <module> FLAIR_bet_data = FLAIR_data*T1_bet_mask_data ValueError: operands could not be broadcast together with shapes (176,252,256) (176,256,256)
[osotolongo@brick03 f5cehbi]$ fslinfo output/sub-0020_T1w.nii.gz data_type INT16 dim1 176 dim2 256 dim3 256 dim4 1 datatype 4 pixdim1 1.000000 pixdim2 0.976562 pixdim3 0.976562 pixdim4 2.200000 cal_max 0.0000 cal_min 0.0000 file_type NIFTI-1+ [osotolongo@brick03 f5cehbi]$ fslinfo output/sub-0020_T2w.nii.gz data_type INT16 dim1 176 dim2 252 dim3 256 dim4 1 datatype 4 pixdim1 1.000000 pixdim2 1.015625 pixdim3 1.015625 pixdim4 5.000000 cal_max 0.0000 cal_min 0.0000 file_type NIFTI-1+
Nota: Registrar T2 a T1 primero!
[osotolongo@brick03 f5cehbi]$ antsRegistrationSyNQuick.sh -d 3 -t a -f input/pre/sub-0020_T1w.nii.gz -m input/pre/sub-0020_T2w.nii.gz -o input/pre/t2tot1_ | tee t2tot1Output.txt ... ... ... [osotolongo@brick03 f5cehbi]$ antsApplyTransforms -d 3 -i input/pre/sub-0020_T2w.nii.gz -r input/pre/sub-0020_T1w.nii.gz -t input/pre/t2tot1_0GenericAffine.mat -o input/pre/sub-0020_T2w_resampled.nii.gz [osotolongo@brick03 f5cehbi]$ ls input/pre/ sub-0020_T1w.nii.gz sub-0020_T2w_resampled.nii.gz t2tot1_InverseWarped.nii.gz sub-0020_T2w.nii.gz t2tot1_0GenericAffine.mat t2tot1_Warped.nii.gz
Ahora si,
[osotolongo@brick03 f5cehbi]$ singularity run --cleanenv -B /nas:/nas -B /old_nas/f5cehbi/output:/output -B /old_nas/f5cehbi/input:/input /nas/usr/local/opt/singularity/pgs.simg sh /WMHs_segmentation_PGS.sh sub-0020_T1w.nii.gz sub-0020_T2w_resampled.nii.gz sub-0020_WMH.nii.gz
This is a highly massive computation, Dont take it lightly!
but results are amazing,
[osotolongo@brick05 f5cehbi]$ fslstats output/sub-0020_WMH.nii.gz -V 2353 2243.995605
Primero hay que sacar las iamgenes de WMH para el proyecto,
https://github.com/asqwerty666/acenip/blob/main/bin/wmh.pl
y luego las metricas de cada imagen,
https://github.com/asqwerty666/acenip/blob/main/bin/wmh_metrics.pl
Para cada proyecto,
[osotolongo@brick03 facehbi]$ xnatapic list_subjects --project_id facehbi --label > xnat_subjects.list [osotolongo@brick03 facehbi]$ for x in `awk -F"," '{print $2}' xnat_subjects.list`; do e=$(xnatapic list_experiments --project_id facehbi --subject_id ${x} --modality MRI --label); echo "${x},${e}"; done > xnat_sub_exp.list [osotolongo@brick03 facehbi]$ for l in `cat xnat_sub_exp.list`; do s=$(echo ${l} | awk -F"," '{print $1}'); e=$(echo ${l} | awk -F"," '{print $2}'); mkdir -p fsresults/${s}; xnatapic get_fsresults --experiment_id ${e} --stats aseg fsresults/${s}/; done [osotolongo@brick03 facehbi]$ for x in `ls fsresults/*/aseg.stats`; do s=$(echo ${x} | awk -F"/" '{print $2}'); v=$(grep " WM-hypointensities" ${x} | awk '{print $4}'); echo "${s},${v}"; done | sed '1iPSubject,WM-hypointensities' > fswmh_results.csv [osotolongo@brick03 facehbi]$ sed 's/;/,/g' facehbi_mri.csv | sed '1iSubject,PSubject' > joiner.csv [osotolongo@brick03 facehbi]$ wmh_metrics.pl facehbi [osotolongo@brick03 facehbi]$ join -t"," joiner.csv facehbi_wmh_metrics.csv | awk -F"," '{print $2","$3}' > pgs_wmh.csv [osotolongo@brick03 facehbi]$ (head -n 1 pgs_wmh.csv; tail -n +2 pgs_wmh.csv | sort -t",") > pgs_wmh_sorted.csv [osotolongo@brick03 facehbi]$ join -t"," fswmh_results.csv pgs_wmh_sorted.csv > compare.csv [osotolongo@brick03 facehbi]$ head compare.csv
y despues se pegan,
[osotolongo@brick03 f5cehbi]$ cat compare.csv /old_nas/facehbi/compare.csv | grep -v PSubject | sed '1iPSubject,WM-hypointensities,WMH' > compare_v05.csv
y el script en R hace el plot,
w <- read.csv("compare_v05.csv") wl <- lm(w$WMH ~ w$WM.hypointensities) pwl <- summary(wl) postscript("wmh_comparing.ps", width=1024, height=600, bg="white") plot(w$WM.hypointensities, w$WMH, main="WMH comparison pgs VS FS", xlab="Freesurfer WMH", ylab="pgs WMH", pch=15, col="blue") abline(wl$coefficients[1],wl$coefficients[2],col="red",lwd=3) text(2500,25000, bquote(R^2 == .(round(pwl$adj.r.squared, digits=3))), cex=2) dev.off()
Poniendo las tres visitas de FACEHBI ($n \sim 550$) juntas tenemos algo asi,
Nota: El T1 original no se registra bien a espacio MNI (o viceversa). Hay que usar el T1 preprocesado de FS.
[osotolongo@brick03 output]$ mri_convert --in_type mgz --out_type nii --conform /old_nas/subjects/bioface_0020/mri/T1.mgz 0020_tmp.nii.gz [osotolongo@brick03 output]$ fslreorient2std 0020_tmp 0020_struct [osotolongo@brick03 output]$ antsRegistrationSyNQuick.sh -d 3 -t s -f 0020_struct.nii.gz -m /old_nas/bioface/bids/sub-0020/anat/sub-0020_T1w.nii.gz -o 00020_T12struct_warp_ [osotolongo@brick03 output]$ antsRegistrationSyNQuick.sh -d 3 -t s -f 0020_struct.nii.gz -m /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz -o 00020_MNI2struct_warp_ [osotolongo@brick03 output]$ antsApplyTransforms -d 3 -i 0020_WMH.nii.gz -r 0020_struct.nii.gz -t 00020_T12struct_warp_1Warp.nii.gz -t 00020_T12struct_warp_0GenericAffine.mat -n GenericLabel -o 0020_WMH_in_struct.nii.gz [osotolongo@brick03 output]$ antsApplyTransforms -d 3 -i /usr/local/fsl/data/atlases/JHU/JHU-ICBM-labels-1mm.nii.gz -r 0020_struct.nii.gz -t 00020_MNI2struct_warp_1Warp.nii.gz -t 00020_MNI2struct_warp_0GenericAffine.mat -n GenericLabel -o 0020_labels_in_struct.nii.gz