-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColorByTypeDraggable.js
158 lines (158 loc) · 11 KB
/
ColorByTypeDraggable.js
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
var draggable = false;
try {
var m = require('WebApollo/View/Track/DraggableHTMLFeatures');
var HTMLFeatures = 'WebApollo/View/Track/DraggableHTMLFeatures';
draggable = true;
} catch (ex) {
var HTMLFeatures = 'JBrowse/View/Track/HTMLFeatures';
}
define([
'dojo/_base/declare',
HTMLFeatures,
'JBrowse/Util',
'plugins/ColorByType/jslib/color-hash/dist/color-hash',
],
function (declare,
HTMLFeatureTrack,
Util,
ColorHash,
draggable) {
var ColorByType = declare(HTMLFeatureTrack,
{
_defaultConfig: function () {
return Util.deepUpdate(
dojo.clone(this.inherited(arguments)),
{
style: {
className: "container-16px",
renderClassName: "gray-center-30pct annot",
arrowheadClass: "arrowhead",
subfeatureClasses: {
UTR: "generic_NCBI-utr",
CDS: "generic_NCBI-cds",
exon: "container-60pct",
stop_codon_read_through: "stop_codon_read_through"
},
minSubfeatureWidth: 1,
centerChildrenVertically: false
},
hooks: {
modify: function (track, feature, div) {
var colorHash = new ColorHash();
var type = feature.get('type'); // get transcript type
var UTRclasses = track.config.style.subfeatureClasses['UTR'];
var CDSclasses = track.config.style.subfeatureClasses['CDS'];
var EXONclasses = track.config.style.subfeatureClasses['exon'];
var STOP_CODENRTclasses = track.config.style.subfeatureClasses['stop_codon_read_through'];
for (var i = 0; i < div.children.length; i++) {
// container
// style of some common transcript type
var ClassName = div.children[i].className;
if (ClassName.includes('subfeature')) {
var concat_ClassName = type.concat(ClassName);
// children of a container
if (div.children[i].children.length > 0) {
for (var j = 0; j < div.children[i].children.length; j++) {
var subClassName = div.children[i].children[j].className;
var concat_subClassName = type.concat(subClassName);
if (typeof UTRclasses !== "undefined" && subClassName.includes(UTRclasses)) {
// UTR
// color of exon
if (type == 'mRNA') {
div.children[i].children[j].style.backgroundColor = '#d7f7c0';
} else if (type == 'lnc_RNA') {
div.children[i].children[j].style.backgroundColor = '#262dff';
} else if (type == 'snoRNA') {
div.children[i].children[j].style.backgroundColor = '#7cedff';
} else if (type == 'transcript') {
div.children[i].children[j].style.backgroundColor = '#c589c6';
} else if (type == 'rRNA') {
div.children[i].children[j].style.backgroundColor = '#fff200';
} else if (type == 'snRNA') {
div.children[i].children[j].style.backgroundColor = '#80a823';
} else if (type == 'tRNA') {
div.children[i].children[j].style.backgroundColor = '#ef7902';
} else {
div.children[i].children[j].style.backgroundColor = colorHash.hex(concat_subClassName);
}
} else if (typeof CDSclasses !== "undefined" && subClassName.includes(CDSclasses)) {
// CDS
// color of CDS
if (type == 'mRNA') {
div.children[i].children[j].style.backgroundColor = '#28db25';
} else {
div.children[i].children[j].style.backgroundColor = colorHash.hex(concat_subClassName);
}
} else {
// other feature type
div.children[i].children[j].className = 'subfeature generic_NCBI-utr';
div.children[i].children[j].style.backgroundColor = colorHash.hex(concat_subClassName);
}
}
} else {
if ((typeof UTRclasses !== "undefined" && ClassName.includes(UTRclasses)) || (typeof EXONclasses !== "undefined" && ClassName.includes(EXONclasses))) {
if (type == 'mRNA') {
div.children[i].style.backgroundColor = '#d7f7c0';
} else if (type == 'lnc_RNA') {
div.children[i].style.backgroundColor = '#262dff';
} else if (type == 'snoRNA') {
div.children[i].style.backgroundColor = '#7cedff';
} else if (type == 'transcript') {
div.children[i].style.backgroundColor = '#c589c6';
} else if (type == 'rRNA') {
div.children[i].style.backgroundColor = '#fff200';
} else if (type == 'snRNA') {
div.children[i].style.backgroundColor = '#80a823';
} else if (type == 'tRNA') {
div.children[i].style.backgroundColor = '#ef7902';
} else {
div.children[i].style.backgroundColor = colorHash.hex(concat_ClassName);
}
} else if (typeof CDSclasses !== "undefined" && ClassName.includes(CDSclasses)) {
if (type == 'mRNA') {
div.children[i].style.backgroundColor = '#28db25';
} else {
div.children[i].style.backgroundColor = colorHash.hex(concat_ClassName);
}
} else if (typeof STOP_CODENRTclasses != "undefined" && ClassName.includes(STOP_CODENRTclasses)) {
div.children[i].className = 'subfeature stop_codon_read_through';
} else {
div.children[i].className = 'subfeature generic_NCBI-utr';
div.children[i].style.backgroundColor = colorHash.hex(concat_ClassName);
}
}
}
}
}
}
}
);
},
renderFeature: function (feature, uniqueId, block, scale, labelScale, descriptionScale, containerStart, containerEnd, rclass, clsName) {
if (draggable == true) {
var featdiv = HTMLFeatureTrack.prototype.renderFeature.call(this, feature, uniqueId, block, scale, labelScale, descriptionScale, containerStart, containerEnd, rclass, clsName);
} else {
var featdiv = this.inherited( arguments );
if ( featdiv ) {
if (!rclass) {
rclass = this.config.style.renderClassName;
}
if (rclass) {
// console.log("in FeatureTrack.renderFeature, creating annot div");
var rendiv = document.createElement("div");
dojo.addClass(rendiv, "feature-render");
dojo.addClass(rendiv, rclass);
if (Util.is_ie6) rendiv.appendChild(document.createComment());
featdiv.appendChild(rendiv);
}
if (clsName) {
dojo.removeClass(featdiv.firstChild, feature.get("type"));
dojo.addClass(featdiv.firstChild, clsName);
}
}
}
return featdiv;
}
});
return ColorByType;
});