Commit e1bdb91a authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch 'feature-c/2641-generic-axis-init' into 'dev'

Feature c/2641 generic axis init

Closes #2641

See merge request !273
parents 40a3acfc c44978ac
Pipeline #36375 failed with stages
in 2 minutes and 59 seconds
......@@ -42,7 +42,9 @@ Axes.prototype = {
"v": {
doc: "V gene (or 5' segment), gathering all alleles",
label:"V/5' gene",
axis: new GermlineAxis(this.m, false, true)
axis: new GermlineAxis(this.m, false, true,
"5", false),
fct: function(clone) {return clone.getGene("5", false)}
},
"d": {
doc: "D gene, gathering all alleles",
......@@ -54,17 +56,23 @@ Axes.prototype = {
"j": {
doc: "J gene (or 3' segment), gathering all alleles",
label:"J/3' gene",
axis: new GermlineAxis(this.m, false, true)
axis: new GermlineAxis(this.m, false, true,
"3", false),
fct: function(clone) {return clone.getGene("3", false)}
},
"allele_v": {
doc: "V gene (or 5' segment), with allele",
label:"V allele",
axis: new GermlineAxis(this.m, false, true)
axis: new GermlineAxis(this.m, false, true,
"5", true),
fct: function(clone) {return clone.getGene("5", true)}
},
"allele_j": {
doc: "J gene (or 3' segment), with allele",
label:"J allele",
axis: new GermlineAxis(this.m, false, true)
axis: new GermlineAxis(this.m, false, true,
"3", true),
fct: function(clone) {return clone.getGene("3", true)}
},
"consensusLength" : {
doc: "length of the consensus sequence",
......
......@@ -242,6 +242,13 @@ GenericAxis.prototype = {
return value;
},
computeBarTab: function(ref) {
ref.barTab = {};
for (var key in this.value_mapping) {
ref.barTab[key] = this.value_mapping[key];
}
},
posBarLabel : function (i) {
var length = Object.keys(this.value_mapping).length;
return (i-0.5)/length ;
......
......@@ -29,37 +29,37 @@
* @constructor
* @param {Model} model
* @reverse {boolean} reverse - by default axis go from low to high but can be revsersed
* @param {string} geneType - "5" or "3"
* @param {boolean} displayAllele - (show/hide allele)
* */
function GermlineAxis (model, reverse, can_undefined) {
function GermlineAxis (model, reverse, can_undefined,
geneType, displayAllele) {
this.m = model
this.labels = [];
this.label_mapping = {};
this.values = [];
this.value_mapping = {};
GenericAxis.call(this, reverse, can_undefined);
this.geneType = geneType
this.displayAllele = displayAllele
}
GermlineAxis.prototype = Object.create(GenericAxis.prototype);
/**
* init axis with a germline object
* @param {Germline} germline
* @param {string} genetype - "V" "D" or "J"
* @param {boolean} displayAllele - (show/hide allele)
* */
GermlineAxis.prototype.init = function (germline, geneType, displayAllele) {
GermlineAxis.prototype.init = function (values, fct) {
this.reset()
this.values = this.m.clones;
this.germline = germline;
this.converter = fct
this.values = values
this.germline = this.geneType == "5" ? this.m.germlineV : this.m.germlineJ
var gene_list = this.germline.gene
var allele_list = this.germline.allele
var total_gene = Object.keys(gene_list).length
if (geneType=="V") this.type2="5"
if (geneType=="D") this.type2="4"
if (geneType=="J") this.type2="3"
var pos;
//labels
for (var key in gene_list){
......@@ -67,7 +67,7 @@ GermlineAxis.prototype = Object.create(GenericAxis.prototype);
this.addLabel("line", key, pos, key, this.germline.gene[key].color);
}
if (displayAllele){
if (this.displayAllele){
for (var al in allele_list){
var gene = al.split("*")[0]
var allele = al.split("*")[1]
......@@ -87,7 +87,6 @@ GermlineAxis.prototype = Object.create(GenericAxis.prototype);
this.gene_list = gene_list;
this.allele_list = allele_list;
this.total_gene = total_gene;
this.displayAllele = displayAllele;
}
/**
......@@ -108,27 +107,11 @@ GermlineAxis.prototype = Object.create(GenericAxis.prototype);
* */
GermlineAxis.prototype.pos = function(clone) {
var pos = this.applyConverter(clone);
return this.label_mapping[pos];
}
GermlineAxis.prototype.converter = function(clone) {
var gene_list = this.gene_list;
var allele_list = this.allele_list;
var total_gene = this.total_gene;
var value;
if (clone.hasSeg(this.type2)) {
var name = clone.seg[this.type2].name;
if (typeof name != 'undefined' &&
typeof gene_list[name.split("*")[0]] != "undefined")
{
if (this.displayAllele){
value = name;
}else {
value = name.split("*")[0];
}
}
var p = this.label_mapping[pos];
if (typeof p == 'undefined') {
p = this.label_mapping["?"];
}
return value;
return (typeof p != 'undefined') ? p : { 'pos': 1 }
}
/**
......
......@@ -561,74 +561,18 @@ ScatterPlot.prototype = {
* compute and update the position of all rectangles representing a clone using selected axis
* */
updateBar: function() {
self = this
//split clones into bar (axisX)
var fct;
switch (this.splitX) {
case this.AXIS_ALLELE_V :
fct = function(clone){return clone.getGene("5")}
this.axisX.init(this.m.germlineV, "V", true)
break;
case this.AXIS_GENE_V :
fct = function(clone){return clone.getGene("5",false)}
this.axisX.init(this.m.germlineV, "V", false)
break;
case this.AXIS_ALLELE_J :
fct = function(clone){return clone.getGene("3")}
this.axisX.init(this.m.germlineJ, "J", true)
break;
case this.AXIS_GENE_J :
fct = function(clone){return clone.getGene("3",false)}
this.axisX.init(this.m.germlineJ, "J", false)
break;
default :
if (typeof this.available_axis[this.splitX])
this.axisX.init(this.m.clones, this.available_axis[this.splitX].fct);
break;
}
this.axisX.init(this.m.clones, this.available_axis[this.splitX].fct);
this.barTab = {};
for (var key in this.axisX.value_mapping) {
this.barTab[key] = this.axisX.value_mapping[key];
}
this.axisX.computeBarTab(this)
//sort each bar (axisY)
this.axisY = new PercentAxis(this.m, true);
var yFct;
switch (this.splitY) {
case this.AXIS_ALLELE_V :
yFct = function(clone){return clone.getGene("5")};
this.axisY.init(this.m.clones, yFct);
this.sortBarTab(fct);
break;
case this.AXIS_GENE_V :
yFct = function(clone){return clone.getGene("5",false)};
this.axisY.init(this.m.clones, yFct);
this.sortBarTab(fct);
break;
case this.AXIS_ALLELE_J :
yFct = function(clone){return clone.getGene("3")};
this.axisY.init(this.m.clones, yFct);
this.sortBarTab(yFct);
break;
case this.AXIS_GENE_J :
yFct = function(clone){return clone.getGene("3",false)};
this.axisY.init(this.m.clones, yFct);
this.sortBarTab(yFct);
break;
default :
yFct = function(clone){return clone.getGene("3")};
if (typeof this.available_axis[this.splitY]){
yFct = this.available_axis[this.splitY].fct;
}
this.axisY.init(this.m.clones, this.available_axis[this.splitY].fct);
this.sortBarTab(this.axisY.converter);
this.axisY.init(this.m.clones, yFct);
this.sortBarTab(yFct);
break;
}
//compute position for each clones
this.computeBarTab();
......@@ -1772,27 +1716,15 @@ ScatterPlot.prototype = {
if (typeof reverse === "undefined") reverse = false;
var axis;
var aa = this.available_axis[splitMethod]
if (aa !== undefined) {
axis = aa.axis;
}
switch (splitMethod) {
case this.AXIS_ALLELE_V :
axis.init(this.m.germlineV, "V", true)
break;
case this.AXIS_GENE_V :
axis.init(this.m.germlineV, "V", false)
break;
case this.AXIS_ALLELE_J :
axis.init(this.m.germlineJ, "J", true)
break;
case this.AXIS_GENE_J :
axis.init(this.m.germlineJ, "J", false)
break;
default :
axis.reverse = reverse;
axis.init(this.m.clones, aa.fct, aa.labels, aa.sort, aa.min, aa.max, aa.log, aa.display_label);
break;
if (aa == undefined) {
console.log('Undefined axis: ' + splitMethod)
return
}
axis = aa.axis;
axis.reverse = reverse;
axis.init(this.m.clones, aa.fct, aa.labels, aa.sort, aa.min, aa.max, aa.log, aa.display_label);
return axis;
},
......
......@@ -39,9 +39,12 @@ QUnit.test("axis", function(assert) {
assert.equal(axis.pos(m.clone(2)).pos.toPrecision(3), 0.548, "clone 2 (12.5%) position -> 0.452")
m.changeGermline("TRG")
axis = new GermlineAxis(m);
//germline V
axis.init(m.germlineV, "V")
axis = new GermlineAxis(m, false, true, "5", false);
axis.init(m.clones, function(clone) {return clone.getGene("5", false)})
console.log(axis.germline)
assert.deepEqual(axis.labels, [
{"geneColor": "rgb(183,110,36)","pos": 0.16666666666666666,"text": "TRGV4","type": "line"},
{"geneColor": "rgb(36,183,171)","pos": 0.5,"text": "TRGV5","type": "line"},
......@@ -55,7 +58,9 @@ QUnit.test("axis", function(assert) {
//germline J
axis.init(axis.m.germlineJ, "J")
axis = new GermlineAxis(m, false, true, "3", false);
axis.init(m.clones, function(clone) {return clone.getGene("3", false)})
assert.deepEqual(axis.labels, [
{"geneColor": "rgb(36,183,171)","pos": 0.25,"text": "TRGJ2","type": "line"},
{"geneColor": "","pos": 0.75,"text": "?","type": "line"}
......@@ -65,9 +70,10 @@ QUnit.test("axis", function(assert) {
assert.equal(axis.pos(m.clone(2)).pos.toPrecision(3), 0.750, "clone 2 (?) position -> 0.75")
//germline allele J
axis.init(axis.m.germlineJ, "J", true)
axis = new GermlineAxis(m, false, true, "3", true);
axis.init(m.clones, function(clone) {return clone.getGene("3", true)})
assert.deepEqual(axis.labels, [
{"geneColor": "rgb(36,183,171)","pos": 0.25,"text": "TRGJ2","type": "line"},
{"geneColor": "rgb(183,110,36)","pos": 0.125,"text": "*02","type": "subline"},
......
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