Mercurial > repos > md-anderson-bioinformatics > heat_map_creation
comparison heatmap.sh @ 38:605ec840a06b draft
Uploaded
author | insilico-bob |
---|---|
date | Thu, 20 Jun 2019 11:30:12 -0400 |
parents | 58437af2d675 |
children |
comparison
equal
deleted
inserted
replaced
37:f2272e907f1b | 38:605ec840a06b |
---|---|
1 #echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} | 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} | |
2 | 3 |
3 #get tool data and tool install directories | 4 #Count total number of parameters and classification parameters |
4 tooldir=$(cut -d';' -f1 <<< ${12}) | 5 parmSize=0 |
5 tooldata=$(cut -d';' -f2 <<< ${12}) | 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 | |
6 | 16 |
17 #Get tool data and tool install directories | |
18 tooldir=$1 | |
19 tooldata=$2 | |
7 #create temp directory for row and col order and dendro files. | 20 #create temp directory for row and col order and dendro files. |
8 tdir=$tooldata/$(date +%y%m%d%M%S) | 21 tdir=$tooldata/$(date +%y%m%d%M%S) |
9 echo $tdir | |
10 mkdir $tdir | 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 | |
11 | 128 |
12 #run R to cluster matrix | 129 #run R to cluster matrix |
13 output="$(R --slave --vanilla --file=$tooldir/CHM.R --args $4 $5 $6 $7 $8 $9 ${10} $tdir/ROfile.txt $tdir/COfile.txt $tdir/RDfile.txt $tdir/CDfile.txt ${13} ${14} ${15} ${16} 2>&1)" | 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)" |
14 rc=$?; | 131 rc=$?; |
15 if [ $rc != 0 ] | 132 if [ $rc != 0 ] |
16 then | 133 then |
17 echo $output; | 134 echo $output; |
18 if [ `echo "$output" | grep -c "Inf in foreign function call"` -gt 0 ] | 135 if [ `echo "$output" | grep -c "Inf in foreign function call"` -gt 0 ] |
22 echo "This error may also be caused when a covariate file has inadvertently been selected as an Input Matrix. Check your Input Matrix entry."; | 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."; |
23 fi | 140 fi |
24 exit $rc; | 141 exit $rc; |
25 fi | 142 fi |
26 | 143 |
27 #there are a variable number of triplicate parameters for classification bars | |
28 count=0 | |
29 classifications='' | |
30 | |
31 #if row cut was done, add that autogenerated classification | |
32 if [ ${13} -gt 1 ] | |
33 then | |
34 classifications="Class $tdir/ROfile.txt.cut row_categorical" | |
35 fi | |
36 | |
37 #if col cut was done, add that autogenerated classification | |
38 if [ ${14} -gt 1 ] | |
39 then | |
40 classifications="$classifications Class $tdir/COfile.txt.cut col_categorical" | |
41 fi | |
42 | |
43 #now add the user provided classification files | |
44 for i in "$@"; do | |
45 if [ $count -gt 16 ] | |
46 then | |
47 classifications=$classifications' '$i | |
48 fi | |
49 count=$((count+1)) | |
50 done | |
51 echo "classifications " $classifications | |
52 echo "${11} " ${11} | |
53 #call java program to generate NGCHM viewer files. | 144 #call java program to generate NGCHM viewer files. |
54 java -jar $tooldir/GalaxyMapGen.jar "${1}" "${2}" "${3}" DataLayer1 $4 linear ${15} ${16} $5 $6 $7 $tdir/ROfile.txt $tdir/RDfile.txt $8 $9 ${10} $tdir/COfile.txt $tdir/CDfile.txt ${11} $classifications | 145 java -jar $tooldir/GalaxyMapGen.jar "$parmJson" |
55 #clean up tempdir | 146 #clean up tempdir |
56 rm -rf $tdir | 147 rm -rf $tdir |