Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce query ids by only using bound nodes for pfocr figure search #211

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading