Table of Contents
Usar la API de XNAT
Uploading Hack
Tengo que separar los DCM por scans. La cosa es que tiene el SeriesNumber en el nombre de arhivo asi que deberia ser simple.
[osotolongo@detritus mopead]$ ls /nas/corachan/MOPEAD/52JAYALW/ | awk -F"." '{print $4}' | uniq 10001 11001 12001 13 14001 15001 16001 17 18001 19 20001 21 22001 23001 24001 25001 26 27001 28001 5001 6001 7001 8001 9001
Voy a crear un tgz por cada serie
[osotolongo@detritus mopead]$ for x in `ls /nas/corachan/MOPEAD/52JAYALW/ | awk -F"." '{print $4}' | uniq`; do tar czvf tmp/${x}.tgz /nas/corachan/MOPEAD/52JAYALW/52JAYALW______.MR.RM_CRANEO_PROT_.${x}.*; done [osotolongo@detritus mopead]$ ls tmp 10001.tgz 12001.tgz 14001.tgz 16001.tgz 18001.tgz 20001.tgz 22001.tgz 24001.tgz 26.tgz 28001.tgz 6001.tgz 8001.tgz 11001.tgz 13.tgz 15001.tgz 17.tgz 19.tgz 21.tgz 23001.tgz 25001.tgz 27001.tgz 5001.tgz 7001.tgz 9001.tgz
Pero si subo todo esto voy a tener problemas seguro.A verque sirve de aqui,
[osotolongo@detritus mopead]$ for x in `ls /nas/corachan/MOPEAD/52JAYALW/ | awk -F"." '{print $4}' | uniq`; do h=$(ls /nas/corachan/MOPEAD/52JAYALW/52JAYALW______.MR.RM_CRANEO_PROT_.${x}* | head -n 1); sd=$(dckey -k "SeriesDescription" ${h} 2>&1); d=$(dckey -k "AcquisitionDate" ${h} 2>&1); if [[ $(echo ${d} |grep -v Error) ]]; then echo "${x},${d},${sd}";fi; done 10001,20180705,mIP_Images(SW) 11001,20180705,SWI_Images 12001,20180705,ep2d_bold_p2_resting_state 14001,20180705,ep2d_fid_basic_bold_p2_AP 15001,20180705,ep2d_fid_basic_bold_p2_PA 16001,20180705,asl_3d_tra_iso_3.0_highres 18001,20180705,Perfusion_Weighted 20001,20180705,DTIep2d_diff_mddw_48dir_p3_AP 22001,20180705,DTIep2d_diff_mddw_48dir_p3_AP_ADC 23001,20180705,DTIep2d_diff_mddw_48dir_p3_AP_TRACEW 24001,20180705,DTIep2d_diff_mddw_48dir_p3_AP_FA 25001,20180705,DTIep2d_diff_mddw_48dir_p3_AP_ColFA 27001,20180705,DTIep2d_diff_mddw_48dir_p3_AP_TENSOR_B0 28001,20180705,DTIep2d_diff_mddw_4b0_PA 5001,20180705,t1_mprage_sag_p2_iso 6001,20180705,t2_space_dark-fluid_sag_p2_iso 7001,20180705,pd+t2_tse_tra_p2_3mm 8001,20180705,Mag_Images 9001,20180705,Pha_Images
Las demas eries dan errores en los tags, no tienen fecha o no tienen Series Description. Un horror. En fin que guardo esto en un csv y solo subo estos.
[osotolongo@detritus mopead]$ for x in `ls /nas/corachan/MOPEAD/52JAYALW/ | awk -F"." '{print $4}' | uniq`; do h=$(ls /nas/corachan/MOPEAD/52JAYALW/52JAYALW______.MR.RM_CRANEO_PROT_.${x}* | head -n 1); sd=$(dckey -k "SeriesDescription" ${h} 2>&1); d=$(dckey -k "AcquisitionDate" ${h} 2>&1); if [[ $(echo ${d} |grep -v Error) ]]; then echo "${x},${d},${sd}";fi; done > tmp/infoups.csv
Filtrando la subida
O mejor aun, ya que se los tags (por el protocolo!) que en realidad me interesan, los pongo en un file independiente y solo creo la estructura de estos. Esto es facil porque los tags buenos son igual para cualquier sujeto.
[osotolongo@detritus mopead]$ cat tmp/protocol.csv ep2d_bold_p2_resting_state ep2d_fid_basic_bold_p2_AP ep2d_fid_basic_bold_p2_PA asl_3d_tra_iso_3.0_highres DTIep2d_diff_mddw_48dir_p3_AP DTIep2d_diff_mddw_4b0_PA t1_mprage_sag_p2_iso t2_space_dark-fluid_sag_p2_iso [osotolongo@detritus mopead]$ grep -f tmp/protocol.csv tmp/infoups.csv 12001,ep2d_bold_p2_resting_state 14001,ep2d_fid_basic_bold_p2_AP 15001,ep2d_fid_basic_bold_p2_PA 16001,asl_3d_tra_iso_3.0_highres 20001,DTIep2d_diff_mddw_48dir_p3_AP 28001,DTIep2d_diff_mddw_4b0_PA 5001,t1_mprage_sag_p2_iso 6001,t2_space_dark-fluid_sag_p2_iso [osotolongo@detritus mopead]$ grep -f tmp/protocol.csv tmp/infoups.csv > tmp/prot2up.csv
Ahora lo que voy a hacer es preparar la estructura para subir todo junto,
[osotolongo@detritus mopead]$ for x in `awk -F"," '{print $1}' tmp/prot2up.csv`; do mkdir tmp/scans/${x}; done [osotolongo@detritus mopead]$ tree tmp/scans/ tmp/scans/ ├── 12001 ├── 14001 ├── 15001 ├── 16001 ├── 20001 ├── 28001 ├── 5001 └── 6001 8 directories, 0 files [osotolongo@detritus mopead]$ for x in `awk -F"," '{print $1}' tmp/prot2up.csv`; do cp /nas/corachan/MOPEAD/52JAYALW/52JAYALW______.MR.RM_CRANEO_PROT_.${x}.* tmp/scans/${x}; done [osotolongo@detritus scans]$ cd tmp/scans [osotolongo@detritus scans]$ [osotolongo@detritus mopead]$ for x in `awk -F"," '{print $1}' tmp/prot2up.csv`; do tar czvf tmp/${x}.tar.gz -C tmp/scans/ ${x}; done
Nota: Esto se tiene que hacer mas rapido pasando el paso de copiar!!!
Comandos simples de gestión
Añadir proyecto, (TestAPI)
$ curl -X PUT -u user:pass http://localhost:8088/data/projects/TestAPI
Añadir sujeto al proyecto, (Test001)
$ curl -X PUT -u user:pass http://localhost:8088/data/projects/TestAPI/subjects/Test001 XNAT_S00010
Subir imagenes. Primero se ha de crear la sesion y el scan,
https://wiki.xnat.org/display/XAPI/Upload+Image+Session+Files+with+REST+API
Ahora si, a subir,
$ f=$(ls /nas/corachan/MOPEAD/52JAYALW/ | head -n 1); d=$(dckey -k "AcquisitionDate" /nas/corachan/MOPEAD/52JAYALW/${f} 2>&1); echo $d 20180705 $ f=$(ls /nas/corachan/MOPEAD/52JAYALW/ | head -n 1); pid=$(dckey -k "PatientID" /nas/corachan/MOPEAD/52JAYALW/${f} 2>&1 | sed 's/^[ \t]*$//'); echo $pid D18318024 $ curl -X PUT -u user:pass http://localhost:8088/data/projects/TestAPI/subjects/Test001/experiments/"${pid}"?xnat:mrSessionData/date="${d}" $ for x in `awk -F"," '{print $1}' tmp/prot2up.csv`; do curl -X PUT -u user:pass http://localhost:8088/data/projects/TestAPI/subjects/Test001/experiments/"${pid}"/scans/"${x}"?xsiType=xnat:mrScanData; done]$ for l in `cat tmp/prot2up.csv`; do x=$(echo ${l} |awk -F"," '{print $1}'); tag=$(echo ${l} |awk -F"," '{print $2}'); curl -X PUT -u user:pass "http://localhost:8088/data/projects/TestAPI/subjects/Test001/experiments/${pid}/scans/${x}?xsiType=xnat:mrScanData&xnat:mrScanData/series_description=${tag}&xnat:imageScanData/quality=usable&xnat:imageScanData/type=${tag}"; done $ for x in `awk -F"," '{print $1}' tmp/prot2up.csv`; do curl -X PUT -u user:pass http://localhost:8088/data/projects/TestAPI/subjects/Test001/experiments/"${pid}"/scans/"${x}"/resources/DICOM/?format=DICOM; done $ for x in `awk -F"," '{print $1}' tmp/prot2up.csv`; do curl -X PUT -u user:pass http://localhost:8088/data/projects/TestAPI/subjects/Test001/experiments/"${pid}"/scans/"${x}"/resources/DICOM/files?extract=true -F "file.tar.gz=@tmp/"${x}".tar.gz"; done
Nota: Hacer scripting de esto y ya tengo el primer paso de la pipeline v0.4, upload_subject