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

Primary knowledge refactor #137

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 8 additions & 12 deletions src/graph/knowledge_graph.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const debug = require('debug')('bte:biothings-explorer-trapi:KnowledgeGraph');

module.exports = class KnowledgeGraph {
constructor() {
constructor(apiList) {
this.nodes = {};
this.edges = {};
this.kg = {
nodes: this.nodes,
edges: this.edges,
};
this.apiList = apiList;
}

getNodes() {
Expand Down Expand Up @@ -84,28 +85,23 @@ module.exports = class KnowledgeGraph {
},
];

const direct_info_providers = this.apiList?.filter(e => e.primarySource)?.map(e => e.name) ?? []

if (kgEdge.attributes['edge-attributes']) {
//handle TRAPI APIs (Situation A of https://github.com/biothings/BioThings_Explorer_TRAPI/issues/208) and APIs that define 'edge-atributes' in x-bte
attributes = [...attributes, ...kgEdge.attributes['edge-attributes']];
} else if (
//handle direct info providers (Situation C of https://github.com/biothings/BioThings_Explorer_TRAPI/issues/208)
[
'Clinical Risk KP API',
'Text Mining Targeted Association API',
'Multiomics Wellness KP API',
'Drug Response KP API',
'Text Mining Co-occurrence API',
'TCGA Mutation Frequency API',
].some((api_name) => kgEdge.apis.has(api_name))
direct_info_providers.some((api_name) => kgEdge.apis.has(api_name))
) {
attributes = [...attributes];
//primary knowledge source
if (Array.from(kgEdge.sources).length) {
if (Array.from(kgEdge.sources).length || Array.from(kgEdge.inforesCuries).length) {
attributes = [
...attributes,
{
attribute_type_id: 'biolink:primary_knowledge_source',
value: Array.from(kgEdge.sources),
value: [...Array.from(kgEdge.inforesCuries), ...Array.from(kgEdge.sources)],
value_type_id: 'biolink:InformationResource',
},
];
Expand All @@ -116,7 +112,7 @@ module.exports = class KnowledgeGraph {
...attributes.filter(attr => attr.attribute_type_id !== 'biolink:aggregator_knowledge_source'),
{
attribute_type_id: 'biolink:aggregator_knowledge_source',
value: ['infores:biothings-explorer', ...Array.from(kgEdge.inforesCuries)],
value: ['infores:biothings-explorer'],
value_type_id: 'biolink:InformationResource',
},
];
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
}

_initializeResponse() {
this.knowledgeGraph = new KnowledgeGraph();
this.knowledgeGraph = new KnowledgeGraph(this.options?.apiList?.include);
this.trapiResultsAssembler = new TrapiResultsAssembler();
this.bteGraph = new Graph();
this.bteGraph.subscribe(this.knowledgeGraph);
Expand Down