annotate heatmap.sh @ 43:2aa91f21a24e draft default tip

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