genoverse 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +197 -0
- package/.github/workflows/test.yml +24 -0
- package/LICENSE.TXT +24 -0
- package/README.md +11 -0
- package/css/controlPanel.css +200 -0
- package/css/fileDrop.css +22 -0
- package/css/font-awesome.css +3 -0
- package/css/fullscreen.css +19 -0
- package/css/genoverse.css +466 -0
- package/css/karyotype.css +85 -0
- package/css/resizer.css +36 -0
- package/css/tooltips.css +26 -0
- package/css/trackControls.css +111 -0
- package/expanded.html +120 -0
- package/fontawesome/css/fontawesome.min.css +5 -0
- package/fontawesome/css/regular.min.css +5 -0
- package/fontawesome/css/solid.min.css +5 -0
- package/fontawesome/webfonts/fa-brands-400.ttf +0 -0
- package/fontawesome/webfonts/fa-brands-400.woff +0 -0
- package/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
- package/fontawesome/webfonts/fa-regular-400.ttf +0 -0
- package/fontawesome/webfonts/fa-regular-400.woff +0 -0
- package/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
- package/fontawesome/webfonts/fa-solid-900.ttf +0 -0
- package/fontawesome/webfonts/fa-solid-900.woff +0 -0
- package/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
- package/help.pdf +0 -0
- package/i/sort_handle.png +0 -0
- package/index.html +68 -0
- package/index.js +83 -0
- package/jest.config.js +4 -0
- package/js/Genoverse.js +1681 -0
- package/js/Track/Controller/Sequence.js +17 -0
- package/js/Track/Controller/Stranded.js +73 -0
- package/js/Track/Controller.js +620 -0
- package/js/Track/Model/File/BAM.js +44 -0
- package/js/Track/Model/File/BED.js +116 -0
- package/js/Track/Model/File/GFF.js +40 -0
- package/js/Track/Model/File/VCF.js +101 -0
- package/js/Track/Model/File/WIG.js +67 -0
- package/js/Track/Model/File.js +36 -0
- package/js/Track/Model/Gene/Ensembl.js +22 -0
- package/js/Track/Model/Gene.js +5 -0
- package/js/Track/Model/Sequence/Ensembl.js +4 -0
- package/js/Track/Model/Sequence/Fasta.js +60 -0
- package/js/Track/Model/Sequence.js +50 -0
- package/js/Track/Model/SequenceVariation.js +41 -0
- package/js/Track/Model/Stranded.js +28 -0
- package/js/Track/Model/Transcript/Ensembl.js +67 -0
- package/js/Track/Model/Transcript.js +5 -0
- package/js/Track/Model.js +303 -0
- package/js/Track/View/Gene/Ensembl.js +46 -0
- package/js/Track/View/Gene.js +6 -0
- package/js/Track/View/Sequence/Variation.js +115 -0
- package/js/Track/View/Sequence.js +63 -0
- package/js/Track/View/Transcript/Ensembl.js +12 -0
- package/js/Track/View/Transcript.js +28 -0
- package/js/Track/View.js +566 -0
- package/js/Track/library/Chromosome.js +145 -0
- package/js/Track/library/File/BAM.js +30 -0
- package/js/Track/library/File/BED.js +24 -0
- package/js/Track/library/File/BIGBED.js +47 -0
- package/js/Track/library/File/BIGWIG.js +52 -0
- package/js/Track/library/File/GFF.js +9 -0
- package/js/Track/library/File/VCF.js +71 -0
- package/js/Track/library/File/WIG.js +5 -0
- package/js/Track/library/File.js +10 -0
- package/js/Track/library/Gene.js +37 -0
- package/js/Track/library/Graph/Bar.js +235 -0
- package/js/Track/library/Graph/Line.js +296 -0
- package/js/Track/library/Graph.js +355 -0
- package/js/Track/library/HighlightRegion.js +292 -0
- package/js/Track/library/Legend.js +224 -0
- package/js/Track/library/Scalebar.js +227 -0
- package/js/Track/library/Scaleline.js +91 -0
- package/js/Track/library/Static.js +78 -0
- package/js/Track/library/dbSNP.js +142 -0
- package/js/Track.js +632 -0
- package/js/genomes/grch37.js +990 -0
- package/js/genomes/grch38.js +990 -0
- package/js/genoverse.min.js +2 -0
- package/js/genoverse.min.js.map +1 -0
- package/js/lib/BWReader.js +578 -0
- package/js/lib/Base.js +145 -0
- package/js/lib/VCFReader.js +286 -0
- package/js/lib/dalliance/js/bam.js +494 -0
- package/js/lib/dalliance/js/bin.js +185 -0
- package/js/lib/dalliance/js/das.js +749 -0
- package/js/lib/dalliance/js/utils.js +370 -0
- package/js/lib/dalliance-lib.js +3594 -0
- package/js/lib/dalliance-lib.min.js +68 -0
- package/js/lib/jDataView.js +2 -0
- package/js/lib/jParser.js +192 -0
- package/js/lib/jquery-ui.js +8 -0
- package/js/lib/jquery.js +2 -0
- package/js/lib/jquery.mousehold.js +53 -0
- package/js/lib/jquery.mousewheel.js +84 -0
- package/js/lib/jquery.tipsy.js +258 -0
- package/js/lib/rtree.js +1 -0
- package/js/plugins/controlPanel.js +395 -0
- package/js/plugins/fileDrop.js +62 -0
- package/js/plugins/focusRegion.js +12 -0
- package/js/plugins/fullscreen.js +77 -0
- package/js/plugins/karyotype.js +210 -0
- package/js/plugins/resizer.js +45 -0
- package/js/plugins/tooltips.js +94 -0
- package/js/plugins/trackControls.js +143 -0
- package/package.json +43 -0
- package/test/View/__snapshots__/render-bar-graph.test.js.snap +111 -0
- package/test/View/__snapshots__/render-blocks.test.js.snap +105 -0
- package/test/View/__snapshots__/render-chromosome.test.js.snap +5 -0
- package/test/View/__snapshots__/render-highlights.test.js.snap +73 -0
- package/test/View/__snapshots__/render-insert-variants.test.js.snap +9 -0
- package/test/View/__snapshots__/render-labels.test.js.snap +241 -0
- package/test/View/__snapshots__/render-legends.test.js.snap +13 -0
- package/test/View/__snapshots__/render-line-graph.test.js.snap +349 -0
- package/test/View/__snapshots__/render-scalebar.test.js.snap +49 -0
- package/test/View/__snapshots__/render-scaleline.test.js.snap +31 -0
- package/test/View/__snapshots__/render-sequence.test.js.snap +23 -0
- package/test/View/__snapshots__/render-stranded.test.js.snap +5 -0
- package/test/View/__snapshots__/render-transcripts.test.js.snap +193 -0
- package/test/View/render-bar-graph.test.js +87 -0
- package/test/View/render-blocks.test.js +171 -0
- package/test/View/render-chromosome.test.js +40 -0
- package/test/View/render-highlights.test.js +67 -0
- package/test/View/render-insert-variants.test.js +11 -0
- package/test/View/render-labels.test.js +266 -0
- package/test/View/render-legends.test.js +31 -0
- package/test/View/render-line-graph.test.js +169 -0
- package/test/View/render-scalebar.test.js +36 -0
- package/test/View/render-scaleline.test.js +28 -0
- package/test/View/render-sequence.test.js +49 -0
- package/test/View/render-stranded.test.js +10 -0
- package/test/View/render-transcripts.test.js +165 -0
- package/test/create-and-destroy.test.js +63 -0
- package/test/track-ordering.test.js +514 -0
- package/test/track_config/__snapshots__/config-settings.test.js.snap +23 -0
- package/test/track_config/config-settings.test.js +321 -0
- package/test/track_config/zoom-level-settings.test.js +98 -0
- package/test/utils.js +80 -0
- package/utils/createGenome.js +52 -0
- package/utils/devServer.js +36 -0
- package/utils/expandedTemplate.html +46 -0
- package/utils/git-hooks/post-commit +9 -0
- package/utils/git-hooks/pre-commit +7 -0
- package/utils/git-hooks/setup +6 -0
- package/utils/makeExpanded.js +19 -0
- package/webpack.config.js +39 -0
package/js/Track/View.js
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
Genoverse.Track.View = Base.extend({
|
|
2
|
+
fontHeight : 10,
|
|
3
|
+
fontFamily : 'sans-serif',
|
|
4
|
+
fontWeight : 'normal',
|
|
5
|
+
fontColor : undefined, // label color defaults to this, or feature color, or track.color (below), in that order of precedence
|
|
6
|
+
color : '#000000',
|
|
7
|
+
minScaledWidth : 0.5,
|
|
8
|
+
precisionFactor : 0, // Rounding factor to be applied to feature start/width when drawing, e.g. 2 = starts and widths will be rounded to the nearest 0.5
|
|
9
|
+
widthCorrection : 1, // Pixels to add to the end of a feature when scale > 1 - ensures that 1bp features are always at least 1px wide
|
|
10
|
+
labels : true,
|
|
11
|
+
repeatLabels : false,
|
|
12
|
+
bump : false,
|
|
13
|
+
alwaysReposition : false,
|
|
14
|
+
depth : undefined,
|
|
15
|
+
featureHeight : undefined, // defaults to track height
|
|
16
|
+
featureMargin : undefined, // e.g. { top: 3, right: 1, bottom: 1, left: 0 }
|
|
17
|
+
|
|
18
|
+
subFeatureJoinStyle : false, // Can be 'line', 'peak', 'curve'
|
|
19
|
+
subFeatureJoinLineWidth : 0.5,
|
|
20
|
+
|
|
21
|
+
constructor: function (properties) {
|
|
22
|
+
$.extend(this, properties);
|
|
23
|
+
Genoverse.wrapFunctions(this);
|
|
24
|
+
this.init();
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// difference between init and constructor: init gets called on reset, if reset is implemented
|
|
28
|
+
init: function () {
|
|
29
|
+
this.setDefaults();
|
|
30
|
+
this.scaleSettings = {};
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
setDefaults: function () {
|
|
34
|
+
this.featureMargin = this.featureMargin || { top: 3, right: 1, bottom: 1, left: 0 };
|
|
35
|
+
|
|
36
|
+
var margin = [ 'top', 'right', 'bottom', 'left' ];
|
|
37
|
+
|
|
38
|
+
for (var i = 0; i < margin.length; i++) {
|
|
39
|
+
if (typeof this.featureMargin[margin[i]] !== 'number') {
|
|
40
|
+
this.featureMargin[margin[i]] = 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.context = $('<canvas>')[0].getContext('2d');
|
|
45
|
+
this.featureHeight = typeof this.featureHeight !== 'undefined' ? this.featureHeight : this.prop('defaultHeight');
|
|
46
|
+
this.font = this.fontWeight + ' ' + this.fontHeight + 'px ' + this.fontFamily;
|
|
47
|
+
this.labelUnits = [ 'bp', 'kb', 'Mb', 'Gb', 'Tb' ];
|
|
48
|
+
|
|
49
|
+
this.context.font = this.font;
|
|
50
|
+
|
|
51
|
+
if (this.labels && this.labels !== 'overlay' && (this.depth || this.bump === 'labels')) {
|
|
52
|
+
this.labels = 'separate';
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
setScaleSettings: function (scale) {
|
|
57
|
+
var chr = this.browser.chr;
|
|
58
|
+
|
|
59
|
+
if (!this.scaleSettings[chr]) {
|
|
60
|
+
this.scaleSettings[chr] = {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!this.scaleSettings[chr][scale]) {
|
|
64
|
+
var featurePositions = new RTree();
|
|
65
|
+
|
|
66
|
+
this.scaleSettings[chr][scale] = {
|
|
67
|
+
imgContainers : $(),
|
|
68
|
+
featurePositions : featurePositions,
|
|
69
|
+
labelPositions : this.labels === 'separate' ? new RTree() : featurePositions
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return this.scaleSettings[chr][scale];
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
roundPixelValue: function (value) {
|
|
77
|
+
if (this.precisionFactor) {
|
|
78
|
+
return Math.round(value * this.precisionFactor) / this.precisionFactor;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return value;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
scaleFeatures: function (features, scale) {
|
|
85
|
+
var add = this.roundPixelValue(Math.max(scale, this.widthCorrection));
|
|
86
|
+
var feature, j;
|
|
87
|
+
|
|
88
|
+
for (var i = 0; i < features.length; i++) {
|
|
89
|
+
feature = features[i];
|
|
90
|
+
|
|
91
|
+
if (!feature.position) {
|
|
92
|
+
feature.position = {};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!feature.position[scale]) {
|
|
96
|
+
feature.position[scale] = {
|
|
97
|
+
start : this.roundPixelValue(feature.start * scale),
|
|
98
|
+
width : Math.max(this.roundPixelValue((feature.end - feature.start) * scale + add), this.minScaledWidth),
|
|
99
|
+
height : feature.height || this.featureHeight
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (feature.subFeatures) {
|
|
104
|
+
for (j = 0; j < feature.subFeatures.length; j++) {
|
|
105
|
+
if (typeof feature.subFeatures[j].height === 'undefined') {
|
|
106
|
+
feature.subFeatures[j].height = feature.position[scale].height;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.scaleFeatures(feature.subFeatures, scale);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return features;
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
positionFeatures: function (features, params) {
|
|
118
|
+
params.margin = this.prop('margin');
|
|
119
|
+
|
|
120
|
+
for (var i = 0; i < features.length; i++) {
|
|
121
|
+
this.positionFeature(features[i], params);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
params.width = Math.ceil(params.width);
|
|
125
|
+
params.height = Math.ceil(params.height);
|
|
126
|
+
params.featureHeight = Math.max(Math.ceil(params.featureHeight), this.prop('resizable') ? Math.max(this.prop('height'), this.prop('minLabelHeight')) : 0);
|
|
127
|
+
params.labelHeight = Math.ceil(params.labelHeight);
|
|
128
|
+
|
|
129
|
+
return features;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
positionFeature: function (feature, params) {
|
|
133
|
+
var scale = params.scale;
|
|
134
|
+
var scaleSettings = this.scaleSettings[feature.chr][scale];
|
|
135
|
+
|
|
136
|
+
if (!scaleSettings) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var subFeatures = feature.subFeatures || [];
|
|
141
|
+
var i;
|
|
142
|
+
|
|
143
|
+
feature.position[scale].X = feature.position[scale].start - params.scaledStart; // FIXME: always have to reposition for X, in case a feature appears in 2 images. Pass scaledStart around instead?
|
|
144
|
+
|
|
145
|
+
for (i = 0; i < subFeatures.length; i++) {
|
|
146
|
+
subFeatures[i].position[scale].x = subFeatures[i].position[scale].start - params.scaledStart;
|
|
147
|
+
|
|
148
|
+
if (this.subFeatureJoinStyle) {
|
|
149
|
+
subFeatures[i].position[scale].join = subFeatures[i].position[scale].join || {};
|
|
150
|
+
subFeatures[i].position[scale].join.x = subFeatures[i].position[scale].start + subFeatures[i].position[scale].width - params.scaledStart;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (this.alwaysReposition || !feature.position[scale].positioned) {
|
|
155
|
+
feature.position[scale].H = feature.position[scale].height + this.featureMargin.bottom;
|
|
156
|
+
feature.position[scale].W = feature.position[scale].width + (feature.marginRight || this.featureMargin.right);
|
|
157
|
+
feature.position[scale].Y = (
|
|
158
|
+
typeof feature.position[scale].y === 'number' ? feature.position[scale].y :
|
|
159
|
+
typeof feature.y === 'number' ? feature.y * feature.position[scale].H : 0
|
|
160
|
+
) + (feature.marginTop || this.featureMargin.top);
|
|
161
|
+
|
|
162
|
+
if (feature.label) {
|
|
163
|
+
if (typeof feature.label === 'string') {
|
|
164
|
+
feature.label = feature.label.split('\n');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var context = this.context;
|
|
168
|
+
|
|
169
|
+
feature.labelHeight = feature.labelHeight || (this.fontHeight + 2) * feature.label.length;
|
|
170
|
+
feature.labelWidth = feature.labelWidth || Math.max.apply(Math, $.map(feature.label, function (l) { return Math.ceil(context.measureText(l).width); })) + 1;
|
|
171
|
+
|
|
172
|
+
if (this.labels === true) {
|
|
173
|
+
feature.position[scale].H += feature.labelHeight;
|
|
174
|
+
feature.position[scale].W = Math.max(feature.labelWidth, feature.position[scale].W);
|
|
175
|
+
} else if (this.labels === 'separate' && !feature.position[scale].label) {
|
|
176
|
+
feature.position[scale].label = {
|
|
177
|
+
x : feature.position[scale].start,
|
|
178
|
+
y : feature.position[scale].Y,
|
|
179
|
+
w : feature.labelWidth,
|
|
180
|
+
h : feature.labelHeight
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
var bounds = {
|
|
186
|
+
x : feature.position[scale].start,
|
|
187
|
+
y : feature.position[scale].Y,
|
|
188
|
+
w : feature.position[scale].W,
|
|
189
|
+
h : feature.position[scale].H + (feature.marginTop || this.featureMargin.top)
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
feature.position[scale].bounds = bounds;
|
|
193
|
+
|
|
194
|
+
if (this.bump === true) {
|
|
195
|
+
this.bumpFeature(bounds, feature, scale, scaleSettings.featurePositions);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
scaleSettings.featurePositions.insert(bounds, feature);
|
|
199
|
+
|
|
200
|
+
feature.position[scale].bottom = feature.position[scale].Y + bounds.h + params.margin;
|
|
201
|
+
feature.position[scale].positioned = true;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var join = this.subFeatureJoinStyle && subFeatures.length ? {
|
|
205
|
+
height : (Math.max.apply(Math, subFeatures.map(function (c) { return c.fake ? 0 : c.position[scale].height; })) / 2) * (feature.strand > 0 ? -1 : 1),
|
|
206
|
+
y : feature.position[scale].Y + feature.position[scale].height / 2
|
|
207
|
+
} : false;
|
|
208
|
+
|
|
209
|
+
for (i = 0; i < subFeatures.length; i++) {
|
|
210
|
+
subFeatures[i].position[scale].y = feature.position[scale].Y + (feature.position[scale].height - subFeatures[i].position[scale].height) / 2;
|
|
211
|
+
|
|
212
|
+
if (join && subFeatures[i + 1]) {
|
|
213
|
+
$.extend(subFeatures[i].position[scale].join, { width: subFeatures[i + 1].position[scale].x - subFeatures[i].position[scale].join.x }, join);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (this.labels === 'separate' && feature.position[scale].label) {
|
|
218
|
+
if (this.alwaysReposition || !feature.position[scale].label.positioned) {
|
|
219
|
+
this.bumpFeature(feature.position[scale].label, feature, scale, scaleSettings.labelPositions);
|
|
220
|
+
|
|
221
|
+
feature.position[scale].label.bottom = feature.position[scale].label.y + feature.position[scale].label.h + params.margin;
|
|
222
|
+
feature.position[scale].label.positioned = true;
|
|
223
|
+
|
|
224
|
+
scaleSettings.labelPositions.insert(feature.position[scale].label, feature);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
params.labelHeight = Math.max(params.labelHeight, feature.position[scale].label.bottom);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
params.featureHeight = Math.max(params.featureHeight, feature.position[scale].bottom);
|
|
231
|
+
params.height = Math.max(params.height, params.featureHeight + params.labelHeight);
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
// FIXME: should label bumping bounds be distinct from feature bumping bounds when label is smaller than feature?
|
|
235
|
+
bumpFeature: function (bounds, feature, scale, tree) {
|
|
236
|
+
var depth = 0;
|
|
237
|
+
var scaleSettings = this.scaleSettings[feature.chr][scale];
|
|
238
|
+
var labels = tree === scaleSettings.labelPositions && tree !== scaleSettings.featurePositions;
|
|
239
|
+
var bump, clash, searchResults, i;
|
|
240
|
+
|
|
241
|
+
do {
|
|
242
|
+
if (this.depth && ++depth >= this.depth) {
|
|
243
|
+
if (!labels) {
|
|
244
|
+
searchResults = scaleSettings.featurePositions.search(bounds);
|
|
245
|
+
i = searchResults.length;
|
|
246
|
+
|
|
247
|
+
while (i--) {
|
|
248
|
+
if (searchResults[i].position[scale].visible !== false) {
|
|
249
|
+
feature.position[scale].visible = false;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
bump = false;
|
|
259
|
+
clash = tree.search(bounds)[0];
|
|
260
|
+
|
|
261
|
+
if (clash && clash.id !== feature.id) {
|
|
262
|
+
bounds.y = clash.position[scale][labels ? 'label' : 'bounds'].y + clash.position[scale][labels ? 'label' : 'bounds'].h;
|
|
263
|
+
bump = true;
|
|
264
|
+
}
|
|
265
|
+
} while (bump);
|
|
266
|
+
|
|
267
|
+
if (!labels) {
|
|
268
|
+
feature.position[scale].Y = bounds.y;
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
draw: function (features, featureContext, labelContext, scale) {
|
|
273
|
+
var feature, f;
|
|
274
|
+
|
|
275
|
+
for (var i = 0; i < features.length; i++) {
|
|
276
|
+
feature = features[i];
|
|
277
|
+
|
|
278
|
+
if (feature.position[scale].visible !== false) {
|
|
279
|
+
// TODO: extend with feature.position[scale], rationalize keys
|
|
280
|
+
f = $.extend({}, feature, {
|
|
281
|
+
x : feature.position[scale].X,
|
|
282
|
+
y : feature.position[scale].Y,
|
|
283
|
+
width : feature.position[scale].width,
|
|
284
|
+
height : feature.position[scale].height,
|
|
285
|
+
labelPosition : feature.position[scale].label
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
this.drawFeature(f, featureContext, labelContext, scale);
|
|
289
|
+
|
|
290
|
+
if (f.legend !== feature.legend) {
|
|
291
|
+
feature.legend = f.legend;
|
|
292
|
+
feature.legendColor = f.color;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
drawFeature: function (feature, featureContext, labelContext, scale) {
|
|
299
|
+
if (feature.color !== false && !feature.color) {
|
|
300
|
+
this.setFeatureColor(feature);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (feature.subFeatures) {
|
|
304
|
+
this.drawSubFeatures(feature, featureContext, labelContext, scale);
|
|
305
|
+
} else {
|
|
306
|
+
if (feature.x < 0 || feature.x + feature.width > this.width) {
|
|
307
|
+
this.truncateForDrawing(feature);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (feature.color !== false) {
|
|
311
|
+
featureContext.fillStyle = feature.color;
|
|
312
|
+
featureContext.fillRect(feature.x, feature.y, feature.width, feature.height);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (feature.clear === true) {
|
|
316
|
+
featureContext.clearRect(feature.x, feature.y, feature.width, feature.height);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (feature.borderColor) {
|
|
320
|
+
featureContext.strokeStyle = feature.borderColor;
|
|
321
|
+
featureContext.strokeRect(feature.x, Math.floor(feature.y) + 0.5, feature.width, feature.height);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (this.labels && feature.label) {
|
|
326
|
+
this.drawLabel(feature, labelContext, scale);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (feature.decorations) {
|
|
330
|
+
this.decorateFeature(feature, featureContext, scale);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
drawSubFeatures: function (feature, featureContext, labelContext, scale) {
|
|
335
|
+
var clonedFeature = $.extend(true, {}, feature, { subFeatures: false, label: false });
|
|
336
|
+
var subFeatures = $.extend(true, [], feature.subFeatures);
|
|
337
|
+
var joinColor = feature.joinColor || feature.color;
|
|
338
|
+
|
|
339
|
+
for (var i = 0; i < subFeatures.length; i++) {
|
|
340
|
+
if (!subFeatures[i].fake) {
|
|
341
|
+
this.drawFeature($.extend({}, clonedFeature, subFeatures[i].position[scale], subFeatures[i]), featureContext, labelContext, scale);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (subFeatures[i].position[scale].join && subFeatures[i].position[scale].join.width > 0) {
|
|
345
|
+
this.drawSubFeatureJoin($.extend({ color: joinColor }, subFeatures[i].position[scale].join), featureContext);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
drawLabel: function (feature, context, scale) {
|
|
351
|
+
var original = feature.untruncated;
|
|
352
|
+
var width = (original || feature).width;
|
|
353
|
+
|
|
354
|
+
if (this.labels === 'overlay' && feature.labelWidth >= Math.floor(width)) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (feature.labelPosition) {
|
|
359
|
+
context.labelPositions = context.labelPositions || new RTree();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (typeof feature.label === 'string') {
|
|
363
|
+
feature.label = [ feature.label ];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var x = (original || feature).x;
|
|
367
|
+
var n = this.repeatLabels ? Math.ceil((width - Math.max(scale, 1) - (this.labels === 'overlay' ? feature.labelWidth : 0)) / this.width) || 1 : 1;
|
|
368
|
+
var spacing = width / n;
|
|
369
|
+
var label, start, j, y, currentY, h;
|
|
370
|
+
|
|
371
|
+
if (this.repeatLabels && (scale > 1 || this.labels !== 'overlay')) { // Ensure there's always a label in each image
|
|
372
|
+
spacing = this.browser.length * scale;
|
|
373
|
+
n = Math.ceil(width / spacing);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (!feature.labelColor) {
|
|
377
|
+
this.setLabelColor(feature);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
context.fillStyle = feature.labelColor;
|
|
381
|
+
|
|
382
|
+
if (this.labels === 'overlay') {
|
|
383
|
+
label = [ feature.label.join(' ') ];
|
|
384
|
+
y = feature.y + (feature.height + 1) / 2;
|
|
385
|
+
h = 0;
|
|
386
|
+
} else {
|
|
387
|
+
label = feature.label;
|
|
388
|
+
y = feature.labelPosition ? feature.labelPosition.y : feature.y + feature.height + this.featureMargin.bottom;
|
|
389
|
+
h = this.fontHeight + 2;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
var i = context.textAlign === 'center' ? 0.5 : 0;
|
|
393
|
+
var offset = feature.labelWidth * i;
|
|
394
|
+
|
|
395
|
+
if (n > 1) {
|
|
396
|
+
i += Math.max(Math.floor(-(feature.labelWidth + x) / spacing), 0);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
for (; i < n; i++) {
|
|
400
|
+
start = x + (i * spacing);
|
|
401
|
+
|
|
402
|
+
if (start + feature.labelWidth >= 0) {
|
|
403
|
+
if ((start - offset > this.width) || (i >= 1 && start + feature.labelWidth > feature.position[scale].X + feature.position[scale].width)) {
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
for (j = 0; j < label.length; j++) {
|
|
408
|
+
currentY = y + (j * h);
|
|
409
|
+
|
|
410
|
+
if (context.labelPositions && context.labelPositions.search({ x: start, y: currentY, w: feature.labelWidth, h: h }).length) {
|
|
411
|
+
feature.position[scale].label.visible = false;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
context.fillText(label[j], start, currentY);
|
|
416
|
+
|
|
417
|
+
if (context.labelPositions) {
|
|
418
|
+
context.labelPositions.insert({ x: start, y: currentY, w: feature.labelWidth, h: h }, label[j]);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
|
|
425
|
+
setFeatureColor: function (feature) {
|
|
426
|
+
feature.color = this.color;
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
setLabelColor: function (feature) {
|
|
430
|
+
feature.labelColor = this.fontColor || feature.color || this.color;
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
// Method to lighten a color by an amount, adapted from https://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors
|
|
434
|
+
shadeColor: function (color, percent) {
|
|
435
|
+
var f = parseInt(color.slice(1), 16);
|
|
436
|
+
var R = f >> 16;
|
|
437
|
+
var G = (f >> 8) & 0x00FF;
|
|
438
|
+
var B = f & 0x0000FF;
|
|
439
|
+
|
|
440
|
+
return '#' + (
|
|
441
|
+
0x1000000 +
|
|
442
|
+
(Math.round((255 - R) * percent) + R) * 0x10000 +
|
|
443
|
+
(Math.round((255 - G) * percent) + G) * 0x100 +
|
|
444
|
+
(Math.round((255 - B) * percent) + B)
|
|
445
|
+
).toString(16).slice(1);
|
|
446
|
+
},
|
|
447
|
+
|
|
448
|
+
// truncate features - make the features start at 1px outside the canvas to ensure no lines are drawn at the borders incorrectly
|
|
449
|
+
truncateForDrawing: function (feature) {
|
|
450
|
+
var start = Math.min(Math.max(feature.x, -1), this.width + 1);
|
|
451
|
+
var width = feature.x - start + feature.width;
|
|
452
|
+
|
|
453
|
+
if (width + start > this.width) {
|
|
454
|
+
width = this.width - start + 1;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
feature.untruncated = { x: feature.x, width: feature.width };
|
|
458
|
+
feature.x = start;
|
|
459
|
+
feature.width = Math.max(width, 0);
|
|
460
|
+
},
|
|
461
|
+
|
|
462
|
+
drawSubFeatureJoin: function (join, context) {
|
|
463
|
+
var coords = this.truncateSubFeatureJoinForDrawing(join);
|
|
464
|
+
|
|
465
|
+
if (!coords) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
var lineWidth = context.lineWidth;
|
|
470
|
+
|
|
471
|
+
context.strokeStyle = join.color;
|
|
472
|
+
context.lineWidth = this.subFeatureJoinLineWidth;
|
|
473
|
+
|
|
474
|
+
context.beginPath();
|
|
475
|
+
context.moveTo(coords.x1, coords.y1);
|
|
476
|
+
|
|
477
|
+
switch (this.subFeatureJoinStyle) {
|
|
478
|
+
case 'line':
|
|
479
|
+
context.lineTo(coords.x3, coords.y1);
|
|
480
|
+
break;
|
|
481
|
+
case 'peak':
|
|
482
|
+
context.lineTo(coords.x2, coords.y2);
|
|
483
|
+
context.lineTo(coords.x3, coords.y3);
|
|
484
|
+
break;
|
|
485
|
+
case 'curve':
|
|
486
|
+
context.quadraticCurveTo(coords.x2, coords.y2, coords.x3, coords.y3);
|
|
487
|
+
break;
|
|
488
|
+
default: break;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
context.stroke();
|
|
492
|
+
|
|
493
|
+
context.lineWidth = lineWidth;
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
truncateSubFeatureJoinForDrawing: function (coords) {
|
|
497
|
+
var y1 = coords.y; // y coord of the ends of the line (half way down the exon box)
|
|
498
|
+
var y3 = y1;
|
|
499
|
+
|
|
500
|
+
if (this.subFeatureJoinStyle === 'line') {
|
|
501
|
+
this.truncateForDrawing(coords);
|
|
502
|
+
y1 += 0.5; // Sharpen line
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
var x1 = coords.x; // x coord of the right edge of the first exon
|
|
506
|
+
var x3 = coords.x + coords.width; // x coord of the left edge of the second exon
|
|
507
|
+
|
|
508
|
+
// Skip if completely outside the image's region
|
|
509
|
+
if (x3 < 0 || x1 > this.width) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
var x2, y2, xMid, yScale;
|
|
514
|
+
|
|
515
|
+
// Truncate the coordinates of the line being drawn, so it is inside the image's region
|
|
516
|
+
if (this.subFeatureJoinStyle === 'peak') {
|
|
517
|
+
xMid = (x1 + x3) / 2;
|
|
518
|
+
x2 = xMid; // x coord of the peak of the peak/curve
|
|
519
|
+
y2 = coords.y + coords.height; // y coord of the peak of the peak/curve (level with the top (forward strand) or bottom (reverse strand) of the exon box)
|
|
520
|
+
yScale = (y2 - y1) / (xMid - x1); // Scale factor for recalculating coords if points lie outside the image region
|
|
521
|
+
|
|
522
|
+
if (xMid < 0) {
|
|
523
|
+
y2 = coords.y + (yScale * x3);
|
|
524
|
+
x2 = 0;
|
|
525
|
+
} else if (xMid > this.width) {
|
|
526
|
+
y2 = coords.y + (yScale * (this.width - coords.x));
|
|
527
|
+
x2 = this.width;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (x1 < 0) {
|
|
531
|
+
y1 = xMid < 0 ? y2 : coords.y - (yScale * coords.x);
|
|
532
|
+
x1 = 0;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (x3 > this.width) {
|
|
536
|
+
y3 = xMid > this.width ? y2 : y2 - (yScale * (this.width - x2));
|
|
537
|
+
x3 = this.width;
|
|
538
|
+
}
|
|
539
|
+
} else if (this.subFeatureJoinStyle === 'curve') {
|
|
540
|
+
// TODO: try truncating when style is curve
|
|
541
|
+
x2 = coords.x + coords.width / 2;
|
|
542
|
+
y2 = coords.y + coords.height;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return {
|
|
546
|
+
x1 : x1,
|
|
547
|
+
y1 : y1,
|
|
548
|
+
x2 : x2,
|
|
549
|
+
y2 : y2,
|
|
550
|
+
x3 : x3,
|
|
551
|
+
y3 : y3
|
|
552
|
+
};
|
|
553
|
+
},
|
|
554
|
+
|
|
555
|
+
formatLabel: function (label) {
|
|
556
|
+
var power = Math.floor((label.toString().length - 1) / 3);
|
|
557
|
+
var unit = this.labelUnits[power];
|
|
558
|
+
|
|
559
|
+
label /= Math.pow(10, power * 3);
|
|
560
|
+
|
|
561
|
+
return Math.floor(label) + (unit === 'bp' ? '' : '.' + (label.toString().split('.')[1] || '').concat('00').substring(0, 2)) + ' ' + unit;
|
|
562
|
+
},
|
|
563
|
+
|
|
564
|
+
drawBackground : $.noop,
|
|
565
|
+
decorateFeature : $.noop // decoration for the features
|
|
566
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Genoverse.Track.Chromosome = Genoverse.Track.extend({
|
|
2
|
+
id : 'chromosome',
|
|
3
|
+
margin : 1,
|
|
4
|
+
featureMargin : { top: 0, right: 0, bottom: 0, left: 0 },
|
|
5
|
+
labels : 'overlay',
|
|
6
|
+
url : false,
|
|
7
|
+
allData : true,
|
|
8
|
+
colors : {
|
|
9
|
+
acen : '#708090',
|
|
10
|
+
gneg : '#FFFFFF',
|
|
11
|
+
gpos : '#000000',
|
|
12
|
+
gpos100 : '#000000',
|
|
13
|
+
gpos25 : '#D9D9D9',
|
|
14
|
+
gpos33 : '#BFBFBF',
|
|
15
|
+
gpos50 : '#999999',
|
|
16
|
+
gpos66 : '#7F7F7F',
|
|
17
|
+
gpos75 : '#666666',
|
|
18
|
+
gvar : '#E0E0E0',
|
|
19
|
+
stalk : '#708090'
|
|
20
|
+
},
|
|
21
|
+
labelColors: {
|
|
22
|
+
gneg : '#000000',
|
|
23
|
+
gvar : '#000000',
|
|
24
|
+
gpos25 : '#000000',
|
|
25
|
+
gpos33 : '#000000'
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
getData: function (chr, start, end) {
|
|
29
|
+
this.receiveData($.extend(true, [], this.browser.genome[chr].bands), chr, start, end);
|
|
30
|
+
return $.Deferred().resolveWith(this);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
insertFeature: function (feature) {
|
|
34
|
+
feature.label = feature.type === 'acen' || feature.type === 'stalk' ? false : feature.id;
|
|
35
|
+
feature.menuTitle = feature.id ? feature.chr + feature.id : feature.chr + ':' + feature.start + '-' + feature.end;
|
|
36
|
+
feature.color = this.prop('colors')[feature.type] || '#FFFFFF';
|
|
37
|
+
feature.labelColor = this.prop('labelColors')[feature.type] || '#FFFFFF';
|
|
38
|
+
|
|
39
|
+
if (feature.id) {
|
|
40
|
+
feature.id = feature.chr + feature.id;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.base(feature);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
drawFeature: function (feature, featureContext, labelContext, scale) {
|
|
47
|
+
featureContext.fillStyle = feature.color;
|
|
48
|
+
featureContext.strokeStyle = '#000000';
|
|
49
|
+
|
|
50
|
+
if (feature.type === 'acen') {
|
|
51
|
+
featureContext.beginPath();
|
|
52
|
+
|
|
53
|
+
if (this.drawnAcen) {
|
|
54
|
+
featureContext.moveTo(feature.x + feature.width, 0.5);
|
|
55
|
+
featureContext.lineTo(feature.x, (feature.height + 0.5) / 2);
|
|
56
|
+
featureContext.lineTo(feature.x + feature.width, feature.height + 0.5);
|
|
57
|
+
} else {
|
|
58
|
+
featureContext.moveTo(feature.x, 0.5);
|
|
59
|
+
featureContext.lineTo(feature.x + feature.width, (feature.height + 0.5) / 2);
|
|
60
|
+
featureContext.lineTo(feature.x, feature.height + 0.5);
|
|
61
|
+
this.drawnAcen = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
featureContext.fill();
|
|
65
|
+
featureContext.stroke();
|
|
66
|
+
} else if (feature.type === 'stalk') {
|
|
67
|
+
for (var i = 0; i < 2; i++) {
|
|
68
|
+
featureContext.beginPath();
|
|
69
|
+
|
|
70
|
+
featureContext.moveTo(feature.x, 0.5);
|
|
71
|
+
featureContext.lineTo(feature.x + feature.width * 0.25, feature.height * 0.25 + 0.5);
|
|
72
|
+
featureContext.lineTo(feature.x + feature.width * 0.75, feature.height * 0.25 + 0.5);
|
|
73
|
+
featureContext.lineTo(feature.x + feature.width, 0.5);
|
|
74
|
+
|
|
75
|
+
featureContext[i ? 'moveTo' : 'lineTo'](feature.x + feature.width, feature.height + 0.5);
|
|
76
|
+
featureContext.lineTo(feature.x + feature.width * 0.75, feature.height * 0.75 - 0.5);
|
|
77
|
+
featureContext.lineTo(feature.x + feature.width * 0.25, feature.height * 0.75 - 0.5);
|
|
78
|
+
featureContext.lineTo(feature.x, feature.height + 0.5);
|
|
79
|
+
|
|
80
|
+
featureContext[i ? 'stroke' : 'fill']();
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
this.base(feature, featureContext, labelContext, scale);
|
|
84
|
+
|
|
85
|
+
featureContext.beginPath();
|
|
86
|
+
|
|
87
|
+
var chrSize = this.browser.getChromosomeSize(feature.chr);
|
|
88
|
+
|
|
89
|
+
if (feature.start === 1 || feature.end === chrSize) {
|
|
90
|
+
if (feature.start === 1) {
|
|
91
|
+
var end = feature.x + feature.width - (feature.end === chrSize ? 5 : 0);
|
|
92
|
+
|
|
93
|
+
featureContext.clearRect(0, 0, 5, feature.height + 0.5);
|
|
94
|
+
|
|
95
|
+
featureContext.fillStyle = feature.color;
|
|
96
|
+
featureContext.moveTo(5, 0.5);
|
|
97
|
+
featureContext.lineTo(end, 0.5);
|
|
98
|
+
featureContext.moveTo(5, feature.height + 0.5);
|
|
99
|
+
featureContext.lineTo(end, feature.height + 0.5);
|
|
100
|
+
featureContext.moveTo(5, 0.5);
|
|
101
|
+
featureContext.bezierCurveTo(-1, 0.5, -1, feature.height + 0.5, 5, feature.height + 0.5);
|
|
102
|
+
featureContext.fill();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (feature.end === chrSize) {
|
|
106
|
+
featureContext.clearRect(feature.x + feature.width - 5, 0, 5, feature.height + 0.5);
|
|
107
|
+
|
|
108
|
+
if (feature.start !== 1) {
|
|
109
|
+
featureContext.fillStyle = feature.color;
|
|
110
|
+
featureContext.moveTo(feature.x, 0.5);
|
|
111
|
+
featureContext.lineTo(feature.x + feature.width - 5, 0.5);
|
|
112
|
+
featureContext.moveTo(feature.x, feature.height + 0.5);
|
|
113
|
+
featureContext.lineTo(feature.x + feature.width - 5, feature.height + 0.5);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
featureContext.moveTo(feature.x + feature.width - 5, 0.5);
|
|
117
|
+
featureContext.bezierCurveTo(this.width + 1, 0.5, this.width + 1, feature.height + 0.5, feature.x + feature.width - 5, feature.height + 0.5);
|
|
118
|
+
featureContext.fill();
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
featureContext.moveTo(feature.x, 0.5);
|
|
122
|
+
featureContext.lineTo(feature.x + feature.width, 0.5);
|
|
123
|
+
featureContext.moveTo(feature.x, feature.height + 0.5);
|
|
124
|
+
featureContext.lineTo(feature.x + feature.width, feature.height + 0.5);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
featureContext.stroke();
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
drawLabel: function (feature) {
|
|
132
|
+
if ((feature.start === 1 || feature.end === this.browser.getChromosomeSize(feature.chr)) && feature.labelWidth >= Math.floor(feature.width - 5)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this.base.apply(this, arguments);
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
populateMenu: function (feature) {
|
|
140
|
+
return {
|
|
141
|
+
title : feature.menuTitle,
|
|
142
|
+
Position : feature.chr + ':' + feature.start + '-' + feature.end
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|