From 9c441889833dcf99a88ad82cee788fa57a7f9912 Mon Sep 17 00:00:00 2001 From: David Glymph Date: Fri, 17 May 2024 16:59:01 -0400 Subject: [PATCH] filter biolink slots by descendants of `related to` --- src/stores/useBiolinkModel.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/stores/useBiolinkModel.js b/src/stores/useBiolinkModel.js index 448417ac..33fde7a8 100644 --- a/src/stores/useBiolinkModel.js +++ b/src/stores/useBiolinkModel.js @@ -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; }