Commit c3a5358c authored by Mathieu Giraud's avatar Mathieu Giraud

merge -- germline genes in the segmenter, experimental feature

Great upcoming new feature, see #1925.
Developed by @aurelBZH. Thanks to @RyanHerb and @mikael-s for the refactoring sprint.
parents 75b95db4 e576bca2
......@@ -135,6 +135,9 @@
<a class="buttonSelector" id="export_csv" onclick="javascript:m.exportCSV()">export csv (visible clones)</a>
<a class="buttonSelector" id="export_fasta" onclick="javascript:m.exportFasta()">export fasta (selected clones)</a>
</div>
<div class="menu_box">
<a class="buttonSelector" id="export_fasta" onclick="javascript:segment.add_all_germline_to_segmenter()">add germline genes (experimental)</a>
</div>
</div></div>
</div>
......
......@@ -39,43 +39,11 @@ GermlineList.prototype = {
* germline.js contain a copy of the germline list used if the server is unavailable
* */
load : function () {
this.fallbackLoad() //just in case
$.ajax({
url: window.location.origin + "/germline/germlines.data",
success: function (result) {
try {
//remove comment (json don't have comment)
var json = result.replace(/ *\/\/[^\n]*\n */g , "")
//convert from js to json (json begin with { or [, never with a var name)
json = json.replace("germline_data = " , "")
self.list = jQuery.parseJSON(json).systems;
}
catch(err){
console.log({"type": "flash", "msg": "germlines.data malformed, use local js file instead (can be outdated) " , "priority": 2});
}
},
error: function (request, status, error) {
console.log({"type": "flash", "msg": "impossible to retrieve germline.data, using local germline.js", "priority": 0});
},
dataType: "text"
});
this.list = germline_data.systems
},
/**
* retrieve the default germline list from germline.js <br>
* germline.js should be rebuild from time to time to keep thegermlines up to date (if you want to use the browser in offline mode)
* */
fallbackLoad : function () {
try {
this.list = germline_data.systems
}
catch(err){
console.log({"type": "popup", "msg": "Incorrect browser installation, 'js/germline.js' is not found<br />please run 'make' in 'germline/'"});
}
},
/**
* add a list of germlines to the default germline list<br>
......@@ -154,18 +122,18 @@ Germline.prototype = {
if (type=="V") type2="5"
if (type=="D") type2="4"
if (type=="J") type2="3"
if (typeof this.m.germlineList.list[system] !== 'undefined' &&
typeof this.m.germlineList.list[system].recombinations !== 'undefined'){
if (typeof this.m.germlineList.list[system].recombinations[type2] !== 'undefined' ){
for (var i=0; i<this.m.germlineList.list[system].recombinations[type2].length; i++){
var filename = this.m.germlineList.list[system].recombinations[type2][i]
filename = filename.split('/')[filename.split('/').length-1] //remove path
typeof this.m.germlineList.list[system].recombinations[0] !== 'undefined'){
if (typeof this.m.germlineList.list[system].recombinations[0][type2] !== 'undefined' ){
for (var i=0; i<this.m.germlineList.list[system].recombinations[0][type2].length; i++){
var filename = this.m.germlineList.list[system].recombinations[0][type2][i]
filename = filename.split('.')[0] //remove file extension
if (typeof germline[filename] != 'undefined'){
for (var key in germline[filename]){
this.allele[key] = germline[filename][key]
this.allele[key] = germline[filename][key].replace(/\./g,"")
}
}else{
console.log({"type": "flash", "msg": "warning : this browser version doesn't have the "+filename+" germline file", "priority": 2});
......
......@@ -49,7 +49,8 @@ function Model() {
for (var f in Model_loader.prototype) {
this[f] = Model_loader.prototype[f]
}
this.germline = {};
this.create_germline_obj();
this.setAll();
this.view = [];
this.checkBrowser();
......@@ -218,6 +219,21 @@ Model.prototype = {
},
create_germline_obj: function() {
for (var locus in germline){
germl = locus.substring(0,3)
if (typeof this.germline[germl]==="undefined") {
this.germline[germl]={};
}
for (var allele in germline[locus]) {
this.germline[germl][allele]="";
this.germline [germl][allele]+=germline[locus][allele];
}
}
return this.germline;
},
/**
* load a germline / attribute a color for each genes / and compute some info
......
This diff is collapsed.
......@@ -75,9 +75,9 @@ json_data = {
"top" : 3,
"germline" : "IGH",
"seg" : {
"5" : "IGHV4*01",
"4" : "IGHD2*03",
"3" : "IGHJ8*01",
"5" : "IGHV1-2*01",
"4" : "IGHD2-2*02",
"3" : "IGHJ6*01",
"3start" : 15,
"5end" : 5
}
......
......@@ -35,10 +35,10 @@ QUnit.test("grid", function(assert) {
assert.equal(document.getElementById("bar1").className.baseVal, "", "check splitMethod V/V /plot : check if bar are displayed")
assert.equal(sp.axisX.labels[0].text, "IGHV4", "first label for 'gene_v' axis is 'IGVH4'")
assert.equal(sp.axisX.labels[0].text, "IGHV1-2", "first label for 'gene_v' axis is 'IGHV1-2'")
assert.equal(sp.axisX.labels[1].text, "?", "second label for 'gene_v' axis is '?'")
assert.equal(m.clone(2).getGene('5'), "IGHV4*01", "clone 2 is 'IGVH4*01'")
assert.equal(m.clone(2).getGene('5'), "IGHV1-2*01", "clone 2 is 'IGHV1-2*01'")
assert.equal(sp.nodes[2].bar_x, sp.axisX.labels[0].pos, "node 2, bar x position is on 'IGVH4'")
......
......@@ -10,7 +10,7 @@ QUnit.test("segmenter", function(assert) {
m.loadGermline()
m.initClones()
var segment = new Segment("segment", m);
var segment = new Segment("segment", m);
segment.init()
//select test
......@@ -35,7 +35,7 @@ QUnit.test("segmenter", function(assert) {
assert.deepEqual(segment.findPotentialField(), ["","cdr3","fr1", "5", "id", "f1", "V-REGION","J-REGION","D-REGION","CDR3-IMGT"], "potentialField : Ok")
m.select(0)
assert.deepEqual(segment.toFasta(), "> test1 // 5.000%\naaaaaaaaaaaaaaaaaaaAG\n","toFasta :Ok")
// assert.deepEqual(segment.toFasta(), "> test1 // 5.000%\naaaaaaaaaaaaaaaaaaaAG\n","toFasta :Ok")
m.focusIn(0)
......@@ -89,9 +89,9 @@ QUnit.test("sequence", function(assert) {
seq1 = new Sequence(1, m, segment)
seq1.load()
seq1_string = seq1.toString()
assert.notEqual(seq1_string.indexOf(">cccccg<"), -1, "v part of segmented sequence")
assert.notEqual(seq1_string.indexOf(">tccccccca<"), -1, "n part of segmented sequence")
assert.notEqual(seq1_string.indexOf(">tca<"), -1, "j part of segmented sequence")
assert.notEqual(seq1.toString().indexOf("cccccg"), -1, "v part of segmented sequence")
assert.notEqual(seq1_string.indexOf("tccccccca"), -1, "n part of segmented sequence")
assert.notEqual(seq1_string.indexOf("tca"), -1, "j part of segmented sequence")
});
QUnit.test("segt", function (assert) {
......@@ -124,6 +124,8 @@ QUnit.test("segt", function (assert) {
assert.equal(h.stop, -1, "stop feature value");
assert.deepEqual(segment.sequence[3].get_positionned_highlight("test_feature",""),{"color": "", "css": "highlight_seq", "seq": "CACCCAGGAGGTGGAGCTGGATATTGAGACT", "start": 94, "stop": 124, "tooltip": ""}, "test feature value")
assert.equal(m.clone(3).getSegLength('test_feature'),31, "feature length");
m.unselectAll();
segment.updateElem([])
m.select(3);
assert.equal(segment.toFasta(), "> test4 // 2.500%\nGGAAGGCCCCACAGCGTCTTCTGTACTATGACGTCTCCACCGCAAGGGATGTGTTGGAATCAGGACTCAGTCCAGGAAAGTATTATACTCATACACCCAGGAGGTGGAGCTGGATATTGAGACTGCAAAATCTAATTGAAAATGATTCTGGGGTCTATTACTGTGCCACCTGGGACAGGCTGAAGGATTGGATCAAGACGTTTGCAAAAGGGACTAGGCTCATAGTAACTTCGCCTGGTAA\n", "fasta seq ")
assert.ok(segment.isDNA('CACCCAGGAGGTGGAGCTGGATATTGAGACT'), "test dna")
......@@ -132,3 +134,24 @@ QUnit.test("segt", function (assert) {
assert.deepEqual(segment.findPotentialField(),["", "cdr3", "fr1", "5", "test_feature", "id", "f1", "V-REGION", "J-REGION", "D-REGION", "CDR3-IMGT"], "find field to highlight")
})
QUnit.test("segt", function (assert) {
var m = new Model();
m.parseJsonData(json_data, 100);
m.initClones();
var segment = new Segment("segment",m);
segment.init();
segment.addGermlineToSegmenter("IGHD1-1*01","IGH");
assert.equal(segment.sequence["IGHD1-1*01"].seq.join(""), "GGGCGCCGGGGCAGATTCTGAACAGCCCCGAGTCACGGTGGGTACAACTGGAACGAC")
m.select(2)
segment.addToSegmenter(2);
segment.add_all_germline_to_segmenter();
// segment.updateElem()
assert.equal(segment.sequence[2].seq.join(" "),"c c c c c c c c c c c c c c c c c c c c", "clone 3 sequence")
assert.equal(segment.sequence["IGHV1-2*01"].seq.join(""),"caggtgcagctggtgcagtctggggctgaggtgaagaagcctggggcctcagtgaaggtctcctgcaaggcttctggatacaccttcaccggctactatatgcactgggtgcgacaggcccctggacaagggcttgagtggatgggacggatcaaccctaacagtggtggcacaaactatgcacagaagtttcagggcagggtcaccagtaccagggacacgtccatcagcacagcctacatggagctgagcaggctgagatctgacgacacggtcgtgtattactgtgcgagaga","5 germline")
assert.equal(segment.sequence["IGHD2-2*02"].seq.join(""),"GCGGGGACAGGAGGATTTTGTGGGGGCTCGTGTCACTGTGAGGATATTGTAGTAGTACCAGCTGCTATACC","4 germline")
assert.equal(segment.sequence["IGHJ6*01"].seq.join(""),"attactactactactacggtatggacgtctgggggcaagggaccacggtcaccgtctcctcag","3 germline")
segment.addSequenceTosegmenter("test","igh", "accccccgtgtagtagtcc")
assert.equal(segment.sequence["test"].seq.join(""),"accccccgtgtagtagtcc"," test sequence ")
})
\ No newline at end of file
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