123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #!/bin/sh
- CAT_DIR=$1
- WORK_DIR=$2
- echo "data folder in ${CAT_DIR}"
- echo "working directory is ${WORK_DIR}"
- chmod -R 777 ${WORK_DIR}
- cd ${WORK_DIR}
- touch ${WORK_DIR}/subjs_p1.txt
- touch ${WORK_DIR}/subjs_p2.txt
- touch ${WORK_DIR}/affines.txt
- for subject in $(find $CAT_DIR/ -maxdepth 5 -mindepth 1 -name "p1*T1w.nii" -printf '%P\n'); do
- p1_path=${CAT_DIR}/$(dirname $subject)
- echo "subject ${p1_path}"
- # gunzip -d --force ${p1_path}/p1*T1w.nii.gz
- # gunzip -d --force ${p1_path}/p2*T1w.nii.gz
- if [ "$?" -ne 0 ]; then
- echo "${subject} failed to copy T1 in node tmp \n"
- fi
- echo \'${p1_path}/$(find ${p1_path}/ -name "p1sub*_T1w.nii" -printf '%P\n')\' >> ${WORK_DIR}/subjs_p1.txt
- echo \'${p1_path}/$(find ${p1_path}/ -name "p2sub*_T1w.nii" -printf '%P\n')\' >> ${WORK_DIR}/subjs_p2.txt
- echo \'${p1_path}/$(find ${p1_path}/ -name "t_*T1w_affine_reorient.mat" -printf '%P\n')\' >> ${WORK_DIR}/affines.txt
- done
- echo "creating batch files"
- #make .m file
- touch ${WORK_DIR}/main_batch.txt
- echo -n "for i=1:1:size(subjs)
- clear matlabbatch
- matlabbatch{1}.spm.util.reorient.prefix = 'r_';
- matlabbatch{2}.spm.spatial.smooth.data(1) = cfg_dep('Reorient Images: Reoriented Images', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
- matlabbatch{2}.spm.spatial.smooth.fwhm = [4 4 4];
- matlabbatch{2}.spm.spatial.smooth.dtype = 0;
- matlabbatch{2}.spm.spatial.smooth.im = 0;
- matlabbatch{2}.spm.spatial.smooth.prefix = 's4';
- matlabbatch{3}.spm.spatial.coreg.write.ref = {'/extras/mask_8mm_binarized.nii,1'};
- matlabbatch{3}.spm.spatial.coreg.write.source(1) = cfg_dep('Smooth: Smoothed Images', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
- matlabbatch{3}.spm.spatial.coreg.write.roptions.interp = 1;
- matlabbatch{3}.spm.spatial.coreg.write.roptions.wrap = [0 0 0];
- matlabbatch{3}.spm.spatial.coreg.write.roptions.mask = 0;
- matlabbatch{3}.spm.spatial.coreg.write.roptions.prefix = 'r8';
- matlabbatch{4}.spm.spatial.coreg.write.ref = {'/extras/mask_4mm_binarized.nii,1'};
- matlabbatch{4}.spm.spatial.coreg.write.source(1) = cfg_dep('Smooth: Smoothed Images', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
- matlabbatch{4}.spm.spatial.coreg.write.roptions.interp = 1;
- matlabbatch{4}.spm.spatial.coreg.write.roptions.wrap = [0 0 0];
- matlabbatch{4}.spm.spatial.coreg.write.roptions.mask = 0;
- matlabbatch{4}.spm.spatial.coreg.write.roptions.prefix = 'r4';
- matlabbatch{5}.spm.spatial.smooth.data(1) = cfg_dep('Reorient Images: Reoriented Images', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
- matlabbatch{5}.spm.spatial.smooth.fwhm = [8 8 8];
- matlabbatch{5}.spm.spatial.smooth.dtype = 0;
- matlabbatch{5}.spm.spatial.smooth.im = 0;
- matlabbatch{5}.spm.spatial.smooth.prefix = 's8';
- matlabbatch{6}.spm.spatial.coreg.write.ref = {'/extras/mask_8mm_binarized.nii,1'};
- matlabbatch{6}.spm.spatial.coreg.write.source(1) = cfg_dep('Smooth: Smoothed Images', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
- matlabbatch{6}.spm.spatial.coreg.write.roptions.interp = 1;
- matlabbatch{6}.spm.spatial.coreg.write.roptions.wrap = [0 0 0];
- matlabbatch{6}.spm.spatial.coreg.write.roptions.mask = 0;
- matlabbatch{6}.spm.spatial.coreg.write.roptions.prefix = 'r8';
- matlabbatch{7}.spm.spatial.coreg.write.ref = {'/extras/mask_4mm_binarized.nii,1'};
- matlabbatch{7}.spm.spatial.coreg.write.source(1) = cfg_dep('Smooth: Smoothed Images', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
- matlabbatch{7}.spm.spatial.coreg.write.roptions.interp = 1;
- matlabbatch{7}.spm.spatial.coreg.write.roptions.wrap = [0 0 0];
- matlabbatch{7}.spm.spatial.coreg.write.roptions.mask = 0;
- matlabbatch{7}.spm.spatial.coreg.write.roptions.prefix = 'r4';
- matlabbatch{1}.spm.util.reorient.srcfiles = subjs(i);
- matlabbatch{1}.spm.util.reorient.transform.transF = affines(i);
- spm_jobman('run', matlabbatch);
- end" >> ${WORK_DIR}/main_batch.txt
- touch ${WORK_DIR}/p1_proc_batch.m
- echo -n 'subjs={' >> ${WORK_DIR}/p1_proc_batch.m
- cat ${WORK_DIR}/subjs_p1.txt >> ${WORK_DIR}/p1_proc_batch.m
- echo '};' >> ${WORK_DIR}/p1_proc_batch.m
- echo -n 'affines={' >> ${WORK_DIR}/p1_proc_batch.m
- cat ${WORK_DIR}/affines.txt >> ${WORK_DIR}/p1_proc_batch.m
- echo '};' >> ${WORK_DIR}/p1_proc_batch.m
- echo "writing from ${WORK_DIR}/main_batch.txt to ${WORK_DIR}/p1_proc_batch.m"
- cat ${WORK_DIR}/main_batch.txt >> ${WORK_DIR}/p1_proc_batch.m
- touch ${WORK_DIR}/p2_proc_batch.m
- echo -n 'subjs={' >> ${WORK_DIR}/p2_proc_batch.m
- cat ${WORK_DIR}/subjs_p2.txt >> ${WORK_DIR}/p2_proc_batch.m
- echo '}' >> ${WORK_DIR}/p2_proc_batch.m
- echo -n 'affines={' >> ${WORK_DIR}/p2_proc_batch.m
- cat ${WORK_DIR}/affines.txt >> ${WORK_DIR}/p2_proc_batch.m
- echo '};' >> ${WORK_DIR}/p2_proc_batch.m
- echo "writing from ${WORK_DIR}/main_batch.txt to ${WORK_DIR}/p2_proc_batch.m"
- cat ${WORK_DIR}/main_batch.txt >> ${WORK_DIR}/p2_proc_batch.m
- # run spm-octave
- chmod 777 ${WORK_DIR}*
- spm12 batch ${WORK_DIR}/p1_proc_batch.m
- spm12 batch ${WORK_DIR}/p2_proc_batch.m
- echo "finished resampling and smoothing"
- echo "starting features extraction"
- python /codes/save_feat.py ${CAT_DIR}
- echo "features are saved in subject's folder"
- python /codes/predict_age_stacking.py ${CAT_DIR}
- echo "age prediction is saved in subject's folder"
|