40
|
1 #echo "1: " $1" 2: " $2" 3: " $3" 4: "$4" 5: "$5 " 6: "$6 "7: "$7" 8: "$8 " 9: "$9" 10: "${10}" 11: "${11} "12: "${12}
|
|
2 #echo " 13: "${13}" 14: "${14}" 15: "${15}" 16: "${16} "17: "${17}" 18: "${18}" 19: "${19}" 20: "${20}" 21: "${21} " 22: "${22}" 23:" ${23}
|
|
3
|
|
4 #Count total number of parameters and classification parameters
|
|
5 parmSize=0
|
|
6 classSize=0
|
|
7 matrixSize=0
|
|
8 for i in "$@"; do
|
|
9 currParm=$(cut -d'|' -f1 <<< $i)
|
|
10 parmSize=$((parmSize+1))
|
|
11 if [ $currParm = "classification" ]
|
|
12 then
|
|
13 classSize=$((classSize+1))
|
|
14 fi
|
|
15 done
|
|
16
|
|
17 #Get tool data and tool install directories
|
|
18 tooldir=$1
|
|
19 tooldata=$2
|
|
20 #create temp directory for row and col order and dendro files.
|
|
21 tdir=$tooldata/$(date +%y%m%d%M%S)
|
|
22 mkdir $tdir
|
|
23 #echo "tdir: "$tdir
|
|
24
|
|
25 #Extract parameters for row and column order and dendro files
|
|
26 rowOrderFile=$tdir/ROfile.txt
|
|
27 rowDendroFile=$tdir/RDfile.txt
|
|
28 colOrderFile=$tdir/COfile.txt
|
|
29 colDendroFile=$tdir/CDfile.txt
|
|
30 rowOrderJson='"order_file": "'$rowOrderFile'",'
|
|
31 rowDendroJson='"dendro_file": "'$rowDendroFile'",'
|
|
32 colOrderJson='"order_file": "'$colOrderFile'",'
|
|
33 colDendroJson='"dendro_file": "'$colDendroFile'",'
|
|
34
|
|
35 #BEGIN: Construct JSON for all non-repeating parameters
|
|
36 parmJson='{'
|
|
37 rowConfigJson='"row_configuration": {'
|
|
38 colConfigJson='"col_configuration": {'
|
|
39
|
|
40 ctr=0
|
|
41 for i in "$@"; do
|
|
42 if [ $ctr -gt 1 ]
|
|
43 then
|
|
44 currParm=$(cut -d'|' -f1 <<< $i)
|
41
|
45 if [ $currParm != "matrix_files" ] && [ $currParm != "row_configuration" ] && [ $currParm != "col_configuration" ] && [ $currParm != "classification" ] && [ $currParm != "chm_name" ]
|
40
|
46 then
|
|
47 #Parse pipe-delimited parameter parameter
|
|
48 parmJson=$parmJson' "'$(cut -d'|' -f1 <<< $i)'":"'$(cut -d'|' -f2 <<< $i)'",'
|
|
49 fi
|
41
|
50 if [ $currParm = "chm_name" ]
|
|
51 then
|
|
52 currVal=$(cut -d'|' -f2 <<< $i)
|
|
53 currEdit=$(echo "$currVal" | sed 's/\//_/g')
|
|
54 parmJson=$parmJson' "'$(cut -d'|' -f1 <<< $i)'":"'$currEdit'",'
|
|
55 fi
|
40
|
56 if [ $currParm = "row_configuration" ]
|
|
57 then
|
|
58 rowOrder=$(cut -d'|' -f3 <<< $i)
|
|
59 rowDistance=$(cut -d'|' -f5 <<< $i)
|
|
60 rowAgglomeration=$(cut -d'|' -f7 <<< $i)
|
|
61 rowCuts=$(cut -d'|' -f9 <<< $i)
|
|
62 rowLabels=$(cut -d'|' -f11 <<< $i)
|
|
63 dataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$rowLabels'"]'
|
|
64 if [ $rowOrder = 'Hierarchical' ]
|
|
65 then
|
|
66 rowConfigJson=$rowConfigJson$rowOrderJson$rowDendroJson
|
|
67 fi
|
|
68 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)'",'$dataTypeJson'},'
|
|
69 fi
|
|
70 if [ $currParm = "col_configuration" ]
|
|
71 then
|
|
72 colOrder=$(cut -d'|' -f3 <<< $i)
|
|
73 colDistance=$(cut -d'|' -f5 <<< $i)
|
|
74 colAgglomeration=$(cut -d'|' -f7 <<< $i)
|
|
75 colCuts=$(cut -d'|' -f9 <<< $i)
|
|
76 colLabels=$(cut -d'|' -f11 <<< $i)
|
|
77 dataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$colLabels'"]'
|
|
78 if [ $colOrder = 'Hierarchical' ]
|
|
79 then
|
|
80 colConfigJson=$colConfigJson$colOrderJson$colDendroJson
|
|
81 fi
|
|
82 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)'",'$dataTypeJson'},'
|
|
83 fi
|
|
84 fi
|
|
85 ctr=$((ctr+1))
|
|
86 done
|
|
87 #END: Construct JSON for all non-repeating parameters
|
|
88 #echo "rowCuts: "$rowCuts
|
|
89 #echo "colCuts: "$colCuts
|
|
90 #echo "ROW CONFIG JSON: "$rowConfigJson
|
|
91 #echo "COL CONFIG JSON: "$colConfigJson
|
|
92
|
|
93 #BEGIN: Construct JSON for data layers
|
|
94 matrixJson='"matrix_files": [ '
|
|
95 inputMatrix=''
|
|
96 for i in "$@"; do
|
|
97 currParm=$(cut -d'|' -f1 <<< $i)
|
|
98 if [ $currParm = "matrix_files" ]
|
|
99 then
|
|
100 #Parse pipe-delimited parameter parameter
|
|
101 matrixJson=$matrixJson' {"'$(cut -d'|' -f2 <<< $i)'":"'$(cut -d'|' -f3 <<< $i)'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'","'$(cut -d'|' -f6 <<< $i)'":"'$(cut -d'|' -f7 <<< $i)'"}'
|
|
102 inputMatrix=$(cut -d'|' -f3 <<< $i)
|
|
103 fi
|
|
104 done
|
|
105 matrixJson=$matrixJson"],"
|
|
106 #END: Construct JSON for data layers
|
|
107
|
|
108 #BEGIN: Construct JSON for classification files
|
|
109 classJson='"classification_files": [ '
|
|
110 classIter=0
|
|
111 for i in "$@"; do
|
|
112 currParm=$(cut -d'|' -f1 <<< $i)
|
|
113 if [ $currParm = "classification" ]
|
|
114 then
|
|
115 classIter=$((classIter+1))
|
|
116 #Parse pipe-delimited 3-part classification bar parameter
|
41
|
117 className=$(cut -d'|' -f3 <<< $i)
|
|
118 if [[ -z "$className" ]]; then
|
|
119 className="covar"$classIter
|
|
120 fi
|
|
121 classJson=$classJson' {"'$(cut -d'|' -f2 <<< $i)'":"'$className'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'"'
|
40
|
122 classCat=$(cut -d'|' -f7 <<< $i)
|
|
123 classColorType=$(cut -d'_' -f2 <<< $classCat)
|
|
124 classJson=$classJson','
|
|
125 classJson=$classJson' "position":"'$(cut -d'_' -f1 <<< $classCat)'","color_map": {"type":"'$classColorType'"}}'
|
|
126 if [ $classIter -lt $classSize ]
|
|
127 then
|
|
128 classJson=$classJson','
|
|
129 fi
|
|
130 fi
|
|
131 done
|
|
132 classJson=$classJson']'
|
|
133 #END: Construct JSON for classification files
|
|
134
|
42
|
135 #Add build platform JSON for distinction between GenePattern and Galaxy Builders
|
|
136 platformJson='"build_platform": "Galaxy",'
|
|
137
|
|
138 parmJson=$parmJson$matrixJson$rowConfigJson$colConfigJson$platformJson$classJson
|
40
|
139 parmJson=$parmJson'}'
|
|
140 #echo "HEATMAP PARAMETERS JSON: "$parmJson
|
|
141
|
|
142 #run R to cluster matrix
|
|
143 output="$(R --slave --vanilla --file=$tooldir/CHM.R --args $inputMatrix $rowOrder $rowDistance $rowAgglomeration $colOrder $colDistance $colAgglomeration $rowOrderFile $colOrderFile $rowDendroFile $colDendroFile $rowCuts $colCuts $rowLabels $colLabels 2>&1)"
|
|
144 rc=$?;
|
|
145 if [ $rc != 0 ]
|
|
146 then
|
|
147 echo $output;
|
|
148 if [ `echo "$output" | grep -c "Inf in foreign function call"` -gt 0 ]
|
|
149 then
|
|
150 echo "";
|
41
|
151 echo "R CLUSTERING: Error in clustering the matrix provided (View Details - stdout). "
|
|
152 echo "Note: This error can occur when:"
|
|
153 echo " 1. There is invalid numeric data in the matrix provided. Try using Matrix Manipulation tools to fix invalid data.";
|
|
154 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.";
|
|
155 echo " 3. A covariate file has inadvertently been selected as an Input Matrix. Check your Input Matrix entry.";
|
40
|
156 fi
|
|
157 exit $rc;
|
|
158 fi
|
|
159
|
|
160 #call java program to generate NGCHM viewer files.
|
|
161 java -jar $tooldir/GalaxyMapGen.jar "$parmJson"
|
|
162 #clean up tempdir
|
|
163 rm -rf $tdir
|