Skip to content

Commit

Permalink
chore: configurable vcf chr transform fn
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jan 14, 2024
1 parent 87edf1f commit ed86133
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
8 changes: 8 additions & 0 deletions epivar-prod/node1/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
};
5 changes: 5 additions & 0 deletions epivar-prod/node2/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
4 changes: 2 additions & 2 deletions models/samples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
GENOTYPE_STATE_HET,
GENOTYPE_STATE_HOM,
GENOTYPE_STATE_REF,
normalizeChrom,
} from "../helpers/genome.mjs";

const { TabixIndexedFile } = Tabix;
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion models/tracks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit ed86133

Please sign in to comment.