Skip to content

Commit 1cf371c

Browse files
committed
add chromosome to fusions and update loggers
1 parent 6e605ce commit 1cf371c

3 files changed

Lines changed: 68 additions & 33 deletions

File tree

src/cosmic/fusions.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { logger } = require('../logging');
1919
const { cosmic: SOURCE_DEFN } = require('../sources');
2020

2121
const RECURRENCE_THRESHOLD = 3;
22+
const cache = {};
2223

2324
const HEADER = {
2425
diseaseId: 'COSMIC_PHENOTYPE_ID',
@@ -32,15 +33,39 @@ const HEADER = {
3233
sampleId: 'COSMIC_SAMPLE_ID',
3334
};
3435

36+
const fetchChromosome = async (conn, sourceId) => {
37+
if (cache[sourceId]) {
38+
return cache[sourceId];
39+
}
40+
const record = await conn.getUniqueRecordBy({
41+
filters: {
42+
AND: [
43+
{ sourceId },
44+
{ biotype: 'chromosome' },
45+
],
46+
},
47+
sort: orderPreferredOntologyTerms,
48+
target: 'Feature',
49+
});
50+
cache[sourceId] = record;
51+
return record;
52+
};
53+
3554

3655
const processVariants = async ({
3756
conn, record, variantType, exonSpecific,
3857
}) => {
3958
// fetch the features
40-
const [gene1] = await _gene.fetchAndLoadBySymbol(conn, record.gene1);
41-
const [gene2] = await _gene.fetchAndLoadBySymbol(conn, record.gene2);
59+
let [gene1] = await _gene.fetchAndLoadBySymbol(conn, record.gene1),
60+
[gene2] = await _gene.fetchAndLoadBySymbol(conn, record.gene2);
4261

4362
// create the variants
63+
if (!gene1) {
64+
gene1 = await fetchChromosome(conn, record.gene1);
65+
}
66+
if (!gene2) {
67+
gene2 = await fetchChromosome(conn, record.gene2);
68+
}
4469
if (!gene1 || !gene2) {
4570
throw new Error(`unable to find genes for record ${record.id}: ${record.gene1}, ${record.gene2}`);
4671
}

src/cosmic/resistance.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,43 +69,45 @@ const processVariants = async ({ conn, record, source }) => {
6969
throw Error(`failed to find the HGNC gene for ${record.gene}`);
7070
}
7171
} catch (err) {
72-
logger.error(err);
72+
logger.warn(err);
7373
}
7474
}
7575

76-
try {
77-
// add the protein variant with its protein translation
78-
const variant = jsonifyVariant(parseVariant(record.protein, false));
79-
variant.type = rid(await conn.getVocabularyTerm(variant.type));
80-
81-
const reference1 = rid(await _ensembl.fetchAndLoadById(
82-
conn,
83-
{ biotype: 'protein', sourceId: variant.reference1 },
84-
));
85-
protein = rid(await conn.addVariant({
86-
content: { ...variant, reference1 },
87-
existsOk: true,
88-
target: 'PositionalVariant',
89-
}));
90-
91-
if (gene) {
92-
// add the same protein variant with the gene notation
93-
generalProtein = rid(await conn.addVariant({
94-
content: { ...variant, reference1: gene },
76+
if (record.protein && record.protein.trim()) {
77+
try {
78+
// add the protein variant with its protein translation
79+
const variant = jsonifyVariant(parseVariant(record.protein, false));
80+
variant.type = rid(await conn.getVocabularyTerm(variant.type));
81+
82+
const reference1 = rid(await _ensembl.fetchAndLoadById(
83+
conn,
84+
{ biotype: 'protein', sourceId: variant.reference1 },
85+
));
86+
protein = rid(await conn.addVariant({
87+
content: { ...variant, reference1 },
9588
existsOk: true,
9689
target: 'PositionalVariant',
9790
}));
9891

99-
// link the translation version to the gene version
100-
await conn.addRecord({
101-
content: { in: generalProtein, out: protein },
102-
existsOk: true,
103-
fetchExisting: false,
104-
target: 'Infers',
105-
});
92+
if (gene) {
93+
// add the same protein variant with the gene notation
94+
generalProtein = rid(await conn.addVariant({
95+
content: { ...variant, reference1: gene },
96+
existsOk: true,
97+
target: 'PositionalVariant',
98+
}));
99+
100+
// link the translation version to the gene version
101+
await conn.addRecord({
102+
content: { in: generalProtein, out: protein },
103+
existsOk: true,
104+
fetchExisting: false,
105+
target: 'Infers',
106+
});
107+
}
108+
} catch (err) {
109+
logger.error(err);
106110
}
107-
} catch (err) {
108-
logger.error(err);
109111
}
110112

111113
// create the cds variant

src/hgnc/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ const fetchAndLoadBySymbol = async ({
203203
CACHE[paramType][symbol] = record;
204204
}
205205
return record;
206-
} catch (err) { }
206+
} catch (err) {
207+
logger.info('Unable to fetch ensembl source for linking records');
208+
}
207209
// fetch from the HGNC API and upload
208210
const uri = `${HGNC_API}/${paramType}/${
209211
paramType === 'hgnc_id'
@@ -218,6 +220,10 @@ const fetchAndLoadBySymbol = async ({
218220
uri,
219221
});
220222

223+
if (!docs || docs.length === 0) {
224+
throw new Error(`No HGNC record found for ${paramType}: ${symbol}`);
225+
}
226+
221227
for (const record of docs) {
222228
checkSpec(validateHgncSpec, record, rec => rec.hgnc_id);
223229
}
@@ -238,7 +244,9 @@ const fetchAndLoadBySymbol = async ({
238244
filters: { name: ensemblSourceName },
239245
target: 'Source',
240246
});
241-
} catch (err) { }
247+
} catch (err) {
248+
logger.info('Unable to fetch ensembl source for linking records');
249+
}
242250
const result = await uploadRecord({
243251
conn,
244252
deprecated: (

0 commit comments

Comments
 (0)