From 9f5ef9ccbeda4bd2909e1c081536a3fb94010648 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Wed, 25 Sep 2024 13:07:19 -0700 Subject: [PATCH 01/13] handle moa loader errors --- src/moa/index.js | 74 ++++++++++++++++++++++++++++++----------------- src/moa/spec.json | 20 +++---------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 63598a70..b36a4c2d 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -256,28 +256,35 @@ const loadVariant = async (conn, moaVariant) => { }); } } else if (moaVariant.feature_type === 'mutational_signature') { - const signature = await conn.getUniqueRecordBy({ + const signature = await conn.getRecords({ filters: { AND: [ { source: { filters: { name: 'cosmic' }, target: 'Source' } }, - { sourceId: `SBS${Number.parseInt(moaVariant.cosmic_signature_number, 10)}` }, - { sourceIdVersion: `${Number.parseInt(moaVariant.cosmic_signature_version, 10)}` }, + { sourceId: moaVariant.cosmic_signature}, ], }, target: 'Signature', }); const variantType = await conn.getVocabularyTerm('signature present'); - return conn.addVariant({ - content: { - // KBDEV-994 adding displayName - // TODO: test displayName in KBDEV-993 and remove both comments. - displayName: `${signature.name.toUpperCase()} signature present`, - reference1: rid(signature), - type: rid(variantType), - }, - existsOk: true, - target: 'CategoryVariant', - }); + try{ + const record = await conn.getUniqueRecordBy({ + filters: { AND: [{ reference1: rid(signature[0])}, { type: rid(variantType) }] }, + target: 'CategoryVariant', + }); + return await conn.updateRecord('CategoryVariant', record['@rid'], { + displayName: `${signature[0].name.toUpperCase()} signature present` + }); + } catch(err) { + return await conn.addVariant({ + content: { + displayName: `${signature[0].name.toUpperCase()} signature present`, + reference1: rid(signature[0]), + type: rid(variantType), + }, + existsOk: true, + target: 'CategoryVariant', + }); + } // } else if (moaVariant.feature_type === 'mutational_burden') { } else if (moaVariant.feature_type === 'copy_number') { const variantType = await conn.getVocabularyTerm(moaVariant.direction); @@ -309,7 +316,6 @@ const loadRecord = async (conn, moaRecord, moaSource, relevanceTerms) => { disease = await conn.getUniqueRecordBy({ filters: { AND: [ - { name: moaRecord.oncotree_term }, { sourceId: moaRecord.oncotree_code }, { source: { filters: { name: 'oncotree' }, target: 'Source' } }, ], @@ -362,18 +368,30 @@ const loadRecord = async (conn, moaRecord, moaSource, relevanceTerms) => { if (sourceRecord.nct && sourceRecord.source_type !== 'Abstract') { articles.push(await _trials.fetchAndLoadById(conn, sourceRecord.nct)); } else if (['FDA', 'Guideline'].includes(sourceRecord.source_type)) { - articles.push(await conn.addRecord({ - content: { + try { + const record = await conn.getUniqueRecordBy({ + filters: { AND: [{ source: rid(moaSource)}, { sourceId: sourceRecord.source_id }, {name: `${sourceRecord.source_type}-${sourceRecord.source_id}`}] }, + target: 'CuratedContent', + }); + articles.push(await conn.updateRecord('CuratedContent', record['@rid'], { citation: sourceRecord.citation, displayName: `${SOURCE_DEFN.displayName} ${sourceRecord.source_type}-${sourceRecord.source_id}`, - name: `${sourceRecord.source_type}-${sourceRecord.source_id}`, - source: rid(moaSource), - sourceId: sourceRecord.source_id, url: sourceRecord.url, - }, - existsOk: true, - target: 'CuratedContent', - })); + })); + } catch(err) { + articles.push(await conn.addRecord({ + content: { + citation: sourceRecord.citation, + displayName: `${SOURCE_DEFN.displayName} ${sourceRecord.source_type}-${sourceRecord.source_id}`, + name: `${sourceRecord.source_type}-${sourceRecord.source_id}`, + source: rid(moaSource), + sourceId: sourceRecord.source_id, + url: sourceRecord.url, + }, + existsOk: true, + target: 'CuratedContent', + })); + } } else { throw Error(`Unable to process evidence (${sourceRecord.source_type})`); } @@ -503,9 +521,9 @@ const parseRelevance = (moaRecord) => { relevance.push('no sensitivity'); } } - if (moaRecord.favorable_prognosis === true) { + if (moaRecord.favorable_prognosis === 1) { relevance.push('favourable prognosis'); - } else if (moaRecord.favorable_prognosis === false) { + } else if (moaRecord.favorable_prognosis === 0) { relevance.push('unfavourable prognosis'); } @@ -553,6 +571,10 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => try { logger.info(`loading: ${rawRecord.assertion_id} / ${records.length}`); const record = fixStringNulls(rawRecord); + // handle empty space in url + if (record.sources[0].url && record.sources[0].url.includes(' ')){ + record.sources[0].url = record.sources[0].url.replace(/\s/g,''); + } checkSpec(validateMoaRecord, record); const key = `${record.assertion_id}`; const lastUpdate = new Date(record.last_updated).getTime(); diff --git a/src/moa/spec.json b/src/moa/spec.json index dc5c5df3..7eb72f3b 100644 --- a/src/moa/spec.json +++ b/src/moa/spec.json @@ -36,10 +36,6 @@ ] }, "rearrangement_type": { - "enum": [ - "Translocation", - "Fusion" - ], "type": [ "string", "null" @@ -56,7 +52,7 @@ { "properties": { "alternate_allele": { - "pattern": "^[ATCG]*$", + "pattern": "^[ATCG-]*$", "type": [ "string", "null" @@ -173,7 +169,7 @@ }, "pathogenic": { "enum": [ - "1.0", + "1", null ] }, @@ -285,24 +281,16 @@ }, { "properties": { - "cosmic_signature_number": { - "pattern": "^\\d+$", + "cosmic_signature": { "type": "string" }, - "cosmic_signature_version": { - "enum": [ - "2.0", - "2" - ] - }, "feature_type": { "const": "mutational_signature" } }, "required": [ "feature_type", - "cosmic_signature_number", - "cosmic_signature_version" + "cosmic_signature" ], "type": "object" }, From 1814293a42d9da066f5b237b93da7eeb9348d9c3 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Wed, 25 Sep 2024 13:25:08 -0700 Subject: [PATCH 02/13] fix lint --- src/moa/index.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index b36a4c2d..06141b1a 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -260,22 +260,23 @@ const loadVariant = async (conn, moaVariant) => { filters: { AND: [ { source: { filters: { name: 'cosmic' }, target: 'Source' } }, - { sourceId: moaVariant.cosmic_signature}, + { sourceId: moaVariant.cosmic_signature }, ], }, target: 'Signature', }); const variantType = await conn.getVocabularyTerm('signature present'); - try{ - const record = await conn.getUniqueRecordBy({ - filters: { AND: [{ reference1: rid(signature[0])}, { type: rid(variantType) }] }, + + try { + const record = await conn.getUniqueRecordBy({ + filters: { AND: [{ reference1: rid(signature[0]) }, { type: rid(variantType) }] }, target: 'CategoryVariant', }); return await conn.updateRecord('CategoryVariant', record['@rid'], { - displayName: `${signature[0].name.toUpperCase()} signature present` + displayName: `${signature[0].name.toUpperCase()} signature present`, }); - } catch(err) { - return await conn.addVariant({ + } catch (err) { + return conn.addVariant({ content: { displayName: `${signature[0].name.toUpperCase()} signature present`, reference1: rid(signature[0]), @@ -370,7 +371,7 @@ const loadRecord = async (conn, moaRecord, moaSource, relevanceTerms) => { } else if (['FDA', 'Guideline'].includes(sourceRecord.source_type)) { try { const record = await conn.getUniqueRecordBy({ - filters: { AND: [{ source: rid(moaSource)}, { sourceId: sourceRecord.source_id }, {name: `${sourceRecord.source_type}-${sourceRecord.source_id}`}] }, + filters: { AND: [{ source: rid(moaSource) }, { sourceId: sourceRecord.source_id }, { name: `${sourceRecord.source_type}-${sourceRecord.source_id}` }] }, target: 'CuratedContent', }); articles.push(await conn.updateRecord('CuratedContent', record['@rid'], { @@ -378,7 +379,7 @@ const loadRecord = async (conn, moaRecord, moaSource, relevanceTerms) => { displayName: `${SOURCE_DEFN.displayName} ${sourceRecord.source_type}-${sourceRecord.source_id}`, url: sourceRecord.url, })); - } catch(err) { + } catch (err) { articles.push(await conn.addRecord({ content: { citation: sourceRecord.citation, @@ -571,9 +572,10 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => try { logger.info(`loading: ${rawRecord.assertion_id} / ${records.length}`); const record = fixStringNulls(rawRecord); + // handle empty space in url - if (record.sources[0].url && record.sources[0].url.includes(' ')){ - record.sources[0].url = record.sources[0].url.replace(/\s/g,''); + if (record.sources[0].url && record.sources[0].url.includes(' ')) { + record.sources[0].url = record.sources[0].url.replace(/\s/g, ''); } checkSpec(validateMoaRecord, record); const key = `${record.assertion_id}`; From 10b43797ba0f1cb0d79e64e8c1709e03344a99a8 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Wed, 25 Sep 2024 14:04:53 -0700 Subject: [PATCH 03/13] fix test --- test/moa.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/moa.test.js b/test/moa.test.js index fe5ae5cd..c4657271 100644 --- a/test/moa.test.js +++ b/test/moa.test.js @@ -77,14 +77,14 @@ describe('parseRelevance', () => { test('favorable prognosis', () => { expect(parseRelevance({ - favorable_prognosis: true, + favorable_prognosis: 1, features: [], })).toEqual(['favourable prognosis']); }); test('unfavorable prognosis', () => { expect(parseRelevance({ - favorable_prognosis: false, + favorable_prognosis: 0, features: [], })).toEqual(['unfavourable prognosis']); }); From 951f5f4f3c285fc354619d384c30613e4147264f Mon Sep 17 00:00:00 2001 From: sshugsc Date: Tue, 1 Oct 2024 14:14:05 -0700 Subject: [PATCH 04/13] update signature present to high signature --- src/moa/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moa/index.js b/src/moa/index.js index 06141b1a..8c1543f5 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -265,7 +265,7 @@ const loadVariant = async (conn, moaVariant) => { }, target: 'Signature', }); - const variantType = await conn.getVocabularyTerm('signature present'); + const variantType = await conn.getVocabularyTerm('high signature'); try { const record = await conn.getUniqueRecordBy({ From 413827bc687ccae9f0871c2f1c60b24950414e72 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Tue, 8 Oct 2024 11:30:23 -0700 Subject: [PATCH 05/13] remove no longer maintained MOA reords --- src/moa/index.js | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 8c1543f5..a22c3cc4 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -544,6 +544,18 @@ const parseRelevance = (moaRecord) => { return relevance; }; +const removeRecords = async (conn, records) => { + if (records.length && records.length > 0) { + for (const record of records) { + try{ + await conn.deleteRecord('Statement', record['@rid']); + logger.info(`Removing Statement ${record['@rid']} that are out of date`); + } catch (err) { + logger.warn(`${err}`); + } + } + } +}; const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => { const source = await conn.addSource(SOURCE_DEFN); @@ -559,6 +571,12 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => const existing = {}; + const newIds = records.map(record => record.assertion_id); + let toRemove = existingRecords.filter( + record => !newIds.includes(parseInt(record.sourceId, 10)), + ); + await removeRecords(conn, toRemove); + for (const record of existingRecords) { const key = record.sourceId; @@ -573,41 +591,31 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => logger.info(`loading: ${rawRecord.assertion_id} / ${records.length}`); const record = fixStringNulls(rawRecord); + if (record.assertion_id === 258){ + logger.info(`loading: ${rawRecord.assertion_id}`); + } // handle empty space in url if (record.sources[0].url && record.sources[0].url.includes(' ')) { record.sources[0].url = record.sources[0].url.replace(/\s/g, ''); } checkSpec(validateMoaRecord, record); const key = `${record.assertion_id}`; - const lastUpdate = new Date(record.last_updated).getTime(); const relevance = parseRelevance(record); - // do we have the expected number of GraphKB records for this MOA assertion - if (existing[key] && existing[key].length === relevance.length) { - // check the last update date of the assertion against the timestamp in GraphKB - if (existing[key].every(r => lastUpdate <= r.updatedAt)) { - logger.debug('Skip. Current record exists and does not need updating'); - counts.skipped++; - continue; - } - } const updatedRecords = (await loadRecord(conn, record, source, relevance)).map(r => r['@rid']); if (existing[key]) { - const toRemove = existing[key].map(r => r['@rid']).filter(r => !updatedRecords.includes(r)); - - if (toRemove.length) { - logger.warn(`Removing ${toRemove.length} records that are out of date`); - - for (const recordId of toRemove) { - await conn.deleteRecord('Statement', recordId); - } - } + toRemove = existing[key].filter(r => !updatedRecords.includes(r['@rid'])); + await removeRecords(conn, toRemove); } counts.success++; } catch (err) { logger.warn(`${err}`); counts.error++; + toRemove = existingRecords.filter( + record => rawRecord.assertion_id === parseInt(record.sourceId, 10), + ); + await removeRecords(conn, toRemove); if (err.toString().includes('Cannot read property')) { throw err; From ae26ba9e41a463bea7df8e7cce4006ae19442ef1 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Tue, 8 Oct 2024 11:41:13 -0700 Subject: [PATCH 06/13] lint --- src/moa/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index a22c3cc4..a4332da0 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -547,7 +547,7 @@ const parseRelevance = (moaRecord) => { const removeRecords = async (conn, records) => { if (records.length && records.length > 0) { for (const record of records) { - try{ + try { await conn.deleteRecord('Statement', record['@rid']); logger.info(`Removing Statement ${record['@rid']} that are out of date`); } catch (err) { @@ -591,9 +591,6 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => logger.info(`loading: ${rawRecord.assertion_id} / ${records.length}`); const record = fixStringNulls(rawRecord); - if (record.assertion_id === 258){ - logger.info(`loading: ${rawRecord.assertion_id}`); - } // handle empty space in url if (record.sources[0].url && record.sources[0].url.includes(' ')) { record.sources[0].url = record.sources[0].url.replace(/\s/g, ''); From f1c577c775d11f347690f2956cd9c35d74c86bf2 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Mon, 21 Oct 2024 12:04:20 -0700 Subject: [PATCH 07/13] remove checking for existing MOA records; add some work around for therapy name --- src/moa/index.js | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index a4332da0..2f4ac8c6 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -323,7 +323,7 @@ const loadRecord = async (conn, moaRecord, moaSource, relevanceTerms) => { }, target: 'Disease', }); - } else if (moaRecord.oncotree_term) { + } else if (moaRecord.oncotree_term & moaRecord.oncotree_term !== 'Any solid tumor') { disease = await conn.getUniqueRecordBy({ filters: { AND: [ @@ -334,6 +334,9 @@ const loadRecord = async (conn, moaRecord, moaSource, relevanceTerms) => { target: 'Disease', }); } else if (moaRecord.disease) { + if (moaRecord.disease === 'Any solid tumor') { + moaRecord.disease = 'all solid tumors'; + } disease = await conn.getUniqueRecordBy({ filters: { AND: [ @@ -563,28 +566,6 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => logger.info(`loaded ${records.length} assertions from MOA API`); const counts = { error: 0, skipped: 0, success: 0 }; - const existingRecords = await conn.getRecords({ - filters: { source: rid(source) }, - returnProperties: ['@rid', 'sourceId', 'updatedAt'], - target: 'Statement', - }); - - const existing = {}; - - const newIds = records.map(record => record.assertion_id); - let toRemove = existingRecords.filter( - record => !newIds.includes(parseInt(record.sourceId, 10)), - ); - await removeRecords(conn, toRemove); - - for (const record of existingRecords) { - const key = record.sourceId; - - if (existing[key] === undefined) { - existing[key] = []; - } - existing[key].push(record); - } for (const rawRecord of records) { try { @@ -595,24 +576,26 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => if (record.sources[0].url && record.sources[0].url.includes(' ')) { record.sources[0].url = record.sources[0].url.replace(/\s/g, ''); } + // work around to match with gkb records + if (record.therapy_name) { + if (record.therapy_name.includes("Amivantamab-vmjw")) { + record.therapy_name = record.therapy_name.replace("Amivantamab-vmjw","amivantamab"); + } else if (record.therapy_name === "KU0058684") { + record.therapy_name = "olaparib"; + } else if (record.therapy_name === "Tovorafenib") { + record.therapy_name = "pan-raf kinase inhibitor tak-580"; + } + } checkSpec(validateMoaRecord, record); const key = `${record.assertion_id}`; const relevance = parseRelevance(record); const updatedRecords = (await loadRecord(conn, record, source, relevance)).map(r => r['@rid']); - if (existing[key]) { - toRemove = existing[key].filter(r => !updatedRecords.includes(r['@rid'])); - await removeRecords(conn, toRemove); - } counts.success++; } catch (err) { logger.warn(`${err}`); counts.error++; - toRemove = existingRecords.filter( - record => rawRecord.assertion_id === parseInt(record.sourceId, 10), - ); - await removeRecords(conn, toRemove); if (err.toString().includes('Cannot read property')) { throw err; From 2f67d58d6261bd3486d44eb70136ff2f66ae1cae Mon Sep 17 00:00:00 2001 From: sshugsc Date: Mon, 21 Oct 2024 12:14:10 -0700 Subject: [PATCH 08/13] lint --- src/moa/index.js | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 2f4ac8c6..9d1d6cf0 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -547,19 +547,6 @@ const parseRelevance = (moaRecord) => { return relevance; }; -const removeRecords = async (conn, records) => { - if (records.length && records.length > 0) { - for (const record of records) { - try { - await conn.deleteRecord('Statement', record['@rid']); - logger.info(`Removing Statement ${record['@rid']} that are out of date`); - } catch (err) { - logger.warn(`${err}`); - } - } - } -}; - const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => { const source = await conn.addSource(SOURCE_DEFN); const records = await requestWithRetry({ json: true, method: 'GET', uri: url }); @@ -578,19 +565,18 @@ const upload = async ({ conn, url = 'https://moalmanac.org/api/assertions' }) => } // work around to match with gkb records if (record.therapy_name) { - if (record.therapy_name.includes("Amivantamab-vmjw")) { - record.therapy_name = record.therapy_name.replace("Amivantamab-vmjw","amivantamab"); - } else if (record.therapy_name === "KU0058684") { - record.therapy_name = "olaparib"; - } else if (record.therapy_name === "Tovorafenib") { - record.therapy_name = "pan-raf kinase inhibitor tak-580"; + if (record.therapy_name.includes('Amivantamab-vmjw')) { + record.therapy_name = record.therapy_name.replace('Amivantamab-vmjw', 'amivantamab'); + } else if (record.therapy_name === 'KU0058684') { + record.therapy_name = 'olaparib'; + } else if (record.therapy_name === 'Tovorafenib') { + record.therapy_name = 'pan-raf kinase inhibitor tak-580'; } } checkSpec(validateMoaRecord, record); - const key = `${record.assertion_id}`; const relevance = parseRelevance(record); - const updatedRecords = (await loadRecord(conn, record, source, relevance)).map(r => r['@rid']); + await loadRecord(conn, record, source, relevance); counts.success++; } catch (err) { From 773acb4f8a27cded40199e07d05bbaae26cf3938 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Mon, 21 Oct 2024 16:37:28 -0700 Subject: [PATCH 09/13] add cosmic signature version to filter --- src/moa/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 9d1d6cf0..9753f246 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -256,11 +256,12 @@ const loadVariant = async (conn, moaVariant) => { }); } } else if (moaVariant.feature_type === 'mutational_signature') { - const signature = await conn.getRecords({ + const signature = await conn.getUniqueRecordBy({ filters: { AND: [ { source: { filters: { name: 'cosmic' }, target: 'Source' } }, { sourceId: moaVariant.cosmic_signature }, + { sourceIdVersion: '3'}, ], }, target: 'Signature', @@ -269,17 +270,17 @@ const loadVariant = async (conn, moaVariant) => { try { const record = await conn.getUniqueRecordBy({ - filters: { AND: [{ reference1: rid(signature[0]) }, { type: rid(variantType) }] }, + filters: { AND: [{ reference1: rid(signature) }, { type: rid(variantType) }] }, target: 'CategoryVariant', }); return await conn.updateRecord('CategoryVariant', record['@rid'], { - displayName: `${signature[0].name.toUpperCase()} signature present`, + displayName: `${signature.name.toUpperCase()} signature present`, }); } catch (err) { return conn.addVariant({ content: { - displayName: `${signature[0].name.toUpperCase()} signature present`, - reference1: rid(signature[0]), + displayName: `${signature.name.toUpperCase()} signature present`, + reference1: rid(signature), type: rid(variantType), }, existsOk: true, From aeac55eb49572cc2bdfe19f6538d6d44a2496fb7 Mon Sep 17 00:00:00 2001 From: sshugsc Date: Mon, 21 Oct 2024 16:56:16 -0700 Subject: [PATCH 10/13] lint --- src/moa/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moa/index.js b/src/moa/index.js index 9753f246..716a666e 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -261,7 +261,7 @@ const loadVariant = async (conn, moaVariant) => { AND: [ { source: { filters: { name: 'cosmic' }, target: 'Source' } }, { sourceId: moaVariant.cosmic_signature }, - { sourceIdVersion: '3'}, + { sourceIdVersion: '3' }, ], }, target: 'Signature', From a632fc1b0d3c6fd83ad02d184500ba1d0b4a265a Mon Sep 17 00:00:00 2001 From: sshugsc Date: Tue, 22 Oct 2024 15:43:07 -0700 Subject: [PATCH 11/13] update signature present to high signature --- src/moa/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 716a666e..553d69f3 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -274,12 +274,12 @@ const loadVariant = async (conn, moaVariant) => { target: 'CategoryVariant', }); return await conn.updateRecord('CategoryVariant', record['@rid'], { - displayName: `${signature.name.toUpperCase()} signature present`, + displayName: `${signature.name.toUpperCase()} high signature`, }); } catch (err) { return conn.addVariant({ content: { - displayName: `${signature.name.toUpperCase()} signature present`, + displayName: `${signature.name.toUpperCase()} high signature`, reference1: rid(signature), type: rid(variantType), }, From ca1337e9dff44616beb6d893e8555a1c60f5227d Mon Sep 17 00:00:00 2001 From: mathieulemieux Date: Wed, 23 Oct 2024 14:54:33 -0700 Subject: [PATCH 12/13] Changes to cosmic signatures handling --- src/moa/index.js | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 553d69f3..9b8a1c2b 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -256,36 +256,45 @@ const loadVariant = async (conn, moaVariant) => { }); } } else if (moaVariant.feature_type === 'mutational_signature') { - const signature = await conn.getUniqueRecordBy({ - filters: { - AND: [ - { source: { filters: { name: 'cosmic' }, target: 'Source' } }, - { sourceId: moaVariant.cosmic_signature }, - { sourceIdVersion: '3' }, - ], - }, - target: 'Signature', - }); - const variantType = await conn.getVocabularyTerm('high signature'); - + // Cosmic signature + let signature = {}; try { - const record = await conn.getUniqueRecordBy({ - filters: { AND: [{ reference1: rid(signature) }, { type: rid(variantType) }] }, - target: 'CategoryVariant', - }); - return await conn.updateRecord('CategoryVariant', record['@rid'], { - displayName: `${signature.name.toUpperCase()} high signature`, + signature = await conn.getUniqueRecordBy({ + target: 'Signature', + filters: { + AND: [ + { + source: { + target: 'Source', + filters: { name: 'cosmic' }, + }, + }, + { sourceId: moaVariant.cosmic_signature }, + { sourceIdVersion: '3' }, + ], + }, }); - } catch (err) { - return conn.addVariant({ + } catch(err) { + // Enforcing usage of v3 Cosmic signatures + throw Error(`Missing Cosmic signature ${moaVariant.cosmic_signature}`); + } + + // 'high signature' variant type (prefered over 'signature present') + const variantType = await conn.getVocabularyTerm('high signature'); + + + // Corresponding 'high signature' CategoryVariant + try { + return await conn.addVariant({ content: { - displayName: `${signature.name.toUpperCase()} high signature`, reference1: rid(signature), type: rid(variantType), }, existsOk: true, target: 'CategoryVariant', }); + } catch (err) { + throw Error(`Unable to add variant for Cosmic signature ${moaVariant.cosmic_signature}`); } // } else if (moaVariant.feature_type === 'mutational_burden') { } else if (moaVariant.feature_type === 'copy_number') { From 51c3868414f451b35018e7d01f8a9706d02684af Mon Sep 17 00:00:00 2001 From: mathieulemieux Date: Wed, 23 Oct 2024 15:02:43 -0700 Subject: [PATCH 13/13] linting --- src/moa/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/moa/index.js b/src/moa/index.js index 9b8a1c2b..3455000e 100644 --- a/src/moa/index.js +++ b/src/moa/index.js @@ -258,6 +258,7 @@ const loadVariant = async (conn, moaVariant) => { } else if (moaVariant.feature_type === 'mutational_signature') { // Cosmic signature let signature = {}; + try { signature = await conn.getUniqueRecordBy({ target: 'Signature', @@ -274,15 +275,14 @@ const loadVariant = async (conn, moaVariant) => { ], }, }); - } catch(err) { + } catch (err) { // Enforcing usage of v3 Cosmic signatures throw Error(`Missing Cosmic signature ${moaVariant.cosmic_signature}`); } // 'high signature' variant type (prefered over 'signature present') const variantType = await conn.getVocabularyTerm('high signature'); - - + // Corresponding 'high signature' CategoryVariant try { return await conn.addVariant({