-
Notifications
You must be signed in to change notification settings - Fork 2
/
melanin_align
executable file
·115 lines (96 loc) · 3.46 KB
/
melanin_align
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
#!/usr/bin/env bash
set -euo pipefail
# @param NMinput - xxxx_NM.nii.gz file
# @param T1DIR - dir containing: 'mprage_warpcoef.nii.gz', 'mprage_bet_fast_wmseg.nii.gz'
# @output - neuromelanin aligned atlases (in CWD)
#
# depends on preprocessMprage, assumes 2mm template used (atlases match 2mm mni2009c)
# 20200909WF - update with VTASNLC, fix SN 2mm, fix NN->NM typo, add doc, add log
[ $# -ne 2 ] && echo "USAGE: $0 NM.nii.gz T1ProcDir" && exit 1
orgiargs="$@"
input="$1"; shift
T1DIR="$1"; shift
test ! -r $T1DIR/mprage_bet.nii.gz && echo "bad t1 preproc dir, bet file DNE: '$_'!" && exit 1
test ! -r $T1DIR/mprage_warpcoef.nii.gz && echo "bad t1 preproc dir, warp file DNE: '$_'!" && exit 1
[ ! -r $input ] && echo "bad input '$input' (pwd: $PWD)!" && exit 1
! [[ $input =~ .nii.gz$ ]] && echo "neuromelanin input must end with nii.gz ('$input')" && exit 1
in=$(basename $input .nii.gz)
[[ $in =~ NN$ ]] && echo "ERROR: expect input '$input' to end in NN.nii.gz" && exit 1
set -x
# link in mprage
! test -r t1-bet.nii.gz &&
ln -s $T1DIR/mprage_bet.nii.gz $_
# 20200909 - this always runs. never changes `-orient` value (always "RPI")
# # reorient to match t1-bet, probably "RPI"
# [ ! -r $in.nii.gz -o $(3dinfo -orient $in.nii.gz ) != $(3dinfo -orient t1-bet.nii.gz) ] &&
# niinote $input \
# fslreorient2std $input $in.nii.gz
! test -r $in-bet.nii.gz &&
niinote $_ \
bet $in.nii.gz $_ -f .01
! test -r ${in}_t1.nii.gz &&
niinote $_ \
flirt -dof 6 -in $in-bet.nii.gz -ref t1-bet.nii.gz -omat $in-T1.mat -out $_
if [ ! -r T12NM.mat ]; then
cat $in-T1.mat
convert_xfm -omat T12NM.mat -inverse $in-T1.mat
fi
# warp others to nn
name=${in%%-NM}
! test -r ${name}-fastwm_NM.nii.gz &&
niinote $_ \
flirt -interp nearestneighbour -in $T1DIR/mprage_bet_fast_wmseg.nii.gz -ref $in.nii.gz -applyxfm -init T12NM.mat -out $_
# 20200909 - to inspect warp put t1 in NM space
! test -r t1-bet_NM.nii.gz &&
niinote $_ \
flirt -in t1-bet.nii.gz -out $_ -ref $in -applyxfm -init T12NM.mat
! test -r mni2t1.nii.gz &&
niinote $_ \
invwarp -w $T1DIR/mprage_warpcoef.nii.gz -r t1-bet.nii.gz -o $_
! test -r ${name}-mnigm_NM.nii.gz &&
niinote $_ \
applywarp \
-i /opt/ni_tools/standard_templates/mni_icbm152_nlin_asym_09c/mni_icbm152_wm_tal_nlin_asym_09c_2mm.nii \
-w mni2t1.nii.gz \
--postmat=T12NM.mat \
-r $in.nii.gz \
-o $_
! test -r $name-CC_NM.nii.gz &&
niinote $_ \
applywarp \
--interp=nn \
-i /opt/ni_tools/atlas/CC/nm_CC_mask_2mm.nii.gz \
-w mni2t1.nii.gz \
--postmat=T12NM.mat \
-r $in.nii.gz \
-o $_
! test -r $name-SN_NM.nii.gz &&
niinote $_ \
applywarp \
--interp=nn \
-i /opt/ni_tools/atlas/CC/nm_SN_mask_2mm.nii.gz \
-w mni2t1.nii.gz \
--postmat=T12NM.mat \
-r $in.nii.gz \
-o $_
! test -r $name-VTASNLC_NM.nii.gz &&
niinote $_ \
applywarp \
--interp=nn \
-i /opt/ni_tools/atlas/CC/VTASNLC_up2mm.nii.gz \
-w mni2t1.nii.gz \
--postmat=T12NM.mat \
-r $in.nii.gz \
-o $_
! test -r ${in}_mni.nii.gz &&
niinote $_ \
applywarp \
-i $in.nii.gz \
-w $T1DIR/mprage_warpcoef.nii.gz \
--premat=$in-T1.mat \
-r /opt/ni_tools/standard_templates/mni_icbm152_nlin_asym_09c/mni_icbm152_t1_tal_nlin_asym_09c_2mm.nii \
-o $_ &&
3dNotes -h "$0 $orgiargs" $_
# log if we made any new files
[ $(find . -type f -mtime -1 |sed 1q | wc -l) -gt 0 ] &&
echo "$0 $orgiargs # ver $(gitver $0) @ $(date)" >> nm_log.txt || :