-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdwi_getPA
executable file
·128 lines (101 loc) · 3.25 KB
/
dwi_getPA
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
#!/bin/bash
#
# Raúl RC
# Febrero 2018
#
#------------------------------------------------------------------------------#
# FUNCTIONS
help() {
echo "
Extrae la B0 de la adquisición DWI Postero-Anterior, para generar el fieldmap.
Ejemplo:
`basename $0` INPUT OUTPUT
INPUT DWI de entrada
OUTPUT Nombre de salida
Raul RC
INB, Febrero 2018
"
}
empty_row() {
Txt=$1
c=`grep -c "^\s*$" $Txt`
if ((c > 0));
then
echo -e "\033[38;5;83m\n[INFO]... Borrando filas en blanco de $Txt \033[0m"
sed -i '/^\s*$/d' $Txt
fi
}
#---------------- FUNCTION: PRINT COLOR COMMAND ----------------#
cmd() {
text=$1
echo -e "\033[38;5;208mCOMMAND --> $text \033[0m"
echo $($text)
}
Info() {
Col="38;5;83m" # Color code
echo -e "\033[$Col\n[INFO]..... $1 \033[0m"
}
Error() {
echo -e "\e[0;31m\n[ERROR]..... $1\n\e[0m"
}
#------------------------------------------------------------------------------#
# WARNINGS
# Number of inputs
if [ $# -lt 2 ]
then
echo -e "\e[0;31m\n[ERROR]... \tAn argument is missing\n\e[0m \t\tDWI IN: \033[38;5;5m$1\033[0m\n\t\tOut name: \033[38;5;5m$2\033[0m\n"
help
exit 0
fi
if [ -f $2 ]; then Error "Output file already exist: $2"; exit 0; fi
if [ ! -f $1 ]; then Error "DWI does not exist: $1"; exit 0; fi
#------------------------------------------------------------------------------#
# RUN
echo -e "\033[48;5;58m\n[INIT]..... \tGet the B0 from the PA-DWI with N4 Bias field: $1\n\033[0m"
#------------------------------------------------------------------------------#
# VARIABLES
dwi=$1
out=`echo $2 | awk -F "." '{print $1}'`
id=`echo $dwi | awk -F "." '{print $1}'`
tmp=/tmp/dwiPA_$RANDOM
grad=${tmp}/vectors.b
b0=${tmp}/${id}_b0.nii.gz
n4=${tmp}/${id}_n4.nii.gz
Info "Checking vectors files existence"
for vec in bval bvec; do
if ls $id*$vec* 1> /dev/null 2>&1; then
test=`ls $id*$vec*`; echo -e "\033[38;5;81m\t\t $test was found \033[0m";
else
Error "$id does not has a $vec file in this directory"; exit 0;
fi
done
bval=`ls $id*bval*`
bvec=`ls $id*bvec*`
# Temporal directory
Info "Temporal directory"
cmd "mkdir $tmp"
#------------------------------------------------------------------------------#
# Do stuff
Info "Erasing empty rows from gradient table"
empty_row $bvec
empty_row $bval
Info "Getting gradient table "
paste $bvec $bval > $grad
cat $grad
Info "Checking if gradient table is in column format"
vol=`fslval $dwi dim4`
rows=`cat $grad | wc -l`
if [ "$vol" -eq "$rows" ]; then echo -e "YES, the number of rows in $grad and number of volumes in $dwi are the same: $rows"; else Error "Missmatch between gradient-table and VOLUMES in $dwi, check format"; rm -R $tmp; exit 1; fi
Info "Bias Field Correction of $dwi "
cmd "/home/inb/lconcha/fmrilab_software/mrtrix3.git/release/../scripts/dwibiascorrect -grad $grad -ants -force $dwi $n4"
Info "Getting the B0 from $dwi"
cmd "/home/inb/lconcha/fmrilab_software/mrtrix3.git/release/bin/dwiextract -bzero -grad $grad $n4 $out.nii.gz"
#------------------------------------------------------------------------------#
# Removes Temoral Files
Info "Deleting temporal files"
cmd "rm -R $tmp"
#------------------------------------------------------------------------------#
# End
Info "Outfile: ${out}.nii.gz\n"