-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeparcellator.sh
executable file
·88 lines (65 loc) · 2.18 KB
/
deparcellator.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
#!/bin/bash
set -e
#define
codedir=${HOME}/code
basedir="$(pwd -P)"
usage()
{
cat<<EOF
usage: $0 options
=============================================================================================
deparcellator.sh
Splits up a numbered volume (e.g. parcellation template) into its constituents & makes a .txt list
Also creates co-ordinates & names them based on Harvard-Oxford cortical structural atlas
Example:
deparcellator.sh parcellation.nii.gz
***Entirely based on code from Dr Rafael Romero-Garcia ('El Cunado'), University of Cambridge - Muchas Gracias Cunado!***
Written by Michael Hart, University of British Columbia, October 2020
=============================================================================================
EOF
exit 1
}
# If empty options
if [[ $1 == "" ]]; then
usage
exit 1
fi
volume=$1
outname=`basename ${volume} .nii.gz`
mkdir -p ${basedir}/${outname}_seeds
outdir=${basedir}/${outname}_seeds
nParcel=1
maxParcel=`fslstats $1 -R | awk '{print $2}'`
numParcels=`printf "%0.0f\n" $maxParcel`
echo "basedir is: ${basedir}"
echo "number of parcels is: ${numParcels}"
echo "outdir is: ${outdir}"
if [ $(imtest ${volume}) == 1 ] ;
then
echo "parcellation template is ok: ${volume}"
else
echo "Cannot locate parcellation template ${volume}. Please ensure the ${volume} dataset is in this directory -> exiting now" >&2
exit 1
fi
#touch xyz.txt
#touch parcelnames.txt
while [ ${nParcel} -le ${numParcels} ]
do
fslmaths \
${volume} \
-thr ${nParcel} \
-uthr ${nParcel} \
-bin \
${outdir}/Seg`printf %04d ${nParcel}`.nii.gz
current_parcel=${outdir}/Seg`printf %04d ${nParcel}`.nii.gz
if [ `fslstats ${current_parcel} -V | awk '{print $1}'` == 0 ]; then
echo "removing ${current_parcel} as it's empty"
rm ${current_parcel}
else
echo ${outdir}/Seg`printf %04d ${nParcel}`.nii.gz >> ${outdir}/seeds_targets_list.txt
fslstats ${outdir}/Seg`printf %04d ${nParcel}` -c >> ${outdir}/xyz.txt
atlasquery -a "Harvard-Oxford Cortical Structural Atlas" \
-m ${outdir}/Seg`printf %04d ${nParcel}` | head -n 1 >> ${outdir}/parcelnames.txt
fi
nParcel=$((${nParcel}+1))
done