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 = {
this.resolution1 = []
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.resolution5[i] = (5 / this.m.reads_segmented[i])
}
......@@ -231,8 +231,8 @@ Graph.prototype = {
var list = document.getElementById("" + this.id + "_list")
list.innerHTML = ""
for (var i=0; i<this.m.time.length; i++){
if ( this.m.time_order.indexOf(i) == -1){
for (var i=0; i<this.m.samples.number; i++){
if ( this.m.samples.order.indexOf(i) == -1){
$("<div/>", {
class: "graph_listElem",
text: this.m.getStrTime(i),
......@@ -259,26 +259,23 @@ Graph.prototype = {
.range([0, 1]);
//abscisse
for (var i = 0; i < this.m.time_order.length; i++) {
this.graph_col[i] = this.marge1 + i * ((1 - (this.marge1 + this.marge2)) / (this.m.time_order.length - 1));
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.samples.order.length - 1));
}
if (this.m.time_order.length == 1) {
if (this.m.samples.order.length == 1) {
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[1] = 3 / 4;
}
for (var i = 0; i < this.m.time.length; i++) {
var t = this.m.time_order.indexOf(i)
for (var i = 0; i < this.m.samples.number; i++) {
var t = this.m.samples.order.indexOf(i)
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 = time_name.split(".")[0]
}
time_name = this.m.getStrTime(i);
time_name = time_name.split(".")[0]
d.type = "axis_v";
d.text = time_name;
......@@ -322,12 +319,12 @@ Graph.prototype = {
}
//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.type = "axis_m";
this.mobil.text = "";
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)
}
......@@ -388,7 +385,7 @@ Graph.prototype = {
.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.resolution5[i] = (5 / this.m.reads_segmented[i])
}
......@@ -674,8 +671,8 @@ Graph.prototype = {
//stock tuples time_point/axis position
var list = []
for (var i = 0; i < this.m.time_order.length; i++) {
var t = this.m.time_order[i]
for (var i = 0; i < this.m.samples.order.length; i++) {
var t = this.m.samples.order[i]
if (t == this.dragged_time_point) {
list.push([t, (coordinates[0] - this.marge4) / this.resizeW]);
} else {
......@@ -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]);
//sort by axis position
......@@ -710,9 +707,9 @@ Graph.prototype = {
this.drag_on = false;
var result = []
for (var i=0; i<this.m.time_order.length; i++){
if (this.m.time_order[i] != this.dragged_time_point){
result.push(this.m.time_order[i])
for (var i=0; i<this.m.samples.order.length; i++){
if (this.m.samples.order[i] != this.dragged_time_point){
result.push(this.m.samples.order[i])
}
}
......@@ -759,9 +756,9 @@ Graph.prototype = {
p.push([0, (1 - this.scale_x(size[0] * this.m.precision))]);
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]);
return p;
......@@ -777,8 +774,8 @@ Graph.prototype = {
var size = []
for (var i = 0; i < this.graph_col.length; i++) {
if (seq_size) size[i] = this.m.getSequenceSize(id, this.m.time_order[i])
else size[i] = this.m.getSize(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.samples.order[i])
}
var x = this.graph_col[0];
......@@ -862,13 +859,13 @@ Graph.prototype = {
for (var i=0; i<this.graph_col.length; 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])
}
for (var i=this.graph_col.length-1; i>=0; 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])
}
......@@ -888,7 +885,7 @@ Stack.prototype = {
//compute sum of all clone +others (dans un monde parfait ca devrait faire 1 mais avec la normalisation...)
init: function () {
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
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
......@@ -903,7 +900,7 @@ Stack.prototype = {
this.sum = [];
this.min = [];
this.max = [];
for (j=0; j<this.m.time.length; j++){
for (j=0; j<this.m.samples.number; j++){
this.sum[j]=1
}
......@@ -912,13 +909,13 @@ Stack.prototype = {
this.max[i] = []
//active clones
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.sum[j] -= this.m.getSize(i,j)
this.max[i][j] = this.sum[j]
}
}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.max[i][j] = this.sum[j]
}
......@@ -926,7 +923,7 @@ Stack.prototype = {
}
//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.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]
......
......@@ -78,8 +78,6 @@ Model.prototype = {
this.mapID = {};
this.top = 10;
this.precision = 1;
this.time = [];
this.time_order = [];
this.isPlaying = false;
this.timestamp = [];
this.timestamp2 = [];
......@@ -270,23 +268,34 @@ Model.prototype = {
self.windows.push(data.windows[i]);
}
}
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 = {
"sequence": 0,
"window": "other",
"top": 0,
"size": []
}
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.segmentation_info = data.segmentation_info;
self.min_sizes = min_sizes;
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 = [];
for (var key in self.system_segmented) self.system_selected.push(key)
self.reads_segmented_total = self.reads_segmented.reduce(function (a, b) {
......@@ -302,15 +311,10 @@ Model.prototype = {
self.reads_total = self.reads_segmented;
}
self.timestamp = data.timestamp;
if (typeof data.point != 'undefined'){
self.time = data.point;
}else{
self.time = data.timestamp;
}
self.scale_color = d3.scale.log()
.domain([1, self.precision])
.range([250, 0]);
for (var i = 0; i < self.time.length; i++) self.time_order.push(i);
//extract germline
if (typeof data.germline != 'undefined') {
......@@ -1032,7 +1036,7 @@ Model.prototype = {
var tmp = this.norm
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)
}
......@@ -1049,8 +1053,8 @@ Model.prototype = {
update_precision: function () {
var min_size = 1
for (var i=0; i<this.time_order.length; i++){
var t = this.time_order[i]
for (var i=0; i<this.samples.order.length; i++){
var t = this.samples.order[i]
var size = this.min_sizes[t]
if (this.norm) size = this.normalize(this.min_sizes[t], t)
if (size < min_size) min_size = size
......@@ -1237,7 +1241,11 @@ Model.prototype = {
switch (format) {
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;
case "sampling_date":
if ((typeof this.timestamp2 != 'undefined') && this.timestamp2[timeID])
......@@ -1660,7 +1668,7 @@ Model.prototype = {
getCloneHtmlInfo: function (id, type) {
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 = ""
//clone/sequence label
......@@ -1674,7 +1682,7 @@ Model.prototype = {
html += "<div id='info_window'><table><tr><th></th>"
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>"
......@@ -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 size (n-reads (total reads) )</td>"
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>"
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>"
}else{
......@@ -1701,13 +1709,13 @@ Model.prototype = {
html += "<tr><td> code </td><td colspan='" + time_length + "'>" + this.getCode(id) + "</td></tr>"
html += "<tr><td> size (n-reads (total reads) )</td>"
for (var i = 0; i < time_length; i++) {
html += "<td>" + this.getSequenceReads(id, this.time_order[i]) +
" (" + this.reads_segmented[this.time_order[i]] + ")</td>"
html += "<td>" + this.getSequenceReads(id, this.samples.order[i]) +
" (" + this.reads_segmented[this.samples.order[i]] + ")</td>"
}
html += "</tr>"
html += "<tr><td> size (%)</td>"
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>"
}
html += "</tr>"
......@@ -1747,7 +1755,7 @@ Model.prototype = {
html += "<tr><td>" + key + "</td>"
if (this.windows[id][key] instanceof Array) {
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 {
html += "<td>" + this.windows[id][key] + "</td>"
......@@ -1765,7 +1773,7 @@ Model.prototype = {
getPointHtmlInfo: function (timeID) {
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 += "<tr><td> reads </td><td>" + this.reads_total[timeID] + "</td></tr>"
html += "<tr><td> reads segmented </td><td>" + this.reads_segmented[timeID] +
......@@ -1876,9 +1884,9 @@ Model.prototype = {
*
* */
switchTimeOrder: function (a, b) {
var tmp = this.time_order[a];
this.time_order[a] = this.time_order[b]
this.time_order[b] = tmp;
var tmp = this.samples.order[a];
this.samples.order[a] = this.samples.order[b]
this.samples.order[b] = tmp;
this.update()
},
......@@ -1886,7 +1894,7 @@ Model.prototype = {
*
* */
changeTimeOrder: function (list) {
this.time_order = list
this.samples.order = list
this.update()
},
......@@ -1894,34 +1902,34 @@ Model.prototype = {
*
* */
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 < this.time_order.length){
if (current_pos+1 < this.samples.order.length){
//next one
this.changeTime(this.time_order[current_pos+1])
this.changeTime(this.samples.order[current_pos+1])
}else{
//back to the beginning
this.changeTime(this.time_order[0])
this.changeTime(this.samples.order[0])
}
}else{
this.changeTime(this.time_order[0])
this.changeTime(this.samples.order[0])
}
},
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 == 0){
//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{
//previous one
this.changeTime(this.time_order[current_pos-1])
this.changeTime(this.samples.order[current_pos-1])
}
}else{
this.changeTime(this.time_order[0])
this.changeTime(this.samples.order[0])
}
},
......@@ -1935,7 +1943,7 @@ Model.prototype = {
this.nextTime();
//check if "stop" is still in time_order and replace it if neccesary
if (this.time_order.indexOf(stop)==-1) stop = this.time_order[0]
if (this.samples.order.indexOf(stop)==-1) stop = this.samples.order[0]
//continue until stop
if (this.t != stop) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment