-
Notifications
You must be signed in to change notification settings - Fork 1
/
compute_testset.sh
138 lines (105 loc) · 4.16 KB
/
compute_testset.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#! /bin/bash
########################################################################
## Input parsing
########################################################################
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
testset_dir=$1
output_dir=$2
if [ $# -lt 1 ]; then
echo $0: "usage: "$( basename $0 )" <test_set_dir> [<output_dir>]"
return 1;
fi
########################################################################
## Functions
########################################################################
exists () {
if [ $# -lt 1 ]; then
echo $0: "usage: exists <filename> "
echo " echo 1 if the file (or folder) exists, 0 otherwise"
return 1;
fi
if [ -d "${1}" ]; then
echo 1;
else
([ -e "${1}" ] && [ -f "${1}" ]) && { echo 1; } || { echo 0; }
fi
};
array_mean () {
if [ $# -lt 1 ]; then
echo $0: "usage: array_mean <array_values>"
echo " array_values: values of the array "
echo " example: array_mean \${array[@]} "
return 1;
fi
local array=("$@")
local val=0
local N=${#array[@]}
local mean=0
for (( i=0; i<$N; i++ )); do
val=${array[$i]}
mean=$(echo "scale=4; ${mean}+${val} " | bc | awk '{printf "%f", $0}')
done
mean=$(echo "scale=4; ${mean}/${N} " | bc | awk '{printf "%f", $0}')
echo $mean
};
array_stdev () {
if [ $# -lt 1 ]; then # usage dello script
echo $0: usage: "array_stdev <vect>"
return 1;
fi
local vect=("$@")
mean=$( array_mean ${vect[@]} )
sqdif=0
for ((i=0; i<${#vect[@]}; i++)); do
sqdif=$(echo "scale=6; ${sqdif}+((${vect[i]}-${mean})^2) " | bc )
done
result=$(echo "scale=6; sqrt(${sqdif}/${#vect[@]}) " | bc | awk '{printf "%f", $0}' )
echo $result
}
########################################################################
## Main
########################################################################
compute_script=${SCRIPT_DIR}/"compute_subjects.sh"
disce_score_script=${SCRIPT_DIR}/"dice_score_subjects.sh"
[ -z ${output_dir} ] && { output_dir=${testset_dir}'/bids/derivatives/bl_app_dbb_ANTsCTSeg/' ; }
mkdir -p ${output_dir}
singularity exec -e docker://brainlife/ants:2.2.0-1bc bash ${compute_script} ${testset_dir} ${output_dir}
singularity exec -e --nv docker://gamorosino/bl_app_dbb_disseg bash ${disce_score_script} ${testset_dir} ${output_dir}
csv_file=${output_dir}'/dice_score.csv'
csv_file_average=${output_dir}'/dice_score_average.csv'
echo "Subject_Id CSF GM WM DGM Brainstem Cerebellum"
echo "Subject_Id CSF GM WM DGM Brainstem Cerebellum" > ${csv_file}
idx=0
for i in $( ls ${output_dir}/* -d ); do
b_name_i=$( basename ${i} )
[ "${b_name_i}" == "bids" ] && { continue; }
[ -d ${i} ] || { continue; }
idx=$(( $idx + 1 ))
echo $( basename ${i} ) $( cat ${i}'/dice_score.txt' )
dice_score_v=( $( cat ${i}'/dice_score.txt' ) )
CSF_ds[$idx]=${dice_score_v[0]}
GM_ds[$idx]=${dice_score_v[1]}
WM_ds[$idx]=${dice_score_v[2]}
DGM_ds[$idx]=${dice_score_v[3]}
BS_ds[$idx]=${dice_score_v[4]}
Cereb_ds[$idx]=${dice_score_v[5]}
dss=$( cat ${i}'/dice_score.txt' )
echo $( basename ${i} ),${dss//' '/','} >> ${csv_file}
done
CSF_mean=$( array_mean ${CSF_ds[@]} )
GM_mean=$( array_mean ${GM_ds[@]} )
WM_mean=$( array_mean ${WM_ds[@]} )
DGM_mean=$( array_mean ${DGM_ds[@]} )
BS_mean=$( array_mean ${BS_ds[@]} )
Cereb_mean=$( array_mean ${Cereb_ds[@]} )
echo >> ${csv_file}
echo Average,${CSF_mean},${GM_mean},${WM_mean},${DGM_mean},${BS_mean},${Cereb_mean} >> ${csv_file}
CSF_stdev=$( array_stdev ${CSF_ds[@]} )
GM_stdev=$( array_stdev ${GM_ds[@]} )
WM_stdev=$( array_stdev ${WM_ds[@]} )
DGM_stdev=$( array_stdev ${DGM_ds[@]} )
BS_stdev=$( array_stdev ${BS_ds[@]} )
Cereb_stdev=$( array_stdev ${Cereb_ds[@]} )
echo >> ${csv_file}
echo STD,${CSF_stdev} ${GM_stdev} ${WM_stdev} ${DGM_stdev} ${BS_stdev} ${Cereb_stdev} >> ${csv_file}
echo ${CSF_mean} "("${CSF_stdev}")",${GM_mean} "("${GM_stdev}")",${WM_mean} "("${WM_stdev}")",${DGM_mean} "("${DGM_stdev}")",${BS_mean} "("${BS_stdev}")",${Cereb_mean} "("${Cereb_stdev}")" > ${csv_file_average}