-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3. PrepareNodifAP.sh
61 lines (43 loc) · 1.67 KB
/
3. PrepareNodifAP.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
#!/bin/env bash
# This script selects nodif images from AP direction
echo "PREPARING NODIF IMAGES"
# definitions
dataDir=/vols/Data/disease/alazari/longitudinal_paTMS/DWI
# list the subjects
subjectList="P1 P2 P3"
# Loop over subjects for AP b0
for subj in $subjectList; do
echo "FINDING AP NODIFS"
# establish the subject-specific directory
rawDir=$dataDir/$subj/dMRI/raw
# delete previous lists of b0s to not get confused
rm $rawDir/list_b0.txt
# extract the b0 from AP images
#create a new version of bval
cp $rawDir/bval $rawDir/bval_b0
#add blank spaces at the beginning and end of bval_b0
sed -i -e 's/^/ /' $rawDir/bval_b0
sed -i -e 's/$/ /' $rawDir/bval_b0
#extract the location of the b0 and crete a .txt file with it
sed -i "s/ 5 / 6 /g" $rawDir/bval_b0
sed -i "s/ /\n/g" $rawDir/bval_b0
grep -o '6' $rawDir/bval_b0 -n >> $rawDir/list_b0.txt
#polish the .txt file
sed -i "s/ /\n/g" $rawDir/list_b0.txt
sed -i 's/..$//' $rawDir/list_b0.txt
#how many b0 are there in the volume?
lengthlist=$(cat $rawDir/list_b0.txt | wc -l)
# loop over all the b0 indices and extract the corresponding volume
for volume in `seq 1 1 $lengthlist`; do
# find out the number of the volume
a=$(awk 'NR == '$volume' {print; exit}' $rawDir/list_b0.txt)
let "a = $a - 2"
echo " extracting volume: $a"
# extract that volume with fslroi
fslroi $rawDir/data_AP.nii.gz $rawDir/datab0_$a $a 1
done
done
# for the AP images, merge them (if the scanner has not merged them automatically)
fslmerge -t $rawDir/all_b0 $rawDir/datab0_*
fslmaths $rawDir/all_b0 -Tmean $rawDir/nodif_AP
echo "NODIFS DONE"