-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsi_nii_converter_folder_loop.sh
103 lines (85 loc) · 2.2 KB
/
dsi_nii_converter_folder_loop.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
#!/bin/bash
###### NIFTI converter for KKI DTI
### Unnecessarily complicated but such is life with KKI IT infrastructure
#JR 11/26/18
#PD 11/22/21
#some important path variables
#route=T:/amri/DATA/Children/3T
route=T:/amri/DTIanalysis/DSI/b-table-testing/Scanner-Test
dcm2niix=T:/amri/DTIanalysis/scripts/dcm2niix.exe
cwd=$(pwd)
me=T:/amri/DTIanalysis/scripts
rm -f $me/error.txt
#scanner1=MR1-Achieva-dStream
#scanner2=MR2-Ingenia-Elition-X
#pre=Pre-b-table-fix
#post=Post-b-table-fix
#change this:
#scanner=$scanner2
#scan=$post
#subject=3922_DSI
cd $route
scan_folds=$(echo *MR*)
for scan_fold in $scan_folds
do
scan="${scan_fold:0:3}"
cd $scan_fold
ID=$(ls)
cd $ID
#check to see that subject's directory exists
DSI_route="$route"/"$scan_fold"/"$ID"/DICOMs
echo "Converting in subject folder $DSI_route"
if [ ! -d nifti_convert ];
then
mkdir nifti_convert
fi
dwi_convert="$route"/"$scan_fold"/"$ID"/nifti_convert
cd $dwi_convert
#Convert DSI, send to dwi folder
# $dcm2niix -f "%p" -o $dwi_convert $DSI_route
# for dsi in DSI_51a DSI_50b
# do
# echo "changing name of $dsi scan"
# mv *$dsi*.bval "$ID"_"$dsi".bval
# mv *$dsi*.bvec "$ID"_"$dsi".bvec
# mv *$dsi*.json "$ID"_"$dsi".json
# mv *$dsi*.nii "$ID"_"$dsi".nii
# done
##Transform B-Tables
file_array=(*"DSI"*.bval *"DSI"*.bvec); #*.bvec
#echo "bval files are $file_array"
#echo "There are ${#file_array[@]} bval bvec scans"
#printf "%s\n" "${file_array[@]}"
rm *_nii_converted_btable.btable
for file in "${file_array[@]}"
do
echo "transposing $file"
awk '
{
for (i=1; i<=NF; i++) {
a[NR,i] = $i
}
}
NF>p { p = NF }
END {
for(j=1; j<=p; j++) {
str=a[1,j]
for(i=2; i<=NR; i++){
str=str" "a[i,j];
}
print str
}
}' $file >> transposed_$file
done
echo "combining b-values and b-vectors into b-table"
for DSI in DSI_51a DSI_50b
do
paste transposed_"$ID"_"$DSI".bval transposed_"$ID"_"$DSI".bvec >> ../"$ID"_"$DSI"_"$scan"_nii_converted_btable.btable
done
rm transposed*
#$dcm2niix -f "$sub"_DSI_50b -o $dwi_convert "$DSI_route/${ID}_DSI_50b.dcm"
#$dcm2niix -f "$sub"_REV_FAT -o $dwi_convert "$DSI_route/${ID}_REV_FAT.dcm"
#$dcm2niix -f "$sub"_%_% -p y -z y -o $dwi_convert $DSI_route
cd $route
done
#done