-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcollect_volumes.sh
executable file
·51 lines (44 loc) · 1.16 KB
/
collect_volumes.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
#!/bin/bash
# Script to collect volumes in parallel, and use names from a csv if available, see https://github.com/CobraLab/atlases for csv examples
# CSV Format
# 1,name
# 2,name
# etc
set -euo pipefail
IFS=$'\n\t'
firstarg=${1:-}
if ! [[ ( $firstarg = *csv ) || ( $firstarg = *mnc ) ]]; then
echo "usage: $0 [ label-mapping.csv ] input.mnc [ input2.mnc ... inputN.mnc ]"
exit 1
fi
AWKCMD='BEGIN{FS=","}
{for(i=1;i<=NF;i++)a[NR,i]=$i}
END{
for(i=1;i<=NF;i++){
for(j=1;j<=NR;j++){
line=line sep a[j,i]
sep=FS
}
print line
line=sep=""
}
}
'
if [[ "$1" == *csv ]]
then
LABELFILE=$1
shift
{ echo "Subject"; cut -d "," -f 2 $LABELFILE; } | awk -f<(echo "$AWKCMD")
for file in "$@"
do
sem -j+0 "itk_label_stats --labels $LABELFILE $file | tail -n +2 | cut -f2 -d"," | { echo -n "$file,"; awk -f<(echo '$AWKCMD') ; }"
done
sem --wait
else
{ echo -n "Subject,"; itk_label_stats $1; } | cut -f1 -d"," | awk -f<(echo "$AWKCMD")
for file in "$@"
do
sem -j+0 "itk_label_stats $file | tail -n +2 | cut -f2 -d"," | { echo -n "$file,"; awk -f<(echo '$AWKCMD') ; }"
done
sem --wait
fi