Skip to content

Commit

Permalink
#692 fixes evidence distances (TODO: fix styling)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnedeklerk committed Aug 29, 2023
1 parent 427db60 commit 066cfc3
Showing 1 changed file with 48 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ let KnetScoreFilter = {
},

// Renders knetscore filter Ui

// TODO: This should be updated to match the Evidence Distance styling.
renderUi(){
const popup = $(`
<div data-id="knetscore" onclick="toggleFilterIcons(this)" class="knetscore-view-overlay"></div>
Expand Down Expand Up @@ -122,8 +124,6 @@ let KnetScoreFilter = {

$('#knetscore-filter').append(popup);
}


}

// Renders Ui and detects graph distance maximum number
Expand Down Expand Up @@ -187,56 +187,53 @@ const geneTableFilterMgr = function() {
}
},
// handles knetscore filtering
filterByDistanceAndScore(event)
{
const element = event.target
const data = [...tableData]

event.preventDefault();
toggleFilterIcons(element);

let filteredData = []

distance = $('#select-distance option:selected').val()
scoreMin = Number($('#score-min').val());
scoreMax = Number($('#score-max').val());

filterByDistanceAndScore: function(event) {
const element = event.target;
const data = [...tableData];
event.preventDefault();
toggleFilterIcons(element);

const distance = $('#select-distance option:selected').val();
const scoreMin = Number($('#score-min').val());
const scoreMax = Number($('#score-max').val());

let filteredData = [];

// Filter through data
for(let genes of data ){

const score = Number(genes.score).toFixed(2);

// Checks if the gene's score falls within the selected range (inclusive of the range boundaries)
const isScoreInRange = ((score >= scoreMin ) && (score <= scoreMax) )

let concepts = genes.conceptEvidences

for(let concept in concepts ){

let evidence = concepts[concept].conceptEvidences;

evidence = evidence.filter( item => item.graphDistance <= distance)

if(!evidence.length){
const newObject = Object.assign({},concepts)
delete newObject[concept];
concepts = newObject;
}
}
// checks if object.Keys has length
const isConceptEmpty = Object.keys(concepts).length
if(isConceptEmpty > 0 && isScoreInRange){
filteredData.push(genes)
}
}

if(filteredData.length){
geneTableFilterMgr.renderFilteredTable(filteredData)
}

geneTableFilterMgr.toggleTableState(filteredData.length)

},
for(let genes of data) {
// Deep clone the gene object to ensure we don't modify the original data
let geneClone = JSON.parse(JSON.stringify(genes));

const score = Number(geneClone.score).toFixed(2);

// Checks if the gene's score falls within the selected range (inclusive of the range boundaries)
const isScoreInRange = ((score >= scoreMin ) && (score <= scoreMax) );
let concepts = geneClone.conceptEvidences;

for(let concept in concepts) {
let evidence = concepts[concept].conceptEvidences;
evidence = evidence.filter(item => item.graphDistance <= distance);

if(!evidence.length){
delete concepts[concept];
} else {
concepts[concept].conceptEvidences = evidence;
}
}

// checks if object.Keys has length
const isConceptEmpty = Object.keys(concepts).length;
if(isConceptEmpty > 0 && isScoreInRange){
filteredData.push(geneClone);
}
}

if(filteredData.length) {
geneTableFilterMgr.renderFilteredTable(filteredData);
}

geneTableFilterMgr.toggleTableState(filteredData.length);
},
renderFilteredTable(table){
genesTableScroller.setTableData (table)
createGeneTableBody(table)
Expand Down

0 comments on commit 066cfc3

Please sign in to comment.