Skip to content

Commit

Permalink
improvements to duplicate detection and deletion using hashmaps #722
Browse files Browse the repository at this point in the history
  • Loading branch information
umut-er committed Jul 2, 2024
1 parent 2aba45b commit e16731a
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions app/js/app-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -3831,34 +3831,37 @@ appUtilities.removeDisconnectedNodesAfterQuery = function( querySeedGenes ){
}

appUtilities.removeDuplicateProcessesAfterQuery = function() {
var arrayEquality = function (arr1, arr2) {
if(arr1.length != arr2.length)
return false;

return arr1.every( (item, idx) => item == arr2[idx]);
}

var cy = appUtilities.getActiveCy();
var chiseInstance = appUtilities.getActiveChiseInstance();

var processes = cy.filter('node[class="process"],[class="omitted process"],[class="uncertain process"],[class="association"],[class="dissociation"]');
var nhoods = [];
let processMap = new Map();
var deletion = cy.collection();
processes.forEach( (process) => {
var curNHood = process.neighborhood().union(process);
var labelStrings = [];
curNHood.forEach( (item) => {
labelStrings.push(item.data("label") || item.data("class"));
let collectionArray = [];
let neighborhoodDescriptorString = "";
var edges = process.connectedEdges();
edges.forEach( (edge) => {
var node = edge.connectedNodes().difference(process);
collectionArray.push(node.union(edge));
})
collectionArray.sort( (first, second) => {
var firstLabel = first.filter("node").data("label") || first.filter("node").data("class");
var secondLabel = second.filter("node").data("label") || second.filter("node").data("class");
return firstLabel.localeCompare(secondLabel);
});
labelStrings.sort();

for(let i = 0; i < nhoods.length; i++) {
if(arrayEquality(nhoods[i], labelStrings)){
deletion.merge(process);
break;
}
collectionArray.forEach( (item) => {
neighborhoodDescriptorString += (item.filter("node").data("label") || item.filter("node").data("class"));
neighborhoodDescriptorString += (item.filter("edge").data("label") || item.filter("edge").data("class"));
})
neighborhoodDescriptorString += process.data("class");
if(processMap.has(neighborhoodDescriptorString)){
deletion.merge(process);
}
else{
processMap.set(neighborhoodDescriptorString, true);
}
nhoods.push(labelStrings);
});

chiseInstance.deleteElesSimple(deletion);
Expand Down

0 comments on commit e16731a

Please sign in to comment.