From ed8613310d023699a1ea39694fc645e4634d1a8c Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Sun, 14 Jan 2024 18:24:43 -0500 Subject: [PATCH] chore: configurable vcf chr transform fn --- config.example.js | 10 ++++++++++ epivar-prod/node1/config.js | 8 ++++++++ epivar-prod/node2/config.js | 5 +++++ models/samples.mjs | 4 ++-- models/tracks.mjs | 2 +- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/config.example.js b/config.example.js index 5d6a85e2..de1497ea 100644 --- a/config.example.js +++ b/config.example.js @@ -31,5 +31,15 @@ module.exports = { * the metadata.json "donor" property). */ vcfSampleNameConverter: name => name.split('_')[1], // name => name + + /* + * When given a contig from a peak as input, produce a contig compatible with the genotype VCF. + * For example, peak contigs may be in the format chr1, chr2, ..., whereas VCF contigs may be + * formatted without the 'chr' prefix (1, 2, ...). Stripping the chr prefix gives the correct + * VCF contig value. + */ + vcfChrTransform: (chr) => chr.replace(/^chr/, ""), // e.g., chr1 => 1 + + // bigWigChrTransform: TODO, }, }; diff --git a/epivar-prod/node1/config.js b/epivar-prod/node1/config.js index 5d6a85e2..3d1ea207 100644 --- a/epivar-prod/node1/config.js +++ b/epivar-prod/node1/config.js @@ -31,5 +31,13 @@ module.exports = { * the metadata.json "donor" property). */ vcfSampleNameConverter: name => name.split('_')[1], // name => name + + /* + * When given a contig from a peak as input, produce a contig compatible with the genotype VCF. + * For example, peak contigs may be in the format chr1, chr2, ..., whereas VCF contigs may be + * formatted without the 'chr' prefix (1, 2, ...). Stripping the chr prefix gives the correct + * VCF contig value. + */ + vcfChrTransform: (chr) => chr.replace(/^chr/, ""), // e.g., chr1 => 1 }, }; diff --git a/epivar-prod/node2/config.js b/epivar-prod/node2/config.js index 9d7c78c6..88731f54 100644 --- a/epivar-prod/node2/config.js +++ b/epivar-prod/node2/config.js @@ -31,5 +31,10 @@ module.exports = { * the metadata.json "donor" property). */ vcfSampleNameConverter: name => name.split('_')[1], // name => name + + /* + * VCF contigs have correct format, use identity function (default value) + */ + // vcfChrTransform: (chr) => chr, }, }; diff --git a/models/samples.mjs b/models/samples.mjs index d7b9ddcf..d1d49ef5 100644 --- a/models/samples.mjs +++ b/models/samples.mjs @@ -13,7 +13,6 @@ import { GENOTYPE_STATE_HET, GENOTYPE_STATE_HOM, GENOTYPE_STATE_REF, - normalizeChrom, } from "../helpers/genome.mjs"; const { TabixIndexedFile } = Tabix; @@ -22,13 +21,14 @@ const VCF_TABIX_FILE = new TabixIndexedFile({ path: envConfig.GENOTYPE_VCF_PATH const vcfParser = new VCF.default({ header: await VCF_TABIX_FILE.getHeader() }); const vcfFilterFn = config.samples?.vcfFindFn ?? ((line) => line.REF.length === 1 && line.ALT.every((a) => a.length === 1)); +const vcfChrTransform = config.samples?.vcfChrTransform ?? ((chr) => chr); export default { queryMap, }; export function queryMap(chrom, start, end = start + 1) { - return vcfQuery(normalizeChrom(chrom), parseInt(start.toString(), 10), parseInt(end.toString(), 10)) + return vcfQuery(vcfChrTransform(chrom), parseInt(start.toString(), 10), parseInt(end.toString(), 10)) .then(normalizeSamplesMap); } diff --git a/models/tracks.mjs b/models/tracks.mjs index 29c42366..f8abf388 100644 --- a/models/tracks.mjs +++ b/models/tracks.mjs @@ -53,7 +53,7 @@ function get(peak) { async function values(peak, usePrecomputed = false) { const k = `values:${peak.id}${usePrecomputed ? ':pre' : ''}`; - const chrom = normalizeChrom(peak.feature.chrom); + const chrom = normalizeChrom(peak.feature.chrom); // TODO: bigWigChrTransform await cache.open();