Skip to content

Commit b8cda23

Browse files
committed
.
1 parent babdedf commit b8cda23

17 files changed

+211
-378
lines changed

js/bam/bamReader.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import BGZBlockLoader from "./bgzBlockLoader.js"
1313
*/
1414
class BamReader {
1515

16-
chrAliasTable = new Map()
16+
chrAliasTable = new Map()
1717

1818
constructor(config, genome) {
1919
this.config = config
@@ -60,6 +60,9 @@ class BamReader {
6060

6161
if (this.chrAliasTable.has(chr)) {
6262
chr = this.chrAliasTable.get(chr)
63+
if (chr === undefined) {
64+
return undefined
65+
}
6366
}
6467

6568
let chrIdx = this.header.chrToIndex[chr]

js/bigwig/bwReader.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ class BWReader {
170170

171171
if (this.chrAliasTable.has(chr)) {
172172
chr = this.chrAliasTable.get(chr)
173+
if (chr === undefined) {
174+
return undefined
175+
}
173176
}
174177

175178
let chrIdx = this.chromTree.nameToId.get(chr)
@@ -245,26 +248,21 @@ class BWReader {
245248
async _searchForRegions(term) {
246249
const searchTrees = await this.#getSearchTrees()
247250
if (searchTrees) {
248-
// First try search term as entered. For now take the first one, we don't support multiple results
249-
for (let bpTree of searchTrees) {
250-
const result = await bpTree.search(term)
251-
if (result) {
252-
return result
253-
}
254-
}
255251

256-
// If no term use a trix index if we have one to map entered term to indexed value in bb file
252+
// Use a trix index if we have one to map entered term to indexed value in bb file
257253
if (this._trix) {
258254
term = term.toLowerCase()
259255
const trixResults = await this._trix.search(term)
260256
if (trixResults && trixResults.has(term)) { // <= exact matches only for now
261-
const term2 = trixResults.get(term)[0]
262-
for (let bpTree of searchTrees) {
263-
const result = await bpTree.search(term2)
264-
if (result) {
265-
return result
266-
}
267-
}
257+
term = trixResults.get(term)[0]
258+
}
259+
}
260+
261+
// For now take the first match, we don't support multiple results
262+
for (let bpTree of searchTrees) {
263+
const result = await bpTree.search(term)
264+
if (result) {
265+
return result
268266
}
269267
}
270268
}

js/bigwig/trix.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {igvxhr} from "../../node_modules/igv-utils/src/index.js"
1010

11+
1112
// this is the number of hex characters to use for the address in ixixx, see
1213
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
1314
const ADDRESS_SIZE = 10
@@ -16,7 +17,7 @@ export default class Trix {
1617

1718
ixFile // URL to the ix file
1819
ixxFile // URL to the ixx file
19-
ixBuffer // Buffer for the ix file contents -- we read it once, they aren't very large
20+
bufferCache = new Map()
2021

2122
constructor(ixxFile, ixFile) {
2223
this.ixFile = ixFile
@@ -50,6 +51,7 @@ export default class Trix {
5051
const match = word.startsWith(searchWord)
5152
if (match) {
5253
matches.push(line)
54+
console.log("match " + line)
5355
}
5456
// we are done scanning if we are lexicographically greater than the search string
5557
if (word.slice(0, searchWord.length) > searchWord) {
@@ -65,6 +67,7 @@ export default class Trix {
6567
const [term, ...parts] = m.split(' ')
6668
results.set(term, parts.map(p => p.split(',')[0]))
6769
}
70+
console.log(results)
6871
return results
6972
}
7073
}
@@ -94,10 +97,6 @@ export default class Trix {
9497

9598
async _getBuffer(searchWord, opts) {
9699

97-
if (!this.ixBuffer) {
98-
this.ixBuffer = await igvxhr.loadString(this.ixFile)
99-
}
100-
101100
let start = 0
102101
let end = 65536
103102
const indexes = await this.getIndex(opts)
@@ -116,6 +115,13 @@ export default class Trix {
116115
return undefined
117116
}
118117

119-
return this.ixBuffer.slice(start, start + len)
118+
if(this.bufferCache.has(start)) {
119+
return this.bufferCache.get(start)
120+
} else {
121+
const buffer = igvxhr.loadString(this.ixFile, {range: {start, size: len}})
122+
this.bufferCache.set(start, buffer)
123+
return buffer
124+
}
125+
120126
}
121127
}

js/browser.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {translateSession} from "./hic/shoeboxUtils.js"
5454
import Hub from "./ucsc/ucscHub.js"
5555
import MultiTrackSelectButton from "./ui/multiTrackSelectButton.js"
5656
import MenuUtils from "./ui/menuUtils.js"
57+
import Genome from "./genome/genome.js"
5758

5859
// css - $igv-scrollbar-outer-width: 14px;
5960
const igv_scrollbar_outer_width = 14
@@ -232,7 +233,7 @@ class Browser {
232233

233234
// chromosome select widget
234235
this.chromosomeSelectWidget = new ChromosomeSelectWidget(this, $genomicLocation.get(0))
235-
if (config.showChromosomeWidget) {
236+
if (config.showChromosomeWidget !== false) {
236237
this.chromosomeSelectWidget.show()
237238
} else {
238239
this.chromosomeSelectWidget.hide()
@@ -553,7 +554,9 @@ class Browser {
553554
console.warn("No genome or reference object specified")
554555
return
555556
}
556-
const genomeConfig = await GenomeUtils.expandReference(this.alert, genomeOrReference)
557+
const genomeConfig = StringUtils.isString(genomeOrReference) ?
558+
await GenomeUtils.expandReference(this.alert, genomeOrReference) :
559+
genomeOrReference
557560

558561

559562
await this.loadReference(genomeConfig, session.locus)
@@ -679,7 +682,7 @@ class Browser {
679682
*/
680683
async loadReference(genomeConfig, initialLocus) {
681684

682-
const genome = await GenomeUtils.loadGenome(genomeConfig)
685+
const genome = await Genome.loadGenome(genomeConfig)
683686

684687
const genomeChange = undefined === this.genome || (this.genome.id !== genome.id)
685688

@@ -735,7 +738,7 @@ class Browser {
735738
let genomeLabel = (genome.id && genome.id.length < 20 ? genome.id : `${genome.id.substring(0,8)}...${genome.id.substring(genome.id.length-8)}`)
736739
this.$current_genome.text(genomeLabel)
737740
this.$current_genome.attr('title', genome.description)
738-
if(this.config.showChromosomeWidget) {
741+
if(this.config.showChromosomeWidget !== false) {
739742
this.chromosomeSelectWidget.update(genome)
740743
}
741744
}
@@ -1452,8 +1455,11 @@ class Browser {
14521455

14531456
this.chromosomeSelectWidget.select.value = referenceFrameList.length === 1 ? this.referenceFrameList[0].chr : ''
14541457

1458+
1459+
14551460
const loc = this.referenceFrameList.map(rf => rf.getLocusString()).join(' ')
1456-
//const loc = this.referenceFrameList.length === 1 ? this.referenceFrameList[0].getLocusString() : '';
1461+
1462+
14571463
this.$searchInput.val(loc)
14581464

14591465
this.fireEvent('locuschange', [this.referenceFrameList])
@@ -2280,16 +2286,5 @@ function toggleTrackLabels(trackViews, isVisible) {
22802286
}
22812287
}
22822288

2283-
async function searchWebService(browser, locus, searchConfig) {
2284-
2285-
let path = searchConfig.url.replace("$FEATURE$", locus.toUpperCase())
2286-
if (path.indexOf("$GENOME$") > -1) {
2287-
path = path.replace("$GENOME$", (browser.genome.id ? browser.genome.id : "hg19"))
2288-
}
2289-
const result = await igvxhr.loadString(path)
2290-
return {result: result, locusSearchString: locus}
2291-
}
2292-
2293-
export {searchWebService}
22942289
export default Browser
22952290

js/genome/chromAliasFile.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class ChromAliasFile {
1616

1717
aliasRecordCache = new Map()
1818

19-
constructor(aliasURL, config, chromosomes) {
19+
constructor(aliasURL, config, genome) {
2020
this.aliasURL = aliasURL
2121
this.config = config
22-
this.chromosomes = chromosomes
22+
this.genome = genome
2323
}
2424

2525
/**
@@ -34,6 +34,7 @@ class ChromAliasFile {
3434

3535

3636
async loadAliases() {
37+
3738
const data = await igvxhr.loadString(this.aliasURL, buildOptions(this.config))
3839
const lines = StringUtils.splitLines(data)
3940
const firstLine = lines[0]
@@ -42,10 +43,19 @@ class ChromAliasFile {
4243
this.altNameSets = this.headings.slice(1)
4344
}
4445

46+
const chromosomeNameSet = this.genome.chromosomes ?
47+
new Set(this.genome.chromosomes.keys()) : new Set()
48+
4549
for (let line of lines) {
4650
if (!line.startsWith("#") && line.length > 0) {
4751
const tokens = line.split("\t")
48-
const aliasRecord = {chr: tokens[0]} // TODO -- in IGV alias file format we don't know this
52+
53+
let chr = tokens.find(t => chromosomeNameSet.has(t))
54+
if(!chr) {
55+
chr = tokens[0]
56+
}
57+
58+
const aliasRecord = {chr}
4959
for (let i = 0; i < tokens.length; i++) {
5060
const key = this.headings ? this.headings[i] : i
5161
aliasRecord[key] = tokens[i]

js/genome/cytobandFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {buildOptions, isDataURL} from "../util/igvUtils.js"
2-
import {BGZip, igvxhr, StringUtils} from "igv-utils"
2+
import {BGZip, igvxhr, StringUtils} from "../../node_modules/igv-utils/src/index.js"
33
import {Cytoband} from "./cytoband.js"
44

55
class CytobandFile {

0 commit comments

Comments
 (0)