This shows you the differences between two versions of the page.
neuroimagen:facehbi [2019/06/07 09:04] osotolongo [Integrar fechas con datos] |
neuroimagen:facehbi [2020/08/04 10:58] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Problemas y soluciones comunes relativas al proyecto FACEHBI ====== | ||
- | |||
- | ===== procesamiento paulatino ====== | ||
- | |||
- | ==== MRI ==== | ||
- | === to NiFTI === | ||
- | Las imagenes van llegando poco a poco y se han de ir procesando paulatinamente. Lo primero es saber cual de las imagenes que han subido no han sido procesadas, | ||
- | |||
- | < | ||
- | $ ls / | ||
- | $ sed ' | ||
- | $ ls / | ||
- | $ grep -v "`cat mri_hechos.dir`" | ||
- | $ for a in `cat yet.dir`; do for x in -d / | ||
- | $ sed ' | ||
- | $ sed ' | ||
- | $ cat / | ||
- | $ for a in `ls processed/ | ||
- | $ pfsl2fs.pl -cut wave2_mri.csv facehbi | ||
- | </ | ||
- | |||
- | ++++ DELETEME | | ||
- | Ya las tengo en el archivo //yet.txt// Ahora las copio en otro sitio (// al que no tenga acceso el que las sube //) y las proceso. | ||
- | |||
- | < | ||
- | $ for a in `cat yet.txt`; do cp -r / | ||
- | $ for a in `cat yet.txt`; do for x in -d / | ||
- | </ | ||
- | |||
- | | ||
- | <code bash> | ||
- | $ ls -d data/ | ||
- | $ ls -d / | ||
- | $ grep -v "`cat ~/ | ||
- | </ | ||
- | |||
- | Ahora viene la parte jodida. He de copiar las imagenes correctamente segun la nomenclatura del procesamiento. < | ||
- | |||
- | Una a una seria asi, | ||
- | |||
- | < | ||
- | $ cp processed/ | ||
- | </ | ||
- | |||
- | **Esto se puede mejorar!!!** | ||
- | |||
- | < | ||
- | $ for a in `ls processed/ | ||
- | </ | ||
- | |||
- | === to Freesurfer === | ||
- | |||
- | Ahora tengo que convertir el archivo //yet.txt// en una lista que entienda el pipeline. | ||
- | |||
- | < | ||
- | $ sed ' | ||
- | </ | ||
- | |||
- | **He modificado el script // | ||
- | |||
- | < | ||
- | $ pfsl2fs.pl -cut wave2_mri.csv facehbi | ||
- | </ | ||
- | |||
- | No se ha de olvidar el incluir las iamgenes nuevas en el listado del estudio | ||
- | |||
- | < | ||
- | $ mv facehbi.csv wave1_mri.csv | ||
- | $ cat wave1_mri.csv wave2_mri.csv > facehbi.csv | ||
- | </ | ||
- | |||
- | ++++ | ||
- | |||
- | Ahora ya se podria procesar con Freesurfer | ||
- | |||
- | < | ||
- | $ precon.pl -cut wave2_mri.csv facehbi | ||
- | </ | ||
- | ==== DTI ==== | ||
- | |||
- | === to NiFTI === | ||
- | <code bash> | ||
- | $ for a in `ls / | ||
- | $ cd / | ||
- | $ for x in `find processed/ -name " | ||
- | </ | ||
- | |||
- | |||
- | === Procesamiento === | ||
- | <code bash> | ||
- | $ cat acqparams.txt | ||
- | 0 1 0 0.12192 | ||
- | 0 -1 0 0.12192 | ||
- | |||
- | $ indx="" | ||
- | $ for ((i=1; i<=143; i+=1)); do indx=" | ||
- | $ echo $indx > dti_index.txt | ||
- | |||
- | $ dti_reg.pl -nocorr facehbi | ||
- | |||
- | $ dti_metrics.pl facehbi | ||
- | $ dti_metrics.pl -a1 facehbi | ||
- | $ dti_metrics_custom.pl -uofm SN facehbi | ||
- | $ dti_metrics_custom.pl -uofm SN_anterior facehbi | ||
- | |||
- | $ dti_track.pl -uofm DMN facehbi | ||
- | $ for x in `ls -d working/ | ||
- | $ dti_metrics_alt.pl -path DMN facehbi | ||
- | </ | ||
- | ==== FBB ==== | ||
- | {{ : | ||
- | === to NiFTI === | ||
- | |||
- | Para ir procesando según vayan llegando las imágenes, | ||
- | |||
- | <code bash> | ||
- | $ cp -ru clinic/* raw_images/ | ||
- | $ ls raw_images/ | ||
- | $ grep -v "`cat facehbi/ | ||
- | $ grep -v "`cat facehbi/ | ||
- | $ sed ' | ||
- | $ sed ' | ||
- | </ | ||
- | |||
- | //Otro ejemplo puede ser, si ya tengo hecho un pedazo, ¿Como saco de las que no he procesado?// | ||
- | |||
- | <code bash> | ||
- | $ ls / | ||
- | $ awk -F";" | ||
- | $ grep -v "`cat hechos.txt`" | ||
- | </ | ||
- | ===== Problemas de almacenamiento y conversión de las imagenes ====== | ||
- | DELETEME | ||
- | |||
- | Los DICOM llegan en carpetas de hasta 500 imagenes DICOM. Esto quiere decir que hay que copiar previamente todas las imagenes que queremos convertir a una misma carpeta y a partir de ahi es que se convierten. | ||
- | |||
- | Si tenemos un archivo txt (// | ||
- | |||
- | <code bash> | ||
- | $ for x in `awk -F";" | ||
- | </ | ||
- | DELETEME | ||
- | |||
- | [[neuroimagen: | ||
- | |||
- | ===== Datos demograficos ===== | ||
- | |||
- | lo que sale del omi es una mierda y hay que convertirlo en algo potable: | ||
- | <code bash> | ||
- | $ awk -F"," | ||
- | </ | ||
- | |||
- | y sacamos la edad de la fecha de nacimiento y la del screening | ||
- | |||
- | <code perl > | ||
- | # | ||
- | |||
- | use strict; | ||
- | use warnings; | ||
- | use utf8; | ||
- | use Date:: | ||
- | use Math:: | ||
- | |||
- | my $ifile = shift; | ||
- | my $heads; | ||
- | open IDF, "< | ||
- | while(< | ||
- | if(/ | ||
- | print " | ||
- | } | ||
- | if(my ($nodate, $date1, $date2) = /(\d{4}, \d+, \d{1,2}), (\d+-\d+-\d+), | ||
- | my $age = nearest(0.1, | ||
- | print " | ||
- | } | ||
- | } | ||
- | close IDF; | ||
- | </ | ||
- | |||
- | ===== Extract image date ===== | ||
- | ==== MRI ==== | ||
- | First approach, | ||
- | |||
- | < | ||
- | [osotolongo@detritus facehbi]$ for y in / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | ....... | ||
- | </ | ||
- | Vamos a ordenarlo un poco, | ||
- | |||
- | < | ||
- | [osotolongo@detritus facehbi]$ for y in / | ||
- | </ | ||
- | |||
- | O mas rapido, | ||
- | DELETEME | ||
- | < | ||
- | [osotolongo@detritus facehbi]$ for y in / | ||
- | </ | ||
- | |||
- | **Cuidado que en la visita 2 hay algunas adquisiciones de la visita 0**. | ||
- | |||
- | < | ||
- | [osotolongo@detritus corachan]$ for y in / | ||
- | ..... | ||
- | / | ||
- | / | ||
- | ...... | ||
- | </ | ||
- | |||
- | Vamos a darle una vuelta, | ||
- | < | ||
- | [osotolongo@detritus corachan]$ for y in / | ||
- | </ | ||
- | |||
- | y voy a hacer un script en perl para que escoja el que tenga la fecha mas alta, | ||
- | <code perl clean_pre_date.pl> | ||
- | # | ||
- | |||
- | use strict; | ||
- | use warnings; | ||
- | |||
- | my $ifile = '/ | ||
- | my $ofile = '/ | ||
- | my %imgdates; | ||
- | |||
- | open IDF, "< | ||
- | while (< | ||
- | (my $subject, my $imdate) = / | ||
- | if (exists($imgdates{$subject})){ | ||
- | $imgdates{$subject} = $imdate unless ($imgdates{$subject} > $imdate); | ||
- | }else{ | ||
- | $imgdates{$subject} = $imdate; | ||
- | } | ||
- | } | ||
- | close IDF; | ||
- | open ODF, "> | ||
- | foreach my $subject (sort keys %imgdates){ | ||
- | print ODF " | ||
- | } | ||
- | close ODF; | ||
- | </ | ||
- | |||
- | A ver ahora, | ||
- | < | ||
- | [osotolongo@detritus facehbi]$ ./ | ||
- | [osotolongo@detritus facehbi]$ grep " | ||
- | 0171; | ||
- | </ | ||
- | |||
- | Parece que funciona. | ||
- | |||
- | === Encontrar los directorios erroneos en la V2 === | ||
- | |||
- | Primero lista de los directorios y fecha de los DCM, | ||
- | <code bash> | ||
- | [osotolongo@detritus facehbi_2]$ for y in / | ||
- | [osotolongo@detritus facehbi_2]$ head / | ||
- | 0001; | ||
- | 0002; | ||
- | 0003; | ||
- | 0005; | ||
- | 0006; | ||
- | 0007; | ||
- | 0008; | ||
- | 0009; | ||
- | 0010; | ||
- | 0011; | ||
- | </ | ||
- | |||
- | hago un script para escoger los de menor fecha, | ||
- | <code perl find_bad_guys.pl> | ||
- | # | ||
- | |||
- | use strict; | ||
- | use warnings; | ||
- | |||
- | my $ifile = '/ | ||
- | my %imgdates; | ||
- | |||
- | open IDF, "< | ||
- | while (< | ||
- | (my $subject, my $imdate, my $imdir) = / | ||
- | if (exists($imgdates{$subject}) && exists($imgdates{$subject}{' | ||
- | if ($imgdates{$subject}{' | ||
- | print " | ||
- | }else{ | ||
- | print " | ||
- | $imgdates{$subject}{' | ||
- | $imgdates{$subject}{' | ||
- | } | ||
- | }else{ | ||
- | $imgdates{$subject}{' | ||
- | $imgdates{$subject}{' | ||
- | } | ||
- | } | ||
- | close IDF; | ||
- | </ | ||
- | |||
- | Y vamos a comprobar cuantos directorios repetidos o de otra visita hay, | ||
- | |||
- | <code bash> | ||
- | [osotolongo@detritus facehbi]$ ./ | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | </ | ||
- | 8-O | ||
- | |||
- | Lo he escrito con la fecha para que me sirva de guia pero en fin, | ||
- | |||
- | <code bash> | ||
- | [osotolongo@detritus facehbi]$ ./ | ||
- | [osotolongo@detritus facehbi]$ su - | ||
- | Password: | ||
- | [root@detritus ~]# cd / | ||
- | [root@detritus facehbi_2]# mkdir badguys | ||
- | [root@detritus facehbi_2]# for x in `cat / | ||
- | [root@detritus facehbi_2]# ls badguys/ | ||
- | F122_._._(1D17105595) | ||
- | F134_._._(1D15001121) | ||
- | F135_._._(1D15004700) | ||
- | F164_._(1D15028382) | ||
- | |||
- | </ | ||
- | |||
- | **Y ahora viene lo bueno pues hay que arreglar y/o rehacer toda la visita 2 por los posibles errores producto de esto.** | ||
- | |||
- | ==== FBB ==== | ||
- | one random file by subject, | ||
- | |||
- | < | ||
- | [osotolongo@detritus facehbi]$ find / | ||
- | / | ||
- | </ | ||
- | |||
- | ahora, | ||
- | |||
- | < | ||
- | [osotolongo@detritus facehbi]$ for y in / | ||
- | [osotolongo@detritus facehbi]$ for y in / | ||
- | </ | ||
- | |||
- | Parece raro pero dado el poco consistente formato de los archivos hay que cambiar las ordenes para cada directorio. | ||
- | |||
- | ==== Pegando ==== | ||
- | |||
- | Las fechas quedan ahora en cuatro archivos, | ||
- | |||
- | <code bash> | ||
- | [osotolongo@detritus facehbi]$ ls -l dicom_* | ||
- | -rw-rw---- 1 osotolongo osotolongo 2800 May 20 10:06 dicom_fbb_v0_date.csv | ||
- | -rw-rw---- 1 osotolongo osotolongo 2786 May 20 10:14 dicom_fbb_v2_date.csv | ||
- | -rw-rw---- 1 osotolongo osotolongo 2884 May 18 14:59 dicom_mri_v0_date.csv | ||
- | -rw-rw---- 1 osotolongo osotolongo 3262 May 20 10:02 dicom_mri_v2_date.csv | ||
- | </ | ||
- | |||
- | Voy a hacer un parser para juntar todo, | ||
- | <code perl date_parser.pl> | ||
- | # | ||
- | # | ||
- | #use strict; | ||
- | #use warnings; | ||
- | |||
- | my %fdates = ( FBBv0 => " | ||
- | FBBv2 => " | ||
- | MRIv0 => " | ||
- | MRIv2 => " | ||
- | ); | ||
- | |||
- | my $fdpath = '/ | ||
- | my %imgdates; | ||
- | |||
- | foreach my $fdate (sort keys %fdates){ | ||
- | $real_file = $fdpath.$fdates{$fdate}; | ||
- | open IDF, "< | ||
- | while(< | ||
- | (my $subject, my $imdate) = / | ||
- | $imgdates{$subject}{$fdate} = $imdate; | ||
- | } | ||
- | close IDF; | ||
- | } | ||
- | print " | ||
- | foreach my $fdate (sort keys %fdates){ | ||
- | print ", $fdate"; | ||
- | } | ||
- | print " | ||
- | foreach my $subject (sort keys %imgdates){ | ||
- | print " | ||
- | foreach my $fdate (sort keys %fdates){ | ||
- | if (exists($imgdates{$subject}{$fdate})){ | ||
- | print ", $imgdates{$subject}{$fdate}"; | ||
- | }else{ | ||
- | print ", -"; | ||
- | } | ||
- | } | ||
- | print " | ||
- | } | ||
- | </ | ||
- | y ahi va, | ||
- | <code bash> | ||
- | [osotolongo@detritus facehbi]$ ./ | ||
- | [osotolongo@detritus facehbi]$ head dicom_dates.csv | ||
- | Subject, FBBv0, FBBv2, MRIv0, MRIv2 | ||
- | 0001, 20141211, 20170126, 20141205, 20170124 | ||
- | 0002, 20141211, 20170420, 20141205, 20170323 | ||
- | 0003, 20141218, 20170126, 20141211, 20170123 | ||
- | 0004, 20141218, -, 20141212, - | ||
- | 0005, 20150122, 20170202, 20150107, 20170123 | ||
- | 0006, 20150115, 20170126, 20141223, 20170124 | ||
- | 0007, 20150115, 20170126, 20141219, 20170120 | ||
- | 0008, 20150115, 20170202, 20141220, 20170125 | ||
- | 0009, 20150129, 20170216, 20150110, 20170207 | ||
- | |||
- | </ | ||
- | |||
- | |||
- | |||
- | ==== Integrar fechas con datos ==== | ||
- | <code perl join_conv.pl> | ||
- | # | ||
- | |||
- | use strict; | ||
- | use warnings; | ||
- | use Data::Dump qw(dump); | ||
- | |||
- | my %fdates = ( FBBv0 => " | ||
- | FBBv2 => " | ||
- | MRIv0 => " | ||
- | MRIv2 => " | ||
- | ); | ||
- | |||
- | my %ofiles = ( FBBv0 => " | ||
- | FBBv2 => " | ||
- | MRIv0 => " | ||
- | MRIv2 => " | ||
- | ); | ||
- | |||
- | my $info_file = " | ||
- | my %internos; | ||
- | |||
- | open IIF, "< | ||
- | while(< | ||
- | if(/ | ||
- | (my $fnumber, my $inumber) = / | ||
- | $internos{$fnumber} = $inumber; | ||
- | } | ||
- | } | ||
- | close IIF; | ||
- | |||
- | my %dates; | ||
- | foreach my $fdate (sort keys %fdates){ | ||
- | open IDF, "< | ||
- | while(< | ||
- | if(/ | ||
- | (my $fnumber, my $date) = / | ||
- | (my $cdate = $date) =~ s/ | ||
- | $dates{$fnumber}{$fdate} = $cdate; | ||
- | } | ||
- | } | ||
- | close IDF; | ||
- | open ODF, "> | ||
- | print ODF " | ||
- | foreach my $fnumber (sort keys %internos){ | ||
- | print ODF " | ||
- | if (exists $internos{$fnumber}){ | ||
- | print ODF " | ||
- | if (exists($dates{$fnumber}) && exists($dates{$fnumber}{$fdate})){ | ||
- | print ODF " | ||
- | }else{ | ||
- | print ODF " | ||
- | } | ||
- | } | ||
- | } | ||
- | close ODF; | ||
- | } | ||
- | | ||
- | </ | ||
- | < | ||
- | osotolongo@daisy: | ||
- | facehbi_mri.csv | ||
- | osotolongo@daisy: | ||
- | osotolongo@daisy: | ||
- | </ | ||
- | |||
- | jodido problemas de permisos m( | ||
- | |||
- | ===== Reprocesamiento ===== | ||
- | |||
- | Primero reconvertir los que estan mal, borrar los directorios de FS, crearlos de nuevo y recalcular FS. | ||
- | |||
- | < | ||
- | [osotolongo@detritus facehbi]$ awk -F"/" | ||
- | ... | ||
- | [osotolongo@detritus v2MriPet]$ awk -F";" | ||
- | [osotolongo@detritus v2MriPet]$ for x in `cat mri_repetir.dir`; | ||
- | [osotolongo@detritus v2MriPet]$ for a in `ls processed/ | ||
- | [osotolongo@detritus v2MriPet]$ for x in `awk -F";" | ||
- | [osotolongo@detritus v2MriPet]$ fsl2fs.pl -cut repetir.csv v2MriPet | ||
- | [osotolongo@detritus v2MriPet]$ precon.pl -cut repetir.csv v2MriPet | ||
- | Submitted batch job 17319 | ||
- | [osotolongo@detritus v2MriPet]$ squeue | ||
- | JOBID PARTITION | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | </ | ||