Commit 87aa6366 authored by Marc Duez's avatar Marc Duez
Browse files

scatterplot.js : refactoring

parent b07210ea
......@@ -148,27 +148,41 @@ Axis.prototype = {
},
custom: function(fct){
custom: function(fct, default_min, default_max, percent, use_log){
percent = typeof percent !== 'undefined' ? percent : false;
use_log= typeof percent !== 'undefined' ? use_log : false;
var self = this;
this.fct = fct;
var min,
max;
var min = default_min;
var max = default_max;
for (var i in this.m.clones){
var tmp;
try{
tmp = fct(i);
if (tmp == 0) tmp = undefined;
}catch(e){}
if ( typeof tmp != "undefined" ){
if ( typeof tmp != "undefined"){
if ( tmp > max || typeof max == "undefined") max = tmp;
if ( tmp < min || typeof min == "undefined") min = tmp;
}
}
this.sizeScale = d3.scale.linear()
.domain([min, max+1])
if (typeof min == "undefined"){
min = 0;
max = 1;
}
if (use_log){
this.sizeScale = d3.scale.log()
.domain([min, max])
.range([0, 1]);
}else{
this.sizeScale = d3.scale.linear()
.domain([min, max])
.range([0, 1]);
}
this.min = min;
this.max = max;
......@@ -189,28 +203,40 @@ Axis.prototype = {
return pos;
}
this.computeCustomLabels(min, max+1, false, true);
this.computeCustomLabels(min, max, percent, use_log);
},
/*
* TODO linear/log percent/value parameter
* */
computeCustomLabels: function(min, max, percent, linear){
computeCustomLabels: function(min, max, percent, use_log){
this.labels = [];
var h = (max-min)/5
var delta = (max-min)
for (var i = 0; i <= 5; i++) {
pos = (h*i)*(1/delta);
var text = Math.round(min+(h*i))
if (percent){
text = ((min+(h*i))*100).toFixed(1) + "%"
if (use_log){
var h=1
for (var i = 0; i < 10; i++) {
var pos = this.sizeScale(h);
var text = this.m.formatSize(h, false)
if (this.reverse) pos = 1 - pos;
if (pos >= 0 && pos <= 1)
this.labels.push(this.label("line", pos, text));
h = h / 10;
}
}else{
var h = (max-min)/5
var delta = (max-min)
for (var i = 0; i <= 5; i++) {
pos = (h*i)*(1/delta);
var text = Math.round(min+(h*i))
if (percent){
text = ((min+(h*i))*100).toFixed(1) + "%"
}
if (this.reverse) pos = 1 - pos;
this.labels.push(this.label("line", pos, text));
}
if (this.reverse) pos = 1 - pos;
this.labels.push(this.label("line", pos, text));
}
},
......
......@@ -323,7 +323,7 @@ Clone.prototype = {
},
getNlength: function () {
if (typeof this.seg != 'undefined'){
if (typeof this.seg != 'undefined' && typeof this.seg['3start'] != 'undefined'){
return this.seg['3start']-this.seg['5end']-1
}else{
return 0
......
......@@ -35,7 +35,7 @@ function ScatterPlot(id, model) {
this.marge_left = 100;
this.marge_right = 10;
this.marge_top = 60;
this.marge_bot = 10;
this.marge_bot = 25;
this.max_precision = 9; //Precision max (default: 9)
......@@ -111,6 +111,16 @@ function ScatterPlot(id, model) {
["lengthCDR3", "CDR3 length"]
];
// Plot axis
this.available_axis = {
"sequenceLength" : { "fct" : function(cloneID) {return m.clone(cloneID).getSequenceLength()} },
"GCContent" : { "fct" : function(cloneID) {return m.clone(cloneID).getGCContent()} },
"n" : { "fct" : function(cloneID) {return m.clone(cloneID).getNlength()} },
"lengthCDR3" : { "fct" : function(cloneID) {return m.clone(cloneID).seg["cdr3"].length} },
"Size" : { "fct" : function(cloneID){return self.m.clone(cloneID).getSize()}, "max" : 1, "percent" : true, "log" :true },
"otherSize" : { "fct" : function(cloneID){return self.m.clone(cloneID).getSize()}, "max" : 1, "percent" : true, "log" :true }
}
// Plot Presets
this.preset = {
"V/J (genes)" : { "mode": "plot", "x" : "gene_v", "y": "gene_j"},
......@@ -789,7 +799,7 @@ ScatterPlot.prototype = {
//split clones into bar (axisX)
switch (this.splitX) {
case "allele_v" :
this.makeBarTab(function(cloneID){return self.self.m.clone(cloneID).getV()}, Object.keys(self.m.germlineV.allele))
this.makeBarTab(function(cloneID){return self.m.clone(cloneID).getV()}, Object.keys(self.m.germlineV.allele))
break;
case "gene_v" :
this.makeBarTab(function(cloneID){return self.m.clone(cloneID).getV(false)}, Object.keys(self.m.germlineV.gene))
......@@ -800,36 +810,9 @@ ScatterPlot.prototype = {
case "gene_j" :
this.makeBarTab(function(cloneID){return self.m.clone(cloneID).getJ(false)}, Object.keys(self.m.germlineJ.gene))
break;
case "Size" :
//this.makeBarTab(function(cloneID){return self.m.clone(cloneID).getSize()})
break;
case "sequenceLength" :
this.makeBarTab(function(cloneID) {
var value = self.m.clone(cloneID).getSequenceLength()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
break;
case "GCContent" :
this.makeBarTab(function(cloneID) {
var value = self.m.clone(cloneID).getGCContent()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
break;
case "n" :
this.makeBarTab(function(cloneID) {
var value = self.m.clone(cloneID).getNlength()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
break;
case "lengthCDR3" :
this.makeBarTab(function(cloneID) {
if (typeof self.m.clone(cloneID).seg != "undefined" && typeof self.m.clone(cloneID).seg["cdr3"] != "undefined")
return self.m.clone(cloneID).seg["cdr3"].length
return undefined;
})
default :
if (typeof this.available_axis[this.splitX])
this.makeBarTab(this.available_axis[this.splitX].fct);
break;
}
......@@ -848,27 +831,9 @@ ScatterPlot.prototype = {
case "gene_j" :
this.sortBarTab(function(cloneID){return self.m.clone(cloneID).getJ(false)});
break;
case "otherSize" :
this.sortBarTab(function(cloneID){return self.m.clone(cloneID).getSize(m.tOther)});
break;
case "Size" :
this.sortBarTab(function(cloneID){return self.m.clone(cloneID).getSize()});
break;
case "sequenceLength" :
this.sortBarTab(function(cloneID) {return self.m.clone(cloneID).getSequenceLength()})
break;
case "GCContent" :
this.sortBarTab(function(cloneID) {return self.m.clone(cloneID).getGCContent()})
break;
case "n" :
this.sortBarTab(function(cloneID) {return self.m.clone(cloneID).getNlength()})
break;
case "lengthCDR3" :
this.sortBarTab(function(cloneID) {
if (typeof self.m.clone(cloneID).seg != "undefined" && typeof self.m.clone(cloneID).seg["cdr3"] != "undefined")
return self.m.clone(cloneID).seg["cdr3"].length
return undefined;
})
default :
if (typeof this.available_axis[this.splitY])
this.sortBarTab(this.available_axis[this.splitY].fct);
break;
}
......@@ -884,8 +849,11 @@ ScatterPlot.prototype = {
for (var i in this.m.clones) {
var clone = this.m.clone(i)
if (!this.use_system_grid || (this.use_system_grid && this.m.germlineV.system == clone.getSystem() ) ){
var v = fct(i);
if (typeof v != "undefined"){
var v;
try{
var v = fct(i);
}catch(e){}
if (typeof v != "undefined" && v != 0){
if (v<min || typeof min == "undefined") min = v;
if (v>max || typeof max == "undefined") max = v;
}
......@@ -903,7 +871,10 @@ ScatterPlot.prototype = {
for (var i in this.m.clones) {
var clone = this.m.clone(i)
if (!this.use_system_grid || (this.use_system_grid && this.m.germlineV.system == clone.getSystem() ) ){
var v = fct(i);
var v;
try{
var v = fct(i);
}catch(e){}
if (typeof v == "undefined" || typeof this.barTab[v] == "undefined" ) {
this.barTab["?"].push(i);
}else{
......@@ -920,8 +891,14 @@ ScatterPlot.prototype = {
for (var i in this.barTab) {
this.barTab[i].sort(function (a,b) {
var va = fct(a);
var vb = fct(b);
var va;
try{
var v = fct(a);
}catch(e){}
var vb;
try{
var v = fct(b);
}catch(e){}
if (typeof va == "undefined") return (typeof vb == "undefined") ? 0 : -1;
if (typeof vb == "undefined") return (typeof va == "undefined") ? 0 : 1;
......@@ -1986,42 +1963,11 @@ ScatterPlot.prototype = {
case "gene_j" :
axis.useGermline(this.m.germlineJ, "J", false)
break;
case "otherSize" :
axis.useSize(true)
break;
case "Size" :
axis.useSize(false)
break;
case "sequenceLength" :
axis.custom(function(cloneID) {
var value = m.clone(cloneID)
.getSequenceLength()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
break;
case "GCContent" :
axis.custom(function(cloneID) {
var value = m.clone(cloneID)
.getGCContent()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
break;
case "n" :
axis.custom(function(cloneID) {
var value = m.clone(cloneID)
.getNlength()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
break;
case "lengthCDR3" :
axis.custom(function(cloneID) {
return m.clone(cloneID)
.seg["cdr3"].length
})
default :
if (typeof this.available_axis[splitMethod]){
var a = this.available_axis[splitMethod];
axis.custom(a.fct, a.min, a.max, a.percent, a.log)
}
break;
}
},
......
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