Skip to content

Commit

Permalink
"hubs" change -- included trackConfigruations in genomeChange event p…
Browse files Browse the repository at this point in the history
…ayload
  • Loading branch information
jrobinso committed Oct 31, 2023
1 parent d3b8a2b commit 1a4dd55
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 41 deletions.
19 changes: 13 additions & 6 deletions dev/ucsc/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
<body>

<select id="select">
<option value = ""></option>
<option value="https://hgdownload.soe.ucsc.edu/hubs/GCF/000/186/305/GCF_000186305.1/hub.txt">Many chromosomes ~ same size
<option value=""></option>
<option value="https://hgdownload.soe.ucsc.edu/hubs/GCF/000/186/305/GCF_000186305.1/hub.txt">Many chromosomes ~ same
size
</option>
<option value="https://hgdownload.soe.ucsc.edu/hubs/GCA/022/747/635/GCA_022747635.1/hub.txt">Many chromosomes - gradually decreasing
<option value="https://hgdownload.soe.ucsc.edu/hubs/GCA/022/747/635/GCA_022747635.1/hub.txt">Many chromosomes -
gradually decreasing
chromosomes
</option>
<option value="https://hgdownload.soe.ucsc.edu/hubs/GCF/013/103/735/GCF_013103735.1/hub.txt">24 large chromosomes
Expand All @@ -26,6 +28,9 @@
<button id="load-genome">Load hub as genome</button>
<button id="load-session">Load hub as session</button>

<br>
<button id="dump-session">Dump session</button>

<div id="igvDiv" style="padding-top: 50px;padding-bottom: 20px; height: auto"></div>

<script type="module">
Expand All @@ -46,8 +51,8 @@

const browser = await igv.createBrowser(document.getElementById('igvDiv'), igvConfig)

browser.on('genomechange', (genome) => {
console.log(genome.trackConfigurations)
browser.on('genomechange', (args) => {
console.log(args)
})

const selector = document.getElementById("select")
Expand All @@ -59,10 +64,12 @@
await browser.loadGenome({url: document.getElementById("hub-input").value})
})


document.getElementById("load-session").addEventListener("click", () =>
browser.loadSession({url: document.getElementById("hub-input").value}))

document.getElementById("dump-session").addEventListener("click", () => {
console.log(browser.toJSON())
})

</script>

Expand Down
7 changes: 3 additions & 4 deletions js/bigwig/trix.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Trix {
const searchWord = searchWords[0].toLowerCase()
const str = await this._getBuffer(searchWord, opts)
if (!str) {
return []
return undefined
}

const lines = str
Expand All @@ -54,7 +54,7 @@ export default class Trix {
}
// we are done scanning if we are lexicographically greater than the search string
if (word.slice(0, searchWord.length) > searchWord) {
//break
break
}
}

Expand All @@ -66,7 +66,6 @@ export default class Trix {
const [term, ...parts] = m.split(' ')
results.set(term, parts.map(p => p.split(',')[0]))
}
console.log(results)
return results
}
}
Expand Down Expand Up @@ -117,7 +116,7 @@ export default class Trix {
if(this.bufferCache.has(start)) {
return this.bufferCache.get(start)
} else {
const buffer = igvxhr.loadString(this.ixFile, {range: {start, size: len}})
const buffer = await igvxhr.loadString(this.ixFile, {range: {start, size: len}})
this.bufferCache.set(start, buffer)
return buffer
}
Expand Down
28 changes: 17 additions & 11 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,22 @@ class Browser {
throw new Error(`Cannot set initial locus ${locus}`)
}

if(genomeChange) {
this.fireEvent('genomechange', [genome])
}

if (genomeChange && this.circularView) {
this.circularView.setAssembly({
name: this.genome.id,
id: this.genome.id,
chromosomes: makeCircViewChromosomes(this.genome)
})
if (genomeChange) {
let trackConfigurations
if (genomeConfig.hubURL) {
// TODO -- refactor this so "hub" is not loaded twice
const hub = await Hub.loadHub(genomeConfig.hubURL)
trackConfigurations = hub.getGroupedTrackConfigurations()
}
this.fireEvent('genomechange', [{genome, trackConfigurations}])

if (this.circularView) {
this.circularView.setAssembly({
name: this.genome.id,
id: this.genome.id,
chromosomes: makeCircViewChromosomes(this.genome)
})
}
}
}

Expand Down Expand Up @@ -1317,7 +1323,7 @@ class Browser {
getTrackURLs() {
return new Set(this.tracks
.filter(track => track.config && StringUtils.isString(track.config.url))
.map(track => track.config.url))
.map(track => track.config.url))
}


Expand Down
4 changes: 0 additions & 4 deletions js/genome/genome.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Genome {
}
}


get description() {
return this.config.description || `${this.id}\n${this.name}`
}
Expand Down Expand Up @@ -279,9 +278,6 @@ class Genome {
this.chromosomes.set("all", new Chromosome("all", 0, l))
}

get trackConfigurations() {
return this.config.trackConfigurations
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion js/genome/twobit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class TwobitSequence {

littleEndian
metaIndex = new Map()
bpt

constructor(config) {
this.url = config.twoBitURL || config.fastaURL
Expand Down
30 changes: 16 additions & 14 deletions js/ucsc/ucscHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,25 @@ class Hub {
}
}

// TODO -- categorize extra "user" supplied and other tracks in some distinctive way before including them
// load includes. Nested includes are not supported
for (let s of stanzas.slice()) {
if ("include" === s.type) {
const includeStanzas = await loadStanzas(baseURL + s.getProperty("include"))
for (s of includeStanzas) {
s.setProperty("visibility", "hide")
stanzas.push(s)
}
}
}
// for (let s of stanzas.slice()) {
// if ("include" === s.type) {
// const includeStanzas = await loadStanzas(baseURL + s.getProperty("include"))
// for (s of includeStanzas) {
// s.setProperty("visibility", "hide")
// stanzas.push(s)
// }
// }
// }

return new Hub(url, stanzas, groups)
}

constructor(url, stanzas, groupStanzas) {

this.url = url;

const idx = url.lastIndexOf("/")
this.baseURL = url.substring(0, idx + 1)

Expand Down Expand Up @@ -110,11 +113,12 @@ isPcr dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
getGenomeConfig(includeTrackGroups = "all") {
// TODO -- add blat? htmlPath?
const config = {
hubURL: this.url,
id: this.genomeStanza.getProperty("genome"),
name: this.genomeStanza.getProperty("scientificName") || this.genomeStanza.getProperty("organism") || this.genomeStanza.getProperty("description"),
twoBitURL: this.baseURL + this.genomeStanza.getProperty("twoBitPath"),
nameSet: "ucsc",
wholeGenomeView: false
wholeGenomeView: false,
}

if (this.genomeStanza.hasProperty("defaultPos")) {
Expand Down Expand Up @@ -178,12 +182,10 @@ isPcr dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
config.tracks = this.#getTracksConfigs(filter)
}

config.trackConfigurations = this.#getGroupedTrackConfigurations()

return config
}

#getGroupedTrackConfigurations() {
getGroupedTrackConfigurations() {

// Organize track configs by group
const trackConfigMap = new Map()
Expand Down Expand Up @@ -259,7 +261,7 @@ isPcr dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
if (config.description) config.description += "<br/>"
config.description =
`<a target="_blank" href="${this.baseURL + t.getProperty("html")}">${t.getProperty("longLabel")}</a>`
} else if (t.hasOwnProperty("longLabel")) {
} else if (t.hasProperty("longLabel")) {
config.description = t.getProperty("longLabel")
}

Expand Down
4 changes: 4 additions & 0 deletions test/testTwobit.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ suite("testTwobit", function () {
const bpTree = await BPTree.loadBpTree(url, 0)
assert.ok(bpTree)

assert.equal(256, bpTree.header.blockSize);
assert.equal(15, bpTree.header.keySize);
assert.equal(8, bpTree.header.valSize);

const result = await bpTree.search("RJWJ011179649.1")
assert.ok(result)

Expand Down
2 changes: 1 addition & 1 deletion test/testUCSC.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ suite("ucsc utilities", function () {
this.timeout(200000)
const ixFile = "test/data/bb/ixIxx/GCF_000009045.1_ASM904v1.ncbiGene.ix"
const ixxFile = "test/data/bb/ixIxx/GCF_000009045.1_ASM904v1.ncbiGene.ixx"
const trix = new Trix(ixxFile, ixFile, 10)
const trix = new Trix(ixxFile, ixFile)
const results = await trix.search("ykoX")
assert.ok(results)
const exactMatches = results.get('ykox')
Expand Down

0 comments on commit 1a4dd55

Please sign in to comment.