From 7dd4c909b04fb1569498d135b8d22f82a441459a Mon Sep 17 00:00:00 2001 From: rjawesome Date: Tue, 1 Oct 2024 15:57:17 -0700 Subject: [PATCH 1/5] properly merge semmedb sentences --- src/graph/kg_edge.ts | 3 ++- src/graph/knowledge_graph.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/graph/kg_edge.ts b/src/graph/kg_edge.ts index 797c82f1..baee66ea 100644 --- a/src/graph/kg_edge.ts +++ b/src/graph/kg_edge.ts @@ -120,7 +120,8 @@ export default class KGEdge { addAdditionalAttributes(name: string, value: string | string[] | TrapiAttribute[]): void { // special handling for full edge attributes if (name === 'edge-attributes') { - this.attributes[name] = value as TrapiAttribute[]; + if (this.attributes[name]) this.attributes[name] = [...this.attributes[name], ...value as TrapiAttribute[]]; + else this.attributes[name] = value as TrapiAttribute[]; return; } diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index 1a28e9ca..339bc11d 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -167,7 +167,14 @@ export default class KnowledgeGraph { }); //handle TRAPI APIs (Situation A of https://github.com/biothings/BioThings_Explorer_TRAPI/issues/208) and APIs that define 'edge-atributes' in x-bte + const seenPmids = new Set(); kgEdge.attributes['edge-attributes']?.forEach((attribute) => { + // Merge SemmedDB sentences + if (attribute.attribute_type_id === "biolink:has_supporting_study_result" && attribute?.attributes?.find((attr) => attr.attribute_type_id === "biolink:publications")) { + const publication = attribute.attributes.find((attr) => attr.attribute_type_id === "biolink:publications").value; + if (seenPmids.has(publication) || seenPmids.size > 50) return; // do not include duplicate publications + seenPmids.add(publication); + } attributes.push(attribute); }); return attributes; From b27a52dc325cdd66176ed41ab0555d34bbf258b4 Mon Sep 17 00:00:00 2001 From: rjawesome Date: Fri, 4 Oct 2024 15:20:50 -0700 Subject: [PATCH 2/5] fix off by one error with pmids --- src/graph/knowledge_graph.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index 339bc11d..cf97c704 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -172,7 +172,7 @@ export default class KnowledgeGraph { // Merge SemmedDB sentences if (attribute.attribute_type_id === "biolink:has_supporting_study_result" && attribute?.attributes?.find((attr) => attr.attribute_type_id === "biolink:publications")) { const publication = attribute.attributes.find((attr) => attr.attribute_type_id === "biolink:publications").value; - if (seenPmids.has(publication) || seenPmids.size > 50) return; // do not include duplicate publications + if (seenPmids.has(publication) || seenPmids.size >= 50) return; // do not include duplicate publications seenPmids.add(publication); } attributes.push(attribute); From b516a74cc95c1d3fd5e2f1eb52d11b1488b3b85f Mon Sep 17 00:00:00 2001 From: rjawesome Date: Fri, 4 Oct 2024 15:27:03 -0700 Subject: [PATCH 3/5] add evidence count attribute based on semmed sentences --- src/graph/knowledge_graph.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index cf97c704..2418ceda 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -177,6 +177,19 @@ export default class KnowledgeGraph { } attributes.push(attribute); }); + + if (seenPmids.size != 0) { + const evidenceAttr = attributes.find(attr => attr.attribute_type_id === 'biolink:evidence_count'); + if (evidenceAttr) { + evidenceAttr.value = seenPmids.size; + } else { + attributes.push({ + attribute_type_id: 'biolink:evidence_count', + value: seenPmids.size, + }); + } + } + return attributes; } From 1d1f94c260a1755cdc042f2fc7c2783c26f46a14 Mon Sep 17 00:00:00 2001 From: rjawesome Date: Fri, 4 Oct 2024 15:32:17 -0700 Subject: [PATCH 4/5] better comments --- src/graph/knowledge_graph.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index 2418ceda..4f5f66b9 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -169,15 +169,17 @@ export default class KnowledgeGraph { //handle TRAPI APIs (Situation A of https://github.com/biothings/BioThings_Explorer_TRAPI/issues/208) and APIs that define 'edge-atributes' in x-bte const seenPmids = new Set(); kgEdge.attributes['edge-attributes']?.forEach((attribute) => { - // Merge SemmedDB sentences + // Do not add multiple SemmedDB sentences/other "supporting study results" from the same publication if (attribute.attribute_type_id === "biolink:has_supporting_study_result" && attribute?.attributes?.find((attr) => attr.attribute_type_id === "biolink:publications")) { const publication = attribute.attributes.find((attr) => attr.attribute_type_id === "biolink:publications").value; - if (seenPmids.has(publication) || seenPmids.size >= 50) return; // do not include duplicate publications + if (seenPmids.has(publication) || seenPmids.size >= 50) return; // publication has been seen or cap reached seenPmids.add(publication); } + attributes.push(attribute); }); + // update evidence count after PMIDs have been merged (for SemmedDB) if (seenPmids.size != 0) { const evidenceAttr = attributes.find(attr => attr.attribute_type_id === 'biolink:evidence_count'); if (evidenceAttr) { From 38f52618ace4f16c1d3b5b68f7fb313c79a7d1a2 Mon Sep 17 00:00:00 2001 From: rjawesome Date: Fri, 18 Oct 2024 10:24:31 -0700 Subject: [PATCH 5/5] remove cap for evidence count --- src/graph/knowledge_graph.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index 4f5f66b9..4897aeb6 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -172,7 +172,11 @@ export default class KnowledgeGraph { // Do not add multiple SemmedDB sentences/other "supporting study results" from the same publication if (attribute.attribute_type_id === "biolink:has_supporting_study_result" && attribute?.attributes?.find((attr) => attr.attribute_type_id === "biolink:publications")) { const publication = attribute.attributes.find((attr) => attr.attribute_type_id === "biolink:publications").value; - if (seenPmids.has(publication) || seenPmids.size >= 50) return; // publication has been seen or cap reached + // publication has been seen or cap reached + if (seenPmids.has(publication) || seenPmids.size >= 50) { + seenPmids.add(publication); + return; + } seenPmids.add(publication); }