Commit 2f619d0e authored by Mikaël Salson's avatar Mikaël Salson

Merge branch 'feature-c/3325-display-codons' into 'dev'

Feature c/3325 display codons

Closes #3325

See merge request !296
parents 73166dc9 de0049cb
Pipeline #41458 failed with stages
in 2 minutes and 20 seconds
......@@ -673,6 +673,9 @@ span .silent {
border-bottom: 3px double #008;
color: #008;
}
span .end-codon {
box-shadow: 1px 0 0 #839496;
}
/*tag*/
.tagSelector {
padding: 5px;
......
......@@ -673,6 +673,9 @@ span .silent {
border-bottom: 3px double #008;
color: #008;
}
span .end-codon {
box-shadow: 1px 0 0 #657b83;
}
/*tag*/
.tagSelector {
padding: 5px;
......
......@@ -673,6 +673,9 @@ span .silent {
border-bottom: 3px double #008;
color: #008;
}
span .end-codon {
box-shadow: 1px 0 0 #657b83;
}
/*tag*/
.tagSelector {
padding: 5px;
......
......@@ -673,6 +673,9 @@ span .silent {
border-bottom: 3px double #008;
color: #008;
}
span .end-codon {
box-shadow: 1px 0 0 #657b83;
}
/*tag*/
.tagSelector {
padding: 5px;
......
......@@ -820,6 +820,12 @@ span .silent {
color: #008;
}
span .end-codon {
box-shadow: 1px 0 0 @default;
}
span .end-codon-not-first {
}
/*tag*/
.tagSelector{
......
......@@ -1235,8 +1235,11 @@ genSeq.prototype= {
* @param {char} other
* @return {string}
* */
spanify_mutation: function (self, other, mutation) {
if (mutation != undefined) {
spanify_mutation: function (self, other, mutation, i_am_first_clone) {
if (mutation != undefined && !i_am_first_clone) {
mutation = mutation.replace(END_CODON, END_CODON_NOT_FIRST)
}
if (mutation != undefined && mutation) {
var span = document.createElement('span');
span.className = mutation
span.setAttribute('other', other + '-' + this.segmenter.first_clone);
......@@ -1296,8 +1299,10 @@ genSeq.prototype= {
ref = this.segmenter.sequence[this.segmenter.first_clone].seq;
}
if (this.segmenter.aligned) {
mutations = get_mutations(ref, seq, reference_phase);
mutations = get_mutations(ref, seq, reference_phase, true);
}
var i_am_first_clone = (this.id == this.segmenter.first_clone)
for (var i = 0; i < this.seq.length; i++) {
for (var m in highlights){
......@@ -1335,7 +1340,7 @@ genSeq.prototype= {
}
}
currentSpan.appendChild(this.spanify_mutation(seq[i], ref[i], mutations.hasOwnProperty(i) ? mutations[i] : undefined))
currentSpan.appendChild(this.spanify_mutation(seq[i], ref[i], mutations.hasOwnProperty(i) ? mutations[i] : undefined, i_am_first_clone))
}
result.appendChild(currentSpan);
var marge = ""
......
......@@ -2,6 +2,8 @@ var SILENT="silent";
var SUBST="substitution";
var INS="insertion";
var DEL="deletion";
var END_CODON = "end-codon ";
var END_CODON_NOT_FIRST = "end-codon-not-first ";
/**
* Get codons from two aligned sequences
......@@ -76,16 +78,16 @@ function get_codons(ref, seq, frame) {
}
/**
* Get positions of mutations and their type between two aligned sequences
* Get positions of mutations and their type, as well as end position of codons, between two aligned sequences
* @pre both sequences are aligned together
* @param ref: reference the sequence
* @param seq: the sequence aligned to ref
* @param frame: the frame in the reference sequence
* 0: first codon starts at first position, etc.
* @return a dictionary whose keys are positions of mutations in the alignment
* and whose values are a type of mutation either SUBST/SILENT/INS/DEL
* @return a dictionary whose keys are positions of mutations / end of codons in the alignment
* and whose values are a combinations of SUBST/SILENT/INS/DEL/END_CODON
*/
function get_mutations(ref, seq, frame) {
function get_mutations(ref, seq, frame, with_end_codon) {
var codons = get_codons(ref, seq, frame);
var mutations = {};
var nb_pos = 0;
......@@ -126,6 +128,8 @@ function get_mutations(ref, seq, frame) {
}
nb_pos++;
}
if (typeof with_end_codon !== undefined && with_end_codon && (i < codons.ref.length - 1 || codons.ref[i].length >= 3))
mutations[nb_pos-1] = END_CODON + (typeof mutations[nb_pos-1] === 'undefined' ? '' : mutations[nb_pos-1])
}
return mutations;
}
......
......@@ -73,7 +73,7 @@ QUnit.test("test get_mutations", function(assert) {
r = 'ATAGATAG-TAG';
s = 'ATA-ATCGATAG';
// 0123456789
// 012345678901
// AG-T > cGAT (no base in the reference → can't tell if the mutation is silent)
mutations = get_mutations(r, s, 0);
......@@ -82,7 +82,7 @@ QUnit.test("test get_mutations", function(assert) {
// ATA > ATc (I)
mutations = get_mutations(r, s, 1);
assert.equal(Object.keys(mutations).length, 3, "Three mutations");
assert.equal(Object.keys(mutations).length, 3, "Three mutations (including a SILENT)");
assert.deepEqual(mutations, {3 : DEL, 6 : SILENT, 8 : INS});
// TAG > TcG (* > S)
......@@ -90,6 +90,19 @@ QUnit.test("test get_mutations", function(assert) {
assert.equal(Object.keys(mutations).length, 3, "Three mutations");
assert.deepEqual(mutations, {3 : DEL, 6 : SUBST, 8 : INS});
// Same example, with end codons
mutations = get_mutations(r, s, 0, true);
assert.equal(Object.keys(mutations).length, 6, "Six mutations + end codons");
assert.deepEqual(mutations, {2 : END_CODON, 3 : DEL, 5 : END_CODON, 6 : SUBST, 8 : INS, 9 : END_CODON});
mutations = get_mutations(r, s, 1, true);
assert.equal(Object.keys(mutations).length, 5, "Five mutations + end codons (including a SILENT)");
assert.deepEqual(mutations, {0 : END_CODON, 3 : END_CODON + DEL, 6 : END_CODON + SILENT, 8 : INS, 10: END_CODON});
mutations = get_mutations(r, s, 2, true);
assert.equal(Object.keys(mutations).length, 7, "Seven mutations + end codons");
assert.deepEqual(mutations, {1 : END_CODON, 3 : DEL, 4 : END_CODON, 6 : SUBST, 7 : END_CODON, 8 : END_CODON + INS, 11 : END_CODON});
// Same example as before but with common indels to check that they are ignored
r = 'ATAGAT-AG-TA--G';
s = 'ATA-AT-CGATA--G';
......
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