-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutility_functions.sh
121 lines (98 loc) · 1.89 KB
/
utility_functions.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
# extracts the option name from any version (-- or -)
get_opt1() {
arg=`echo $1 | sed 's/=.*//'`
echo $arg
}
# get image filename from -- options
get_imarg1()
{
arg=`get_arg1 $1`;
arg=`$FSLDIR/bin/remove_ext $arg`;
echo $arg
}
# get arg of image filenames for - options (need to pass both $1 and $2 to this)
get_imarg2()
{
arg=`get_arg2 $1 $2`;
arg=`$FSLDIR/bin/remove_ext $arg`;
echo $arg
}
# get arg for -- options
get_arg1() {
if [ X`echo $1 | grep '='` = X ] ; then
echo "Option $1 requires an argument" 1>&2
exit 1
else
arg=`echo $1 | sed 's/.*=//'`
if [ X$arg = X ] ; then
echo "Option $1 requires an argument" 1>&2
exit 1
fi
echo $arg
fi
}
# get arg for - options (need to pass both $1 and $2 to this)
get_arg2()
{
if [ X$2 = X ] ; then
echo "Option $1 requires an argument" 1>&2
exit 1
fi
echo $2
}
run()
{
echo $@ >> $LOGFILE
$@
if [ $? -eq 0 ]; then
return 0
else
echo "error executing : $@"
return 1
fi
}
check_run()
{
force_overwrite=$1; shift;
output_file=$1; shift;
if [ ! -f $output_file -o $force_overwrite -eq 1 ]; then
echo $@ >> $LOGFILE
$@
fi
}
run_check()
{
echo $@ >> $LOGFILE
$@
if [ $? -gt 0 ]; then
echo "ERROR detected" >> $LOGFILE
return 1
fi
return 0
}
run_check_exit()
{
echo $@ >> $LOGFILE
$@
if [ $? -gt 0 ]; then
echo "ERROR detected....exiting" >> $LOGFILE
exit
fi
return 0
}
run_notexisting_img()
{
img=$1; shift
if [ `$FSLDIR/bin/imtest $img` = 0 ]; then
echo $@ >> $LOGFILE
$@
fi
}
quick_smooth() {
in=$1
out=$2
run $FSLDIR/bin/fslmaths $in -subsamp2 -subsamp2 -subsamp2 -subsamp2 vol16
run $FSLDIR/bin/flirt -in vol16 -ref $in -out $out -noresampblur -applyxfm -paddingsize 16
# possibly do a tiny extra smooth to $out here?
run $FSLDIR/bin/imrm vol16
}