annotate heatmap.sh @ 40:8f8ab332a050 draft

Uploaded
author insilico-bob
date Thu, 20 Jun 2019 11:39:46 -0400
parents
children 8acca16f3921
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)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
45 if [ $currParm != "matrix_files" ] && [ $currParm != "row_configuration" ] && [ $currParm != "col_configuration" ] && [ $currParm != "classification" ]
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
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
50 if [ $currParm = "row_configuration" ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
51 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
52 rowOrder=$(cut -d'|' -f3 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
53 rowDistance=$(cut -d'|' -f5 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
54 rowAgglomeration=$(cut -d'|' -f7 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
55 rowCuts=$(cut -d'|' -f9 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
56 rowLabels=$(cut -d'|' -f11 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
57 dataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$rowLabels'"]'
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
58 if [ $rowOrder = 'Hierarchical' ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
59 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
60 rowConfigJson=$rowConfigJson$rowOrderJson$rowDendroJson
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
61 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
62 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
63 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
64 if [ $currParm = "col_configuration" ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
65 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
66 colOrder=$(cut -d'|' -f3 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
67 colDistance=$(cut -d'|' -f5 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
68 colAgglomeration=$(cut -d'|' -f7 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
69 colCuts=$(cut -d'|' -f9 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
70 colLabels=$(cut -d'|' -f11 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
71 dataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$colLabels'"]'
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
72 if [ $colOrder = 'Hierarchical' ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
73 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
74 colConfigJson=$colConfigJson$colOrderJson$colDendroJson
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
75 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
76 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
77 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
78 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
79 ctr=$((ctr+1))
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
80 done
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
81 #END: Construct JSON for all non-repeating parameters
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
82 #echo "rowCuts: "$rowCuts
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
83 #echo "colCuts: "$colCuts
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
84 #echo "ROW CONFIG JSON: "$rowConfigJson
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
85 #echo "COL CONFIG JSON: "$colConfigJson
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
86
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
87 #BEGIN: Construct JSON for data layers
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
88 matrixJson='"matrix_files": [ '
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
89 inputMatrix=''
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
90 for i in "$@"; do
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
91 currParm=$(cut -d'|' -f1 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
92 if [ $currParm = "matrix_files" ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
93 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
94 #Parse pipe-delimited parameter parameter
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
95 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
96 inputMatrix=$(cut -d'|' -f3 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
97 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
98 done
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
99 matrixJson=$matrixJson"],"
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
100 #END: Construct JSON for data layers
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
101
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
102 #BEGIN: Construct JSON for classification files
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
103 classJson='"classification_files": [ '
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
104 classIter=0
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
105 for i in "$@"; do
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
106 currParm=$(cut -d'|' -f1 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
107 if [ $currParm = "classification" ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
108 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
109 classIter=$((classIter+1))
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
110 #Parse pipe-delimited 3-part classification bar parameter
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
111 classJson=$classJson' {"'$(cut -d'|' -f2 <<< $i)'":"'$(cut -d'|' -f3 <<< $i)'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'"'
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
112 classCat=$(cut -d'|' -f7 <<< $i)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
113 classColorType=$(cut -d'_' -f2 <<< $classCat)
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
114 classJson=$classJson','
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
115 classJson=$classJson' "position":"'$(cut -d'_' -f1 <<< $classCat)'","color_map": {"type":"'$classColorType'"}}'
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
116 if [ $classIter -lt $classSize ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
117 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
118 classJson=$classJson','
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
119 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
120 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
121 done
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
122 classJson=$classJson']'
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
123 #END: Construct JSON for classification files
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
124
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
125 parmJson=$parmJson$matrixJson$rowConfigJson$colConfigJson$classJson
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
126 parmJson=$parmJson'}'
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
127 #echo "HEATMAP PARAMETERS JSON: "$parmJson
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
128
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
129 #run R to cluster matrix
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
130 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
131 rc=$?;
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
132 if [ $rc != 0 ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
133 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
134 echo $output;
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
135 if [ `echo "$output" | grep -c "Inf in foreign function call"` -gt 0 ]
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
136 then
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
137 echo "";
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
138 echo "Note: This error can occur when there is no variation in a row or column. Try a different distance measure or remove rows/columns without variation.";
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
139 echo "This error may also be caused when a covariate file has inadvertently been selected as an Input Matrix. Check your Input Matrix entry.";
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
140 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
141 exit $rc;
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
142 fi
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
143
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
144 #call java program to generate NGCHM viewer files.
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
145 java -jar $tooldir/GalaxyMapGen.jar "$parmJson"
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
146 #clean up tempdir
8f8ab332a050 Uploaded
insilico-bob
parents:
diff changeset
147 rm -rf $tdir