User Tools

Site Tools


neuroimagen:bioface_sbm

Analisis SBM con Freesurfer (a.k.a. FSGA) para BIOFACE

Haciendo los archivos

Para construir los archivos .fsgd a partir de la base de datos han de hacerse una serie de pasos. Voy a poner el ejemplo con la variable RLPP. Para cualquier otra variable simplemente se cambia.

[osotolongo@brick03 fsga2]$ sed 's/;/,/g' ../bioface_mri.csv > bioface_join.csv
[osotolongo@brick03 fsga2]$ awk -F"," '{print $3","$5","$6","$7","$21}' ../bioface_np.csv > bioface_rlpp.csv
[osotolongo@brick03 fsga2]$ sed -i 's/Subjecte/PSubject/g' bioface_rlpp.csv
[osotolongo@brick03 fsga2]$ join -t"," -1 2 -2 1 bioface_join.csv bioface_rlpp.csv > bioface_data_rlpp.csv
[osotolongo@brick03 fsga2]$ awk -F"," '{print "bioface_"$2","$3","$4","$5","$6}' bioface_data_rlpp.csv | sed 's/bioface_Subject/Variables/;s/Edad/Age/;s/Sexo/Gender/;s/Años_Estudios/Education/' | sed 's/bioface_\([^,]*\),/Input bioface_\1 Main /; s/,/ /g' > rlpp_body.csv
[osotolongo@brick03 fsga2]$ head rlpp_body.csv
Variables Age Gender Education RLPP
Input bioface_0001 Main 64 1 11 2
Input bioface_0002 Main 53 2 9 10
Input bioface_0003 Main 60 2 8 3
Input bioface_0004 Main 64 2 7 3
Input bioface_0005 Main 62 2 16 7
Input bioface_0006 Main 64 2 5 7
Input bioface_0007 Main 62 2 11 5
Input bioface_0008 Main 58 2 11 8
Input bioface_0009 Main 51 2 11 7
[osotolongo@brick03 fsga2]$ cat headers_rlpp.txt
GroupDescriptorFile 1
Title BIOFACE_rlpp
Class Main
[osotolongo@brick03 fsga2]$ cat headers_rlpp.txt rlpp_body.csv > rlpp.fsgd

y por otra parte el modelo,

[osotolongo@brick03 fsga2]$ cat rlpp.mtx
0 0 0 0 1

Preparando la ejecucion

Ahora voy a hacer un script que corra todo el proceso, para no saltarme ningun paso

[osotolongo@brick03 fsga2]$ cat fsga_rlpp.sh 
#!/bin/bash
mris_preproc --fsgd rlpp.fsgd --cache-in thickness.fwhm10.fsaverage --target fsaverage --hemi lh --out lh.rlpp.thickness.10.mgh
mris_preproc --fsgd rlpp.fsgd --cache-in thickness.fwhm10.fsaverage --target fsaverage --hemi rh --out rh.rlpp.thickness.10.mgh
mri_glmfit --y lh.rlpp.thickness.10.mgh --fsgd rlpp.fsgd --C rlpp.mtx --surf fsaverage lh --glmdir lh.rlpp.glmdir
mri_glmfit --y rh.rlpp.thickness.10.mgh --fsgd rlpp.fsgd --C rlpp.mtx --surf fsaverage rh --glmdir rh.rlpp.glmdir
mri_glmfit-sim --glmdir lh.rlpp.glmdir --cache 2 neg --cwp 0.05 --2spaces
mri_glmfit-sim --glmdir lh.rlpp.glmdir --cache 2 pos --cwp 0.05 --2spaces
mri_glmfit-sim --glmdir rh.rlpp.glmdir --cache 2 neg --cwp 0.05 --2spaces
mri_glmfit-sim --glmdir rh.rlpp.glmdir --cache 2 pos --cwp 0.05 --2spaces

y se lanza todo con,

[osotolongo@brick03 fsga2]$ ./fsga_rlpp.sh

Buscando resultados

Para encontrar los clusters hacemos,

[osotolongo@brick03 fsga2]$ for x in `find ./ -name "*.summary"`; do echo ${x}; grep -v "^#" ${x}; done
./lh.rlpn.glmdir/rlpn/cache.th20.neg.sig.cluster.summary
./lh.rlpn.glmdir/rlpn/cache.th20.pos.sig.cluster.summary
./lh.rlpp.glmdir/rlpp/cache.th20.neg.sig.cluster.summary
./lh.rlpp.glmdir/rlpp/cache.th20.pos.sig.cluster.summary
   1        3.519  112413   3477.26    -18.5  -75.6   28.2  0.00020  0.00000  0.00040   6595    15036.07  precuneus
   2        3.947  157071   2138.53    -58.6  -51.1    1.7  0.00020  0.00000  0.00040   4377    10588.38  bankssts
   3        4.314   99360   1135.62    -44.3    7.6    5.7  0.00878  0.00719  0.01057   2749     7526.91  parsopercularis
./rh.rlpn.glmdir/rlpn/cache.th20.neg.sig.cluster.summary
./rh.rlpn.glmdir/rlpn/cache.th20.pos.sig.cluster.summary
./rh.rlpp.glmdir/rlpp/cache.th20.neg.sig.cluster.summary
./rh.rlpp.glmdir/rlpp/cache.th20.pos.sig.cluster.summary
   1        4.982  104537   7071.55     46.5  -57.5   23.1  0.00020  0.00000  0.00040  14015    35733.48  inferiorparietal
   2        3.430   29029   2647.45     27.8   19.3   42.7  0.00020  0.00000  0.00040   5370    11735.45  caudalmiddlefrontal
   3        4.229   45003   1848.86     12.5  -52.8   30.8  0.00020  0.00000  0.00040   4269    10182.11  precuneus
   4        2.481  143807   1116.95     30.5  -49.7  -13.8  0.01276  0.01077  0.01475   2172     4473.95  fusiform

Ahora, en el hemisferio/modelo que hemos encontrado resultados podemos identificar estos clusters con,

$ freeview -f $SUBJECTS_DIR/fsaverage/surf/rh.inflated:overlay=rh.rlpp.glmdir/rlpp/cache.th20.pos.sig.cluster.mgh:overlay_threshold=0.1,5:annot=rh.rlpp.glmdir/rlpp/cache.th20.pos.sig.ocn.annot -viewport 3d &

Para superponer el atlas DK,

$ freeview -f $SUBJECTS_DIR/fsaverage/surf/rh.inflated:overlay=rh.rlpp.glmdir/rlpp/cache.th20.pos.sig.cluster.mgh:overlay_threshold=0.1,5:annot=aparc.annot:annot_outline=1 -viewport 3d &

y para ver las areas de Brodman afectadas,

$ freeview -f $SUBJECTS_DIR/fsaverage/surf/rh.inflated:overlay=rh.rlpp.glmdir/rlpp/cache.th20.pos.sig.cluster.mgh:overlay_threshold=0.1,5:annot=PALS_B12_Brodmann.annot:annot_outline=1 -viewport 3d &

Cambiando a Volumen

Para area y/o otra variable es los mismo, con un solo ejemplo ya la idea la tenemos. Hay que hacer las 9 combinaciones pero no deberia tomar demasiado.

Extraer ICV

[osotolongo@brick03 fsga]$ awk -F"," '{print $1","$67}' ../fsrecon/aseg_stats.csv > bioface_icv.csv
[osotolongo@brick03 fsga]$ head bioface_icv.csv
Subject,EstimatedTotalIntraCranialVol
0001,1486505.98285
0002,1249118.11926
0003,1333969.51364
0004,1344500.90389
0005,1408317.34379
0006,1321218.04232
0007,1501903.59123
0008,1480617.98715
0009,1368664.47062
[osotolongo@brick03 fsga]$ cat convert_icv.r
setwd("/nas/data/bioface/fsga")
read.csv("bioface_icv.csv") -> x
x$zICV <- (x$EstimatedTotalIntraCranialVol - mean(x$EstimatedTotalIntraCranialVol))/sd(x$EstimatedTotalIntraCranialVol)
write.csv(x, file="bioface_zic_tempv.csv", row.names=FALSE)
[osotolongo@brick03 fsga]$ Rscript convert_icv.r 
[osotolongo@brick03 fsga]$ head bioface_zic_tempv.csv
"Subject","EstimatedTotalIntraCranialVol","zICV"
1,1486505.98285,0.41844790218558
2,1249118.11926,-1.20476544891787
3,1333969.51364,-0.624567648851558
4,1344500.90389,-0.552555992480593
5,1408317.34379,-0.116191236089841
6,1321218.04232,-0.711759800041669
7,1501903.59123,0.523733838540968
8,1480617.98715,0.378186900266852
9,1368664.47062,-0.387330089465778
[osotolongo@brick03 fsga]$ awk -F"," '{$1 = sprintf("%04d",$1); print $1","$3}' bioface_zic_tempv.csv | sed 's/"//g;s/0000/Subject/' > bioface_zicv.csv
[osotolongo@brick03 fsga]$ head bioface_zicv.csv
Subject,zICV
0001,0.41844790218558
0002,-1.20476544891787
0003,-0.624567648851558
0004,-0.552555992480593
0005,-0.116191236089841
0006,-0.711759800041669
0007,0.523733838540968
0008,0.378186900266852
0009,-0.387330089465778

Integrando con los datos

[osotolongo@brick03 fsga]$ join -t"," -1 2 -2 1 bioface_data.csv bioface_zicv.csv > bioface_vdata.csv
[osotolongo@brick03 fsga]$ head bioface_vdata.csv
Subject,PSubject,Edad,Sexo,Estudios,FACEmem,zICV
0001,B001,64,1,11,13,0.41844790218558
0002,B002,53,2,9,48,-1.20476544891787
0003,B003,60,2,8,10,-0.624567648851558
0004,B004,64,2,7,21,-0.552555992480593
0005,B005,62,2,16,30,-0.116191236089841
0006,B006,64,2,5,25,-0.711759800041669
0007,B007,62,2,11,39,0.523733838540968
0008,B008,58,2,11,45,0.378186900266852
0009,B009,51,2,11,28,-0.387330089465778
[osotolongo@brick03 fsga]$ awk -F"," '{print "bioface_"$1","$3","$4","$5","$6","$7}' bioface_vdata.csv | sed 's/bioface_Subject/Variables/;s/Edad/Age/;s/Sexo/Gender/;s/Estudios/Education/' | sed 's/bioface_\([^,]*\),/Input bioface_\1 Main /; s/,/ /g' > memv_body.csv
[osotolongo@brick03 fsga]$ head memv_body.csv
Variables Age Gender Education FACEmem zICV
Input bioface_0001 Main 64 1 11 13 0.41844790218558
Input bioface_0002 Main 53 2 9 48 -1.20476544891787
Input bioface_0003 Main 60 2 8 10 -0.624567648851558
Input bioface_0004 Main 64 2 7 21 -0.552555992480593
Input bioface_0005 Main 62 2 16 30 -0.116191236089841
Input bioface_0006 Main 64 2 5 25 -0.711759800041669
Input bioface_0007 Main 62 2 11 39 0.523733838540968
Input bioface_0008 Main 58 2 11 45 0.378186900266852
Input bioface_0009 Main 51 2 11 28 -0.387330089465778
[osotolongo@brick03 fsga]$ cat headers.txt
GroupDescriptorFile 1
Title BIOFACE_mem
Class Main
[osotolongo@brick03 fsga]$ cat headers.txt memv_body.csv > memv.fsgd
[osotolongo@brick03 fsga]$ head memv.fsgd
GroupDescriptorFile 1
Title BIOFACE_mem
Class Main
Variables Age Gender Education FACEmem zICV
Input bioface_0001 Main 64 1 11 13 0.41844790218558
Input bioface_0002 Main 53 2 9 48 -1.20476544891787
Input bioface_0003 Main 60 2 8 10 -0.624567648851558
Input bioface_0004 Main 64 2 7 21 -0.552555992480593
Input bioface_0005 Main 62 2 16 30 -0.116191236089841
Input bioface_0006 Main 64 2 5 25 -0.711759800041669

Preparando el run

[osotolongo@brick03 fsga]$ cat memv.mtx
0 0 0 0 1 0
fsgav.sh
#!/bin/bash
mris_preproc --fsgd memv.fsgd --cache-in volume.fwhm10.fsaverage --target fsaverage --hemi lh --out lh.bioface.volume.10.mgh
mris_preproc --fsgd memv.fsgd --cache-in volume.fwhm10.fsaverage --target fsaverage --hemi rh --out rh.bioface.volume.10.mgh
mri_glmfit --y lh.bioface.volume.10.mgh --fsgd memv.fsgd --C memv.mtx --surf fsaverage lh --glmdir lh.bioface.vglmdir
mri_glmfit --y rh.bioface.volume.10.mgh --fsgd memv.fsgd --C memv.mtx --surf fsaverage rh --glmdir rh.bioface.vglmdir
mri_glmfit-sim --glmdir lh.bioface.vglmdir --cache 2 neg --cwp 0.05 --2spaces
mri_glmfit-sim --glmdir lh.bioface.vglmdir --cache 2 pos --cwp 0.05 --2spaces
mri_glmfit-sim --glmdir rh.bioface.vglmdir --cache 2 neg --cwp 0.05 --2spaces
mri_glmfit-sim --glmdir rh.bioface.vglmdir --cache 2 pos --cwp 0.05 --2spaces

Sacar resultados

Ahora,

$ ./fsgav.sh

y buscamos los resultados,

[osotolongo@brick03 fsga]$ for x in `find *vglmdir/memv/ -name "*.th20.*.summary"`; do echo ${x}; grep -v "^#" ${x}; done
lh.bioface.vglmdir/memv/cache.th20.neg.sig.cluster.summary
lh.bioface.vglmdir/memv/cache.th20.pos.sig.cluster.summary
   1        3.959   79787    828.17    -32.6  -76.7  -11.8  0.00180  0.00100  0.00260   1178     3049.31  fusiform
   2        2.513   56552    625.22    -47.9  -26.0  -10.1  0.01574  0.01355  0.01792   1292     2610.65  middletemporal
rh.bioface.vglmdir/memv/cache.th20.neg.sig.cluster.summary
rh.bioface.vglmdir/memv/cache.th20.pos.sig.cluster.summary
   1        5.991   47819    954.75     45.3  -50.6   24.1  0.00060  0.00020  0.00100   2214     6368.82  inferiorparietal
   2        3.719    5713    674.59     54.4    3.4  -15.3  0.01157  0.00958  0.01355   1372     3261.33  superiortemporal

;-)

neuroimagen/bioface_sbm.txt · Last modified: 2021/07/05 10:04 by osotolongo