-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmy_fba_stdSignal.sh
executable file
·85 lines (60 loc) · 1.69 KB
/
my_fba_stdSignal.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
#!/bin/bash
echo " [INFO] Running on `hostname`"
if [ "$#" -lt 1 ]
then
echo " [ERROR]. Insufficient arguments."
echo " Usage: `basename $0` $subj"
echo ""
echo " This script is part of the set of scripts required for fixel-based analyses."
echo " See my_fba.sh for help."
exit 2
fi
subj=$1
metric=$2
tmpDir=/tmp/`hostname`_$$
mkdir $tmpDir
dwi=${FBA_DIR}/${subj}/dwis.mif
mask=${FBA_DIR}/${subj}/mask.mif
dwi_std=${FBA_DIR}/${subj}/dwis_std.mif
isOK=1
for f in $dwi $mask
do
if [ ! -f $f ]
then
echo " [ERROR] Cannot find file: $f"
isOK=0
else
echo " [INFO] found file: $f"
fi
done
if [ $isOK -eq 0 ]
then
echo "THINGS ARE NOT OK"
exit 2
fi
if [ -f $dwi_std ]
then
echo " [INFO] File exists: $dwi_std"
exit 0
fi
dwiextract -bzero $dwi - | mrmath -axis 3 - mean ${tmpDir}/avb0.mif
maskfilter -npass 4 $mask erode ${tmpDir}/mask_eroded.mif
if [[ "$metric" = "adc" ]]
then
dwi2tensor -mask $mask $dwi - | tensor2metric -adc - - | \
mrthreshold -abs 0.002 - - | \
mrcalc - ${tmpDir}/mask_eroded.mif -mult ${tmpDir}/tissuemask.mif
fi
if [[ "$metric" = "fa" ]]
then
echo " [INFO] Using FA to find average b=0 signal in WM"
dwi2tensor -mask $mask $dwi - | tensor2metric -fa - - | \
mrthreshold -abs 0.5 - - | \
mrcalc - ${tmpDir}/mask_eroded.mif -mult ${tmpDir}/tissuemask.mif
fi
nVoxels=`mrstats -mask ${tmpDir}/tissuemask.mif ${tmpDir}/tissuemask.mif -output count`
theMean=`mrstats -mask ${tmpDir}/tissuemask.mif ${tmpDir}/avb0.mif -output mean`
echo " [INFO] Number of voxels in tissue mask: $nVoxels"
echo " [INFO] The mean of the average of the b=0 images is $theMean"
mrcalc $dwi $theMean -div $dwi_std
rm -fR $tmpDir