Skip to content

Commit

Permalink
Merge pull request #164 from bcgsc/feature/KBDEV-1240-update-entrez-g…
Browse files Browse the repository at this point in the history
…ene-records

Feature/kbdev 1240 update entrez gene records
mathieulemieux authored Sep 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 9d0c49d + 5a83dc3 commit cf2606e
Showing 3 changed files with 36 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/entrez/gene.js
Original file line number Diff line number Diff line change
@@ -49,19 +49,29 @@ const parseRecord = (record) => {
*
* @param {ApiConnection} api connection to GraphKB
* @param {Array.<string>} 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
14 changes: 13 additions & 1 deletion src/entrez/util.js
Original file line number Diff line number Diff line change
@@ -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,23 @@ const preLoadCache = async (api, { sourceDefn, cache, target }) => {
* @param {Array.<string>} 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 +291,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);
1 change: 1 addition & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -234,6 +234,7 @@ module.exports = {
hashStringToId,
loadDelimToJson,
loadXmlToJson,
logger,
parseXmlToJson,
request,
requestWithRetry,

0 comments on commit cf2606e

Please sign in to comment.