Commit 422df321 authored by flothoni's avatar flothoni

Update fct to be call directly inside a sort call

link to #2632
parent 6710ebc5
Pipeline #59859 passed with stages
in 4 minutes and 56 seconds
......@@ -325,7 +325,7 @@ Model_loader.prototype = {
self.system_available.push(system)
}
}
self.system_available = sort_list_locus(self.system_available)
self.system_available.sort(locus_cmp)
for (var sa in self.system_available){
system = this.system_available[sa]
......
......@@ -4,7 +4,7 @@ var INS="insertion";
var DEL="deletion";
var END_CODON = "end-codon ";
var END_CODON_NOT_FIRST = "end-codon-not-first ";
var LOCUS_ORDER = [ "TRA", "TRB", "TRB+", "TRG", "TRD", "TRA+D", "TRD+", "IGH", "IGH+", "IGK", "IGK+", "IGL"]
/**
* Get codons from two aligned sequences
* @pre both sequences are aligned together ref.length == seq.length
......@@ -649,37 +649,33 @@ 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
* Compare two locus to sort them.
* The list is ordered on a preordered list of locus (LOCUS_ORDER).
* By this way, locus that are not in this list will be added at the end of it.
* @param {String} valA One locus value
* @param {String} valB Another locus value to compare
* @return {Number} A number -1 if A before B, else 1
*/
function sort_list_locus(key_list){
function locus_cmp(valA, valB){
// 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"]
var index;
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) {
index = generic_locus_2.indexOf(generic_locus_1[i]);
generic_locus_2.splice(index, 1);
} else {
// else deletion of list given
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 j = 0; j < key_list.length; j++) {
generic_locus_2.push( key_list[j] )
var index_A = LOCUS_ORDER.indexOf(valA)
var index_B = LOCUS_ORDER.indexOf(valB)
if (index_A == -1 && index_B == -1){
// Neither A or B are present in LOCUS_ORDER
return valA.localeCompare(valB)
} else if (index_A != -1 && index_B == -1){
// Only A is present in LOCUS_ORDER
return -1
} else if (index_A == -1 && index_B != -1){
// Only B is present in LOCUS_ORDER
return 1
} else if (index_A != -1 && index_B != -1){
// A & B are present in LOCUS_ORDER
return index_A - index_B
}
return generic_locus_2
return 0
}
......@@ -397,19 +397,15 @@ QUnit.test("Pearson coefficient", function(assert) {
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+", "unknow_locus", "IGK+", "IGL", "testlocus", "TRA", "TRB", "TRB+", "TRG", "TRD"]
wait_test_2 = [ "TRA", "TRB", "TRB+", "TRG", "TRD", "IGH", "IGH+", "IGK+", "IGL", "testlocus", "unknow_locus"]
list_test_1.sort(locus_cmp)
list_test_2.sort(locus_cmp)
// 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")
assert.deepEqual(list_test_1, wait_test_1, "list2 is correctly sorted")
assert.deepEqual(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