Commit 55499659 authored by Mikaël Salson's avatar Mikaël Salson

Merge branch 'feature-tc/3943-implement-null-for-normalized_reads' into 'dev'

Resolve "Implement null for normalized_reads"

Closes #3943

See merge request !485
parents bfa588c4 25d0a6e5
Pipeline #87861 passed with stages
in 48 minutes and 19 seconds
......@@ -27,6 +27,7 @@
"sequence" : "seq-1",
"reads" : [ 300 ] ,
"normalized_reads" : [ 500 ] ,
"top" : 1,
"germline" : "IGH"
},
......
......@@ -699,8 +699,11 @@ changeAlleleNotation: function(alleleNotation) {
* if raw is defined, do not normalize
*/
normalize_reads: function(clone, time, raw) {
if (this.normalization_mode == this.NORM_EXTERNAL && clone.normalized_reads != undefined && raw == undefined) {
return clone.normalized_reads[time] ;
if (this.normalization_mode == this.NORM_EXTERNAL &&
clone.normalized_reads != undefined &&
clone.normalized_reads[time] != null &&
raw == undefined) {
return clone.normalized_reads[time] ;
} else {
return clone.reads[time] ;
}
......
......@@ -119,7 +119,7 @@ var json_clone6 = {
"id" : "id6",
"germline" : "TRG",
"reads" : [10,10,0,30],
"normalized_reads" : [20,20,0,30],
"normalized_reads" : [20,20,0,null],
}
QUnit.test("name, informations, getHtmlInfo", function(assert) {
......
......@@ -423,6 +423,12 @@ QUnit.test("normalization", function(assert) {
m.initClones()
assert.equal(m.have_external_normalization, false, "Model have_external_normalization is correctly resetted")
m.set_normalization(m.NORM_EXTERNAL)
assert.equal(m.normalize_reads(c6, 0, undefined), 20, "normalize_reads; get normalized value if present")
assert.equal(m.normalize_reads(c6, 0, false), 10, "normalize_reads; get raw value if specified" )
assert.equal(m.normalize_reads(c6, 2, undefined), 0, "normalize_reads; get value at 0 as computed by external normalization" )
assert.equal(m.normalize_reads(c6, 3, undefined), 30, "normalize_reads; get raw value if normalization equal null")
})
QUnit.test("findGermlineFromGene", function(assert) {
......
......@@ -317,10 +317,11 @@ class ListWindows(VidjilJson):
for clone in self:
for i, s in enumerate(clone.d["reads"]):
for r in range(len(ranges)):
if s*1. / self.d['reads'].d['segmented'][i] >= ranges[r]:
break
result[r][i] += s
if self.d['reads'].d['segmented'][i] > 0:
for r in range(len(ranges)):
if s*1. / self.d['reads'].d['segmented'][i] >= ranges[r]:
break
result[r][i] += s
for r in range(len(ranges)):
ratio_in_string = '{0:.10f}'.format(ranges[r]).rstrip('0')
......
!LAUNCH: python ../../fuse.py $FUSE_OPTIONS ../../../algo/tests/data/no_clones.vidjil ../../../algo/tests/data/results-two-clones-1-2.vidjil -o normalized_zero.vidjil; cat normalized_zero.vidjil
$ Case zero; No field normalized_reads if not contain in the given files/clones
0: normalized_reads
!LAUNCH: python ../../fuse.py $FUSE_OPTIONS ../../../algo/tests/data/results-two-clones-1-3.vidjil ../../../algo/tests/data/results-two-clones-1-3.vidjil -o normalized_both.vidjil; cat normalized_both.vidjil
$ Case both; Should find 1 field normalized_reads (clone id-1)
1: normalized_reads
$ Case both; Correct fusion of normalized_reads field if both clones are informatives
lr: normalized_reads.*500,.*500
!LAUNCH: python ../../fuse.py $FUSE_OPTIONS ../../../algo/tests/data/no_clones.vidjil ../../../algo/tests/data/results-two-clones-1-3.vidjil -o normalized_one.vidjil; cat normalized_one.vidjil
$ Case only one; Should find 1 filed normalized_reads
1: normalized_reads
$ Case only one; First value is null if on of file have not been annalysed by the normalization script
1: null
rl1: normalized_reads.*null,.*500
!LAUNCH: python ../../fuse.py $FUSE_OPTIONS ../../../algo/tests/data/results-two-clones-1-3.vidjil ../../../algo/tests/data/no_clones.vidjil -o normalized_one_revert.vidjil; cat normalized_one_revert.vidjil
$ Case inverse; Should find 1 filed normalized_reads
1: normalized_reads
$ Case inverse; Idem, but reverse files
1: null
lr: "normalized_reads".*500,.*null
!LAUNCH: python ../../fuse.py $FUSE_OPTIONS normalized_one.vidjil ../../../algo/tests/data/results-two-clones-1-3.vidjil -o normalized_double.vidjil; cat normalized_double.vidjil
$ Case double timepoint; Should find 1 filed normalized_reads
1: normalized_reads
$ Case double timepoint; Correct fusion if one of the file is a already fused vidjil
1: null
lr: "normalized_reads".*null,.*500,.*500
\ No newline at end of file
......@@ -52,8 +52,13 @@ def concatenate_with_padding(d,
continue
d[key] = d1[key]
if key not in d2 :
d[key] += t2
### For field normalized_reads, we prefer set it at None if not available for a timepoint
# Create a specific loop for it
if key not in d2:
if key != "normalized_reads":
d[key] += t2
elif key == "normalized_reads":
d[key] += [None]*len(d2["reads"])
for key in d2:
if key in ignore_keys:
......@@ -61,8 +66,11 @@ def concatenate_with_padding(d,
if type(d2[key]) is not list:
continue
if key not in d :
d[key] = t1 + d2[key]
if key not in d:
if key != "normalized_reads":
d[key] = t1 + d2[key]
elif key == "normalized_reads":
d[key] = [None]*len(d1["reads"]) + d2[key]
else :
d[key] = d[key] + d2[key]
......
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