From 236278e864c2a4f532cad4436897fb1743d9a4ee Mon Sep 17 00:00:00 2001 From: David Glymph Date: Sun, 16 Feb 2025 13:42:33 -0500 Subject: [PATCH 1/2] add curies back to csv + header --- src/components/DownloadDialog.jsx | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/components/DownloadDialog.jsx b/src/components/DownloadDialog.jsx index 171bfdf0..a78578b2 100644 --- a/src/components/DownloadDialog.jsx +++ b/src/components/DownloadDialog.jsx @@ -19,6 +19,27 @@ const jsonToCsvString = (json) => new Promise((res, rej) => { }); }); +const constructCsvObj = (message) => { + const nodeLabelHeaders = Object.keys( + message.results[0].node_bindings, + ).flatMap((node_label) => [`${node_label} (Name)`, `${node_label} (CURIE)`]); + const header = [...nodeLabelHeaders, 'Score']; + + const body = message.results.map((result) => { + const row = []; + Object.values(result.node_bindings).forEach((nb) => { + const curie = nb[0].id; + const node = message.knowledge_graph.nodes[curie]; + row.push(node.name || node.categories[0]); + row.push(curie); + }); + row.push(result.score); + return row; + }); + + return [header, ...body]; +}; + export default function DownloadDialog({ open, setOpen, message, }) { @@ -35,12 +56,7 @@ export default function DownloadDialog({ blob = new Blob([JSON.stringify({ message }, null, 2)], { type: 'application/json' }); } if (type === 'csv') { - const subsetMessage = message.results.map((r) => [ - ...Object.values(r.node_bindings).map((nb) => { - const node = message.knowledge_graph.nodes[nb[0].id]; - return node.name || node.categories[0]; - }), r.score]); - const csvString = await jsonToCsvString(subsetMessage); + const csvString = await jsonToCsvString(constructCsvObj(message)); blob = new Blob([csvString], { type: 'text/csv' }); } From b3c81afcb0e0a8d7828c7c94ed6f621735401285 Mon Sep 17 00:00:00 2001 From: David Glymph Date: Sun, 16 Feb 2025 14:08:04 -0500 Subject: [PATCH 2/2] add publications to csv --- src/components/DownloadDialog.jsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/DownloadDialog.jsx b/src/components/DownloadDialog.jsx index a78578b2..637383d9 100644 --- a/src/components/DownloadDialog.jsx +++ b/src/components/DownloadDialog.jsx @@ -19,11 +19,32 @@ const jsonToCsvString = (json) => new Promise((res, rej) => { }); }); +const constructPmidOrPmcLink = (id) => { + if (id.startsWith('PMID')) { + return `https://pubmed.ncbi.nlm.nih.gov/${id.split(':')[1]}`; + } + if (id.startsWith('PMC')) { + return `https://pmc.ncbi.nlm.nih.gov/articles/${id.split(':')[1]}`; + } + return ''; +}; + +const getConcatPublicationsForResult = (result, message) => { + const edgeIds = Object.values(result.analyses[0].edge_bindings) + .flat() + .map((e) => e.id); + const publications = edgeIds.flatMap((edgeId) => message.knowledge_graph.edges[edgeId].attributes.filter( + (attr) => attr.attribute_type_id === 'biolink:publications', + ).flatMap((attr) => attr.value)).map(constructPmidOrPmcLink); + + return publications; +}; + const constructCsvObj = (message) => { const nodeLabelHeaders = Object.keys( message.results[0].node_bindings, ).flatMap((node_label) => [`${node_label} (Name)`, `${node_label} (CURIE)`]); - const header = [...nodeLabelHeaders, 'Score']; + const header = [...nodeLabelHeaders, 'Score', 'Publications']; const body = message.results.map((result) => { const row = []; @@ -34,6 +55,8 @@ const constructCsvObj = (message) => { row.push(curie); }); row.push(result.score); + row.push(getConcatPublicationsForResult(result, message).join('\n')); + return row; });