Skip to content

Commit

Permalink
filter biolink slots by descendants of related to
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed May 17, 2024
1 parent 1f2a600 commit 9c44188
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/stores/useBiolinkModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ export default function useBiolinkModel() {
const [ancestorsMap, setAncestorsMap] = useState([]);
const colorMap = useCallback(getNodeCategoryColorMap(hierarchies), [hierarchies]);

function checkIfDescendantOfRelatedTo([name, slot]) {
let currentName = name;
let current = slot;
while (current.is_a) {
currentName = current.is_a;
current = biolinkModel.slots[current.is_a];
}
return currentName === 'related to';
}

/**
* Get a list of all predicates in the biolink model
* @returns {object[]} list of predicate objects
*/
function getEdgePredicates() {
const newPredicates = Object.entries(biolinkModel.slots).map(([identifier, predicate]) => ({
predicate: strings.edgeFromBiolink(identifier),
domain: strings.nodeFromBiolink(predicate.domain),
range: strings.nodeFromBiolink(predicate.range),
}));
const newPredicates =
Object.entries(biolinkModel.slots)
.filter(checkIfDescendantOfRelatedTo)
.map(([identifier, predicate]) => ({
predicate: strings.edgeFromBiolink(identifier),
domain: strings.nodeFromBiolink(predicate.domain),
range: strings.nodeFromBiolink(predicate.range),
}));
return newPredicates;
}

Expand Down

0 comments on commit 9c44188

Please sign in to comment.