Commit f0fdb02a authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch 'feature-c/normalization' into 'dev'

Normalization, details

Closes #3662

See merge request !381
parents 58d7baf2 394fec68
Pipeline #56960 passed with stages
in 59 minutes and 21 seconds
......@@ -208,6 +208,9 @@
<input id="expected_normalization_input" type="radio" name="normalization" value="expected_normalization" />
set on a given clone
</label>
</form>
<form name="normalize_list" id="normalize_list" class="devel-mode">
</form>
</div>
<div class="menu_box">
......
......@@ -624,8 +624,9 @@ Clone.prototype = {
*/
getPrintableSize: function (time) {
time = this.m.getTime(time)
var reads = this.getReads(time)
var reads = this.getRawReads(time)
s = this.getSequenceLength() + ' nt'
if (!this.quantifiable)
......@@ -634,6 +635,11 @@ Clone.prototype = {
s += ', '
s += this.m.toStringThousands(reads) + ' read' + (reads > 1 ? 's' : '') + ' '
reads = this.getReads(time)
if (this.normalized_reads && this.m.normalization_mode == this.m.NORM_EXTERNAL)
s += "[" + this.m.toStringThousands(Math.floor(reads * 100) / 100) + " normalized] "
if (reads < this.m.NB_READS_THRESHOLD_QUANTIFIABLE)
return s
......@@ -688,21 +694,25 @@ Clone.prototype = {
},
/* compute the clone reads number ( sum of all reads of clones clustered )
* @t : tracking point (default value : current tracking point)
* @time : tracking point (default value : current tracking point)
* @raw: do not normalize
* */
getReads: function (time) {
getReads: function (time, raw) {
time = this.m.getTime(time)
var result = 0;
var cluster = this.getCluster()
for (var j = 0; j < cluster.length; j++) {
result += this.m.normalize_reads(this.m.clone(cluster[j]), time);
result += this.m.normalize_reads(this.m.clone(cluster[j]), time, raw);
}
return result
}, //end getSize
},
getRawReads: function (time) {
return this.getReads(time, true)
},
/* return a list of read numbers (sum of all reads of clustered clones) for all samples
* */
......@@ -1196,10 +1206,17 @@ Clone.prototype = {
html += row_1("clone name", this.getName())
html += row_1("clone short name", this.getShortName())
html += "<tr><td>clone size (n-reads (total reads))</td>"
html += "<tr><td>clone size (n-reads (total reads))"
if (this.normalized_reads && this.m.normalization_mode == this.m.NORM_EXTERNAL) {
html += "<br />[normalized]"
}
html += "</td>"
for (var j = 0; j < time_length; j++) {
html += "<td>"
html += this.getReads(this.m.samples.order[j]) + " (" + this.m.reads.segmented[this.m.samples.order[j]] + ")"
html += this.getRawReads(this.m.samples.order[j]) + " (" + this.m.reads.segmented[this.m.samples.order[j]] + ")"
if (this.normalized_reads && this.m.normalization_mode == this.m.NORM_EXTERNAL) {
html += "<br />[" + this.getReads(this.m.samples.order[j]).toFixed(2) + "]"
}
if ($('#debug_menu').is(':visible') && (typeof this.m.db_key.config != 'undefined' )) {
html += "<br/>"
call_reads = "db.call('default/run_request', { "
......
......@@ -689,10 +689,11 @@ changeAlleleNotation: function(alleleNotation) {
},
/**
* normalize a number of reads
* normalize a number of reads according to this.NORM_EXTERNAL
* if raw is defined, do not normalize
*/
normalize_reads: function(clone, time) {
if (this.normalization_mode == this.NORM_EXTERNAL && clone.normalized_reads != undefined) {
normalize_reads: function(clone, time, raw) {
if (this.normalization_mode == this.NORM_EXTERNAL && clone.normalized_reads != undefined && raw == undefined) {
return clone.normalized_reads[time] ;
} else {
return clone.reads[time] ;
......
......@@ -994,6 +994,7 @@ Segment.prototype = {
var list = this.m.getSelected()
var sumPercentage = 0;
var sumReads = 0;
var sumRawReads = 0;
var length = 0;
var lastActiveClone = 0;
......@@ -1004,14 +1005,18 @@ Segment.prototype = {
length += 1;
sumPercentage += this.m.clone(list[i]).getSize();
sumReads+= this.m.clone(list[i]).getReads();
sumRawReads+= this.m.clone(list[i]).getRawReads();
}
}
var t = ""
if (sumReads > 0) {
if (sumRawReads > 0) {
t += length + " clone" + (length>1 ? "s" : "") + ", "
t += this.m.toStringThousands(sumReads) + " read" + (sumReads>1 ? "s" : "")
t += this.m.toStringThousands(sumRawReads) + " read" + (sumRawReads>1 ? "s" : "")
if (sumRawReads != sumReads)
t += " [" + this.m.toStringThousands(Math.floor(sumReads*100)/100) + " norm.]"
percentageStr = this.m.getStrAnySize(this.m.t, sumPercentage)
if (percentageStr != "+")
......
......@@ -117,6 +117,7 @@ var json_clone5 = {
// Clone with normalized_reads
var json_clone6 = {
"id" : "id6",
"germline" : "TRG",
"reads" : [10,10,0,30],
"normalized_reads" : [20,20,0,30],
}
......
......@@ -357,7 +357,7 @@ QUnit.test("model: primer detection", function(assert) {
QUnit.test("normalization: test", function(assert) {
QUnit.test("normalization", function(assert) {
var m = new Model();
m.parseJsonData(json_data, 100)
var c1 = new Clone(json_clone1, m, 0)
......@@ -379,11 +379,15 @@ QUnit.test("normalization: test", function(assert) {
assert.equal(m.normalize(c2.getSize(),0),0.8000000000000002,"normalize")
m.set_normalization(m.NORM_FALSE)
m.compute_normalization(-1,0)
assert.equal(c6.getSize(), 0.05, "no normalization: 10 / 200")
assert.includes(c6.getPrintableSize(), "10 reads (5.000%", "no normalization: 10 / 200")
assert.equal(c2.getSize(), 0.05, "clone3 size ")
// Switch normalization to external (field normalized_reads)
m.set_normalization(m.NORM_EXTERNAL)
assert.equal(c6.getSize(), 0.1, "external normalization: 20 / 200")
assert.includes(c6.getPrintableSize(), "10 reads [20 normalized] (10.00%", "external normalization: 10 / 200, getPrintableSize")
assert.equal(c6.getSize(2), 0, "external normalization: 0 / 100")
assert.equal(c6.getSize(3), 0.3, "external normalization: 30 / 100")
assert.equal(c2.getSize(), 0.05, "external normalization have no effect on clone without field")
......
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