From bfe79ce323acf5802dc401dbeeaf253f36d06460 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Mon, 20 Feb 2023 18:07:08 -0800 Subject: [PATCH 1/4] use api list to identify primary knowledge source --- src/graph/knowledge_graph.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/graph/knowledge_graph.js b/src/graph/knowledge_graph.js index 47047719..a75385c5 100644 --- a/src/graph/knowledge_graph.js +++ b/src/graph/knowledge_graph.js @@ -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() { @@ -84,19 +85,14 @@ 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 @@ -105,7 +101,7 @@ module.exports = class KnowledgeGraph { ...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', }, ]; @@ -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', }, ]; From a782d7b37058acc0c662b43bd594d5c28fbc2d08 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Mon, 20 Feb 2023 18:07:18 -0800 Subject: [PATCH 2/4] pass api list to knowledge graph --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f44db287..76584433 100644 --- a/src/index.js +++ b/src/index.js @@ -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); From c308aa6ac483c652fec054a50ca84b73c2cd8c48 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Mon, 20 Feb 2023 18:22:29 -0800 Subject: [PATCH 3/4] handle abscense of api list --- src/graph/knowledge_graph.js | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph/knowledge_graph.js b/src/graph/knowledge_graph.js index a75385c5..004016eb 100644 --- a/src/graph/knowledge_graph.js +++ b/src/graph/knowledge_graph.js @@ -85,7 +85,7 @@ module.exports = class KnowledgeGraph { }, ]; - const direct_info_providers = this.apiList.filter(e => e.primarySource).map(e => e.name) + 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 diff --git a/src/index.js b/src/index.js index 76584433..b1711686 100644 --- a/src/index.js +++ b/src/index.js @@ -118,7 +118,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { } _initializeResponse() { - this.knowledgeGraph = new KnowledgeGraph(this.options.apiList['include']); + this.knowledgeGraph = new KnowledgeGraph(this.options?.apiList?.include); this.trapiResultsAssembler = new TrapiResultsAssembler(); this.bteGraph = new Graph(); this.bteGraph.subscribe(this.knowledgeGraph); From 3fffbd9554fe0350ffc87a798012b52edb30c997 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Thu, 9 Mar 2023 20:53:07 -0800 Subject: [PATCH 4/4] fix logic error --- src/graph/knowledge_graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph/knowledge_graph.js b/src/graph/knowledge_graph.js index 004016eb..4153cc64 100644 --- a/src/graph/knowledge_graph.js +++ b/src/graph/knowledge_graph.js @@ -96,7 +96,7 @@ module.exports = class KnowledgeGraph { ) { attributes = [...attributes]; //primary knowledge source - if (Array.from(kgEdge.sources).length) { + if (Array.from(kgEdge.sources).length || Array.from(kgEdge.inforesCuries).length) { attributes = [ ...attributes, {