Mercurial > repos > md-anderson-bioinformatics > heat_map_creation
comparison heatmap.sh @ 40:8f8ab332a050 draft
Uploaded
author | insilico-bob |
---|---|
date | Thu, 20 Jun 2019 11:39:46 -0400 |
parents | |
children | 8acca16f3921 |
comparison
equal
deleted
inserted
replaced
39:436f03b71cf6 | 40:8f8ab332a050 |
---|---|
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) | |
45 if [ $currParm != "matrix_files" ] && [ $currParm != "row_configuration" ] && [ $currParm != "col_configuration" ] && [ $currParm != "classification" ] | |
46 then | |
47 #Parse pipe-delimited parameter parameter | |
48 parmJson=$parmJson' "'$(cut -d'|' -f1 <<< $i)'":"'$(cut -d'|' -f2 <<< $i)'",' | |
49 fi | |
50 if [ $currParm = "row_configuration" ] | |
51 then | |
52 rowOrder=$(cut -d'|' -f3 <<< $i) | |
53 rowDistance=$(cut -d'|' -f5 <<< $i) | |
54 rowAgglomeration=$(cut -d'|' -f7 <<< $i) | |
55 rowCuts=$(cut -d'|' -f9 <<< $i) | |
56 rowLabels=$(cut -d'|' -f11 <<< $i) | |
57 dataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$rowLabels'"]' | |
58 if [ $rowOrder = 'Hierarchical' ] | |
59 then | |
60 rowConfigJson=$rowConfigJson$rowOrderJson$rowDendroJson | |
61 fi | |
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'},' | |
63 fi | |
64 if [ $currParm = "col_configuration" ] | |
65 then | |
66 colOrder=$(cut -d'|' -f3 <<< $i) | |
67 colDistance=$(cut -d'|' -f5 <<< $i) | |
68 colAgglomeration=$(cut -d'|' -f7 <<< $i) | |
69 colCuts=$(cut -d'|' -f9 <<< $i) | |
70 colLabels=$(cut -d'|' -f11 <<< $i) | |
71 dataTypeJson='"'$(cut -d'|' -f10 <<< $i)'":["'$colLabels'"]' | |
72 if [ $colOrder = 'Hierarchical' ] | |
73 then | |
74 colConfigJson=$colConfigJson$colOrderJson$colDendroJson | |
75 fi | |
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'},' | |
77 fi | |
78 fi | |
79 ctr=$((ctr+1)) | |
80 done | |
81 #END: Construct JSON for all non-repeating parameters | |
82 #echo "rowCuts: "$rowCuts | |
83 #echo "colCuts: "$colCuts | |
84 #echo "ROW CONFIG JSON: "$rowConfigJson | |
85 #echo "COL CONFIG JSON: "$colConfigJson | |
86 | |
87 #BEGIN: Construct JSON for data layers | |
88 matrixJson='"matrix_files": [ ' | |
89 inputMatrix='' | |
90 for i in "$@"; do | |
91 currParm=$(cut -d'|' -f1 <<< $i) | |
92 if [ $currParm = "matrix_files" ] | |
93 then | |
94 #Parse pipe-delimited parameter parameter | |
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)'"}' | |
96 inputMatrix=$(cut -d'|' -f3 <<< $i) | |
97 fi | |
98 done | |
99 matrixJson=$matrixJson"]," | |
100 #END: Construct JSON for data layers | |
101 | |
102 #BEGIN: Construct JSON for classification files | |
103 classJson='"classification_files": [ ' | |
104 classIter=0 | |
105 for i in "$@"; do | |
106 currParm=$(cut -d'|' -f1 <<< $i) | |
107 if [ $currParm = "classification" ] | |
108 then | |
109 classIter=$((classIter+1)) | |
110 #Parse pipe-delimited 3-part classification bar parameter | |
111 classJson=$classJson' {"'$(cut -d'|' -f2 <<< $i)'":"'$(cut -d'|' -f3 <<< $i)'","'$(cut -d'|' -f4 <<< $i)'":"'$(cut -d'|' -f5 <<< $i)'"' | |
112 classCat=$(cut -d'|' -f7 <<< $i) | |
113 classColorType=$(cut -d'_' -f2 <<< $classCat) | |
114 classJson=$classJson',' | |
115 classJson=$classJson' "position":"'$(cut -d'_' -f1 <<< $classCat)'","color_map": {"type":"'$classColorType'"}}' | |
116 if [ $classIter -lt $classSize ] | |
117 then | |
118 classJson=$classJson',' | |
119 fi | |
120 fi | |
121 done | |
122 classJson=$classJson']' | |
123 #END: Construct JSON for classification files | |
124 | |
125 parmJson=$parmJson$matrixJson$rowConfigJson$colConfigJson$classJson | |
126 parmJson=$parmJson'}' | |
127 #echo "HEATMAP PARAMETERS JSON: "$parmJson | |
128 | |
129 #run R to cluster matrix | |
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)" | |
131 rc=$?; | |
132 if [ $rc != 0 ] | |
133 then | |
134 echo $output; | |
135 if [ `echo "$output" | grep -c "Inf in foreign function call"` -gt 0 ] | |
136 then | |
137 echo ""; | |
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."; | |
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."; | |
140 fi | |
141 exit $rc; | |
142 fi | |
143 | |
144 #call java program to generate NGCHM viewer files. | |
145 java -jar $tooldir/GalaxyMapGen.jar "$parmJson" | |
146 #clean up tempdir | |
147 rm -rf $tdir |