Commit 0ae273fa authored by Mikaël Salson's avatar Mikaël Salson
Browse files

Merge branch 'feature-c/2876-exporter-l-alignement' into 'dev'

Resolve "Exporter l'alignement"

Closes #2876

See merge request !408
parents 91ee1c0f 16046b73
Pipeline #65832 failed with stages
in 46 seconds
......@@ -139,6 +139,7 @@
<a class="buttonSelector" id="export_svg2" onclick="javascript:m.exportViewToPNG(document.querySelector('#visu_svg'))">export bottom graph (PNG)</a>
<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>
<a class="buttonSelector disabledClass" id="export_fasta_align" onclick="javascript:segment.exportAlignFasta()">export aligned 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>
......
......@@ -2213,12 +2213,11 @@ changeAlleleNotation: function(alleleNotation) {
* save a csv file of the currently visibles clones.
* @return {string} csv
* */
exportFasta: function () {
getFasta: function () {
var list = this.getSelected()
if (list.length>0){
var w = window.open("", "_blank", "selected=0, toolbar=yes, scrollbars=yes, resizable=yes");
var fasta = '<pre>'
var fasta = ''
for (var i=0; i<list.length; i++){
fasta += this.clone(list[i]).getFasta() + '\n'
}
......@@ -2238,7 +2237,6 @@ changeAlleleNotation: function(alleleNotation) {
}
}
for (var k=0; k<listGene.length; k++){
var germName = gene_germline[k].substring(0, 3);
if (this.germline[germName] != undefined) {
......@@ -2249,16 +2247,22 @@ changeAlleleNotation: function(alleleNotation) {
}
}
}
var result = $('<div/>', {
html: fasta
}).appendTo(w.document.body);
}else{
return fasta
} else {
console.log({msg: "Export FASTA: please select clones to be exported", type: 'flash', priority: 2});
}
return -1
},
exportFasta: function () {
var fasta = this.getFasta()
if (fasta != -1) {
openAndFillNewTab( "<pre>" + fasta )
}
},
/**
* Bypass the germline name to ge tthe sequence of a gene
* This function is used for case of unexpected
......
......@@ -67,6 +67,7 @@ function Segment(id, model, database) {
this.is_open = false;
this.amino = false;
this.aligned = false;
this.fixed = false; // whether the segmenter is fixed
this.germline = this.m.germline;
//elements to be highlited in sequences
......@@ -665,6 +666,7 @@ Segment.prototype = {
var self = this;
this.aligned = false ;
this.resetAlign()
this.sequence[cloneID] = new Sequence(cloneID, this.m, this)
var divParent = document.getElementById("listSeq");
......@@ -774,6 +776,7 @@ Segment.prototype = {
addSequenceTosegmenter : function(id, locus, str){
var self =this
this.aligned = false ;
this.resetAlign()
if ( typeof this.sequence[id]=="undefined"){
this.sequence[id] = new genSeq(id, locus, this.m, this)
this.sequence[id].load("str")
......@@ -934,6 +937,15 @@ Segment.prototype = {
console.log({"type": "flash", "msg": "cgi error : impossible to connect", "priority": 2});
}
});
// Allow to use button of the export menu
try {
div = document.getElementById("export_fasta_align")
div.classList.remove("disabledClass")
} catch (err) {
// Div doesn't exist (qunit only ?)
}
},
/**
......@@ -941,15 +953,15 @@ Segment.prototype = {
* @return {string} fasta
* */
toFasta: function () {
var selected = this.sequenceListInSegmenter();
var result = "";
var selected = this.m.orderedSelectedClones;
var result = '';
for (var i = 0; i < selected.length; i++) {
if (typeof this.sequence[selected[i]] !== "undefined" &&
typeof this.sequence[selected[i]].seq !== "undefined") {
var seq = this.sequence[selected[i]];
if (seq.is_clone) {
result +="> " + this.m.clone(selected[i]).getName() + " // " + this.m.clone(selected[i]).getStrSize() + "\n";
result += "> " + this.m.clone(selected[i]).getName() + " // " + this.m.clone(selected[i]).getStrSize() + "\n";
} else {
result += "> " + selected[i];
}
......@@ -960,6 +972,23 @@ Segment.prototype = {
},
/**
* save a csv file of the currently visibles clones.
* @return {string} csv
* */
exportAlignFasta: function () {
var list = this.m.getSelected()
if (list.length>0){
var fasta = this.toFasta()
openAndFillNewTab( "<pre>" + fasta )
}else{
console.log({msg: "Export FASTA: please select clones to be exported", type: 'flash', priority: 2});
}
},
/**
* remove alignement
......@@ -969,9 +998,21 @@ Segment.prototype = {
this.aligned = false
for (var i = 0; i < selected.length; i++) {
var spanM = document.getElementById("m" + selected[i])
spanM.innerHTML = this.sequence[selected[i]].load().toString(this)
try {
div = document.getElementById("export_fasta_align")
div.classList.add("disabledClass")
} catch (err) {
// Div doesn't exist (qunit only ?)
}
try{
if( selected.length ){
for (var i = 0; i < selected.length; i++) {
var spanM = document.getElementById("m" + selected[i])
spanM.innerHTML = this.sequence[selected[i]].load().toString(this)
}
}
} catch (err) {
}
},
......@@ -984,12 +1025,12 @@ Segment.prototype = {
var json = JSON.parse(file)
// Load all (aligned) sequences
// Load all (aligned) sequences
for (var i = 0; i < json.seq.length; i++) {
this.sequence[this.memTab[i]].load(json.seq[i])
}
}
// Render all (aligned) sequences
// Render all (aligned) sequences
for (var j = 0; j < json.seq.length; j++) {
// global container
......
......@@ -679,3 +679,18 @@ function locus_cmp(valA, valB){
}
return 0
}
/**
* Open a new tab and put content in it.
* This function is use to show fasta export
* @param {String} content Clones as fasta format
*/
function openAndFillNewTab (content){
var w = window.open("", "_blank", "selected=0, toolbar=yes, scrollbars=yes, resizable=yes");
var result = $('<div/>', {
html: content
}).appendTo(w.document.body);
return
}
\ No newline at end of file
......@@ -447,6 +447,28 @@ QUnit.test("findGermlineFromGene", function(assert) {
var getted = m.findGermlineFromGene("unknown_gene")
assert.equal(getted, undefined, 'function return undefined value for the gene J: unknown_gene')
})
QUnit.test("getFasta", function(assert) {
var m = new Model();
m.parseJsonData(json_data, 100)
var c1 = new Clone(json_clone1, m, 0)
var c2 = new Clone(json_clone2, m, 1)
var c3 = new Clone(json_clone3, m, 2)
var c4 = new Clone(json_clone4, m, 3)
var c5 = new Clone(json_clone5, m, 4)
var c6 = new Clone(json_clone6, m, 4)
m.initClones()
m.select(0)
m.select(1)
var fasta = m.getFasta()
console.log( fasta )
fasta_to_get = ">hello 19 nt, 10 reads (5.000%, 10.00% of TRG)\naaaaaa\naaaattttt\ntttt\n\n>IGHV3-23*01 6/ACGTG/4 IGHD1-1*01 5/CCCACGTGGGGG/4 IGHJ5*02 11 nt, 10 reads (5.000%, 10.00% of IGH)\nAACGTACCAGG\n\n"
assert.equal(fasta, fasta_to_get, "getFasta return the correct content")
});
......
......@@ -73,6 +73,10 @@ QUnit.test("segmenter", function(assert) {
// Clone 2 is more abundant than clone 1 more abundant than clone 0
assert.ok(clone2_pos < clone1_pos);
assert.ok(clone1_pos < clone0_pos);
var fasta = segment.toFasta();
assert.ok(fasta.indexOf('> test3') < fasta.indexOf('> test2'));
assert.ok(fasta.indexOf('> test2') < fasta.indexOf('> test1'));
m.unselectAll()
m.select(2)
......
......@@ -39,6 +39,11 @@ CGTCTT"
assert ($b.clone_in_segmenter('0').text.include? 'CGTCTT'), "We should have sequence CGTCTT, %s instead" % $b.clone_in_segmenter('0').text
end
def test_02_export_align_sequences
assert ( $b.menu_item_export_fasta_align(:class => 'disabledClass').exists?), ">> export align sequences is disable by default"
end
def test_zz_close
close_everything
end
......
......@@ -174,6 +174,10 @@ class VidjilBrowser < Watir::Browser
return menu_item_export('export_fasta')
end
def menu_item_export_fasta_align
return menu_item_export('export_fasta_align')
end
def merge
return element(:id => 'merge')
end
......
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