6
|
1 #echo "1: " $1 " 2: " $2 " 3: " $3 " 4: " $4 " 5: " $5 " 6: " $6 " 7: " $7 " 8: " $8 " 9: " $9 " 10: " ${10}
|
|
2 #echo "11: " ${11} " 12: " ${12} 13: " ${13} 14: " ${14} " 15: " ${15} " 16: " ${16} " 17: " ${17} " 18: " ${18} " 19: " ${19} " 20: " ${20}
|
|
3 #echo "21: "${21}" 22: "${22}" 23: "${23}" 24: "${24}" 25: "${25}" 26: "${26}" 27: "${27}" 28: "${28}" 29: "${29}" 30: "${30}
|
0
|
4
|
6
|
5 #Count total number of parameters, dataLayer parameters, and classification parameters
|
|
6 parmSize=0
|
|
7 classSize=0
|
|
8 dataLayerSize=0
|
|
9 attribSize=0
|
|
10 for i in "$@"; do
|
|
11 currParm=$(cut -d'|' -f1 <<< $i)
|
|
12 parmSize=$((parmSize+1))
|
|
13 if [ $currParm = "classification" ]
|
|
14 then
|
|
15 classSize=$((classSize+1))
|
|
16 fi
|
|
17 if [ $currParm = "matrix_files" ]
|
|
18 then
|
|
19 dataLayerSize=$((dataLayerSize+1))
|
|
20 fi
|
|
21 if [ $currParm = "attribute" ]
|
|
22 then
|
|
23 attribSize=$((attribSize+1))
|
|
24 fi
|
|
25 done
|
2
|
26
|
6
|
27 if [ $dataLayerSize -lt 1 ]
|
|
28 then
|
|
29 noDataLayer="ERROR: No Heat Map Matrices provided. Please add at least one Heat Map Matrix to your request and try again."
|
|
30 echo $noDataLayer
|
|
31 exit $noDataLayer
|
|
32 fi
|
|
33
|
|
34 #Get tool data and tool install directories
|
|
35 tooldir=$1
|
|
36 tooldata=$2
|
0
|
37 #create temp directory for row and col order and dendro files.
|
2
|
38 tdir=$tooldata/$(date +%y%m%d%M%S)
|
0
|
39 mkdir $tdir
|
6
|
40 #echo "tdir: "$tdir
|
|
41
|
|
42 #Extract parameters for row and column order and dendro files
|
|
43 rowOrderFile=$tdir/ROfile.txt
|
|
44 rowDendroFile=$tdir/RDfile.txt
|
|
45 colOrderFile=$tdir/COfile.txt
|
|
46 colDendroFile=$tdir/CDfile.txt
|
|
47 rowOrderJson='"order_file": "'$rowOrderFile'",'
|
|
48 rowDendroJson='"dendro_file": "'$rowDendroFile'",'
|
|
49 colOrderJson='"order_file": "'$colOrderFile'",'
|
|
50 colDendroJson='"dendro_file": "'$colDendroFile'",'
|
|
51
|
|
52 #BEGIN: Construct JSON for all non-repeating parameters
|
|
53 parmJson='{'
|
|
54 rowConfigJson='"row_configuration": {'
|
|
55 colConfigJson='"col_configuration": {'
|
|
56
|
|
57 ctr=0
|
|
58 for i in "$@"; do
|
|
59 if [ $ctr -gt 1 ]
|
|
60 then
|
|
61 currParm=$(cut -d'|' -f1 <<< $i)
|
7
|
62 if [ $currParm != "matrix_files" ] && [ $currParm != "row_configuration" ] && [ $currParm != "col_configuration" ] && [ $currParm != "classification" ] && [ $currParm != "attribute" ] && [ $currParm != "chm_name" ]
|
6
|
63 then
|
|
64 #Parse pipe-delimited parameter parameter
|
|
65 parmJson=$parmJson' "'$(cut -d'|' -f1 <<< $i)'":"'$(cut -d'|' -f2 <<< $i)'",'
|
|
66 fi
|
7
|
67 if [ $currParm = "chm_name" ]
|
|
68 then
|
|
69 currVal=$(cut -d'|' -f2 <<< $i)
|
|
70 currEdit=$(echo "$currVal" | sed 's/\//_/g')
|
|
71 parmJson=$parmJson' "'$(cut -d'|' -f1 <<< $i)'":"'$currEdit'",'
|
|
72 fi
|
6
|
73 if [ $currParm = "row_configuration" ]
|
|
74 then
|
|
75 rowOrder=$(cut -d'|' -f3 <<< $i)
|
|
76 rowDistance=$(cut -d'|' -f5 <<< $i)
|
|
77 rowAgglomeration=$(cut -d'|' -f7 <<< $i)
|
|
78 rowCuts=$(cut -d'|' -f9 <<< $i)
|
|
79 rowLabels=$(cut -d'|' -f11 <<< $i)
|
|
80 rowDataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$rowLabels'"],'
|
|
81 rowCutType=$(cut -d'|' -f16 <<< $i)
|
|
82 rowTopItemsJson=''
|
|
83 rowTopItems=$(cut -d'|' -f13 <<< $i)
|
|
84 if [ $rowTopItems != "None" ] && [ $rowTopItems != "" ]
|
|
85 then
|
|
86 rowTopItemsJson='"'$(cut -d'|' -f12 <<< $i)'": ['
|
|
87 rowTopItems=${rowTopItems//,/'","'}
|
|
88 rowTopItemsJson=$rowTopItemsJson'"'$rowTopItems'"],'
|
|
89 fi
|
|
90 rowCutsJson=''
|
|
91 if [ $rowCutType != "none" ]
|
|
92 then
|
|
93 cutValues=$(cut -d'|' -f15 <<< $i)
|
|
94 if [ $cutValues != "None" ] && [ $cutValues != "0" ]
|
|
95 then
|
|
96 if [ $rowCutType = "treecuts" ]
|
|
97 then
|
|
98 rowCutsJson=$rowCutsJson'"tree_cuts": "'$cutValues'",'
|
|
99 rowCutsJson=$rowCutsJson'"cut_width": "5",'
|
|
100 fi
|
|
101 if [ $rowCutType = "positional" ]
|
|
102 then
|
|
103 rowCutErrorVal=0
|
|
104 [[ $cutValues != ?(-)+([0-9,]) ]] && rowCutErrorVal=$((rowCutErrorVal+1))
|
|
105 if [ $rowCutErrorVal -gt 0 ]
|
|
106 then
|
|
107 echo "GALAXY PARAMETER WARNING: Non-numeric values found for Row Fixed Gap Locations. Ignoring parameter value: "$cutValues
|
|
108 else
|
|
109 rowCutsJson=$rowCutsJson'"cut_locations": ['$cutValues'],'
|
|
110 rowCutsJson=$rowCutsJson'"cut_width": "5",'
|
|
111 fi
|
|
112 fi
|
|
113 fi
|
|
114 fi
|
|
115 rowConfigJson=$rowConfigJson$rowDataTypeJson$rowCutsJson$rowTopItemsJson
|
|
116 if [ $rowOrder = 'Hierarchical' ]
|
|
117 then
|
|
118 rowConfigJson=$rowConfigJson$rowOrderJson$rowDendroJson
|
|
119 fi
|
|
120 rowConfigJson=$rowConfigJson' "'$(cut -d'|' -f2 <<< $i)'":"'$(cut -d'|' -f3 <<< $i)'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'","'$(cut -d'|' -f6 <<< $i)'":"'$(cut -d'|' -f7 <<< $i)'","'$(cut -d'|' -f17 <<< $i)'":"'$(cut -d'|' -f18 <<< $i)'","'$(cut -d'|' -f19 <<< $i)'":"'$(cut -d'|' -f20 <<< $i)'"},'
|
|
121 fi
|
|
122 if [ $currParm = "col_configuration" ]
|
|
123 then
|
|
124 colOrder=$(cut -d'|' -f3 <<< $i)
|
|
125 colDistance=$(cut -d'|' -f5 <<< $i)
|
|
126 colAgglomeration=$(cut -d'|' -f7 <<< $i)
|
|
127 colCuts=$(cut -d'|' -f9 <<< $i)
|
|
128 colLabels=$(cut -d'|' -f11 <<< $i)
|
|
129 colDataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$colLabels'"],'
|
|
130 colCutType=$(cut -d'|' -f16 <<< $i)
|
|
131 colTopItemsJson=''
|
|
132 colTopItems=$(cut -d'|' -f13 <<< $i)
|
|
133 if [ $colTopItems != "None" ] && [ $colTopItems != "" ]
|
|
134 then
|
|
135 colTopItemsJson='"'$(cut -d'|' -f12 <<< $i)'": ['
|
|
136 colTopItems=${colTopItems//,/'","'}
|
|
137 colTopItemsJson=$colTopItemsJson'"'$colTopItems'"],'
|
|
138 fi
|
|
139 colCutsJson=''
|
|
140 if [ $colCutType != "none" ]
|
|
141 then
|
|
142 cutValues=$(cut -d'|' -f15 <<< $i)
|
|
143 if [ $cutValues != "None" ] && [ $cutValues != "0" ]
|
|
144 then
|
|
145 if [ $colCutType = "treecuts" ]
|
|
146 then
|
|
147 colCutsJson=$colCutsJson'"tree_cuts": "'$cutValues'",'
|
|
148 colCutsJson=$colCutsJson'"cut_width": "5",'
|
|
149 fi
|
|
150 if [ $colCutType = "positional" ]
|
|
151 then
|
|
152 colCutErrorVal=0
|
|
153 [[ $cutValues != ?(-)+([0-9,]) ]] && colCutErrorVal=$((colCutErrorVal+1))
|
|
154 if [ $colCutErrorVal -gt 0 ]
|
|
155 then
|
|
156 echo "GALAXY PARAMETER WARNING: Non-numeric values found for Column Fixed Gap Locations. Ignoring parameter value: "$cutValues
|
|
157 else
|
|
158 colCutsJson=$colCutsJson'"cut_locations": ['$cutValues'],'
|
|
159 colCutsJson=$colCutsJson'"cut_width": "5",'
|
|
160 fi
|
|
161 fi
|
|
162 fi
|
|
163 fi
|
|
164 colConfigJson=$colConfigJson$colDataTypeJson$colCutsJson$colTopItemsJson
|
|
165 if [ $colOrder = 'Hierarchical' ]
|
|
166 then
|
|
167 colConfigJson=$colConfigJson$colOrderJson$colDendroJson
|
|
168 fi
|
|
169 colConfigJson=$colConfigJson' "'$(cut -d'|' -f2 <<< $i)'":"'$(cut -d'|' -f3 <<< $i)'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'","'$(cut -d'|' -f6 <<< $i)'":"'$(cut -d'|' -f7 <<< $i)'","'$(cut -d'|' -f17 <<< $i)'":"'$(cut -d'|' -f18 <<< $i)'","'$(cut -d'|' -f19 <<< $i)'":"'$(cut -d'|' -f20 <<< $i)'"},'
|
|
170 fi
|
|
171 fi
|
|
172 ctr=$((ctr+1))
|
|
173 done
|
|
174
|
|
175 #END: Construct JSON for all non-repeating parameters
|
|
176 #echo "rowOrder: "$rowOrder
|
|
177 #echo "rowDistance: "$rowDistance
|
|
178 #echo "rowAgglomeration: "$rowAgglomeration
|
|
179 #echo "rowCuts: "$rowCuts
|
|
180 #echo "rowLabels: "$rowLabels
|
|
181 #echo "ROW CONFIG JSON: "$rowConfigJson
|
|
182 #echo "colOrder: "$colOrder
|
|
183 #echo "colDistance: "$colDistance
|
|
184 #echo "colAgglomeration: "$colAgglomeration
|
|
185 #echo "colCuts: "$colCuts
|
|
186 #echo "colLabels: "$colLabels
|
|
187 #echo "COL CONFIG JSON: "$colConfigJson
|
|
188
|
|
189 #BEGIN: Construct JSON for data layers
|
|
190 matrixJson='"matrix_files": [ '
|
|
191 inputMatrix=''
|
|
192 dataLayerIter=0
|
|
193 dataLayerNames=''
|
|
194 for i in "$@"; do
|
|
195 currParm=$(cut -d'|' -f1 <<< $i)
|
|
196 if [ $currParm = "matrix_files" ]
|
|
197 then
|
|
198 if [ $dataLayerIter -lt 1 ]
|
|
199 then
|
|
200 inputMatrix=$(cut -d'|' -f3 <<< $i)
|
|
201 fi
|
|
202 currMatrixName=$(cut -d'|' -f5 <<< $i)
|
|
203 dataLayerIter=$((dataLayerIter+1))
|
|
204 if [[ $dataLayerNames =~ $currMatrixName ]]
|
|
205 then
|
|
206 currMatrixName=$currMatrixName$dataLayerIter
|
|
207 fi
|
|
208 dataLayerNames=$dataLayerNames$currMatrixName
|
|
209 colorPref=$(cut -d'|' -f16 <<< $i)
|
|
210 colorMapJson=''
|
|
211 if [ $colorPref = "defined" ]
|
|
212 then
|
|
213 #validations to place leading zero on first breakpoint (if necessary)
|
|
214 b1=$(cut -d'|' -f20 <<< $i)
|
|
215 b1first=$(cut -d'.' -f1 <<< $b1)
|
|
216 if [ $b1first = "-" ]
|
|
217 then
|
|
218 b1="-0."$(cut -d'.' -f2 <<< $b1)
|
|
219 fi
|
|
220 if [ "$b1first" = "" ]
|
|
221 then
|
|
222 b1="0"$b1
|
|
223 fi
|
|
224 #validations to place leading zero on second breakpoint (if necessary)
|
|
225 b2=$(cut -d'|' -f21 <<< $i)
|
|
226 b2first=$(cut -d'.' -f1 <<< $b2)
|
|
227 if [ $b2first = "-" ]
|
|
228 then
|
|
229 b2="-0."$(cut -d'.' -f2 <<< $b2)
|
|
230 fi
|
|
231 if [ "$b2first" = "" ]
|
|
232 then
|
|
233 b2="0"$b2
|
|
234 fi
|
|
235 #validations to place leading zero on third breakpoint (if necessary)
|
|
236 b3=$(cut -d'|' -f22 <<< $i)
|
|
237 b3first=$(cut -d'.' -f1 <<< $b3)
|
|
238 if [ $b3first = "-" ]
|
|
239 then
|
|
240 b3="-0."$(cut -d'.' -f2 <<< $b3)
|
|
241 fi
|
|
242 if [ "$b3first" = "" ]
|
|
243 then
|
|
244 b3="0"$b3
|
|
245 fi
|
|
246 #validation to ensure that all entered breakpoints are numeric values
|
|
247 regExp='^[+-]?([0-9]+\.?|[0-9]*\.[0-9]+)$'
|
|
248 if [[ $b1 =~ $regExp ]] && [[ $b2 =~ $regExp ]] && [[ $b3 =~ $regExp ]]
|
|
249 then
|
|
250 colorMapJson=$colorMapJson'"color_map": {"colors": ["'$(cut -d'|' -f17 <<< $i)'","'$(cut -d'|' -f18 <<< $i)'","'$(cut -d'|' -f19 <<< $i)'"],'
|
|
251 colorMapJson=$colorMapJson'"thresholds": ['$b1','$b2','$b3'],'
|
|
252 colorMapJson=$colorMapJson'"missing":"'$(cut -d'|' -f23 <<< $i)'"},'
|
|
253 else
|
|
254 echo "GALAXY PARAMETER WARNING: Not all user-defined breakpoints are numbers. Defined breakpoints and colors will be ignored."
|
|
255 fi
|
|
256 fi
|
|
257 #Parse pipe-delimited parameter parameter
|
|
258 matrixJson=$matrixJson' {'$colorMapJson'"'$(cut -d'|' -f2 <<< $i)'":"'$(cut -d'|' -f3 <<< $i)'","'$(cut -d'|' -f4 <<< $i)'":"'$currMatrixName'","'$(cut -d'|' -f6 <<< $i)'":"'$(cut -d'|' -f7 <<< $i)'","'$(cut -d'|' -f8 <<< $i)'":"'$(cut -d'|' -f9 <<< $i)'","'$(cut -d'|' -f10 <<< $i)'":"'$(cut -d'|' -f11 <<< $i)'","'$(cut -d'|' -f12 <<< $i)'":"'$(cut -d'|' -f13 <<< $i)'","'$(cut -d'|' -f14 <<< $i)'":"'$(cut -d'|' -f15 <<< $i)'"}'
|
|
259 if [ $dataLayerIter -lt $dataLayerSize ]
|
|
260 then
|
|
261 matrixJson=$matrixJson','
|
|
262 fi
|
|
263 fi
|
|
264 done
|
|
265 matrixJson=$matrixJson"],"
|
|
266 #END: Construct JSON for data layers
|
|
267 #echo "DATA LAYER JSON: "$matrixJson
|
|
268 #echo "INPUT MATRIX: "$inputMatrix
|
|
269
|
|
270 #BEGIN: Construct JSON for attributes
|
|
271 attribJson='"chm_attributes": [ '
|
|
272 attribIter=0
|
|
273 for i in "$@"; do
|
|
274 currParm=$(cut -d'|' -f1 <<< $i)
|
|
275 if [ $currParm = "attribute" ]
|
|
276 then
|
|
277 attribIter=$((attribIter+1))
|
|
278 attribParam=$(cut -d'|' -f2 <<< $i)
|
|
279 #Parse pipe-delimited 2-part data layer parameter
|
|
280 attribJson=$attribJson' {"'$(cut -d':' -f1 <<< $attribParam)'":"'$(cut -d':' -f2 <<< $attribParam)'"}'
|
|
281 if [ $attribIter -lt $attribSize ]
|
|
282 then
|
|
283 attribJson=$attribJson','
|
|
284 fi
|
|
285 fi
|
|
286 done
|
|
287 attribJson=$attribJson'],'
|
|
288 #END: Construct JSON for attributes
|
|
289 #echo "ATTRIB JSON: "$attribJson
|
|
290
|
|
291 #BEGIN: Construct JSON for classification files
|
|
292 classJson='"classification_files": [ '
|
|
293 colCutClass=''
|
|
294 rowCutClass=''
|
|
295 if [ $rowCuts -gt 1 ]
|
|
296 then
|
|
297 rowCutClass='{"name": "Class", "path": "'$tdir'/ROfile.txt.cut","position": "row", "color_map": {"type": "discrete"}, "bar_type": "color_plot"}'
|
|
298 fi
|
|
299
|
|
300 if [ $colCuts -gt 1 ]
|
|
301 then
|
|
302 if [ $rowCuts -gt 1 ]
|
|
303 then
|
|
304 rowCutClass=$rowCutClass','
|
|
305 fi
|
|
306 colCutClass='{"name": "Class", "path": "'$tdir'/COfile.txt.cut","position": "column", "color_map": {"type": "discrete"}, "bar_type": "color_plot"}'
|
|
307 if [ $classSize -gt 0 ]
|
|
308 then
|
|
309 colCutClass=$colCutClass','
|
|
310 fi
|
|
311 else
|
|
312 if [ $rowCuts -gt 1 ] && [ $classSize -gt 0 ]
|
|
313 then
|
|
314 rowCutClass=$rowCutClass','
|
|
315 fi
|
|
316 fi
|
|
317
|
|
318 classJson=$classJson$rowCutClass$colCutClass
|
|
319 classIter=0
|
|
320 for i in "$@"; do
|
|
321 currParm=$(cut -d'|' -f1 <<< $i)
|
|
322 if [ $currParm = "classification" ]
|
|
323 then
|
|
324 classIter=$((classIter+1))
|
|
325 className=$(cut -d'|' -f3 <<< $i)
|
|
326 #Parse pipe-delimited 3-part classification bar parameter
|
7
|
327 if [[ -z "$className" ]]; then
|
|
328 className="covar"$classIter
|
|
329 fi
|
|
330 classJson=$classJson' {"'$(cut -d'|' -f2 <<< $i)'":"'$className'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'","'$(cut -d'|' -f8 <<< $i)'":"'$(cut -d'|' -f9 <<< $i)'","'$(cut -d'|' -f12 <<< $i)'":"'$(cut -d'|' -f13 <<< $i)'","'$(cut -d'|' -f14 <<< $i)'":"'$(cut -d'|' -f15 <<< $i)'"'
|
6
|
331 classCat=$(cut -d'|' -f7 <<< $i)
|
|
332 classColorType=$(cut -d'_' -f2 <<< $classCat)
|
|
333 classJson=$classJson','
|
|
334 classHeight=$(cut -d'|' -f11 <<< $i)
|
|
335 heightErrorVal=0
|
|
336 [[ $classHeight != ?(-)+([0-9]) ]] && heightErrorVal=$((heightErrorVal+1))
|
|
337 if [ $heightErrorVal -gt 0 ]
|
|
338 then
|
|
339 echo 'GALAXY PARAMETER WARNING: Non-numeric values found for covariate bar ('$className') height. Height value ignored and default of 15 used: '$classHeight
|
|
340 else
|
|
341 classJson=$classJson'"height": "'$classHeight'",'
|
|
342 fi
|
|
343 classJson=$classJson' "position":"'$(cut -d'_' -f1 <<< $classCat)'","color_map": {"type":"'$classColorType'"}}'
|
|
344 if [ $classIter -lt $classSize ]
|
|
345 then
|
|
346 classJson=$classJson','
|
|
347 fi
|
|
348 fi
|
|
349 done
|
|
350 classJson=$classJson']'
|
|
351 #END: Construct JSON for classification files
|
|
352 #echo "CLASSIFICATION JSON: "$classJson
|
|
353
|
|
354 #Complete construction of Parameter JSON file by adding all JSON sections created above
|
|
355 parmJson=$parmJson$rowConfigJson$colConfigJson$attribJson$matrixJson$classJson
|
|
356 parmJson=$parmJson'}'
|
|
357 #echo "COMPLETED PARAMETER JSON: "$parmJson
|
|
358
|
0
|
359 #run R to cluster matrix
|
6
|
360 output="$(R --slave --vanilla --file=$tooldir/CHM_Advanced.R --args $inputMatrix $rowOrder $rowDistance $rowAgglomeration $colOrder $colDistance $colAgglomeration $rowOrderFile $colOrderFile $rowDendroFile $colDendroFile $rowCuts $colCuts $rowLabels $colLabels 2>&1)"
|
|
361 # Check for errors from R step, log them if found, and exit script
|
0
|
362 rc=$?;
|
|
363 if [ $rc != 0 ]
|
|
364 then
|
|
365 echo $output;
|
|
366 if [ `echo "$output" | grep -c "Inf in foreign function call"` -gt 0 ]
|
|
367 then
|
|
368 echo "";
|
7
|
369 echo "";
|
|
370 echo "R CLUSTERING: Error in clustering the matrix provided (View Details stdout). "
|
|
371 echo "Note: This error can occur when:"
|
|
372 echo " 1. There is invalid numeric data in the matrix provided. Try using Matrix Manipulation tools to fix invalid data.";
|
|
373 echo " 2. There is no variation in a row or column in the matrix. Try a different distance measure or remove rows/columns without variation using Matrix Manipulation tools.";
|
|
374 echo " 3. A covariate file has inadvertently been selected as an Input Matrix. Check your Input Matrix entry.";
|
0
|
375 fi
|
|
376 exit $rc;
|
|
377 fi
|
1
|
378
|
6
|
379 #Call java program to generate NGCHM viewer files.
|
|
380 java -jar $tooldir/GalaxyMapGen.jar "$parmJson"
|
0
|
381 #clean up tempdir
|
|
382 rm -rf $tdir
|