-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.sh
executable file
·100 lines (87 loc) · 2.92 KB
/
run.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
#!/bin/bash
## This app will align a mp2rage image to the ACPC plane (specifically, the MNI152_T1m template from
## FSL using a 6 DOF alignment via FSL commands. This protocol was adapted from the HCP Preprocessing
## Pipeline (https://github.com/Washington-University/HCPpipelines.git). Requires a mp2rage image input
## and outputs an acpc_aligned T1w image.
set -x
set -e
mag_inv1=`jq -r '.mag_inv1' config.json`
mag_inv1_json=`jq -r '.mag_inv1_json' config.json`
mag_inv2=`jq -r '.mag_inv2' config.json`
mag_inv2_json=`jq -r '.mag_inv2_json' config.json`
phase_inv1=`jq -r '.phase_inv1' config.json`
phase_inv1_json=`jq -r '.phase_inv1_json' config.json`
phase_inv2=`jq -r '.phase_inv2' config.json`
phase_inv2_json=`jq -r '.phase_inv2_json' config.json`
unit1=`jq -r '.unit1' config.json`
unit1_json=`jq -r '.unit1_json' config.json`
template=`jq -r '.template' config.json`
resample=`jq -r '.resample' config.json`
interp=`jq -r '.interp' config.json`
product=""
#we use space from
#https://bids-specification.readthedocs.io/en/stable/99-appendices/08-coordinate-systems.html#template-based-coordinate-systems
case $template in
nihpd_asym*)
space="NIHPD"
template=templates/${template}_t1w.nii
;;
*)
space="MNI152NLin6Asym"
template=templates/MNI152_T1_1mm
;;
esac
# identify the volumes in mp2rage datatype
echo "identifying mp2rage volumes"
volumes=""
potential_volumes="mag_inv1 mag_inv2 phase_inv1 phase_inv2 unit1"
for i in ${potential_volumes}
do
test_vol=$(eval "echo \$${i}")
if [ -f ${test_vol} ]; then
volumes=${volumes}" ${i}"
fi
done
# crop data
robustfov -i ${unit1} -m roi2full.mat -r unit1.cropped.nii.gz
convert_xfm -omat full2roi.mat -inverse roi2full.mat
if [[ ${resample} == true ]]; then
echo "computing flirt with resample"
flirt -interp ${interp} -in unit1.cropped.nii.gz -ref $template -omat roi2std.mat -out acpc_mni.nii.gz
else
echo "computing flirt without resample"
flirt -interp ${interp} -noresample -in unit1.cropped.nii.gz -ref $template -omat roi2std.mat -out acpc_mni.nii.gz
fi
convert_xfm -omat full2std.mat -concat roi2std.mat full2roi.mat
aff2rigid full2std.mat outputmatrix
mkdir -p output
for i in ${volumes}
do
input=$(eval "echo \$${i}")
outname=`echo ${i/_/.}`
if [[ ${interp} == 'nearestneighbour' ]]; then
interp="nn"
fi
applywarp --rel --interp=${interp} -i $input -r $template --premat=outputmatrix -o ./output/${outname}.nii.gz
done
for i in ${volumes}
do
vol_json=$(eval "echo \$${i}_json")
cp -v ${vol_json} ./output/
done
# make png
slicer ./output/mag.inv1.nii.gz -x 0.5 out_aligncheck.png
# create product.json
cat << EOF > product.json
{
"output": { "meta": { "Space": "$space" }, "tags": [ "space-$space"] },
"brainlife": [
{
"type": "image/png",
"name": "Alignment Check (-x 0.5)",
"base64": "$(base64 -w 0 out_aligncheck.png)"
}
]
}
EOF
echo "all done!"