-
Notifications
You must be signed in to change notification settings - Fork 3
/
cluster_genXML.bash
executable file
·204 lines (165 loc) · 6.76 KB
/
cluster_genXML.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
201
202
203
204
#!/bin/bash
#
# cluster_genXML.bash
#
# Copyright 2009 Dan Ginsburg
# Children's Hospital Boston
#
# GPL v2
#
source common.bash
declare -i Gi_verbose=0
declare -i Gb_singleLine=0
declare -i Gi_lineNumber=0
declare -i Gb_generateXMLHeader=0
G_CLUSTERFILE="-x"
G_SYNOPSIS="
NAME
cluster_genXML.bash
SYNOPSIS
cluster_genXML.bash -f <clusterScheduleLog> \\
-l <lineNumber> \\
[-h]
DESCRIPTION
'cluster_genXML.bash' takes as input a <clusterScheduleLog> file
and traverses all of the jobs in the file to produce an XML detailed
summary of each of the jobs. This XML file is used by the web
front-end to display a rich browser for the cluster jobs.
CLUSTER LOG
The <clusterScheduleLog> contains a log of all the scheduled jobs
for the cluster. This file is generated by tract_meta.bash and
fs_meta.bash when they are passed the -C option.
ARGUMENTS
-f <clusterScheduleLog>
The cluster schedule.log file to process
-l <lineNumber> (Optional)
Only output XML for the specified line in the cluster schedule log.
-h (Optional, Default: off)
Generate XML header, regardless of whether the -l option is specified.
PRECONDITIONS
o A FreeSurfer 'std' or 'dev' environment.
o 'tract_meta.bash', 'fs_meta.bash' and related.
POSTCONDITIONS
HISTORY
19 February 2010
o Initial design and coding.
"
###\\\
# Globals are in capital letters. Immutable globals are prefixed by 'G'.
###///
# Actions
A_noclusterFileArg="checking on -f <clusterScheduleLog> argument"
A_stageRun="running a stage in the processing pipeline"
# Error messages
EM_noclusterFileArg="it seems as though you didn't specify a -f <clusterScheduleLog>."
EM_stageRun="I encountered an error processing this stage."
# Error codes
EC_noClusterFile=41
EC_stageRun=30
# Defaults
D_whatever=
###\\\
# Function definitions
###///
function echo_stripped
{
# ARGS
# $1 string to print
#
# DESC
# Strip out any non-UTF8 characters before echoing
#
echo -e "$@" | iconv -f UTF-8 -t UTF-8 -c | sed -e 's/\&/\&/g' -e 's/</\</g' -e 's/>/\>/g' -e 's/\"/\"/g' -e 's/\x27/\'/g'
}
###\\\
# Process command options
###///
while getopts f:l:h option ; do
case "$option"
in
f) G_CLUSTERFILE=$OPTARG ;;
l) Gb_singleLine=1
Gi_lineNumber=$OPTARG ;;
h) Gb_generateXMLHeader=1 ;;
\?) synopsis_show
exit 0;;
esac
done
if (( !Gb_singleLine || Gb_generateXMLHeader )) ; then
echo "<?xml version=\"1.0\"?>"
fi
# Iterate over each line in the cluster file
exec<$G_CLUSTERFILE
declare -i curLine=0
while read line
do
curLine=curLine+1
if (( Gb_singleLine )) ; then
if (( curLine != Gi_lineNumber )) ; then
continue
fi
fi
# Determine the cluster script name
CLUSTERCMD=$(echo $line | awk -F \| 'NF > 1 {print $3}'| sed 's/ Stage //' | sed 's/^[ \t]*//;s/[ \t]*$//')
# Determine the project name from the schedule.log. Unfortunately, some early projects did not have names
# so we go through some hoops to call those ones "unnamed"
PROJECT=$(echo $line | awk -F'|' '{print $3}' | awk '{print $2}' | xargs -i% dirname % | xargs -i% basename % | awk -F'-' '{
if(NF<=4)
{
printf "unnamed\n"
}
else
{
for(i=5; i<NF;i++)
printf "%s-",$i;
if(NF==5 && $NF == "")
{
printf "unnamed\n"
}
else
{
printf "%s\n",$NF
}
}}')
if [ -f $CLUSTERCMD ] ; then
DATE=$(echo $line | awk '{print $1,$2,$3,$4,$5,$6}' | xargs -i$ date --date='$' +"%D %R:%S %a")
CLUSTERSH=$(cat $CLUSTERCMD)
SCANFILE=$(echo $CLUSTERSH | grep '\-d .*' -o | awk '{print $2}')
SUBMITUSER=$(echo $line | awk '{print $8}')
TOCFILEPATH=$(dirname $(dirname $CLUSTERCMD))"/toc.txt"
METASCRIPT=$(cat $CLUSTERCMD | grep '_meta.bash' | awk '{ print $1 }')
CMDARGUMENTS=$(cat $CLUSTERCMD | grep '_meta.bash' | awk -F '>' '{print $1}' | awk '{for(f=2;f<=NF;f++) printf("%s ",$f) }')
if [ -f $TOCFILEPATH ] ; then
TOCFILE=$(cat -E $TOCFILEPATH | sed 's/\$/\\n/g')
PATIENT_ID=$(echo $TOCFILE | grep "Patient ID" | awk '{print $3}')
PATIENT_NAME=$(echo -e $TOCFILE | grep "Patient Name" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
PATIENT_AGE=$(echo -e $TOCFILE | grep "Patient Age" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
PATIENT_SEX=$(echo -e $TOCFILE | grep "Patient Sex" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
PATIENT_BIRTHDAY=$(echo -e $TOCFILE | grep "Patient Birthday" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
IMAGE_SCAN_DATE=$(echo -e $TOCFILE | grep "Image Scan-Date" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
SCANNER_MANUFACTURER=$(echo -e $TOCFILE | grep "Scanner Manufacturer" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
SCANNER_MODEL=$(echo -e $TOCFILE | grep "Scanner Model" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
SOFTWARE_VER=$(echo -e $TOCFILE | grep "Software Ver" | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//')
SCANNAME=$(echo -e $TOCFILE | grep $SCANFILE | awk '{$1="";$2="";print}' | sed -e 's/^[ \t]*//' | tr -d "<>")
echo -e "<ClusterJob>"
echo -e " <Command>$(echo_stripped $CLUSTERCMD)</Command>"
echo -e " <Arguments>$(echo_stripped $CMDARGUMENTS)</Arguments>"
echo -e " <MetaScript>$(echo_stripped $METASCRIPT)</MetaScript>"
echo -e " <Date>$(echo_stripped $DATE)</Date>"
echo -e " <User>$(echo_stripped $SUBMITUSER)</User>"
echo -e " <Project>$(echo_stripped $PROJECT)</Project>"
echo -e " <PatientID>$(echo_stripped $PATIENT_ID)</PatientID>"
echo -e " <PatientName>$(echo_stripped $PATIENT_NAME)</PatientName>"
echo -e " <PatientAge>$(echo_stripped $PATIENT_AGE)</PatientAge>"
echo -e " <PatientSex>$(echo_stripped $PATIENT_SEX)</PatientSex>"
echo -e " <PatientBirthday>$(echo_stripped $PATIENT_BIRTHDAY)</PatientBirthday>"
echo -e " <ImageScanDate>$(echo_stripped $IMAGE_SCAN_DATE)</ImageScanDate>"
echo -e " <ScannerManufacturer>$(echo_stripped $SCANNER_MANUFACTURER)</ScannerManufacturer>"
echo -e " <ScannerModel>$(echo_stripped $SCANNER_MODEL)</ScannerModel>"
echo -e " <SoftwareVer>$(echo_stripped $SOFTWARE_VER)</SoftwareVer>"
echo -e " <ScanName>$(echo_stripped $SCANNAME)</ScanName>"
echo -e " <JobId>$curLine</JobId>"
echo -e "</ClusterJob>"
fi
fi
done