-
Notifications
You must be signed in to change notification settings - Fork 12
/
KUL_bids_crop.sh
executable file
·137 lines (108 loc) · 2.61 KB
/
KUL_bids_crop.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
#!/bin/bash -e
# Bash shell script to crop T1w
#
# Requires MRtrix3
#
# @ Stefan Sunaert - UZ/KUL - [email protected]
# 19/03/2021
version="0.1"
kul_main_dir=`dirname "$0"`
source $kul_main_dir/KUL_main_functions.sh
cwd=$(pwd)
# FUNCTIONS --------------
# function Usage
function Usage {
cat <<USAGE
`basename $0` crops T1w data in the z-axis, to remove the neck
Usage:
`basename $0` <OPT_ARGS>
Example:
`basename $0` -p JohnDoe
Arguments:
-a: run on all BIDS participants
-p: participant name
-n: number of cpu to use (default 15)
-v: show output from commands
Documentation:
USE AT OWN RISK!!!
This is to be used with extreme caution!
This will crop T1w images given a number of slices to delete from the bottom of the image, this is to delete extracranial tissue, such as the neck.
It can be needed for qsiprep, since it cannot deal well with large fov acquired sagittal images.
It will change you BIDS.
It does not check anything, does not take into account any anatomical feature, just deletes data!
USE AT OWN RISK!!!
USAGE
exit 1
}
# CHECK COMMAND LINE OPTIONS -------------
#
# Set defaults
silent=1 # default if option -v is not given
ncpu=15
# Set required options
p_flag=0
auto=0
if [ "$#" -lt 1 ]; then
Usage >&2
exit 1
else
while getopts "p:n:av" OPT; do
case $OPT in
p) #participant
participant=$OPTARG
p_flag=1
;;
n) #ncpu
ncpu=$OPTARG
;;
a) #verbose
auto=1
;;
v) #verbose
silent=0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo
Usage >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
echo
Usage >&2
exit 1
;;
esac
done
fi
# verbose or not?
if [ $silent -eq 1 ] ; then
export MRTRIX_QUIET=1
ants_verbose=0
fs_silent=" > /dev/null 2>&1"
fi
# --- MAIN ---
printf "\n\n\n"
# here we give the data
if [ $auto -eq 0 ]; then
if [ -z "$session" ]; then
fullsession1=""
fullsession2=""
else
fullsession1="ses-${session}/"
fullsession2="ses-${session}_"
fi
datadir="$cwd/BIDS/sub-${participant}/${fullsession1}anat"
T1w=("$datadir/sub-${participant}_${fullsession2}T1w.nii.gz")
#T2w=("$datadir/sub-${participant}_${fullsession2}T2w.nii.gz")
#FLAIR=("$datadir/sub-${participant}_${fullsession2}FLAIR.nii.gz")
#MTI=("$datadir/sub-${participant}_${fullsession2}MTI.nii.gz")
else
T1w=($(find $cwd/BIDS -type f -name "*T1w.nii.gz" | sort ))
fi
for test_T1w in ${T1w[@]}; do
my_cmd="mrgrid $test_T1w crop -axis 2 80,0 $test_T1w -force"
echo $my_cmd
eval $my_cmd
done