From f00e0277d82a46681a029226dcd87e68842fd749 Mon Sep 17 00:00:00 2001 From: mathieulemieux Date: Wed, 28 Aug 2024 14:57:03 -0700 Subject: [PATCH 1/3] KBDEV-1240 make entrez gene records updatable --- src/entrez/gene.js | 34 ++++++++++++++++++++++------------ src/entrez/util.js | 7 ++++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/entrez/gene.js b/src/entrez/gene.js index 2c7b428a..dd1cdeed 100644 --- a/src/entrez/gene.js +++ b/src/entrez/gene.js @@ -49,19 +49,29 @@ const parseRecord = (record) => { * * @param {ApiConnection} api connection to GraphKB * @param {Array.} idList list of gene IDs + * @param {object} opt + * @param {boolean} opt.fetchFirst override util.uploadRecord() fetchFirst + * @param {boolean} opt.upsert override util.uploadRecord() upsert */ -const fetchAndLoadGeneByIds = async (api, idListIn) => util.fetchAndLoadByIds( - api, - idListIn, - { - MAX_CONSEC, - cache: CACHE, - dbName: DB_NAME, - parser: parseRecord, - sourceDefn: SOURCE_DEFN, - target: 'Feature', - }, -); +const fetchAndLoadGeneByIds = async (api, idListIn, opt = {}) => { + // For record update, set fetchFirst to false & upsert to true. + const { fetchFirst, upsert } = opt; + + return util.fetchAndLoadByIds( + api, + idListIn, + { + MAX_CONSEC, + cache: CACHE, + dbName: DB_NAME, + fetchFirst, + parser: parseRecord, + sourceDefn: SOURCE_DEFN, + target: 'Feature', + upsert, + }, + ) +}; /** * Given a gene symbol, search the genes and upload the resulting records to graphkb diff --git a/src/entrez/util.js b/src/entrez/util.js index afb6ee7e..ef2e67c4 100644 --- a/src/entrez/util.js +++ b/src/entrez/util.js @@ -138,6 +138,7 @@ const fetchRecord = async (api, { * @param {boolean} opt.fetchFirst attempt to get the record by source Id before uploading it * @param {string} opt.target * @param {object} opt.sourceDefn + * @param {boolean} opt.upsert update the record if already exists * @param {function} opt.createDisplayName */ const uploadRecord = async (api, content, opt = {}) => { @@ -257,14 +258,16 @@ const preLoadCache = async (api, { sourceDefn, cache, target }) => { * @param {Array.} idListIn list of pubmed IDs * @param {Object} opt * @param {string} opt.dbName name of the entrez db to pull from ex. gene + * @param {boolean} opt.fetchFirst override uploadRecord() fetchFirst * @param {function} opt.parser function to convert records from the api to the graphkb format * @param {object} opt.cache * @param {number} opt.MAX_CONSEC maximum consecutive records to upload at once * @param {string} opt.target the graphkb api target to upload to * @param {object} opt.sourceDefn the object with the source information + * @param {boolean} opt.upsert override uploadRecord() upsert */ const fetchAndLoadByIds = async (api, idListIn, { - dbName, parser, cache, MAX_CONSEC = 100, target, sourceDefn, + dbName, fetchFirst, parser, cache, MAX_CONSEC = 100, target, sourceDefn, upsert }) => { const records = await fetchByIdList( idListIn, @@ -281,8 +284,10 @@ const fetchAndLoadByIds = async (api, idListIn, { const newRecords = await Promise.all(current.map( async record => uploadRecord(api, record, { cache, + fetchFirst, sourceDefn, target, + upsert, }), )); result.push(...newRecords); From 51e587f8a7117d299c4b4936908338ea811279f5 Mon Sep 17 00:00:00 2001 From: mathieulemieux Date: Wed, 28 Aug 2024 15:01:03 -0700 Subject: [PATCH 2/3] linting --- src/entrez/gene.js | 2 +- src/entrez/util.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/entrez/gene.js b/src/entrez/gene.js index dd1cdeed..c7c645d6 100644 --- a/src/entrez/gene.js +++ b/src/entrez/gene.js @@ -70,7 +70,7 @@ const fetchAndLoadGeneByIds = async (api, idListIn, opt = {}) => { target: 'Feature', upsert, }, - ) + ); }; /** diff --git a/src/entrez/util.js b/src/entrez/util.js index ef2e67c4..8dc7bcd4 100644 --- a/src/entrez/util.js +++ b/src/entrez/util.js @@ -267,7 +267,14 @@ const preLoadCache = async (api, { sourceDefn, cache, target }) => { * @param {boolean} opt.upsert override uploadRecord() upsert */ const fetchAndLoadByIds = async (api, idListIn, { - dbName, fetchFirst, parser, cache, MAX_CONSEC = 100, target, sourceDefn, upsert + dbName, + fetchFirst, + parser, + cache, + MAX_CONSEC = 100, + target, + sourceDefn, + upsert, }) => { const records = await fetchByIdList( idListIn, From 5a83dc3879d9f0c3aa1de6fc824cb0c11279078a Mon Sep 17 00:00:00 2001 From: mathieulemieux Date: Thu, 29 Aug 2024 10:54:06 -0700 Subject: [PATCH 3/3] Add logger to util exports --- src/util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.js b/src/util.js index 6fa40c8e..45c492ab 100644 --- a/src/util.js +++ b/src/util.js @@ -234,6 +234,7 @@ module.exports = { hashStringToId, loadDelimToJson, loadXmlToJson, + logger, parseXmlToJson, request, requestWithRetry,