-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmp_trk_reprocess.bash
executable file
·205 lines (147 loc) · 5.4 KB
/
cmp_trk_reprocess.bash
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# "include" the set of common script functions
source common.bash
source getoptx.bash
G_LOGFILE="-x"
G_TRKFILE="-x"
G_SYNOPSIS="
NAME
cmp_trk_reprocess.bash
SYNOPSIS
cmp_trk_reprocess.bash -l <connectomeLogFile> \\
-t <trkFile>
DESCRIPTION
'cmp_trk_reprocess.bash' re-runs the final stages of the
connectivity pipeline, using the passed <trkFile> as source
for determining connectivity maps.
It is something of a hack, and somewhat automated. The 'hack'
part is because this script relies on a successfully completed
prior analysis that it then swaps out a previous track file
on the filesystem and re-runs, followed by some housekeeping
on the create cff file. The 'automated' part is that the script
tries to create the least disruption possible to the orignal
output file tree.
ARGUMENTS
-v <level> (Optional)
Verbosity level. A value of '10' is a good choice here.
-l <connectomeLogFile>
The log file created by a previously successful run of the
original pipeline. This log file is parsed to extract the
'connectome_web.py' line, which is slightly edited
and re-run.
-t <trkFile>
The tract file to swap into the system.
OUTPUT
Any previous output file, '3-cmt_.cff' will be overwritten. To
conserve this, the existing cff is backed up. When completed,
the 'new' cff file is appropriately renamed, and the original
restored.
In addition, the created cff is also unpacked (with an
appropriate name).
PRECONDITIONS
o A successfully completed connectome run.
POSTCONDITIONS
o New connectivity object built off passed track file.
SEE ALSO
o connectome_meta.bash -- main script controlling connectome
runs.
HISTORY
03 November 2011
o Initial design and coding.
"
# Actions
A_noLogFileArg="checking on the log file"
A_noTrkFileArg="checking on the trk file"
A_badLogFile="accessing the log file"
A_badTrkFile="accessing the trk file"
A_noStreamTrk="checking on the original streamline trk"
A_noCmtCff="checking on the original cff output"
# Error messages
EM_noLogFileArg="you must specify a '-l <connectomeLogFile>."
EM_noTrkFileArg="you must specify a '-t <trkFile>."
EM_badLogFile="I couldn't access the log file. Does it exist?"
EM_badTrkFile="I couldn't access the trk file. Does it exist?"
EM_noStreamTrk="I couldn't access the file. Does it exist?"
EM_noCmtCff="I couldn't access the file. Does it exist?"
# Error codes
EC_noLogFileArg=11
EC_noTrkFileArg=12
EC_badLogFile=21
EC_badTrkFile=22
EC_noStreamTrk=31
EC_noCmtCff=32
###\\\
# Process command options
###///
while getoptex "v: l: t: h" "$@" ; do
case "$OPTOPT"
in
v) Gi_verbose=$OPTARG ;;
l) G_LOGFILE=$OPTARG ;;
t) G_TRKFILE=$OPTARG ;;
h) synopsis_show
exit 0;;
esac
done
verbosity_check
topDir=$(pwd)
echo ""
cprint "hostname" "[ $(hostname) ]"
statusPrint "Checking -l <connectomeLogFile>"
if [[ "$G_LOGFILE" == "-x" ]] ; then fatal noLogFileArg ; fi
ret_check $?
statusPrint "Accessing <connectomeLogFile>"
fileExist_check $G_LOGFILE || fatal badLogFile
statusPrint "Checking -t <trkFile>"
if [[ "$G_TRKFILE" == "-x" ]] ; then fatal noTrkFileArg ; fi
ret_check $?
statusPrint "Accessing <trkFile>"
fileExist_check $G_TRKFILE || fatal badTrkFile
LOGCONTENTS=$(cat $G_LOGFILE)
CMPWEB=$(echo "$LOGCONTENTS" |\
grep connectome_web.py |\
head -n 1 |\
awk -F\| '{print $3}' |\
sed 's/Stage RUN \(.*\)/\1/')
# re-direct to the 'trk' version
NEWCMPPCKL=$(echo "$CMPWEB" | sed 's/ connectome_web.py\(.*\)/connectome_trk.py \1/')
NEWCMP=$(echo "$NEWCMPPCKL" | awk -F'--writePickle' '{print $1}')
echo $NEWCMP
ROOTDIR=$(echo "$NEWCMP" | awk -F'-d' '{print $2}' | awk '{print $1}')
CMTTRKDIR=${ROOTDIR}/CMP/fibers
STREAMLINETRK=${CMTTRKDIR}/streamline_filtered.trk
CMTCFFDIR=${ROOTDIR}/CMP/cff
CMTCFF=${CMTCFFDIR}/3-cmt_.cff
statusPrint "Checking on streamline_filtered.trk"
fileExist_check $STREAMLINETRK || fatal noStreamTrk
statusPrint "Backing up streamline_filtered.trk"
cp $STREAMLINETRK ${STREAMLINETRK}.$G_PID
ret_check $?
statusPrint "Checking on the original cff output"
fileExist_check $CMTCFF || fatal noCmtCff
statusPrint "Backing up original cff output"
cp $CMTCFF ${CMTCFF}.$G_PID
ret_check $?
statusPrint "Swapping out trk file"
cp $G_TRKFILE $STREAMLINETRK
ret_check $?
statusPrint "Generating new connectivity structures" "\n"
eval $NEWCMP
statusPrint "Unpacking new connectivity structures"
BASETRK=$(basename $G_TRKFILE)
cp $CMTCFF $CMTCFF.$BASETRK
UNPACKDIR=${CMTCFFDIR}/$BASETRK
mkdir -p $UNPACKDIR
cd $UNPACKDIR
unzip -o ../3-cmt_.cff
ret_check $?
statusPrint "Extracting MatLAB matrices" "\n"
cd CNetwork >/dev/null
cnt_mat.py connectome_freesurferaparc.gpickle $(basename $(dirname $(pwd))) .trk
statusPrint "Restoring previous streamline_filtered.trk"
mv ${STREAMLINETRK}.$G_PID $STREAMLINETRK
ret_check $?
statusPrint "Restoring previous cff file"
mv ${CMTCFF}.$G_PID $CMTCFF
ret_check $?
shut_down 0