-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathepiviz-ideogram-track.html
286 lines (237 loc) · 9.18 KB
/
epiviz-ideogram-track.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!-- Polymer dependency -->
<link rel="import" href="bower_components/polymer/polymer-element.html">
<!-- Epiviz imports dependency -->
<!-- <link rel="import" href="bower_components/epiviz-imports/epiviz-common-js.html"> -->
<!-- Ideogram library dependency -->
<script src="src/cyto-chromosome-vis/cyto-chromosome.js"></script>
<!--
<h2> Chart Component </h2>
epiviz-chart components are a collection of reusable and extensible visualization components for
genomic data.
<a href="http://biojs.io/d/cyto-chromosome-vis">Ideogram Track</a> is a biojs visualization and
creates a ideogram track chart for a given chromosome.
`epiviz-ideogram-track` integrates ideogram track in a web component framework and adds additional features to
highlight region of interest, display the gene close to the center
To create a ideogram track on a HTML page, add
<epiviz-ideogram-track
chr="chr11"
start=1000
end=250000
></epiviz-ideogram-track>
@demo demo/index-ideogram.html Example page showing a ideogram track
-->
<dom-module id="epiviz-ideogram-track">
<template>
<style>
:host {
display: inline-block;
min-width: 250px;
}
#chart {
position: relative;
}
</style>
<!-- local DOM goes here -->
<div id="chart">
<div id="{{plotId}}"></div>
</div>
</template>
<script>
// Extend Polymer.Element base class
class EpivizIdeogramTrack extends Polymer.Element {
static get is() { return 'epiviz-ideogram-track'; }
static get properties() {
return {
/**
* Chromosome location.
* Default Location Attribute to set to all the children chart elements.
*
* @example: chr1
*
* @type {string}
*/
chromosome: {
type: String,
notify: true
},
/**
* Chromosome start.
* Default Chromosome start value to use. (defaults to 0).
*
* @type {number}
*/
start: {
type: Number,
notify: true
},
/**
* Chromosome end.
* Default Chromosome end value to use. (defaults to the `<chr>` length).
*
* @type {number}
*/
end: {
type: Number,
notify: true
},
/**
* Unique plot ID for the chart
*
* @type {string}
*/
plotId: {
type: String,
reflectToAttribute: true,
notify: true
},
/**
* Computed Range from `<chr>`, `<start>` & `<end>`.
*
* @type {Object<epiviz.datatypes.GenomicRange>}
*/
range: {
type: Object,
notify: true
},
/**
* Current gene in range (set automatically)
*
* @type {string}
*/
geneInRange: {
type: String,
notify: true
}
}
}
static get observers() {
return [
/* observer array just like 1.x */
'_rangeChanged(chromosome.*, start.*, end.*)'
]
}
constructor() {
super();
}
connectedCallback() {
super.connectedCallback();
}
disconnectedCallback() {
super.connectedCallback();
}
ready() {
super.ready();
var self = this;
self.plotId = self.plotId || self._generatePlotId();
var parent = self.parentNode;
if (parent.nodeName === "IRON-COLLAPSE") {
parent = parent.parentNode;
}
parent.addEventListener('hoverAllCharts', function (e) {
self.chart.hover(e.detail.data);
}.bind(self));
parent.addEventListener('unHoverAllCharts', function (e) {
self.chart.unHover();
}.bind(self));
self.chromosomeFactory = cyto_chr;
self._rangeChanged();
self.chartObject = new epiviz.ui.charts.ChartObject(self.plotId, self.start, self.end, undefined, undefined, undefined, undefined, undefined);
}
/**
* Draws the chart.
*/
_draw() {
var self = this;
$(self.shadowRoot.querySelector("#" + self.plotId)).empty();
self.segment = self.chromosome.replace("chr", "");
self.chart = self.chromosomeFactory.chromosome()
.segment(self.segment)
// .resolution("850")
.useRelative(false)
.showAxis(true)
.target(self.shadowRoot.querySelector("#" + self.plotId))
// .height(100)
.width(300)
.render();
// TODO: use callback instead after the chart is rendered
setTimeout(function () {
self.chart.on("selectorhover", function (e) {
self.dispatchEvent(new CustomEvent('hover',
{
detail: {
data: self.chartObject
},
bubbles: true
}
)
);
}.bind(self));
self.chart.on("selectorunhover", function (e) {
self.dispatchEvent(new CustomEvent('hover',
{
detail: {
data: null
},
bubbles: true
}
)
);
}.bind(self));
self.chart.getSVGTarget().append('text')
.text("chr: " + self.segment)
.attr('x', self.chart.getSVGTarget().attr("width") - 285)
.attr('y', self.chart.getSVGTarget().attr("height") * 1 / 3)
.attr('text-anchor', 'left')
.style('font', '12px sans-serif');
self.chart.getSVGTarget().append('text')
.text("Gene: " + self.geneInRange)
.attr('x', self.chart.getSVGTarget().attr("width") - 240)
.attr('y', self.chart.getSVGTarget().attr("height") * 1 / 3)
.attr('text-anchor', 'left')
.style('font', '12px sans-serif');
self.chart.newSelector(self.start, self.end);
self.chartObject = new epiviz.ui.charts.ChartObject(self.plotId, self.start, self.end, undefined, undefined, undefined, undefined, undefined, self.chromosome);
}, 1000);
}
/**
* Generates a unique chart ID
*
* @return {string}
*/
_generatePlotId() {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var result = '';
var size = 7;
for (var i = 0; i < size; ++i) {
result += chars[Math.round(Math.random() * (chars.length - 1))];
}
return 'epiviz-' + result;
}
/**
* ChartLocation/RangeChange event handler.
*/
_rangeChanged() {
if (!(this.chromosome === undefined || this.start === undefined || this.end === undefined)) {
if (this.plotId) {
this._draw();
}
}
}
/**
* Hover event handler.
*
* @param {object} data data object currently hovered.
*/
hover(data) {
this.chart.doHover(data);
}
/**
* unHover event handler.
*/
unHover() {
this.chart.doUnhover();
}
};
customElements.define(EpivizIdeogramTrack.is, EpivizIdeogramTrack);
</script>
</dom-module>