Commit dc9d7bd4 authored by Marc Duez's avatar Marc Duez

model.js/graph.js : replace time and time_order

parent c49ee7d7
...@@ -145,7 +145,7 @@ Graph.prototype = { ...@@ -145,7 +145,7 @@ Graph.prototype = {
this.resolution1 = [] this.resolution1 = []
this.resolution5 = [] this.resolution5 = []
for (i = 0; i < this.m.time.length; i++) { for (i = 0; i < this.m.samples.number; i++) {
this.resolution1[i] = (1 / this.m.reads_segmented[i]) this.resolution1[i] = (1 / this.m.reads_segmented[i])
this.resolution5[i] = (5 / this.m.reads_segmented[i]) this.resolution5[i] = (5 / this.m.reads_segmented[i])
} }
...@@ -231,8 +231,8 @@ Graph.prototype = { ...@@ -231,8 +231,8 @@ Graph.prototype = {
var list = document.getElementById("" + this.id + "_list") var list = document.getElementById("" + this.id + "_list")
list.innerHTML = "" list.innerHTML = ""
for (var i=0; i<this.m.time.length; i++){ for (var i=0; i<this.m.samples.number; i++){
if ( this.m.time_order.indexOf(i) == -1){ if ( this.m.samples.order.indexOf(i) == -1){
$("<div/>", { $("<div/>", {
class: "graph_listElem", class: "graph_listElem",
text: this.m.getStrTime(i), text: this.m.getStrTime(i),
...@@ -259,26 +259,23 @@ Graph.prototype = { ...@@ -259,26 +259,23 @@ Graph.prototype = {
.range([0, 1]); .range([0, 1]);
//abscisse //abscisse
for (var i = 0; i < this.m.time_order.length; i++) { for (var i = 0; i < this.m.samples.order.length; i++) {
this.graph_col[i] = this.marge1 + i * ((1 - (this.marge1 + this.marge2)) / (this.m.time_order.length - 1)); this.graph_col[i] = this.marge1 + i * ((1 - (this.marge1 + this.marge2)) / (this.m.samples.order.length - 1));
} }
if (this.m.time_order.length == 1) { if (this.m.samples.order.length == 1) {
this.graph_col[0] = 1 / 2 this.graph_col[0] = 1 / 2
} }
if (this.m.time_order.length == 2) { if (this.m.samples.order.length == 2) {
this.graph_col[0] = 1 / 4; this.graph_col[0] = 1 / 4;
this.graph_col[1] = 3 / 4; this.graph_col[1] = 3 / 4;
} }
for (var i = 0; i < this.m.time.length; i++) { for (var i = 0; i < this.m.samples.number; i++) {
var t = this.m.time_order.indexOf(i) var t = this.m.samples.order.indexOf(i)
d = {} d = {}
var time_name = "fu" + (i + 1);
if (typeof this.m.time != "undefined" && typeof this.m.time[i] != "undefined") {
time_name = this.m.getStrTime(i); time_name = this.m.getStrTime(i);
time_name = time_name.split(".")[0] time_name = time_name.split(".")[0]
}
d.type = "axis_v"; d.type = "axis_v";
d.text = time_name; d.text = time_name;
...@@ -322,12 +319,12 @@ Graph.prototype = { ...@@ -322,12 +319,12 @@ Graph.prototype = {
} }
//current time_point //current time_point
if ( this.m.time_order.indexOf(this.m.t) != -1 ){ if ( this.m.samples.order.indexOf(this.m.t) != -1 ){
this.mobil = {}; this.mobil = {};
this.mobil.type = "axis_m"; this.mobil.type = "axis_m";
this.mobil.text = ""; this.mobil.text = "";
this.mobil.orientation = "vert"; this.mobil.orientation = "vert";
this.mobil.pos = this.graph_col[this.m.time_order.indexOf(this.m.t)]; this.mobil.pos = this.graph_col[this.m.samples.order.indexOf(this.m.t)];
this.data_axis.push(this.mobil) this.data_axis.push(this.mobil)
} }
...@@ -388,7 +385,7 @@ Graph.prototype = { ...@@ -388,7 +385,7 @@ Graph.prototype = {
.appendChild(line); .appendChild(line);
} }
for (i = 0; i < this.m.time.length; i++) { for (i = 0; i < this.m.samples.number; i++) {
this.resolution1[i] = (1 / this.m.reads_segmented[i]) this.resolution1[i] = (1 / this.m.reads_segmented[i])
this.resolution5[i] = (5 / this.m.reads_segmented[i]) this.resolution5[i] = (5 / this.m.reads_segmented[i])
} }
...@@ -674,8 +671,8 @@ Graph.prototype = { ...@@ -674,8 +671,8 @@ Graph.prototype = {
//stock tuples time_point/axis position //stock tuples time_point/axis position
var list = [] var list = []
for (var i = 0; i < this.m.time_order.length; i++) { for (var i = 0; i < this.m.samples.order.length; i++) {
var t = this.m.time_order[i] var t = this.m.samples.order[i]
if (t == this.dragged_time_point) { if (t == this.dragged_time_point) {
list.push([t, (coordinates[0] - this.marge4) / this.resizeW]); list.push([t, (coordinates[0] - this.marge4) / this.resizeW]);
} else { } else {
...@@ -683,7 +680,7 @@ Graph.prototype = { ...@@ -683,7 +680,7 @@ Graph.prototype = {
} }
} }
if (this.m.time_order.indexOf(this.dragged_time_point) == -1) if (this.m.samples.order.indexOf(this.dragged_time_point) == -1)
list.push([this.dragged_time_point, (coordinates[0] - this.marge4) / this.resizeW]); list.push([this.dragged_time_point, (coordinates[0] - this.marge4) / this.resizeW]);
//sort by axis position //sort by axis position
...@@ -710,9 +707,9 @@ Graph.prototype = { ...@@ -710,9 +707,9 @@ Graph.prototype = {
this.drag_on = false; this.drag_on = false;
var result = [] var result = []
for (var i=0; i<this.m.time_order.length; i++){ for (var i=0; i<this.m.samples.order.length; i++){
if (this.m.time_order[i] != this.dragged_time_point){ if (this.m.samples.order[i] != this.dragged_time_point){
result.push(this.m.time_order[i]) result.push(this.m.samples.order[i])
} }
} }
...@@ -759,9 +756,9 @@ Graph.prototype = { ...@@ -759,9 +756,9 @@ Graph.prototype = {
p.push([0, (1 - this.scale_x(size[0] * this.m.precision))]); p.push([0, (1 - this.scale_x(size[0] * this.m.precision))]);
for (var i = 0; i < this.graph_col.length; i++) { for (var i = 0; i < this.graph_col.length; i++) {
p.push([(this.graph_col[i]), (1 - this.scale_x(size[this.m.time_order[i]] * this.m.precision))]); p.push([(this.graph_col[i]), (1 - this.scale_x(size[this.m.samples.order[i]] * this.m.precision))]);
} }
p.push([1, (1 - this.scale_x(size[this.m.time_order[this.graph_col.length - 1]] * this.m.precision))]); p.push([1, (1 - this.scale_x(size[this.m.samples.order[this.graph_col.length - 1]] * this.m.precision))]);
p.push([1, 1 + 0.1]); p.push([1, 1 + 0.1]);
return p; return p;
...@@ -777,8 +774,8 @@ Graph.prototype = { ...@@ -777,8 +774,8 @@ Graph.prototype = {
var size = [] var size = []
for (var i = 0; i < this.graph_col.length; i++) { for (var i = 0; i < this.graph_col.length; i++) {
if (seq_size) size[i] = this.m.getSequenceSize(id, this.m.time_order[i]) if (seq_size) size[i] = this.m.getSequenceSize(id, this.m.samples.order[i])
else size[i] = this.m.getSize(id, this.m.time_order[i]) else size[i] = this.m.getSize(id, this.m.samples.order[i])
} }
var x = this.graph_col[0]; var x = this.graph_col[0];
...@@ -862,13 +859,13 @@ Graph.prototype = { ...@@ -862,13 +859,13 @@ Graph.prototype = {
for (var i=0; i<this.graph_col.length; i++){ for (var i=0; i<this.graph_col.length; i++){
var x = this.graph_col[i]; var x = this.graph_col[i];
var y = stack.min[id][this.m.time_order[i]] var y = stack.min[id][this.m.samples.order[i]]
p.push([x,y]) p.push([x,y])
} }
for (var i=this.graph_col.length-1; i>=0; i--){ for (var i=this.graph_col.length-1; i>=0; i--){
var x = this.graph_col[i]; var x = this.graph_col[i];
var y = stack.max[id][this.m.time_order[i]] var y = stack.max[id][this.m.samples.order[i]]
p.push([x,y]) p.push([x,y])
} }
...@@ -888,7 +885,7 @@ Stack.prototype = { ...@@ -888,7 +885,7 @@ Stack.prototype = {
//compute sum of all clone +others (dans un monde parfait ca devrait faire 1 mais avec la normalisation...) //compute sum of all clone +others (dans un monde parfait ca devrait faire 1 mais avec la normalisation...)
init: function () { init: function () {
this.total_size = []; this.total_size = [];
for (j=0; j<this.m.time.length; j++){ for (j=0; j<this.m.samples.number; j++){
this.total_size[j]=0 this.total_size[j]=0
for (i=0; i<this.m.windows.length; i++){ for (i=0; i<this.m.windows.length; i++){
if (this.m.windows[i].active) this.total_size[j] += this.m.getSize(i,j); //active clones if (this.m.windows[i].active) this.total_size[j] += this.m.getSize(i,j); //active clones
...@@ -903,7 +900,7 @@ Stack.prototype = { ...@@ -903,7 +900,7 @@ Stack.prototype = {
this.sum = []; this.sum = [];
this.min = []; this.min = [];
this.max = []; this.max = [];
for (j=0; j<this.m.time.length; j++){ for (j=0; j<this.m.samples.number; j++){
this.sum[j]=1 this.sum[j]=1
} }
...@@ -912,13 +909,13 @@ Stack.prototype = { ...@@ -912,13 +909,13 @@ Stack.prototype = {
this.max[i] = [] this.max[i] = []
//active clones //active clones
if (this.m.windows[i].active) { if (this.m.windows[i].active) {
for (j=0; j<this.m.time.length; j++){ for (j=0; j<this.m.samples.number; j++){
this.min[i][j] = this.sum[j] this.min[i][j] = this.sum[j]
this.sum[j] -= this.m.getSize(i,j) this.sum[j] -= this.m.getSize(i,j)
this.max[i][j] = this.sum[j] this.max[i][j] = this.sum[j]
} }
}else{ }else{
for (j=0; j<this.m.time.length; j++){ for (j=0; j<this.m.samples.number; j++){
this.min[i][j] = this.sum[j] this.min[i][j] = this.sum[j]
this.max[i][j] = this.sum[j] this.max[i][j] = this.sum[j]
} }
...@@ -926,7 +923,7 @@ Stack.prototype = { ...@@ -926,7 +923,7 @@ Stack.prototype = {
} }
//other //other
for (j=0; j<this.m.time.length; j++){ for (j=0; j<this.m.samples.number; j++){
this.min[this.m.windows.length-1][j] = this.sum[j] this.min[this.m.windows.length-1][j] = this.sum[j]
this.sum[this.m.windows.length-1] += this.m.getSize(this.m.windows.length-1,j) this.sum[this.m.windows.length-1] += this.m.getSize(this.m.windows.length-1,j)
this.max[this.m.windows.length-1][j] = this.sum[j] this.max[this.m.windows.length-1][j] = this.sum[j]
......
...@@ -78,8 +78,6 @@ Model.prototype = { ...@@ -78,8 +78,6 @@ Model.prototype = {
this.mapID = {}; this.mapID = {};
this.top = 10; this.top = 10;
this.precision = 1; this.precision = 1;
this.time = [];
this.time_order = [];
this.isPlaying = false; this.isPlaying = false;
this.timestamp = []; this.timestamp = [];
this.timestamp2 = []; this.timestamp2 = [];
...@@ -271,22 +269,33 @@ Model.prototype = { ...@@ -271,22 +269,33 @@ Model.prototype = {
} }
} }
self.samples = data.samples
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 = { var other = {
"sequence": 0, "sequence": 0,
"window": "other", "window": "other",
"top": 0, "top": 0,
"size": [] "size": []
} }
self.windows.push(other); self.windows.push(other);
// default order
if (typeof self.samples.number == 'string'){
self.samples.number = parseInt(self.samples.number)
}
if (typeof self.samples.order == 'undefined'){
self.samples.order = []
for (var i = 0; i < self.samples.number; i++) self.samples.order.push(i);
}
self.n_windows = self.windows.length; self.n_windows = self.windows.length;
self.segmentation_info = data.segmentation_info;
self.min_sizes = min_sizes; self.min_sizes = min_sizes;
self.n_max = n_max; self.n_max = n_max;
self.links = data.links;
self.normalization_factor = data.normalization_factor;
self.reads_segmented = data.reads_segmented;
self.system_segmented = data.system_segmented;
self.system_selected = []; self.system_selected = [];
for (var key in self.system_segmented) self.system_selected.push(key) for (var key in self.system_segmented) self.system_selected.push(key)
self.reads_segmented_total = self.reads_segmented.reduce(function (a, b) { self.reads_segmented_total = self.reads_segmented.reduce(function (a, b) {
...@@ -302,15 +311,10 @@ Model.prototype = { ...@@ -302,15 +311,10 @@ Model.prototype = {
self.reads_total = self.reads_segmented; self.reads_total = self.reads_segmented;
} }
self.timestamp = data.timestamp; self.timestamp = data.timestamp;
if (typeof data.point != 'undefined'){
self.time = data.point;
}else{
self.time = data.timestamp;
}
self.scale_color = d3.scale.log() self.scale_color = d3.scale.log()
.domain([1, self.precision]) .domain([1, self.precision])
.range([250, 0]); .range([250, 0]);
for (var i = 0; i < self.time.length; i++) self.time_order.push(i);
//extract germline //extract germline
if (typeof data.germline != 'undefined') { if (typeof data.germline != 'undefined') {
...@@ -1032,7 +1036,7 @@ Model.prototype = { ...@@ -1032,7 +1036,7 @@ Model.prototype = {
var tmp = this.norm var tmp = this.norm
this.norm = false this.norm = false
for (var i=0; i<this.time.length; i++){ for (var i=0; i<this.samples.number; i++){
this.normalization.A[i] = this.getSize(cloneID, i) this.normalization.A[i] = this.getSize(cloneID, i)
} }
...@@ -1049,8 +1053,8 @@ Model.prototype = { ...@@ -1049,8 +1053,8 @@ Model.prototype = {
update_precision: function () { update_precision: function () {
var min_size = 1 var min_size = 1
for (var i=0; i<this.time_order.length; i++){ for (var i=0; i<this.samples.order.length; i++){
var t = this.time_order[i] var t = this.samples.order[i]
var size = this.min_sizes[t] var size = this.min_sizes[t]
if (this.norm) size = this.normalize(this.min_sizes[t], t) if (this.norm) size = this.normalize(this.min_sizes[t], t)
if (size < min_size) min_size = size if (size < min_size) min_size = size
...@@ -1237,7 +1241,11 @@ Model.prototype = { ...@@ -1237,7 +1241,11 @@ Model.prototype = {
switch (format) { switch (format) {
case "name": case "name":
result = this.time[timeID] if (typeof this.samples.names != 'undefined' && this.samples.names[timeID] != ""){
result = this.samples.names[timeID]
}else{
result = this.samples.original_names[timeID]
}
break; break;
case "sampling_date": case "sampling_date":
if ((typeof this.timestamp2 != 'undefined') && this.timestamp2[timeID]) if ((typeof this.timestamp2 != 'undefined') && this.timestamp2[timeID])
...@@ -1660,7 +1668,7 @@ Model.prototype = { ...@@ -1660,7 +1668,7 @@ Model.prototype = {
getCloneHtmlInfo: function (id, type) { getCloneHtmlInfo: function (id, type) {
if (this.clones[id].cluster.length <= 1) type = "sequence" if (this.clones[id].cluster.length <= 1) type = "sequence"
var time_length = this.time_order.length var time_length = this.samples.order.length
var html = "" var html = ""
//clone/sequence label //clone/sequence label
...@@ -1674,7 +1682,7 @@ Model.prototype = { ...@@ -1674,7 +1682,7 @@ Model.prototype = {
html += "<div id='info_window'><table><tr><th></th>" html += "<div id='info_window'><table><tr><th></th>"
for (var i = 0; i < time_length; i++) { for (var i = 0; i < time_length; i++) {
html += "<td>" + this.time[this.time_order[i]] + "</td>" html += "<td>" + this.getStrTime(this.samples.order[i], "name") + "</td>"
} }
html += "</tr>" html += "</tr>"
...@@ -1684,11 +1692,11 @@ Model.prototype = { ...@@ -1684,11 +1692,11 @@ Model.prototype = {
html += "<tr><td> clone name </td><td colspan='" + time_length + "'>" + this.getName(id) + "</td></tr>" html += "<tr><td> clone name </td><td colspan='" + time_length + "'>" + this.getName(id) + "</td></tr>"
html += "<tr><td> clone size (n-reads (total reads) )</td>" html += "<tr><td> clone size (n-reads (total reads) )</td>"
for (var i = 0; i < time_length; i++) { for (var i = 0; i < time_length; i++) {
html += "<td>" + this.getReads(id, this.time_order[i]) + " (" + this.reads_segmented[this.time_order[i]] + ")</td>" html += "<td>" + this.getReads(id, this.samples.order[i]) + " (" + this.reads_segmented[this.samples.order[i]] + ")</td>"
} }
html += "</tr><tr><td> clone size (%)</td>" html += "</tr><tr><td> clone size (%)</td>"
for (var i = 0; i < time_length; i++) { for (var i = 0; i < time_length; i++) {
html += "<td>" + (this.getSize(id, this.time_order[i]) * 100).toFixed(3) + " % </td>" html += "<td>" + (this.getSize(id, this.samples.order[i]) * 100).toFixed(3) + " % </td>"
} }
html += "<tr><td class='header' colspan='" + (time_length + 1) + "'> clone's main sequence information</td></tr>" html += "<tr><td class='header' colspan='" + (time_length + 1) + "'> clone's main sequence information</td></tr>"
}else{ }else{
...@@ -1701,13 +1709,13 @@ Model.prototype = { ...@@ -1701,13 +1709,13 @@ Model.prototype = {
html += "<tr><td> code </td><td colspan='" + time_length + "'>" + this.getCode(id) + "</td></tr>" html += "<tr><td> code </td><td colspan='" + time_length + "'>" + this.getCode(id) + "</td></tr>"
html += "<tr><td> size (n-reads (total reads) )</td>" html += "<tr><td> size (n-reads (total reads) )</td>"
for (var i = 0; i < time_length; i++) { for (var i = 0; i < time_length; i++) {
html += "<td>" + this.getSequenceReads(id, this.time_order[i]) + html += "<td>" + this.getSequenceReads(id, this.samples.order[i]) +
" (" + this.reads_segmented[this.time_order[i]] + ")</td>" " (" + this.reads_segmented[this.samples.order[i]] + ")</td>"
} }
html += "</tr>" html += "</tr>"
html += "<tr><td> size (%)</td>" html += "<tr><td> size (%)</td>"
for (var i = 0; i < time_length; i++) { for (var i = 0; i < time_length; i++) {
html += "<td>" + (this.getSequenceSize(id, this.time_order[i]) * 100) html += "<td>" + (this.getSequenceSize(id, this.samples.order[i]) * 100)
.toFixed(3) + " % </td>" .toFixed(3) + " % </td>"
} }
html += "</tr>" html += "</tr>"
...@@ -1747,7 +1755,7 @@ Model.prototype = { ...@@ -1747,7 +1755,7 @@ Model.prototype = {
html += "<tr><td>" + key + "</td>" html += "<tr><td>" + key + "</td>"
if (this.windows[id][key] instanceof Array) { if (this.windows[id][key] instanceof Array) {
for (var i = 0; i < time_length; i++) { for (var i = 0; i < time_length; i++) {
html += "<td>" + this.windows[id][key][this.time_order[i]] + "</td>" html += "<td>" + this.windows[id][key][this.samples.order[i]] + "</td>"
} }
} else { } else {
html += "<td>" + this.windows[id][key] + "</td>" html += "<td>" + this.windows[id][key] + "</td>"
...@@ -1765,7 +1773,7 @@ Model.prototype = { ...@@ -1765,7 +1773,7 @@ Model.prototype = {
getPointHtmlInfo: function (timeID) { getPointHtmlInfo: function (timeID) {
var html = "" var html = ""
html = "<h2>Point info : " + this.time[timeID] + "("+this.timestamp[timeID]+")</h2>" html = "<h2>Point info : " + this.getStrTime(timeID, "name") + "("+this.timestamp[timeID]+")</h2>"
html += "<div id='info_timepoint'><table><tr><th></th>" 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 </td><td>" + this.reads_total[timeID] + "</td></tr>"
html += "<tr><td> reads segmented </td><td>" + this.reads_segmented[timeID] + html += "<tr><td> reads segmented </td><td>" + this.reads_segmented[timeID] +
...@@ -1876,9 +1884,9 @@ Model.prototype = { ...@@ -1876,9 +1884,9 @@ Model.prototype = {
* *
* */ * */
switchTimeOrder: function (a, b) { switchTimeOrder: function (a, b) {
var tmp = this.time_order[a]; var tmp = this.samples.order[a];
this.time_order[a] = this.time_order[b] this.samples.order[a] = this.samples.order[b]
this.time_order[b] = tmp; this.samples.order[b] = tmp;
this.update() this.update()
}, },
...@@ -1886,7 +1894,7 @@ Model.prototype = { ...@@ -1886,7 +1894,7 @@ Model.prototype = {
* *
* */ * */
changeTimeOrder: function (list) { changeTimeOrder: function (list) {
this.time_order = list this.samples.order = list
this.update() this.update()
}, },
...@@ -1894,34 +1902,34 @@ Model.prototype = { ...@@ -1894,34 +1902,34 @@ Model.prototype = {
* *
* */ * */
nextTime: function () { nextTime: function () {
var current_pos = this.time_order.indexOf(this.t) var current_pos = this.samples.order.indexOf(this.t)
if (current_pos != -1){ if (current_pos != -1){
if (current_pos+1 < this.time_order.length){ if (current_pos+1 < this.samples.order.length){
//next one //next one
this.changeTime(this.time_order[current_pos+1]) this.changeTime(this.samples.order[current_pos+1])
}else{ }else{
//back to the beginning //back to the beginning
this.changeTime(this.time_order[0]) this.changeTime(this.samples.order[0])
} }
}else{ }else{
this.changeTime(this.time_order[0]) this.changeTime(this.samples.order[0])
} }
}, },
previousTime: function (){ previousTime: function (){
var current_pos = this.time_order.indexOf(this.t) var current_pos = this.samples.order.indexOf(this.t)
if (current_pos != -1){ if (current_pos != -1){
if (current_pos == 0){ if (current_pos == 0){
//teleport to the end //teleport to the end
this.changeTime(this.time_order[this.time_order.length-1]) this.changeTime(this.samples.order[this.samples.order.length-1])
}else{ }else{
//previous one //previous one
this.changeTime(this.time_order[current_pos-1]) this.changeTime(this.samples.order[current_pos-1])
} }
}else{ }else{
this.changeTime(this.time_order[0]) this.changeTime(this.samples.order[0])
} }
}, },
...@@ -1935,7 +1943,7 @@ Model.prototype = { ...@@ -1935,7 +1943,7 @@ Model.prototype = {
this.nextTime();