From 2b418afe4a7d013647076b26ebdd2523b2079922 Mon Sep 17 00:00:00 2001 From: jrobinso <933148+jrobinso@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:44:52 -0700 Subject: [PATCH] Use indexes wherever possible --- js/bam/bamReader.js | 42 +++++++++++++++++++++++------------------- js/bigwig/bwReader.js | 36 +++++------------------------------- js/browser.js | 5 +---- js/ucsc/ucscHub.js | 6 ++++-- 4 files changed, 33 insertions(+), 56 deletions(-) diff --git a/js/bam/bamReader.js b/js/bam/bamReader.js index fdcdb03bc..8f023da3a 100644 --- a/js/bam/bamReader.js +++ b/js/bam/bamReader.js @@ -26,25 +26,7 @@ class BamReader { } async readAlignments(chr, bpStart, bpEnd) { - - const chrToIndex = await this.getChrIndex() - - if(!this.chrAliasTable.has(chr)) { - const chromosome = this.genome.getChromosome(chr) - if(chromosome) { - const aliases = chromosome.altNames - for(let a of aliases) { - if(this.chrNames.has(a)) { - this.chrAliasTable.set(chr, a) - } - } - } - if(!this.chrAliasTable.has(chr)) this.chrAliasTable.set(chr, chr) - } - - const queryChr = this.chrAliasTable.get(chr) || chr - - const chrId = chrToIndex[queryChr] + const chrId = await this.#getChrIdx(chr) const alignmentContainer = new AlignmentContainer(chr, bpStart, bpEnd, this.config) if (chrId === undefined) { @@ -71,6 +53,28 @@ class BamReader { } } + async #getChrIdx(chr) { + const chrToIndex = await this.getChrIndex() + + if (!this.chrAliasTable.has(chr)) { + const chromosome = this.genome.getChromosome(chr) + if (chromosome) { + const aliases = chromosome.altNames + for (let a of aliases) { + if (this.chrNames.has(a)) { + this.chrAliasTable.set(chr, a) + } + } + } + if (!this.chrAliasTable.has(chr)) this.chrAliasTable.set(chr, chr) + } + + const queryChr = this.chrAliasTable.get(chr) || chr + + const chrId = chrToIndex[queryChr] + return chrId + } + async getHeader() { if (!this.header) { const genome = this.genome diff --git a/js/bigwig/bwReader.js b/js/bigwig/bwReader.js index d4046c57b..5be5b0cd1 100644 --- a/js/bigwig/bwReader.js +++ b/js/bigwig/bwReader.js @@ -81,36 +81,8 @@ class BWReader { await this.loadHeader() - let chrIdx1 = await this.#getIdForChr(chr1) // this.chromTree.nameToId.get(chr1) - let chrIdx2 = await this.#getIdForChr(chr2) // this.chromTree.nameToId.get(chr2) - - // // Try alias - // if (chrIdx1 === undefined) { - // const aliasRecord = await this.genome.getAliasRecord(chr1) - // if (aliasRecord) { - // const aliases = Object.keys(aliasRecord) - // .filter(k => k !== "start" && k !== "end") - // .map(k => aliasRecord[k]) - // .filter(a => this.chromTree.nameToId.has(a)) - // if (aliases.length > 0) { - // chrIdx1 = this.chromTree.nameToId.get(aliases[0]) - // this.chrAliasTable.set(chr1, aliases[0]) - // } - // } - // } - // if (chrIdx2 === undefined) { - // const aliasRecord = await this.genome.getAliasRecord(chr2) - // if (aliasRecord) { - // const aliases = Object.keys(aliasRecord) - // .filter(k => k !== "start" && k !== "end") - // .map(k => aliasRecord[k]) - // .filter(a => this.chromTree.nameToId.has(a)) - // if (aliases.length > 0) { - // chrIdx2 = this.chromTree.nameToId.get(aliases[0]) - // this.chrAliasTable.set(chr2, aliases[0]) - // } - // } - // } + let chrIdx1 = await this.#getIdForChr(chr1) + let chrIdx2 = await this.#getIdForChr(chr2) if (chrIdx1 === undefined || chrIdx2 === undefined) { return [] @@ -205,16 +177,18 @@ class BWReader { // Try alias if (chrIdx === undefined) { const aliasRecord = await this.genome.getAliasRecord(chr) + let alias if (aliasRecord) { const aliases = Object.keys(aliasRecord) .filter(k => k !== "start" && k !== "end") .map(k => aliasRecord[k]) .filter(a => this.chromTree.nameToId.has(a)) if (aliases.length > 0) { + alias = aliases[0] chrIdx = this.chromTree.nameToId.get(aliases[0]) - this.chrAliasTable.set(chr, aliases[0]) } } + this.chrAliasTable.set(chr, alias) // alias may be undefined => no alias exists. Setting prevents repeated attempts } return chrIdx } diff --git a/js/browser.js b/js/browser.js index 466b10fc9..33fd95ff4 100755 --- a/js/browser.js +++ b/js/browser.js @@ -235,9 +235,6 @@ class Browser { // chromosome select widget this.chromosomeSelectWidget = new ChromosomeSelectWidget(this, $genomicLocation.get(0)) - if (undefined === config.showChromosomeWidget) { - config.showChromosomeWidget = true // Default to true - } if (true === config.showChromosomeWidget) { this.chromosomeSelectWidget.show() } else { @@ -738,7 +735,7 @@ class Browser { let genomeLabel = (genome.id && genome.id.length < 20 ? genome.id : `${genome.id.substring(0,8)}...${genome.id.substring(genome.id.length-8)}`) this.$current_genome.text(genomeLabel) this.$current_genome.attr('title', genome.description) - if(false !== this.config.showChromosomeWidget) { + if(this.config.showChromosomeWidget) { this.chromosomeSelectWidget.update(genome) } } diff --git a/js/ucsc/ucscHub.js b/js/ucsc/ucscHub.js index a0893e83a..14beca9ba 100644 --- a/js/ucsc/ucscHub.js +++ b/js/ucsc/ucscHub.js @@ -31,8 +31,10 @@ class Hub { } static supportedTypes = new Set(["bigBed", "bigWig", "bigGenePred"]) - static filterTracks = new Set(["cytoBandIdeo", "assembly", "gap", "gapOverlap", "allGaps", - "cpgIslandExtUnmasked", "windowMasker"]) + static filterTracks = new Set(["cytoBandIdeo"]) + + //["cytoBandIdeo", "assembly", "gap", "gapOverlap", "allGaps", + // "cpgIslandExtUnmasked", "windowMasker"]) constructor(url, stanzas, groups) {