Commit 0a44fa39 authored by flothoni's avatar flothoni

browser; add a fct to make a specific sort of list of locus

link to #2632
parent c8e14cca
Pipeline #59789 failed with stages
in 15 seconds
......@@ -332,7 +332,7 @@ Info.prototype = {
var keys = 0;
var key_list = this.m.system_available;
key_list.sort();
var last_key = "";
......
......@@ -325,6 +325,8 @@ Model_loader.prototype = {
self.system_available.push(system)
}
}
self.system_available = sort_list_locus(self.system_available)
for (var sa in self.system_available){
system = this.system_available[sa]
self.system_selected.push(system)
......
......@@ -648,3 +648,38 @@ function pearsonCoeff(l1, l2) {
}
function logadd1(x) { return Math.log(x + 1) ; }
/**
* Sort list of available locus.
* The list is ordered on a preordered list of locus.
* Locus that are not in this list will be added a supplmeent of this one at the end of it.
* @param {Array} key_list List of system available in model, or a list of locus
* @return {Array} Ordered list of locus
*/
function sort_list_locus(key_list){
// Ordered list of all generic locus
var generic_locus_1 = [ "TRA", "TRB", "TRB+", "TRG", "TRD", "TRA+D", "TRD+", "IGH", "IGH+", "IGK", "IGK+", "IGL"]
var generic_locus_2 = [ "TRA", "TRB", "TRB+", "TRG", "TRD", "TRA+D", "TRD+", "IGH", "IGH+", "IGK", "IGK+", "IGL"]
for (var i = 0; i < generic_locus_1.length; i++) {
// If not present, deletion of result list
if (key_list.indexOf(generic_locus_1[i]) == -1) {
var index = generic_locus_2.indexOf(generic_locus_1[i]);
generic_locus_2.splice(index, 1);
} else {
// else deletion of list given
var index = key_list.indexOf(generic_locus_1[i]);
key_list.splice(index, 1);
}
}
// key_list will only contain locus that are not in generic list of locus
// Sort keeped elements
key_list.sort()
// Add these elements to result list
for (var i = 0; i < key_list.length; i++) {
generic_locus_2.push( key_list[i] )
}
return generic_locus_2
}
......@@ -393,3 +393,23 @@ QUnit.test("Pearson coefficient", function(assert) {
assert.equal(pearsonCoeff([3, 2, 1], [10, 20, 30]), -1)
}
);
QUnit.test("Sort list locus", function(assert) {
liste_sort_1 = [ "TRA", "TRB", "TRB+", "TRG", "TRD", "TRA+D", "TRD+", "IGH", "IGH+", "IGK", "IGK+", "IGL"]
console.log( "sort_list_locus" )
list_test_1 = [ "TRA", "TRB", "TRG", "TRD", "testlocus", "IGH", "IGK", "IGL"]
wait_test_1 = [ "TRA", "TRB", "TRG", "TRD", "IGH", "IGK", "IGL", "testlocus"]
list_test_2 = [ "IGH", "IGH+", "testlocus", "IGK+", "IGL", "unknow_locus", "TRA", "TRB", "TRB+", "TRG", "TRD"]
wait_test_2 = [ "TRA", "TRB", "TRB+", "TRG", "TRD", "IGH", "IGH+", "IGK+", "IGL", "testlocus", "unknow_locus"]
// console.log( "result_1" )
// console.log( sort_list_locus(list_test_1))
// console.log( "result_2" )
// console.log( sort_list_locus(list_test_2))
assert.deepEqual(sort_list_locus(list_test_1), wait_test_1, "list1 is correctly sorted")
assert.deepEqual(sort_list_locus(list_test_2), wait_test_2, "list2 is correctly sorted")
}
);
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