Skip to content

Commit

Permalink
Merge pull request #211 from biothings/pfocr-changes
Browse files Browse the repository at this point in the history
Reduce query ids by only using bound nodes for pfocr figure search
  • Loading branch information
tokebe authored Aug 22, 2024
2 parents f4ae7fa + 5a527a5 commit f90197c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/results_assembly/pfocr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,16 @@ export async function enrichTrapiResultsWithPfocrFigures(response: TrapiResponse
const curiesByResult: Map<TrapiResult, Set<string>> = new Map();

const curieCombos: Set<string> = results.reduce((combos: Set<string>, result: TrapiResult) => {
const nodes: Set<TrapiKGNode> = traverseResultForNodes(result, response);
const nodes: Set<TrapiKGNode> = new Set();
Object.values(result.node_bindings).forEach((bindings) =>
bindings.forEach((binding) => nodes.add(response.message.knowledge_graph.nodes[binding.id])),
);
const combo: Set<string> = 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}:`, '');
Expand Down Expand Up @@ -257,7 +260,18 @@ 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<string> = [...resultNodes].reduce((curies, node) => {
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}:`, '');
if (Object.keys(SUPPORTED_PREFIXES).includes(prefix)) curies.add(suffix);
});
return curies;
}, new Set<string>());

const resultGenesInAllFigures = intersection(allGenesInAllFigures, resultCuries);

(figuresByCuries[curieCombosByResult.get(trapiResult)] ?? []).forEach((figure) => {
Expand Down

0 comments on commit f90197c

Please sign in to comment.