-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.sh
executable file
·133 lines (122 loc) · 4.13 KB
/
run.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
#!/bin/bash
echo "copying moving and static tractograms"
subjID=`jq -r '._inputs[0].meta.subject' config.json`
static=`jq -r '.tractogram_static' config.json`
t1_static=`jq -r '.t1_static' config.json`
segmentations=`jq -r '.segmentations' config.json`
movings=`jq -r '.tractograms_moving' config.json`
t1s=`jq -r '.t1s_moving' config.json`
# Building arrays
arr_seg=()
arr_seg+=(${segmentations})
arr_mov=()
arr_mov+=(${movings})
arr_t1s=()
arr_t1s+=(${t1s})
echo "Check the inputs subject id"
num_ex=$((${#arr_seg[@]} - 2))
if [ ! $subjID == `jq -r '._inputs[1].meta.subject' config.json` ]; then
echo "Inputs subject id incorrectly inserted. Check them again."
exit 1
fi
for i in `seq 1 $num_ex`;
do
id_seg=$(jq -r "._inputs[1+$i].meta.subject" config.json | tr -d "_")
id_mov=$(jq -r "._inputs[1+$i+$num_ex].meta.subject" config.json | tr -d "_")
id_t1=$(jq -r "._inputs[1+$i+$num_ex+$num_ex].meta.subject" config.json | tr -d "_")
if [ $id_seg == $id_mov -a $id_seg == $id_t1 ]; then
echo "Inputs subject id correctly inserted"
else
echo "Inputs subject id incorrectly inserted. Check them again."
exit 1
fi
done
echo "Tractogram conversion to trk"
mkdir tractograms_directory;
if [[ $static == *.tck ]];then
echo "Input in tck format. Convert it to trk."
cp $static ./tractogram_static.tck;
python tck2trk.py $t1_static tractogram_static.tck -f;
cp tractogram_static.trk $subjID'_track.trk';
for i in `seq 1 $num_ex`;
do
t1_moving=${arr_t1s[i]//[,\"]}
id_mov=$(jq -r "._inputs[1+$i+$num_ex].meta.subject" config.json | tr -d "_")
cp ${arr_mov[i]//[,\"]} ./${id_mov}_tractogram_moving.tck;
python tck2trk.py $t1_moving ${id_mov}_tractogram_moving.tck -f;
mv ${id_mov}_tractogram_moving.trk tractograms_directory/$id_mov'_track.trk';
done
else
echo "Tractogram already in .trk format"
cp $static $subjID'_track.trk';
for i in `seq 1 $num_ex`;
do
id_mov=$(jq -r "._inputs[1+$i+$num_ex].meta.subject" config.json | tr -d "_")
cp ${arr_mov[i]//[,\"]} tractograms_directory/$id_mov'_track.trk';
done
fi
if [ -z "$(ls -A -- "tractograms_directory")" ]; then
echo "tractograms_directory is empty.";
exit 1;
else
echo "tractograms_directory created.";
fi
echo "Create examples directory"
mkdir examples_directory;
if [[ ${arr_seg[1]//[,\"]} == *.trk ]];then
echo "Tracts already in .trk format"
tract_name=$(jq -r "._inputs[2].tags[0]" config.json | tr -d "_")
echo $tract_name > tract_name_list.txt
mkdir examples_directory/$tract_name;
for i in `seq 1 $num_ex`;
do
id_mov=$(jq -r "._inputs[1+$i+$num_ex].meta.subject" config.json | tr -d "_")
cp ${arr_seg[i]//[,\"]} examples_directory/$tract_name/$id_mov'_'$tract_name'_tract.trk';
done
else
echo "Tracts conversion to trk"
for i in `seq 1 $num_ex`;
do
t1_moving=${arr_t1s[i]//[,\"]}
id_mov=$(jq -r "._inputs[1+$i+$num_ex].meta.subject" config.json | tr -d "_")
tractogram_moving=tractograms_directory/$id_mov'_track.trk'
seg_file=${arr_seg[i]//[,\"]}
rm -f tract_name_list.txt;
python wmc2trk.py -tractogram $tractogram_moving -classification $seg_file
while read tract_name; do
echo "Tract name: $tract_name";
if [ ! -d "examples_directory/$tract_name" ]; then
mkdir examples_directory/$tract_name;
fi
mv $tract_name'_tract.trk' examples_directory/$tract_name/$id_mov'_'$tract_name'_tract.trk';
if [ -z "$(ls -A -- "examples_directory/$tract_name")" ]; then
echo "examples_directory is empty.";
exit 1;
else
echo "examples_directory created.";
fi
done < tract_name_list.txt
done
fi
echo "Running Classifyber"
mkdir tracts_trks;
singularity exec -e docker://brainlife/dipy:0.16.0 python classifyber.py \
-moving_dir tractograms_directory \
-static $subjID'_track.trk' \
-ex_dir examples_directory \
-list 'tract_name_list.txt' \
-out_dir tracts_trks
if [ -z "$(ls -A -- "tracts_trks")" ]; then
echo "Classifyber failed."
exit 1
else
echo "Classifyber done."
fi
echo "Building the wmc structure"
singularity exec -e docker://brainlife/dipy:0.16.0 python build_wmc.py -tractogram $static
if [ -f 'classification.mat' ]; then
echo "WMC structure created."
else
echo "WMC structure missing."
exit 1
fi