Commit 1791cd51 authored by flothoni's avatar flothoni Committed by Mikaël Salson
Browse files

model_loader; refactor function that allow to keep consistant order even with added/deleted sampels

Also add a test on a particular case
Link to #4541
parent 3ae87eb0
......@@ -494,36 +494,67 @@ Model_loader.prototype = {
}
}
// Delete values of analysis that are not present in current loaded samples
var pos = 0
for (var delpos = 0; delpos < analysis.id.length; delpos++) {
var analysis_file = analysis.id[delpos]
if (samples.original_names.indexOf(analysis_file) == -1){
// delete this value and decrease greater values
analysis.id.splice(delpos,1); // remove file
analysis.order = removeEltAndDecrease(analysis.order, delpos)
analysis.stock_order = removeEltAndDecrease(analysis.stock_order, delpos)
delpos = delpos-1
} else { pos += 1 }
}
pos = analysis.id.length
// Add values of samples that are not present in analysis
for (var addpos = 0; addpos < samples.original_names.length; addpos++) {
var sample_file = samples.original_names[addpos]
if (analysis.id.indexOf(sample_file) == -1){
analysis.id.push( sample_file )
analysis.order.push(pos)
analysis.stock_order.push(pos)
pos += 1
}
}
this.delRemovedSample(analysis, samples)
clone.order = analysis.order
clone.stock_order = analysis.stock_order
return clone;
},
/**
* Make housekeeping of order_stock_order field of analysis
* Allow to remove deleted samples and add new one and keep a consistant order
* @param {string} analysis - json_text / content of .analysis file
* @param {string} samples - json_text / content of .vidjil file
* */
delRemovedSample: function (analysis, samples) {
var self = this
var current_names = samples.original_names
var analysis_names = analysis.id
var order = analysis.order
var stock = analysis.stock_order
// Convert value into filename and delete delted samples from arrays
// ... for order field
for (var i = 0; i < order.length; i++) {
order[i] = analysis_names[order[i]]
}
for (var k = order.length - 1; k >= 0; k--) {
if (current_names.indexOf(order[k]) == -1){
order.splice(k, 1)
}
}
// ... for stock_order field
for (var j = 0; j < stock.length; j++) {
stock[j] = analysis_names[stock[j]]
}
for (var l = stock.length - 1; l >= 0; l--) {
if (current_names.indexOf(stock[l]) == -1){
stock.splice(l, 1)
}
}
// Add new samples
for (var m = 0; m < current_names.length; m++) {
if (stock.indexOf(current_names[m]) == -1){
order.push(current_names[m])
stock.push(current_names[m])
}
}
// retro convert filename into position in the loaded analysis
for (var p = 0; p < order.length; p++) {
order[p] = current_names.indexOf(order[p])
}
for (var q = 0; q < stock.length; q++) {
stock[q] = current_names.indexOf(stock[q])
}
},
/**
* parse a json or a json_text and complete the model with it's content
* @param {string} analysis - json_text / content of .analysis file
......
{
"clones": [],
"producer": "browser",
"samples": {
"id": [
"file_deleted_1",
"file_fu_1",
"file_fu_2",
"file_deleted_2",
"file_rechute"
],
"names": [
"impossible",
"Fu-1",
"Fu-2",
"impossible 2",
"Rechute"
],
"order": [
4, 1, 0
],
"stock_order": [
4, 1, 2, 0, 3
]
},
"timestamp": "2020-12-2 20:27:27",
"vidjil_json_version": "2014.09"
}
\ No newline at end of file
{
"germlines": {},
"producer": "vidjil fuse",
"similarity": [],
"timestamp": "2019-11-07 10:36:42",
"vidjil_json_version": "2016b",
"reads": {
"segmented": [
1967259, 1892061, 1950799, 1612765, 1819609
],
"total": [
2390273, 2451185, 2419756, 2037793, 2251642
],
"germline": {
}
},
"samples": {
"log": [
"log_0", "log_1", "log_2", "log_3", "log_4"
],
"producer": [
"algo", "algo", "algo", "algo", "algo"
],
"timestamp": [
"2019-11-06", "2019-11-06", "2019-11-06", "2019-11-06", "2019-11-06"
],
"commandline": [
"cmd line 0", "cmd line 1", "cmd line 2", "cmd line 3", "cmd line 4"
],
"number": 5,
"original_names": [
"file_diag_1",
"file_fu_1",
"file_fu_2",
"file_fu_3",
"file_rechute"
],
"run_timestamp": [
"2019-11-06", "2019-11-06", "2019-11-06", "2019-11-06", "2019-11-06"
]
},
"clones": [
],
"clusters": [
0,
0,
0
]
}
\ No newline at end of file
......@@ -77,6 +77,16 @@ class TestGraph < BrowserTest
assert ( $b.graph_x_legend('2').text == 'file2_name')
end
def test_06_load_analysis_duplicate_in_order
set_browser("/browser/test/data/issues/issues_4541/4541_06.fused", "/browser/test/data/issues/issues_4541/4541_06.analysis")
assert ( $b.span(:id => "visu2_title").text == "4 / 5" ), "Ratio show is correct at init"
assert ( $b.graph_x_legend('4').text == 'Rechute')
assert ( $b.graph_x_legend('1').text == 'Fu-1')
assert (not $b.graph_x_legend('2').present?)
assert ( $b.graph_x_legend('0').text == 'file_diag_1')
assert ( $b.graph_x_legend('3').text == 'file_fu_3')
end
# Not really a test
def test_zz_close
......
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