Skip to content

Commit dc0e664

Browse files
authored
Merge pull request #149 from broadinstitute/demo-2
log transformation handling
2 parents f115d6d + 77cd570 commit dc0e664

File tree

7 files changed

+51
-33
lines changed

7 files changed

+51
-33
lines changed

build/js/gtex-viz.bundle.dev.js

Lines changed: 18 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

html/GTExViz.dendroHeatmap.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ <h5>GTEx DendroHeatmap</h5>
130130
const config = {
131131
id: 'userDendroHeatmap',
132132
data: data,
133+
useLog: true,
134+
logBase: 10,
133135
width: 600, // outer width
134136
height: 300, // outer height
135137
marginLeft: 20,

html/GTExViz.heatmap.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ <h5>GTEx Heatmap</h5>
2727

2828
<script src="/build/js/gtex-viz.bundle.dev.js"></script>
2929
<script>
30-
let data = generateRandomMatrix({x:50, y:6, scaleFactor:50});
30+
let data = generateRandomMatrix({x:50, y:6, scaleFactor:100});
31+
console.log(JSON.stringify(data));
32+
3133
GTExViz.heatmap();
3234
GTExViz.heatmap({
3335
id: 'userHeatmap',
3436
data: data,
37+
useLog: false,
38+
logBase: null,
3539
width: 800,
3640
height: 200,
3741
marginLeft: 20,
@@ -44,23 +48,25 @@ <h5>GTEx Heatmap</h5>
4448
columnLabelAngle: 60,
4549
columnLabelPosAdjust: 10,
4650
rowLabelWidth: 100,
51+
4752
});
4853
function generateRandomMatrix(par={x:20, y:20, scaleFactor:1}){
4954
let range = n => Array.from(Array(n).keys());
5055
let X = range(par.x); // generates a 1-based list.
5156
let Y = range(par.y);
5257
let data = [];
5358
X.forEach((x)=>{
54-
x = 'x' + x.toString();
59+
x = 'col ' + x.toString();
5560
Y.forEach((y)=>{
56-
y = 'y' + y.toString();
61+
y = 'row ' + y.toString();
5762
let v = Math.random()*par.scaleFactor;
58-
data.push({
63+
let dataPoint = {
5964
x: x,
6065
y: y,
6166
value: v,
62-
displayValue: v
63-
});
67+
displayValue: v.toPrecision(3)
68+
};
69+
data.push(dataPoint);
6470
})
6571
});
6672
return data;

src/GTExViz.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
* Licensed under the BSD 3-clause license (https://github.com/broadinstitute/gtex-viz/blob/master/LICENSE.md)
44
*/
55

6+
/*
7+
1. Color legend for log scale is not spaced correctly.
8+
*/
69
'use strict';
710
import {createSvg, generateRandomMatrix} from "./modules/utils";
811
import Heatmap from "./modules/Heatmap";
912
import DendroHeatmapConfig from "./modules/DendroHeatmapConfig";
1013
import DendroHeatmap from "./modules/DendroHeatmap";
1114

1215
const demoData = {
13-
heatmap:generateRandomMatrix({x:50, y:10, scaleFactor:100}),
16+
heatmap:generateRandomMatrix({x:50, y:10, scaleFactor:1000}),
1417
dendroHeatmap: {
1518
rowTree: "(((TP53:0.17,SLK:0.17):1.18,NDRG4:1.34):1.33,ACTN3:2.67);",
1619
colTree: "(((Adipose Visceral Omentum:0.06,Adipose Subcutaneous:0.06):0.00,Bladder:0.06):0.16,Adrenal Gland:0.22);",
@@ -130,7 +133,9 @@ const heatmapDemoConfig = {
130133
columnLabelAngle: 60,
131134
columnLabelPosAdjust: 10,
132135
rowLabelWidth: 100,
133-
legendSpace: 50
136+
legendSpace: 50,
137+
useLog: true,
138+
logBase: 10
134139
};
135140

136141
/**
@@ -159,14 +164,16 @@ export function heatmap(par=heatmapDemoConfig){
159164

160165
// render the heatmap
161166
let tooltipId = `${par.id}Tooltip`;
162-
let h = new Heatmap(par.data, false, null, par.colorScheme, par.cornerRadius, tooltipId);
167+
let h = new Heatmap(par.data, par.useLog, par.logBase, par.colorScheme, par.cornerRadius, tooltipId);
163168
h.draw(svg, {w:inWidth, h:inHeight}, par.columnLabelAngle, false, par.columnLabelPosAdjust);
164169
h.drawColorLegend(svg, {x:20, y: -20}, 10);
165170
}
166171

167172
const dendroHeatmapDemoConfig = {
168173
id: 'gtexVizDendroHeatmap',
169174
data: demoData.dendroHeatmap,
175+
useLog: true,
176+
logBase: 10,
170177
width: 600, // outer width
171178
height: 300, // outer height
172179
marginLeft: 20,
@@ -204,9 +211,9 @@ export function dendroHeatmap(par=dendroHeatmapDemoConfig){
204211
let svgId = `${par.id}Svg`;
205212
let tooltipId = `${par.id}Tooltip`;
206213
let dmapConfig = new DendroHeatmapConfig(par.width, par.rowTreePanelWidth, par.colTreePanelHeight, margin);
207-
let dmap = new DendroHeatmap(par.data.colTree, par.data.rowTree, par.data.heatmap, par.colorScheme, par.cornerRadius, dmapConfig, tooltipId)
214+
let dmap = new DendroHeatmap(par.data.colTree, par.data.rowTree, par.data.heatmap, par.colorScheme, par.cornerRadius, dmapConfig, tooltipId, par.useLog, par.logBase)
208215
let showColTree = par.data.colTree !== undefined;
209216
let showRowTree = par.data.rowTree !== undefined;
210-
dmap.render(par.id, svgId, showColTree, showRowTree, "top", 5);
217+
dmap.render(par.id, svgId, showColTree, showRowTree, "top", 8);
211218
}
212219

src/modules/Heatmap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export default class Heatmap {
221221
dom.selectAll(".exp-map-ylabel").filter(`.${colClass}`)
222222
.classed('highlighted', true);
223223
selected.classed('highlighted', true);
224-
const displayValue = d.displayValue === undefined?parseFloat(d.value.toExponential()).toPrecision(4):parseFloat(d.displayValue.toExponential()).toPrecision(4);
224+
const displayValue = d.displayValue === undefined?parseFloat(d.value.toExponential()).toPrecision(4):d.displayValue;
225225
this.tooltip.show(`Column: ${d.x} <br/> Row: ${d.y}<br/> Value: ${displayValue}`);
226226
}
227227

src/modules/colors.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ export function setColorScale(data, colors="YlGnBu", dmin = 0) {
154154
* @param orientation {enum} h or v, i.e. horizontal or vertical
155155
* @param cell
156156
*/
157-
export function drawColorLegend(title, dom, scale, config, useLog, ticks=10, base=10, cell={h:10, w:50}, orientation="h"){
158-
159-
const data = [0].concat(scale.ticks(ticks).slice(1)); // why doesn't this provide consistent number of ticks??
160-
157+
export function drawColorLegend(title, dom, scale, config, useLog, ticks=10, base=10, cell={h:10, w:40}, orientation="h"){
158+
let range = [...Array(ticks+1).keys()];
159+
let interval = scale.domain()[1]/ticks;
160+
const data = range.map((d)=>d*interval);
161161

162162
// legend groups
163163
const legends = dom.append("g").attr("transform", `translate(${config.x}, ${config.y})`)
@@ -185,7 +185,7 @@ export function drawColorLegend(title, dom, scale, config, useLog, ticks=10, bas
185185

186186
g.append("text")
187187
.attr("class", "color-legend")
188-
.text((d) => useLog?(Math.pow(base, d)-1).toPrecision(2):d.toPrecision(2))
188+
.text((d) => useLog?(Math.pow(base, d)).toPrecision(2):d.toPrecision(2))
189189
.attr("x", (d, i) => cell.w * i)
190190
.attr("y", 0);
191191
} else {

src/modules/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function generateRandomMatrix(par={x:20, y:20, scaleFactor:1}){
124124
x: x,
125125
y: y,
126126
value: v,
127-
displayValue: v
127+
displayValue: parseFloat(v.toExponential()).toPrecision(3)
128128
});
129129
})
130130
});

0 commit comments

Comments
 (0)