Skip to content

Commit

Permalink
Use indexes wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 19, 2023
1 parent b6198d0 commit 2b418af
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 56 deletions.
42 changes: 23 additions & 19 deletions js/bam/bamReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
36 changes: 5 additions & 31 deletions js/bigwig/bwReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
6 changes: 4 additions & 2 deletions js/ucsc/ucscHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down

0 comments on commit 2b418af

Please sign in to comment.