Commit 8176ebc2 authored by Mathieu Giraud's avatar Mathieu Giraud
Browse files

Merge 'rework_analysis': take into account new .analysis format (ongoing, #1)

parents 84f1fcf8 9d195ef0
......@@ -59,7 +59,7 @@
// GIT_VERSION should be defined in "git-version.h", created by "create-git-version-h.sh", to be used outside of releases
#include "git-version.h"
#define VIDJIL_JSON_VERSION "2014.02"
#define VIDJIL_JSON_VERSION "2014.09"
//$$ #define (mainly default options)
......@@ -1462,12 +1462,22 @@ int main (int argc, char **argv)
JsonArray json_timestamp;
json_timestamp.add(time_buffer);
JsonArray jsonSortedWindows = windowsStorage->sortedWindowsToJsonArray(json_data_segment,
norm_list,
nb_segmented);
JsonList *json_samples;
json_samples=new JsonList();
json_samples->add("number", "1");
JsonArray json_original_names;
json_original_names.add(f_reads);
json_samples->add("original_names", json_original_names);
json->add("vidjil_json_version", VIDJIL_JSON_VERSION);
json->add("samples", *json_samples);
json->add("timestamp", json_timestamp);
json->add("commandline", stream_cmdline.str());// TODO: escape "s in argv
json->add("segmentation_info", stream_segmentation_info.str());
......@@ -1479,7 +1489,7 @@ int main (int argc, char **argv)
json->add("windows", jsonSortedWindows);
//Added edges in the json output file
json->add("links", jsonLevenshtein);
//json->add("links", jsonLevenshtein);
out_json << json->toString();
delete index ;
......
......@@ -284,7 +284,7 @@ Builder.prototype = {
var input = document.createElement('input');
input.type = "text";
input.id = "edit_value";
input.value = self.m[data][self.m.t];
input.value = self.m.samples[data][self.m.t];
input.style.width = "200px";
input.style.border = "0px";
input.style.margin = "0px";
......@@ -300,7 +300,7 @@ Builder.prototype = {
a.appendChild(document.createTextNode("save"));
a.id = "btnSave";
a.onclick = function () {
self.m[data][self.m.t] = document.getElementById("edit_value").value
self.m.samples[data][self.m.t] = document.getElementById("edit_value").value
self.build_info_container()
self.m.update()
}
......@@ -568,7 +568,7 @@ Builder.prototype = {
editTimeName.appendChild(document.createTextNode("edit"));
editTimeName.className = "button_right"
editTimeName.onclick = function () {
self.edit(this, "time");
self.edit(this, "names");
}
div_point.appendChild(editTimeName)
......
......@@ -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]
......
......@@ -48,7 +48,7 @@
* split
*
* */
VIDJIL_JSON_VERSION = '2014.02';
VIDJIL_JSON_VERSION = '2014.09';
/*Model constructor
*
......@@ -67,7 +67,7 @@ Model.prototype = {
reset: function () {
this.analysis = {
custom: [],
clones: [],
cluster: [],
date: []
};
......@@ -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,38 @@ 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 samples
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);
}
if (typeof self.samples.names =='undefined'){
self.samples.names = []
for (var i = 0; i < self.samples.number; i++) self.samples.names.push("");
}
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 +315,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') {
......@@ -366,14 +374,37 @@ Model.prototype = {
var self = this
this.analysis = JSON.parse(analysis);
if (self.analysis.time && (self.analysis.time.length == self.time.length)) {
self.time = self.analysis.time;
self.time_order = self.analysis.time_order;
self.t = self.time_order[0]
//samples
var match = 0;
if (self.analysis.samples) {
var s = self.analysis.samples
for (var i=0; i<s.number; i++){
var pos = self.samples.original_names.indexOf(s.original_names[i])
if (pos != -1){
if (s.names[i] != "") self.samples.names[pos] = s.names[i]
match++
}
}
if (match == s.number && match == self.samples.number) self.samples.order = s.order
}
if (self.analysis.normalization) {
self.normalization= self.analysis.normalization;
//tags
if (self.analysis.tags) {
var s = self.analysis.tags
var keys = Object.keys(s.names);
for (var i=0; i<keys.length; i++){
tagName[parseInt(keys[i])] = s.names[keys[i]]
}
for (var i=0; i<s.hide.length; i++){
tagDisplay[s.hide[i]] = 0;
}
}
if (self.analysis.timestamp2) {
self.timestamp2 = self.analysis.timestamp2;
}
......@@ -680,14 +711,16 @@ Model.prototype = {
}
}
this.applyAnalysis(this.analysis.custom);
this.applyAnalysis(this.analysis);
}, //end initClones
/*
*
* */
applyAnalysis: function (c) {
applyAnalysis: function (analysis) {
var c = analysis.clones
// CUSTOM TAG / NAME
// EXPECTED VALUE
var max = {"id" : -1 , "size" : 0 } //store biggest expected value ( will be used for normalization)
......@@ -696,8 +729,8 @@ Model.prototype = {
var id = -1
var f = 1;
//check if we have a clone with a similar window
if (typeof c[i].window != "undefined" && typeof this.mapID[c[i].window] != "undefined") {
id = this.mapID[c[i].window]
if (typeof c[i].id != "undefined" && typeof this.mapID[c[i].id] != "undefined") {
id = this.mapID[c[i].id]
}
//check if we have a window who can match the sequence
......@@ -758,20 +791,19 @@ Model.prototype = {
}
// CUSTOM CLUSTER
var cluster = this.analysis.cluster;
var cluster = analysis.cluster;
for (var i = 0; i < cluster.length; i++) {
if (typeof self.mapID[cluster[i].l] != "undefined" && typeof self.mapID[cluster[i].f] != "undefined") {
var new_cluster = [];
new_cluster = new_cluster.concat(this.clones[self.mapID[cluster[i].l]].cluster);
new_cluster = new_cluster.concat(this.clones[self.mapID[cluster[i].f]].cluster);
this.clones[self.mapID[cluster[i].l]].cluster = new_cluster;
this.clones[self.mapID[cluster[i].f]].cluster = [];
var new_cluster = [];
var l = self.mapID[cluster[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 = [];
}
this.clones[l].cluster = new_cluster;
}
this.init()
},
......@@ -779,8 +811,10 @@ Model.prototype = {
*
*/
findWindow: function (sequence) {
for ( var i=0; i<this.windows.length; i++ ){
if ( sequence.indexOf(this.windows[i].window) != -1 ) return i
if (sequence != 0){
for ( var i=0; i<this.windows.length; i++ ){
if ( sequence.indexOf(this.windows[i].window) != -1 ) return i
}
}
return -1
},
......@@ -805,9 +839,19 @@ Model.prototype = {
*
* */
strAnalysis: function() {
var date = new Date;
var timestamp = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate()
+ " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds()
var analysisData = {
custom: [],
cluster: []
producer : "browser",
timestamp : timestamp,
vidjil_json_version : VIDJIL_JSON_VERSION,
samples : this.samples,
clones : [],
cluster : [],
tags : {}
}
for (var i = 0; i < this.n_windows; i++) {
......@@ -818,7 +862,7 @@ Model.prototype = {
typeof this.windows[i].expected != "undefined") {
var elem = {};
elem.window = this.windows[i].window;
elem.id = this.windows[i].window;
elem.sequence = this.windows[i].sequence;
if (typeof this.windows[i].tag != "undefined" && this.windows[i].tag != 8)
......@@ -828,25 +872,28 @@ Model.prototype = {
if (typeof this.windows[i].expected != "undefined")
elem.expected = this.windows[i].expected;
analysisData.custom.push(elem);
analysisData.clones.push(elem);
}
//clones / cluster
if (this.clones[i].cluster.length > 1) {
var elem = [];
for (var j = 0; j < this.clones[i].cluster.length; j++) {
if (this.clones[i].cluster[j] != i) {
var elem = {};
elem.l = this.windows[i].window;
elem.f = this.windows[this.clones[i].cluster[j]].window;
analysisData.cluster.push(elem);
}
elem.push(this.windows[this.clones[i].cluster[j]].window);
}
analysisData.cluster.push(elem);
}
}
//name time/point
analysisData.time = this.time
analysisData.time_order = this.time_order
//tags
analysisData.tags.names = {}
analysisData.tags.hide = []
for (var i=0; i<tagName.length; i++){
analysisData.tags.names[""+i] = tagName[i]
if (!tagDisplay[i]) analysisData.tags.hide.push(i)
}
analysisData.normalization = this.normalization
analysisData.timestamp2 = this.timestamp2
......@@ -859,7 +906,7 @@ Model.prototype = {
resetAnalysis: function () {
myConsole.log("resetAnalysis()");
this.analysis = {
custom: [],
clones: [],
cluster: [],
date: []
};
......@@ -1044,7 +1091,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)
}
......@@ -1061,8 +1108,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
......@@ -1249,7 +1296,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])
......@@ -1672,7 +1723,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
......@@ -1686,7 +1737,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>"
......@@ -1696,11 +1747,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