Commit 164115ae authored by Marc Duez's avatar Marc Duez

browser : rework

clones become clusters ( now stored as array instead of object)
split move to clone.js
use reads object from data file
auto detect germline
and more ...
parent 37b0c46a
......@@ -139,8 +139,8 @@ Axis.prototype = {
var n_min = 0;
var n_max = 1;
for (var i=0; i<this.m.windows.length; i++){
if (this.m.windows[i].Nlength > n_max) n_max = this.m.windows[i].Nlength;
for (var i=0; i<this.m.n_windows; i++){
if (this.m.clone(i).Nlength > n_max) n_max = this.m.clone(i).Nlength;
}
this.sizeScale = d3.scale.linear()
......@@ -149,7 +149,7 @@ Axis.prototype = {
//clone position
this.pos = function(cloneID) {
return self.sizeScale(self.m.windows[cloneID].Nlength)
return self.sizeScale(self.m.clone(cloneID).Nlength)
}
//labels
......
......@@ -375,7 +375,7 @@ Builder.prototype = {
$("#system_menu").css("display", "")
$("#color_system_button").css("display", "")
for (var key in this.m.system_segmented) {
for (var key in this.m.reads.germline) {
var radio=document.createElement("input");
radio.type="radio";
......@@ -587,17 +587,17 @@ Builder.prototype = {
span.appendChild(document.createTextNode("edit"));
span.className = "button_right"
span.onclick = function () {
self.edit(this, "timestamp2");
self.edit(this, "timestamp");
}
div_date.appendChild(span)
parent.appendChild(div_date)
var percent = (this.m.reads_segmented[this.m.t] / this.m.reads_total[this.m.t]) * 100
var val = "" + this.m.reads_segmented[this.m.t] + " reads" + " (" + percent.toFixed(2) + "%)"
var percent = (this.m.reads.segmented[this.m.t] / this.m.reads.total[this.m.t]) * 100
var val = "" + this.m.reads.segmented[this.m.t] + " reads" + " (" + percent.toFixed(2) + "%)"
var div_segmented = this.build_info_line("info_segmented", "segmented", val)
parent.appendChild(div_segmented)
var div_total = this.build_info_line("info_total", "total", this.m.reads_total[this.m.t] + " reads")
var div_total = this.build_info_line("info_total", "total", this.m.reads.total[this.m.t] + " reads")
parent.appendChild(div_total)
/*TODO put this somewhere else
......@@ -622,7 +622,7 @@ Builder.prototype = {
var keys = 0 ;
for (var key in this.m.system_segmented) {
for (var key in this.m.reads.germline) {
if (key == "IGH" && keys > 0) {
span2.appendChild(document.createElement("br"));
......
......@@ -20,6 +20,7 @@
function Clone(data, model, hash) {
this.m = model
this.hash = hash
this.split = false
var key = Object.keys(data)
for (var i=0; i<key.length; i++ ){
this[key[i]]=data[key[i]]
......@@ -58,10 +59,8 @@ Clone.prototype = {
}, //end getCode
getSystem: function () {
if (typeof (this.system) != 'undefined') {
return this.system;
} else {
if (this.m.system != 'multi' ) return this.m.system;
if (typeof (this.germline) != 'undefined') {
return this.germline;
}
},
......@@ -71,8 +70,8 @@ Clone.prototype = {
getSize: function (time) {
time = typeof time !== 'undefined' ? time : this.m.t;
if (this.m.reads_segmented[time] == 0 ) return 0
var result = this.getReads(time) / this.m.reads_segmented[time]
if (this.m.reads.segmented[time] == 0 ) return 0
var result = this.getReads(time) / this.m.reads.segmented[time]
if (this.m.norm) {
result = this.m.normalize(result, time)
......@@ -96,8 +95,8 @@ Clone.prototype = {
getSequenceSize: function (time) {
time = typeof time !== 'undefined' ? time : this.m.t;
if (this.m.reads_segmented[time] == 0 ) return 0
var result = this.getSequenceReads(time) / this.m.reads_segmented[time]
if (this.m.reads.segmented[time] == 0 ) return 0
var result = this.getSequenceReads(time) / this.m.reads.segmented[time]
if (this.norm) {
result = this.m.normalize(result, time)
......@@ -115,8 +114,8 @@ Clone.prototype = {
time = typeof time !== 'undefined' ? time : this.m.t;
var result = 0;
for (var j = 0; j < this.m.clones[this.hash].cluster.length; j++) {
result += this.m.clone(this.m.clones[this.hash].cluster[j]).size[time];
for (var j = 0; j < this.m.clusters[this.hash].length; j++) {
result += this.m.clone(this.m.clusters[this.hash][j]).size[time];
}
return result
......@@ -241,7 +240,7 @@ Clone.prototype = {
*
* */
getHtmlInfo: function () {
var isCluster = this.m.clones[this.hash].cluster.length
var isCluster = this.m.clusters[this.hash].length
var time_length = this.m.samples.order.length
var html = ""
......@@ -265,7 +264,7 @@ Clone.prototype = {
html += "<tr><td> clone name </td><td colspan='" + time_length + "'>" + this.getName() + "</td></tr>"
html += "<tr><td> clone size (n-reads (total reads) )</td>"
for (var i = 0; i < time_length; i++) {
html += "<td>" + this.getReads(this.m.samples.order[i]) + " (" + this.m.reads_segmented[this.m.samples.order[i]] + ")</td>"
html += "<td>" + this.getReads(this.m.samples.order[i]) + " (" + this.m.reads.segmented[this.m.samples.order[i]] + ")</td>"
}
html += "</tr><tr><td> clone size (%)</td>"
for (var i = 0; i < time_length; i++) {
......@@ -283,7 +282,7 @@ Clone.prototype = {
html += "<tr><td> size (n-reads (total reads) )</td>"
for (var i = 0; i < time_length; i++) {
html += "<td>" + this.getSequenceReads(this.m.samples.order[i]) +
" (" + this.m.reads_segmented[this.m.samples.order[i]] + ")</td>"
" (" + this.m.reads.segmented[this.m.samples.order[i]] + ")</td>"
}
html += "</tr>"
html += "<tr><td> size (%)</td>"
......
......@@ -148,8 +148,8 @@ Graph.prototype = {
this.resolution5 = []
for (i = 0; i < this.m.samples.number; i++) {
this.resolution1[i] = (1 / this.m.reads_segmented[i])
this.resolution5[i] = (5 / this.m.reads_segmented[i])
this.resolution1[i] = (1 / this.m.reads.segmented[i])
this.resolution5[i] = (5 / this.m.reads.segmented[i])
}
this.data_res.push({
......@@ -388,8 +388,8 @@ Graph.prototype = {
}
for (i = 0; i < this.m.samples.number; i++) {
this.resolution1[i] = (1 / this.m.reads_segmented[i])
this.resolution5[i] = (5 / this.m.reads_segmented[i])
this.resolution1[i] = (1 / this.m.reads.segmented[i])
this.resolution5[i] = (5 / this.m.reads.segmented[i])
}
if(this.mode=="stack"){
......@@ -399,15 +399,15 @@ Graph.prototype = {
this.data_res[1].path = this.constructPathR(this.resolution5);
for (var i = 0; i < this.m.n_windows; i++) {
for (var j = 0; j < this.m.clones[i].cluster.length; j++) {
this.data_graph[this.m.clones[i].cluster[j]].path = this.constructPath(i, false);
for (var j = 0; j < this.m.clusters[i].length; j++) {
this.data_graph[this.m.clusters[i][j]].path = this.constructPath(i, false);
}
}
for (var i = 0; i < this.m.n_windows; i++) {
var cloneID = i
for (var j = 0; j < this.m.clones[cloneID].cluster.length; j++) {
var seqID = this.m.clones[cloneID].cluster[j]
if (this.m.clones[cloneID].split) {
for (var j = 0; j < this.m.clusters[cloneID].length; j++) {
var seqID = this.m.clusters[cloneID][j]
if (this.m.clone(cloneID).split) {
this.data_graph[seqID].path = this.constructPath(seqID, true);
} else {
this.data_graph[seqID].path = this.constructPath(cloneID, false);
......@@ -423,7 +423,6 @@ Graph.prototype = {
},
updateStack: function () {
console.log("bam")
var stack = new Stack(this.m)
stack.compute();
for (var i = 0; i < this.m.n_length; i++) {
......@@ -440,9 +439,9 @@ Graph.prototype = {
}else{
for (var i = 0; i < list.length; i++) {
var cloneID = list[i]
for (var j = 0; j < this.m.clones[cloneID].cluster.length; j++) {
var seqID = this.m.clones[cloneID].cluster[j]
if (this.m.clones[cloneID].split) {
for (var j = 0; j < this.m.clusters[cloneID].length; j++) {
var seqID = this.m.clusters[cloneID][j]
if (this.m.clone(cloneID).split) {
this.data_graph[seqID].path = this.constructPath(seqID, true);
} else {
this.data_graph[seqID].path = this.constructPath(cloneID, false);
......
......@@ -232,8 +232,8 @@ List.prototype = {
var span_cluster = document.createElement('span')
span_cluster.className = "clusterBox";
if (this.m.clones[cloneID].cluster.length > 1) {
if (this.m.clones[cloneID].split) {
if (this.m.clusters[cloneID].length > 1) {
if (this.m.clone(cloneID).split) {
span_cluster.onclick = function () {
self.hideCluster(cloneID)
}
......@@ -286,17 +286,17 @@ List.prototype = {
div_cluster.id = "cluster" + cloneID;
div_cluster.id2 = cloneID;
var display = this.m.clones[cloneID].split
if (this.m.clones[cloneID].cluster.length < 2) display = false
var display = this.m.clone(cloneID).split
if (this.m.clusters[cloneID].length < 2) display = false
if (!display) div_cluster.style.display = "none";
var clusterSize = this.m.clone(cloneID).getSize()
var clusterReads = this.m.clone(cloneID).getReads()
for (var i = 0; i < this.m.clones[cloneID].cluster.length; i++) {
for (var i = 0; i < this.m.clusters[cloneID].length; i++) {
(function (i) {
var id = this.m.clones[cloneID].cluster[i]
var id = this.m.clusters[cloneID][i]
var div_clone = document.createElement('div');
div_clone.id = "_" + id;
div_clone.id2 = id;
......@@ -403,7 +403,7 @@ List.prototype = {
var div = this.index[list[i]];
if ((this.m.clone(list[i]).isActive() && this.m.clones[list[i]].cluster.length != 0) || this.m.clone(list[i]).window == "other") {
if ((this.m.clone(list[i]).isActive() && this.m.clusters[list[i]].length != 0) || this.m.clone(list[i]).window == "other") {
div.innerHTML = '';
......@@ -589,7 +589,7 @@ List.prototype = {
showCluster: function (cloneID) {
var self = this
this.m.clones[cloneID].split = true
this.m.clone(cloneID).split = true
$("#cluster" + cloneID)
.show(50, function () {
self.m.updateElem([cloneID])
......@@ -598,7 +598,7 @@ List.prototype = {
hideCluster: function (cloneID) {
var self = this
this.m.clones[cloneID].split = false
this.m.clone(cloneID).split = false
$("#cluster" + cloneID)
.hide(50, function () {
self.m.updateElem([cloneID])
......
......@@ -77,9 +77,7 @@ Model.prototype = {
this.top = 10;
this.precision = 1;
this.isPlaying = false;
this.timestamp = [];
this.timestamp2 = [];
this.clones = [];
this.clusters = [];
this.windows = [];
this.germline = {}
this.germlineV = new Germline(this)
......@@ -160,11 +158,11 @@ Model.prototype = {
try {
var data = JSON.parse(oFREvent.target.result);
} catch (e) {
popupMsg(myConsole.msgfile_error);
myConsole.popupMsg(myConsole.msg.file_error);
return 0
}
if ((typeof (data.vidjil_json_version) == 'undefined') || (data.vidjil_json_version < VIDJIL_JSON_VERSION)) {
popupMsg(myConsole.msgversion_error);
myConsole.popupMsg(myConsole.msg.version_error);
return 0;
}
self.reset()
......@@ -247,7 +245,7 @@ Model.prototype = {
if (data.windows[i].top <= limit) {
//search for min_size
for (var k = 0; k < data.windows[i].size.length; k++) {
var size = (data.windows[i].size[k] / data.reads_segmented[k])
var size = (data.windows[i].size[k] / data.reads.segmented[k])
if (min_sizes[k] > size && data.windows[i].size[k] != 0)
min_sizes[k] = size;
......@@ -273,10 +271,8 @@ Model.prototype = {
}
self.samples = data.samples
self.reads = data.reads
self.links = data.links;
self.reads_segmented = data.reads_segmented;
self.system_segmented = data.system_segmented;
self.segmentation_info = data.segmentation_info;
// synthetic window
var other = {
......@@ -437,9 +433,6 @@ Model.prototype = {
}
}
if (self.analysis.timestamp2) {
self.timestamp2 = self.analysis.timestamp2;
}
if (self.analysis.patient) {
self.dataFileName = self.analysis.patient;
}
......@@ -466,7 +459,7 @@ Model.prototype = {
loadGermline: function (system) {
console.log("loadGermline : " + system)
system = typeof system !== 'undefined' ? system : this.system;
if (system == "multi") system = Object.keys(this.system_segmented)[0]
if (system == "multi") system = Object.keys(this.reads.germline)[0]
return this.germlineV.load(system, "V", this)
.germlineD.load(system, "D", this)
......@@ -555,7 +548,7 @@ Model.prototype = {
var maxNlength = 0;
var nsize;
self.mapID = [];
this.clones = [];
this.clusters = [];
// NSIZE
for (var i = 0; i < this.n_windows; i++) {
......@@ -570,10 +563,7 @@ Model.prototype = {
nsize = -1;
}
self.mapID[clone.window] = i;
this.clones[i] = {
cluster: [i],
split: false
};
this.clusters[i] = [i]
clone.Nlength = nsize;
clone.tag = default_tag;
}
......@@ -690,18 +680,18 @@ Model.prototype = {
}
// CUSTOM CLUSTER
var cluster = analysis.cluster;
for (var i = 0; i < cluster.length; i++) {
var clusters = analysis.clusters;
for (var i = 0; i < clusters.length; i++) {
var new_cluster = [];
var l = self.mapID[cluster[i][0]]
var l = self.mapID[clusters[i][0]]
for (var j=0; j<cluster[i].length;j++){
var cloneID = self.mapID[cluster[i][j]]
new_cluster = new_cluster.concat(this.clones[cloneID].cluster);
this.clones[cloneID].cluster = [];
for (var j=0; j<clusters[i].length;j++){
var cloneID = self.mapID[clusters[i][j]]
new_cluster = new_cluster.concat(this.clusters[cloneID]);
this.clusters[cloneID] = [];
}
this.clones[l].cluster = new_cluster;
this.clusters[l] = new_cluster;
}
}
this.init()
......@@ -749,7 +739,7 @@ Model.prototype = {
vidjil_json_version : VIDJIL_JSON_VERSION,
samples : this.samples,
clones : [],
cluster : [],
clusters : [],
tags : {}
}
......@@ -776,12 +766,12 @@ Model.prototype = {
}
//clones / cluster
if (this.clones[i].cluster.length > 1) {
if (this.clusters[i].length > 1) {
var elem = [];
for (var j = 0; j < this.clones[i].cluster.length; j++) {
elem.push(this.clone(this.clones[i].cluster[j]).window);
for (var j = 0; j < this.clusters[i].length; j++) {
elem.push(this.clone(this.clusters[i][j]).window);
}
analysisData.cluster.push(elem);
analysisData.clusters.push(elem);
}
}
......@@ -795,7 +785,6 @@ Model.prototype = {
analysisData.normalization = this.normalization
analysisData.timestamp2 = this.timestamp2
return JSON.stringify(analysisData, undefined, 2);
},
......@@ -831,16 +820,16 @@ Model.prototype = {
* */
update_selected_system: function(){
//reset reads_segmented
for (var i=0 ; i<this.reads_segmented.length; i++){
this.reads_segmented[i]=0
//reset reads.segmented
for (var i=0 ; i<this.reads.segmented.length; i++){
this.reads.segmented[i]=0
}
//reset system
this.system_selected = []
//check system currently selected in menu
for (var key in this.system_segmented) {
for (var key in this.reads.germline) {
if (document.getElementById("checkbox_system_"+key).checked){
this.system_selected.push(key)
}
......@@ -848,16 +837,16 @@ Model.prototype = {
//if 0 box checked in menu then all selected
if (this.system_selected.length == 0) {
for (var key in this.system_segmented) {
for (var key in this.reads.germline) {
this.system_selected.push(key)
}
}
//compute new reads_segmented value (sum of reads_segmented of selected system)
//compute new reads.segmented value (sum of reads.segmented of selected system)
for (var i=0; i<this.system_selected.length; i++){
var key = this.system_selected[i]
for (var j=0; j<this.reads_segmented.length; j++){
this.reads_segmented[j] += this.system_segmented[key][j]
for (var j=0; j<this.reads.segmented.length; j++){
this.reads.segmented[j] += this.reads.germline[key][j]
}
}
......@@ -948,8 +937,8 @@ Model.prototype = {
},
getSegmentationInfo: function (timeID) {
if (typeof this.segmentation_info != 'undefined'){
return this.segmentation_info[timeID].replace(/(?:\r\n|\r|\n)/g, '<br />')
if (typeof this.samples.segmentation_info != 'undefined'){
return this.samples.segmentation_info[timeID].replace(/(?:\r\n|\r|\n)/g, '<br />')
}else{
return "not specified";
}
......@@ -1013,12 +1002,8 @@ Model.prototype = {
}
break;
case "sampling_date":
if ((typeof this.timestamp2 != 'undefined') && this.timestamp2[timeID])
result = this.timestamp2[timeID].split(" ")[0]
break;
case "run_date":
if ((typeof this.timestamp != 'undefined') && this.timestamp[timeID])
result = this.timestamp[timeID].split(" ")[0]
if ((typeof this.samples.timestamp != 'undefined') && this.samples.timestamp[timeID])
result = this.samples.timestamp[timeID].split(" ")[0]
break;
}
return result
......@@ -1185,11 +1170,11 @@ Model.prototype = {
leader = list[i];
top = this.clone(list[i]).top;
}
new_cluster = new_cluster.concat(this.clones[list[i]].cluster);
this.clones[list[i]].cluster = [];
new_cluster = new_cluster.concat(this.clusters[list[i]]);
this.clusters[list[i]] = [];
}
this.clones[leader].cluster = new_cluster;
this.clusters[leader] = new_cluster;
this.unselectAll()
this.updateElem(list)
this.select(leader)
......@@ -1203,16 +1188,16 @@ Model.prototype = {
myConsole.log("split() (cloneA " + cloneID + " windowB " + windowID + ")")
if (cloneID == windowID) return
var nlist = this.clones[cloneID].cluster;
var nlist = this.clusters[cloneID];
var index = nlist.indexOf(windowID);
if (index == -1) return
nlist.splice(index, 1);
//le clone retrouve sa liste de windows -1
this.clones[cloneID].cluster = nlist;
this.clusters[cloneID] = nlist;
//la window forme son propre clone a part
this.clones[windowID].cluster = [windowID];
this.clusters[windowID] = [windowID];
this.updateElem([windowID, cloneID]);
},
......@@ -1234,18 +1219,18 @@ Model.prototype = {
*
* */
updateModel: function () {
for (var i = 0; i < this.clones.length; i++) {
for (var i = 0; i < this.clusters.length; i++) {
// compute only non empty clones
if (this.clones[i].cluster.length != 0) {
if (!this.clones[i].split) {
for (var j = 0; j < this.clones[i].cluster.length; j++) {
var seq = this.clones[i].cluster[j]
if (this.clusters[i].length != 0) {
if (!this.clone(i).split) {
for (var j = 0; j < this.clusters[i].length; j++) {
var seq = this.clusters[i][j]
this.clone(seq).active = false;
}
this.active(i)
} else {
for (var j = 0; j < this.clones[i].cluster.length; j++) {
var seq = this.clones[i].cluster[j]
for (var j = 0; j < this.clusters[i].length; j++) {
var seq = this.clusters[i][j]
this.active(seq)
}
}
......@@ -1391,16 +1376,16 @@ Model.prototype = {
computeOtherSize: function () {
var other = [];
for (var j = 0; j < this.reads_segmented.length; j++) {
other[j] = this.reads_segmented[j]
for (var j = 0; j < this.reads.segmented.length; j++) {
other[j] = this.reads.segmented[j]
}
for (var i = 0; i < this.n_windows - 1; i++) {
for (var j = 0; j < this.reads_segmented.length; j++) {
if (this.clone(i).isActive) {
for (var k = 0; k < this.clones[i].cluster.length; k++) {
if (this.clones[i].cluster[k] != this.n_windows - 1)
other[j] -= this.clone(this.clones[i].cluster[k]).size[j];
for (var j = 0; j < this.reads.segmented.length; j++) {
if (this.clone(i).isActive()) {
for (var k = 0; k < this.clusters[i].length; k++) {
if (this.clusters[i][k] != this.n_windows - 1)
other[j] -= this.clone(this.clusters[i][k]).size[j];
}
}
}
......@@ -1416,11 +1401,11 @@ Model.prototype = {
getPointHtmlInfo: function (timeID) {
var html = ""
html = "<h2>Point info : " + this.getStrTime(timeID, "name") + "("+this.timestamp[timeID]+")</h2>"
html = "<h2>Point info : " + this.getStrTime(timeID, "name") + "("+this.samples.timestamp[timeID]+")</h2>"
html += "<div id='info_timepoint'><table><tr><th></th>"
html += "<tr><td> reads </td><td>" + this.reads_total[timeID] + "</td></tr>"
html += "<tr><td> reads segmented </td><td>" + this.reads_segmented[timeID] +
" ("+ (this.reads_segmented[timeID]*100/this.reads_total[timeID]).toFixed(3) + " % )</td></tr>"
html += "<tr><td> reads </td><td>" + this.reads.total[timeID] + "</td></tr>"
html += "<tr><td> reads segmented </td><td>" + this.reads.segmented[timeID] +
" ("+ (this.reads.segmented[timeID]*100/this.reads.total[timeID]).toFixed(3) + " % )</td></tr>"
html += "<tr><td> segmentation </td><td>" + this.getSegmentationInfo(timeID) + "</td></tr>"
html += "</table></div>"
......@@ -1435,8 +1420,8 @@ Model.prototype = {
this.currentCluster = data_name;
//save user cluster
if ( this.cluster_key==""){
this.clones_copy = this.clones
this.clones = []
this.clusters_copy = this.clusters
this.clusters = []
}
var tmp = {}
......@@ -1475,18 +1460,16 @@ Model.prototype = {
//reset cluster
for (var i = 0; i < this.windows.length; i++) {
this.clones[i] = {
cluster: [i]
};
this.clusters[i] = []
}
//new cluster
for (var i in tmp) {
this.clones[tmp[i][0]].cluster = tmp[i]
this.clones[tmp[i][0]].name = i
this.clusters[tmp[i][0]] = tmp[i]
this.clusters[tmp[i][0]].name = i
for (var j = 1; j < tmp[i].length; j++) {
this.clones[tmp[i][j]].cluster = []
this.clusters[tmp[i][j]] = []
}
}
this.cluster_key = data_name