Commit f1933a2b authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch 'feature-c/color-by-cdr3' into 'dev'

Provide a color by CDR3 method

See merge request !309
parents 7cbdce4e 0bb84e40
Pipeline #43195 failed with stages
in 7 minutes and 6 seconds
...@@ -166,6 +166,7 @@ ...@@ -166,6 +166,7 @@
<div class="div-menu-selector"><select class="menu-selector" onchange="m.changeColorMethod(this.value)"> <div class="div-menu-selector"><select class="menu-selector" onchange="m.changeColorMethod(this.value)">
<option value="Tag">tag</option> <option value="Tag">tag</option>
<option value="clone">clone</option> <option value="clone">clone</option>
<option value="cdr3">CDR3</option>
<option value="V">V/5'</option> <option value="V">V/5'</option>
<option value="J">J/3'</option> <option value="J">J/3'</option>
<option value="N">N</option> <option value="N">N</option>
......
...@@ -977,6 +977,8 @@ Clone.prototype = { ...@@ -977,6 +977,8 @@ Clone.prototype = {
} }
} else if (this.m.colorMethod == 'clone') { } else if (this.m.colorMethod == 'clone') {
this.color = colorGeneratorIndex(this.index) this.color = colorGeneratorIndex(this.index)
} else if (this.m.colorMethod == 'cdr3') {
this.color = this.getCDR3Color();
}else if (this.m.colorMethod == "Tag"){ }else if (this.m.colorMethod == "Tag"){
this.color = this.m.tag[this.getTag()].color; this.color = this.m.tag[this.getTag()].color;
}else if (this.m.colorMethod == "dbscan"){ }else if (this.m.colorMethod == "dbscan"){
...@@ -1509,6 +1511,22 @@ Clone.prototype = { ...@@ -1509,6 +1511,22 @@ Clone.prototype = {
} }
}, },
/**
* Deterministically return a color associated with the CDR3 (if any)
*/
getCDR3Color: function() {
var junction = this.getSegAASequence('junction');
if (junction.length == 0)
return '';
// Convert CDR3 to int
var intcdr3 = 0;
junction = junction.toUpperCase();
for (var i = 0; i < junction.length; i++) {
intcdr3 += (junction.charCodeAt(i)-65) * (Math.pow(26, i));
}
return colorGeneratorIndex(intcdr3);
},
/** /**
* Get the number of occurrences of the clone in cloneDB * Get the number of occurrences of the clone in cloneDB
* @return {int} res - the number of occurrences, undefined if cloneDB wasn't called * @return {int} res - the number of occurrences, undefined if cloneDB wasn't called
......
...@@ -388,6 +388,23 @@ QUnit.test("tag / color", function(assert) { ...@@ -388,6 +388,23 @@ QUnit.test("tag / color", function(assert) {
}); });
QUnit.test("color by CDR3", function(assert) {
var m = new Model();
m.parseJsonData(json_data);
var c1 = new Clone(json_clone1, m, 0);
var c2 = new Clone(json_clone2, m, 0);
m.initClones();
var color = c1.getCDR3Color();
c1.seg.junction.aa = "AZERTY";
var color2 = c1.getCDR3Color();
// Actually it could happen that some different CDR3s have the same colours
assert.equal(color != color2, true, "two CDR3 should have different"
+ " colors");
assert.equal(c2.getCDR3Color(), '');
});
QUnit.test("export", function(assert) { QUnit.test("export", function(assert) {
var m = new Model(); var m = new Model();
......
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