-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshowAllChromosomes.js
155 lines (103 loc) · 3.36 KB
/
showAllChromosomes.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
'use strict';
requirejs.config({
baseUrl: 'js',
paths:{
main:'kt/main',
util:'kt/util',
spans:'kt/spans',
colors:'kt/colors',
datatrack:'kt/datatrack',
label:'kt/label',
karyotype:'kt/karyotype',
jquery:'vendor/jquery-2.0.2.min',
pako:'vendor/pako-0.2.6.min'
}
});
var karyotypesvg ;
var kts = [];
require(['kt/main'], function(KT){
karyotypesvg = KT;
$( document ).ready(function() {
console.log(karyotypesvg.about);
var kt = new karyotypesvg.KT();
kt.init();
kt.addListener('viewerReady', function () {
var chromosomes = kt.getChromosomeList();
//console.log(chromosomes);
var sizes = kt.getChromosomeSizes();
//console.log(sizes);
// determine longest chromosome
// usually it should be chr1, but what if the input file is for a custom species?
var maxChromosome = "";
var maxChromosomeLength = 0;
var keys = Object.keys(sizes);
for (var i = 0 ; i < keys.length ; i++){
var chrLen = sizes[keys[i]];
if ( chrLen > maxChromosomeLength) {
maxChromosome = keys[i];
maxChromosomeLength = chrLen;
}
}
console.log("longest chromosome : " + maxChromosome + " length: " + maxChromosomeLength);
for (var i = 0 ; i < chromosomes.length ; i++){
// we skip the alternatives...
if ( chromosomes[i].indexOf('_') > -1) {
continue;
}
// we also won't show chrM, it is too small to get displayed.
if ( chromosomes[i] === "chrM") {
continue;
}
var chrLen = sizes[chromosomes[i]];
var percent = chrLen / maxChromosomeLength;
var newkt = addNewKaryotypeView(kt,chromosomes[i],percent);
kts.push(newkt);
if ( chromosomes[i] === "chr1"){
newkt.addLabel("LYPD8",248902716,248903151);
}
if ( chromosomes[i] === "chr17") {
//41196311 41277500
newkt.addLabel("BRCA1", 41196311,41277500);
}
if ( chromosomes[i] === "chr2") {
newkt.addLabel("TMEM178A",39892637, 39945104);
}
if (chromosomes[i] === "chr3"){
newkt.addLabel("TKT",53259652,53290130);
}
if (chromosomes[i] === "chr4"){
newkt.addLabel("TMEM175",926174,952443);
}
if (chromosomes[i] === "chr8"){
newkt.addLabel("ZNF16",146155743,146176274);
}
}
});
});
function disableAllThumbs(){
for (var i = 0 ; i < kts.length ; i++){
var kt = kts[i];
kt.showThumb(false);
}
}
function addNewKaryotypeView(kt, chr, percent){
//console.log("adding new chromosome " + chr + " " + percent);
var div = $("#ktContainer").append("<div id='row"+chr+"' class='row'>");
$("#row"+chr).append("<div id='div"+chr+"'>");
var newkt = new karyotypesvg.KT();
newkt.setParent('#div' +chr);
newkt.setScale(percent);
newkt.showThumb(false);
// no need to re-load...
newkt.setBands(kt.getBands());
newkt.update(chr) ;
newkt.updateScale(chr);
newkt.addListener('bandClicked',function(event){
console.log(event);
disableAllThumbs();
newkt.showThumb(true);
newkt.update(newkt.getChr(),event.min, event.max);
});
return newkt;
}
});