Commit 50ae1a2f authored by flothoni's avatar flothoni
Browse files

model_loader; refactor copySampleFields function

Use now the filename field of samples and anlysis files to know which sample should be hidden or not
Link to #
parent 0cb094b4
Pipeline #190333 failed with stages
in 25 seconds
......@@ -64,7 +64,7 @@ Builder.prototype = {
this.build_clusterSelector()
this.initTag();
if (this.m.samples.order.length == 1)
if (this.m.samples.stock_order.length == 1)
// One sample, two scatterplots
setTimeout(function() {
switch_visu2('scatterplot');
......
......@@ -494,39 +494,49 @@ Model_loader.prototype = {
}
if (analysis.order != undefined){
analysis.order = removeDuplicate(analysis.order)
}
if (analysis.stock_order != undefined){
analysis.stock_order = removeDuplicate(analysis.stock_order)
}
if ('order' in analysis && 'stock_order' in analysis) {
// Jquery Extend don't work on samples.order.
clone.order = analysis.order
clone.stock_order = analysis.stock_order
// Check if new sample have been added
if (clone.stock_order.length < this.samples.number){
for (var j = clone.stock_order.length; j < this.samples.number; j++) {
clone.order.push(j)
clone.stock_order.push(j)
}
} else {
// Create new values of stock_order for old analysis files
analysis.stock_order = JSON.parse(JSON.stringify(analysis.order));
for (var i = 0; i < analysis.id.length; i++) {
if (analysis.order.indexOf(i) == -1){
analysis.stock_order.push(i)
}
}
}
// stock_order should not be different than number of samples present in vidjil/analysis (issue #4408).
// Order should not be bigger than number of samples present in vidjil/analysis (but can have less)
// TODO: be able to reset order in case of config 1 have same number of sample than config 2 (particular case of #4407)
if (typeof this.samples != 'undefined' && (clone.stock_order.length != this.samples.number || clone.order.length > this.samples.number)){
clone.order = Array.from(Array(this.samples.number).keys())
clone.stock_order = Array.from(Array(this.samples.number).keys())
// Delete values of analysis that are not present in current loaded samples
var pos = 0
for (var i = 0; i < analysis.id.length; i++) {
var file = analysis.id[i]
if (samples.original_names.indexOf(file) == -1){
// delete this value and decrease greater values
analysis.id.splice(i,1); // remove file
analysis.order = removeEltAndDecrease(analysis.order, i)
analysis.stock_order = removeEltAndDecrease(analysis.stock_order, i)
i = i-1
} else { pos += 1 }
}
pos = analysis.id.length
// Add values of samples that are not present in analysis
for (var i = 0; i < samples.original_names.length; i++) {
var file = samples.original_names[i]
if (analysis.id.indexOf(file) == -1){
analysis.id.push( file )
analysis.order.push(pos)
analysis.stock_order.push(pos)
pos += 1
}
} else if ('order' in analysis && !('stock_order' in analysis) && analysis.id.length != clone.original_names.length) {
clone.order = this.calculateOrder(clone.order);
}
clone.order = analysis.order
clone.stock_order = analysis.stock_order
return clone;
},
/**
* parse a json or a json_text and complete the model with it's content
* @param {string} analysis - json_text / content of .analysis file
......
......@@ -50,3 +50,17 @@ QUnit.test("loadCluster", function(assert) {
assert.deepEqual(m.clusters[2], [], "another top order; Correct cluster for clone 2" )
});
QUnit.test("copySampleFields", function(assert) {
model_loader = new Model_loader()
var samples = {"original_names": ["f0", "f1", "f3", "f4", "f5", "f7"], "order": [0,1,2,3,4,5] , "stock_order": [0,1,2,3,4,5] }
var analysis = {"id": ["f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7"], "order": [0,2,6,4], "stock_order": [0,1,2,3,7,6,5,4] }
var loaded = model_loader.copySampleFields(samples, analysis)
console.log(loaded)
assert.deepEqual(loaded.original_names, ["f0", "f1", "f3", "f4", "f5", "f7"], "original_names" )
assert.deepEqual(loaded.order, [0,3], "order" )
assert.deepEqual(loaded.stock_order, [0,1,2,5,4,3], "stock_order" )
});
\ No newline at end of file
{"clones":[{"germline":"TRD+","id":"cid_1","name":"c_name_1","reads":[18290,421157,0],"sequence":0,"top":1},{"germline":"IGK+","id":"cid_2","name":"c_name_2","reads":[111765,0,0],"sequence":0,"top":1},{"germline":"IGH","id":"cid_3","name":"c_name_3","reads":[2113,21638,258546],"sequence":0,"top":1},{"germline":"IGH","id":"cid_4","name":"c_name_4","reads":[60,296,3528],"sequence":0,"top":2},{"germline":"IGH+","id":"cid_5","name":"c_name_5","reads":[782,12753,48504],"sequence":0,"top":2},{"germline":"TRD+","id":"cid_6","name":"c_name_6","reads":[2720,36889,0],"sequence":0,"top":2}],"clusters":[0,0,0,0],"config_name":"multi+inc+xxx","dataFileName":"XXX (multi+inc+xxx)","germlines":{},"group_id":1,"info":"Patient de XXX","logs":[],"patient_id":1,"producer":"vidjil fuse","reads":{"germline":{"IGH":[6085,185456,532086],"IGH+":[62,2709,2640],"IGK":[1,0,0],"IGK+":[150436,3,0],"IGL":[0,0,0],"TRA":[0,1,0],"TRA+D":[1648,14218,0],"TRB":[0,0,0],"TRB+":[0,0,0],"TRD":[51,68,0],"TRD+":[23378,535563,0],"TRG":[112204,26,0],"unexpected":[189,6,345]},"segmented":[294054,738050,535071],"total":[316307,818553,625708]},"sample_name":"KXXX","sample_set_id":1,"samples":{"commandline":["cmdline 0","cmdline 1","cmdline 2"],"config_id":["25","25","25"],"db_key":["","",""],"id":[101,102,103],"info":["file0_info","file1_info","file2_info"],"log":["log 0","log 1","log 2"],"names":["file0_name","file1_name","file2_name"],"number":3,"original_names":["file0.fastq","file1.fastq","file2.fastq"],"patient_id":[100,100,100],"producer":["2017.03","2017.03","2017.09"],"results_file_id":[29410,29204,29699],"run_id":[101,102,103],"run_timestamp":["2017-05-29 11:47:47","2017-07-17 10:48:38","2017-10-09 13:03:33"],"sample_name":[101,102,103],"sequence_file_id":[101,102,103],"timestamp":["2015-10-19","2015-10-19","None"]},"similarity":[],"timestamp":"2017-10-09 13:12:40","vidjil_json_version":"2016b"}
\ No newline at end of file
{"clones":[],"clusters":[],"custom":[],"samples":{"id":["file0.fastq","file1.fastq","file2.fastq"],"info":["file0_info","file1_info","file2_info"],"names":["file0_name","file1_name","file2_name"],"order":[0,2],"stock_order":[1,0,2]},"tags":{"hide":[],"names":{"0":"clone 1","1":"clone 2","2":"clone 3","3":"standard","4":"standard (noise)","5":"custom 1","6":"custom 2","7":"custom 3","8":"-/-"}},"vidjil_json_version":"2014.09"}
\ No newline at end of file
{"clones":[],"clusters":[],"custom":[],"samples":{"id":["file0.fastq","file1.fastq","file2.fastq"],"info":["file0_info","file1_info","file2_info"],"names":["file0_name","file1_name","file2_name"],"order":[0,2]},"tags":{"hide":[],"names":{"0":"clone 1","1":"clone 2","2":"clone 3","3":"standard","4":"standard (noise)","5":"custom 1","6":"custom 2","7":"custom 3","8":"-/-"}},"vidjil_json_version":"2014.09"}
\ No newline at end of file
{"clones":[{"germline":"TRD+","id":"cid_1","name":"c_name_1","reads":[18290,421157,421157,0],"sequence":0,"top":1},{"germline":"IGK+","id":"cid_2","name":"c_name_2","reads":[111765,0,0,0],"sequence":0,"top":1},{"germline":"IGH","id":"cid_3","name":"c_name_3","reads":[2113,21638,21638,258546],"sequence":0,"top":1}],"clusters":[0,0,0,0],"config_name":"multi+inc+xxx","dataFileName":"XXX (multi+inc+xxx)","germlines":{},"group_id":1,"info":"Patient de XXX","logs":[],"patient_id":1,"producer":"vidjil fuse","reads":{"germline":{"IGH":[6085,185456,185456,532086],"IGH+":[62,2709,2709,2640],"IGK":[1,0,0,0],"IGK+":[150436,3,3,0],"IGL":[0,0,0,0],"TRA":[0,1,1,0],"TRA+D":[1648,14218,14218,0],"TRB":[0,0,0,0],"TRB+":[0,0,0,0],"TRD":[51,68,68,0],"TRD+":[23378,535563,535563,0],"TRG":[112204,26,26,0],"unexpected":[189,6,6,345]},"segmented":[294054,738050,738050,535071],"total":[316307,818553,818553,625708]},"sample_name":"KXXX","sample_set_id":1,"samples":{"commandline":["cmdline 0","cmdline 1","cmdline 2","cmdline 3"],"config_id":["25","25","25","25"],"db_key":["","","",""],"id":[101,102,103,104],"info":["file0_info","file1_info","file2_info","file3_info"],"log":["log 0","log 1","log 2","log 3"],"names":["file0_name","file1_name","file2_name","file3_name"],"number":4,"original_names":["file0.fastq","file1.fastq","file2.fastq","file3.fastq"],"patient_id":[100,100,100,100],"producer":["2017.03","2017.03","2017.03","2017.09"],"results_file_id":[210,211,212,213],"run_id":[101,102,103,104],"run_timestamp":["2017-05-29 11:47:47","2017-07-17 10:48:38","2017-07-17 10:48:38","2017-10-09 13:03:33"],"sample_name":[101,102,103,104],"sequence_file_id":[101,102,103,104],"timestamp":["2015-10-19","2015-10-19","2015-10-19","2015-10-19"]},"similarity":[],"timestamp":"2017-10-09 13:12:40","vidjil_json_version":"2016b"}
\ No newline at end of file
{"clones":[{"germline":"TRD+","id":"cid_1","name":"c_name_1","reads":[18290,421157],"sequence":0,"top":1},{"germline":"IGK+","id":"cid_2","name":"c_name_2","reads":[111765,0],"sequence":0,"top":1},{"germline":"IGH","id":"cid_3","name":"c_name_3","reads":[2113,21638],"sequence":0,"top":1},{"germline":"IGH","id":"cid_4","name":"c_name_4","reads":[60,296],"sequence":0,"top":2},{"germline":"IGH+","id":"cid_5","name":"c_name_5","reads":[782,12753],"sequence":0,"top":2},{"germline":"TRD+","id":"cid_6","name":"c_name_6","reads":[2720,36889],"sequence":0,"top":2}],"clusters":[0,0,0,0],"config_name":"multi+inc+xxx","dataFileName":"XXX (multi+inc+xxx)","germlines":{},"group_id":1,"info":"Patient de XXX","logs":[],"patient_id":1,"producer":"vidjil fuse","reads":{"germline":{"IGH":[6085,185456],"IGH+":[62,2709],"IGK":[1,0],"IGK+":[150436,3],"IGL":[0,0],"TRA":[0,1],"TRA+D":[1648,14218],"TRB":[0,0],"TRB+":[0,0],"TRD":[51,68],"TRD+":[23378,535563],"TRG":[112204,26],"unexpected":[189,6]},"segmented":[294054,738050],"total":[316307,818553]},"sample_name":"XXX","sample_set_id":1,"samples":{"commandline":["cmdline 0","cmdline 1"],"config_id":["25","25"],"db_key":["",""],"id":[101,102],"info":["file0_info","file1_info"],"log":["log 0","log 1"],"names":["file0_name","file1_name"],"number":2,"original_names":["file0.fastq","file1.fastq"],"patient_id":[100,100],"producer":["2017.03","2017.03"],"results_file_id":[29410,29204],"run_id":[101,102],"run_timestamp":["2017-05-29 11:47:47","2017-07-17 10:48:38"],"sample_name":[101,102],"sequence_file_id":[101,102],"timestamp":["2015-10-19","2015-10-19"]},"similarity":[],"timestamp":"2017-10-09 13:12:40","vidjil_json_version":"2016b"}
\ No newline at end of file
{"clones":[],"clusters":[],"custom":[],"samples":{"id":["file0b.fastq","file1b.fastq","file2b.fastq"],"info":["file0b_info","file1b_info","file2b_info"],"names":["file0b_name","file1b_name","file2b_name"],"order":[0,2]},"tags":{"hide":[],"names":{"0":"clone 1","1":"clone 2","2":"clone 3","3":"standard","4":"standard (noise)","5":"custom 1","6":"custom 2","7":"custom 3","8":"-/-"}},"vidjil_json_version":"2014.09"}
\ No newline at end of file
{"clones":[],"clusters":[],"custom":[],"samples":{"id":["file0.fastq","file1.fastq","file2.fastq"],"info":["file0_info","file1_info","file2_info"],"names":["file0_name","file1_name","file2_name"],"order":[0,2,2],"stock_order":[1,0,2]},"tags":{"hide":[],"names":{"0":"clone 1","1":"clone 2","2":"clone 3","3":"standard","4":"standard (noise)","5":"custom 1","6":"custom 2","7":"custom 3","8":"-/-"}},"vidjil_json_version":"2014.09"}
\ No newline at end of file
# coding: utf-8
load 'vidjil_browser.rb'
load 'browser_test.rb'
#browser test suite
class TestGraph < BrowserTest
def setup
super
if not defined? $b
# set_browser("/browser/test/data/bug_stock_order/4541.vidjil")
end
end
def after_tests
end
########################
### DESCRIPTION FILE ###
########################
# Vidijl file with 3 samples, only 6 clones keeped
# Analysis
### Issue 4541;
def test_00_load_analysis_simple_reorder
set_browser("/browser/test/data/bug_stock_order/4541.vidjil", "/browser/test/data/bug_stock_order/4541_00_stock.analysis")
assert ( $b.span(:id => "visu2_title").text == "2 / 3" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('0').text == 'file0_name')
assert (not $b.graph_x_legend('1').present?)
assert ( $b.graph_x_legend('2').text == 'file2_name')
end
# Samples here haven't stock_order field (old one)
def test_01_load_analysis_hidden_sample
set_browser("/browser/test/data/bug_stock_order/4541.vidjil", "/browser/test/data/bug_stock_order/4541_01.analysis")
assert ( $b.span(:id => "visu2_title").text == "2 / 3" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('0').text == 'file0_name')
assert (not $b.graph_x_legend('1').present?)
assert ( $b.graph_x_legend('2').text == 'file2_name')
end
def test_02_load_analysis_one_more_sample
set_browser("/browser/test/data/bug_stock_order/4541_02.vidjil", "/browser/test/data/bug_stock_order/4541_01.analysis")
assert ( $b.span(:id => "visu2_title").text == "3 / 4" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('0').text == 'file0_name')
assert (not $b.graph_x_legend('1').present?)
assert ( $b.graph_x_legend('2').text == 'file2_name')
assert ( $b.graph_x_legend('3').text == 'file3_name')
end
def test_03_load_analysis_deleted_sample
set_browser("/browser/test/data/bug_stock_order/4541_03_deleted_sample.vidjil", "/browser/test/data/bug_stock_order/4541_00_stock.analysis")
assert ( $b.span(:id => "visu2_title").text == "1 / 2" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('0').text == 'file0_name')
assert (not $b.graph_x_legend('1').present?)
end
def test_04_load_analysis_all_new_samples
set_browser("/browser/test/data/bug_stock_order/4541.vidjil", "/browser/test/data/bug_stock_order/4541_04_all_new_samples.analysis")
assert ( $b.span(:id => "visu2_title").text == "3 / 3" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('0').text == 'file0_name')
assert ( $b.graph_x_legend('1').text == 'file1_name')
assert ( $b.graph_x_legend('2').text == 'file2_name')
end
def test_05_load_analysis_duplicate_in_order
set_browser("/browser/test/data/bug_stock_order/4541.vidjil", "/browser/test/data/bug_stock_order/4541_05_duplicate_in_order.analysis")
assert ( $b.span(:id => "visu2_title").text == "2 / 3" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('0').text == 'file0_name')
assert (not $b.graph_x_legend('1').present?)
assert ( $b.graph_x_legend('2').text == 'file2_name')
end
# Not really a test
def test_zz_close
close_everything
end
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