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