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