From 79e71757fc0f4ac1da5a779a1b46dbdd65cb1aac Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:42:33 -0400 Subject: [PATCH 1/2] chore: reduce query ids by only using bound nodes --- src/results_assembly/pfocr.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/results_assembly/pfocr.ts b/src/results_assembly/pfocr.ts index fbe651c2..41f0dee7 100644 --- a/src/results_assembly/pfocr.ts +++ b/src/results_assembly/pfocr.ts @@ -188,13 +188,16 @@ export async function enrichTrapiResultsWithPfocrFigures(response: TrapiResponse const curiesByResult: Map> = new Map(); const curieCombos: Set = results.reduce((combos: Set, result: TrapiResult) => { - const nodes: Set = traverseResultForNodes(result, response); + const nodes: Set = new Set(); + Object.values(result.node_bindings).forEach((bindings) => + bindings.forEach((binding) => nodes.add(response.message.knowledge_graph.nodes[binding.id])), + ); const combo: Set = new Set(); let matchedNodes = 0; [...nodes].forEach((node) => { let nodeMatched = false; - const equivalentCuries = node.attributes?.find((attribute) => attribute.attribute_type_id === 'biolink:xref') - .value as string[]; + const equivalentCuries = + (node.attributes?.find((attribute) => attribute.attribute_type_id === 'biolink:xref')?.value as string[]) ?? []; equivalentCuries.forEach((curie) => { const prefix = curie.split(':')[0]; const suffix = curie.replace(`${prefix}:`, ''); @@ -257,7 +260,14 @@ export async function enrichTrapiResultsWithPfocrFigures(response: TrapiResponse // No figures match this result if (!figuresByCuries[curieCombosByResult.get(trapiResult)]) continue; - const resultCuries = curiesByResult.get(trapiResult); + const resultNodes = traverseResultForNodes(trapiResult, response); + const resultCuries: Set = [...resultNodes].reduce((curies, node) => { + const equivalentCuries = + (node.attributes?.find((attribute) => attribute.attribute_type_id === 'biolink:xref')?.value as string[]) ?? []; + equivalentCuries.forEach((curie) => curies.add(curie.split(':').slice(1).join(''))); + return curies; + }, new Set()); + const resultGenesInAllFigures = intersection(allGenesInAllFigures, resultCuries); (figuresByCuries[curieCombosByResult.get(trapiResult)] ?? []).forEach((figure) => { From 5a527a5627535e0a8f06adb5637136f8988d13ef Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:55:41 -0400 Subject: [PATCH 2/2] fix: only keep supported prefixes --- src/results_assembly/pfocr.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/results_assembly/pfocr.ts b/src/results_assembly/pfocr.ts index 41f0dee7..5fab0980 100644 --- a/src/results_assembly/pfocr.ts +++ b/src/results_assembly/pfocr.ts @@ -264,7 +264,11 @@ export async function enrichTrapiResultsWithPfocrFigures(response: TrapiResponse const resultCuries: Set = [...resultNodes].reduce((curies, node) => { const equivalentCuries = (node.attributes?.find((attribute) => attribute.attribute_type_id === 'biolink:xref')?.value as string[]) ?? []; - equivalentCuries.forEach((curie) => curies.add(curie.split(':').slice(1).join(''))); + equivalentCuries.forEach((curie) => { + const prefix = curie.split(':')[0]; + const suffix = curie.replace(`${prefix}:`, ''); + if (Object.keys(SUPPORTED_PREFIXES).includes(prefix)) curies.add(suffix); + }); return curies; }, new Set());