Skip to content

Commit

Permalink
refinements to hub genome & session -- genome => fewer initial tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 26, 2023
1 parent c3fd5d2 commit 724bbcf
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 143 deletions.
14 changes: 11 additions & 3 deletions dev/ucsc/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,29 @@
includeTracks: true
}

const hub = await Hub.loadHub("https://hgdownload.soe.ucsc.edu/hubs/GCA/018/471/515/GCA_018471515.1/hub.txt", hubOptions)
const hub = await Hub.loadHub("https://hgdownload.soe.ucsc.edu/hubs/GCA/009/914/755/GCA_009914755.4/hub.txt", hubOptions)
const ref = hub.getGenomeConfig()

const igvConfig = {
locus: hub.getDefaultPosition(),
showChromosomeWidget: false,
reference: ref
}

// for(let tc of hub.getTrackConfigurations()) {
// for(let t of tc.tracks) {
// if(t.url.endsWith("undefined")) console.log(`${tc.label} ${t.name} ${t.url}`)
// }
// }

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

const selector = document.getElementById("select")
selector.addEventListener("change", () => document.getElementById("hub-input").value = selector.value)

document.getElementById("hub-input").value = "https://hgdownload.soe.ucsc.edu/hubs/GCA/009/914/755/GCA_009914755.4/hub.txt"

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

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

Expand Down
1 change: 0 additions & 1 deletion js/bigwig/trix.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default class Trix {
const match = word.startsWith(searchWord)
if (match) {
matches.push(line)
console.log("match " + line)
}
// we are done scanning if we are lexicographically greater than the search string
if (word.slice(0, searchWord.length) > searchWord) {
Expand Down
141 changes: 53 additions & 88 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ class Browser {
/**
* Initialize a session from an object, json, or by loading from a file.
*
* TODO Really should be split into at least 2 functions, load from file and load from object/json
*
* @param options
* @returns {*}
*/
Expand All @@ -463,14 +461,6 @@ class Browser {
let session
if (options.url || options.file) {
session = await loadSessionFile(options)

// Hack to accomodate ucsc Hubs. Refactor this -- hide based on genome characteristics, not session
if (this.config.showChromosomeWidget === false || session.showChromosomeWidget === false) {
this.chromosomeSelectWidget.hide()
} else {
this.chromosomeSelectWidget.show()
}

} else {
session = options
}
Expand Down Expand Up @@ -499,13 +489,9 @@ class Browser {
} else if (filename.endsWith("hub.txt")) {

const hub = await Hub.loadHub(urlOrFile, options)
const genomeConfig = hub.getGenomeConfig(options.includeTracks)
const initialLocus = hub.getDefaultPosition()
const genomeConfig = hub.getGenomeConfig()
const config = {
showChromosomeWidget: false,
locus: initialLocus,
reference: genomeConfig,
_isHub: true
reference: genomeConfig
}
return setDefaults(config)
} else if (filename.endsWith(".json")) {
Expand All @@ -517,7 +503,6 @@ class Browser {
}
}


/**
* Note: public API function
* @param session
Expand Down Expand Up @@ -669,20 +654,23 @@ class Browser {

}

createCenterLineList(columnContainer) {
cleanHouseForSession() {

const centerLines = columnContainer.querySelectorAll('.igv-center-line')
for (let i = 0; i < centerLines.length; i++) {
centerLines[i].remove()
for (let trackView of this.trackViews) {
// empty axis column, viewport columns, sampleName column, scroll column, drag column, gear column
trackView.removeDOMFromColumnContainer()
}

const centerLineList = []
const viewportColumns = columnContainer.querySelectorAll('.igv-column')
for (let i = 0; i < viewportColumns.length; i++) {
centerLineList.push(new ViewportCenterLine(this, this.referenceFrameList[i], viewportColumns[i]))
// discard all columns
const elements = this.columnContainer.querySelectorAll('.igv-axis-column, .igv-column-shim, .igv-column, .igv-sample-info-column, .igv-sample-name-column, .igv-scrollbar-column, .igv-track-drag-column, .igv-gear-menu-column')
elements.forEach(column => column.remove())

this.trackViews = []

if (this.circularView) {
this.circularView.clearChords()
}

return centerLineList
}

/**
Expand All @@ -702,20 +690,16 @@ class Browser {

this.updateNavbarDOMWithGenome(genome)

// TODO -- I don't understand the genomeChange test. We always want to trigger a fresh start on loading a session or genome
//if (genomeChange) {
this.removeAllTracks()
//}

let locus = getInitialLocus(initialLocus, genome)
let locus = initialLocus || genome.initialLocus
if (Array.isArray(locus)) {
locus = locus.join(' ')
}

const locusFound = await this.search(locus, true)
if (!locusFound) {
console.log("Initial locus not found: " + locus)
locus = genome.getHomeChromosomeName()
const locusFound = await this.search(locus, true)
if (!locusFound) {
throw new Error("Cannot set initial locus")
}
throw new Error(`Cannot set initial locus ${locus}`)
}

if (genomeChange && this.circularView) {
Expand All @@ -727,31 +711,23 @@ class Browser {
}
}

cleanHouseForSession() {

for (let trackView of this.trackViews) {
// empty axis column, viewport columns, sampleName column, scroll column, drag column, gear column
trackView.removeDOMFromColumnContainer()
}

// discard all columns
const elements = this.columnContainer.querySelectorAll('.igv-axis-column, .igv-column-shim, .igv-column, .igv-sample-info-column, .igv-sample-name-column, .igv-scrollbar-column, .igv-track-drag-column, .igv-gear-menu-column')
elements.forEach(column => column.remove())

this.trackViews = []

if (this.circularView) {
this.circularView.clearChords()
}

}

updateNavbarDOMWithGenome(genome) {
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 (this.config.showChromosomeWidget !== false) {

// chromosome select widget -- Show this IFF its not explicitly hidden AND the genome has pre-loaded chromosomes
const showChromosomeWidget =
this.config.showChromosomeWidget !== false &&
genome.getChromosomes().size > 1 &&
(genome.wgChromosomeNames || genome.getChromosomes().size < 1000)

if (showChromosomeWidget) {
this.chromosomeSelectWidget.update(genome)
this.chromosomeSelectWidget.show()
} else {
this.chromosomeSelectWidget.hide()
}
}

Expand All @@ -772,7 +748,7 @@ class Browser {
genomeConfig = idOrConfig //await GenomeUtils.expandReference(this.alert, idOrConfig)
}

await this.loadReference(genomeConfig, undefined)
await this.loadReference(genomeConfig)

const tracks = genomeConfig.tracks || []

Expand All @@ -784,14 +760,6 @@ class Browser {

await this.loadTrackList(tracks)

// Hack to accomodate ucsc Hubs. Refactor this -- hide based on genome characteristics, not session
if (this.config.showChromosomeWidget === false) {
this.chromosomeSelectWidget.hide()
} else {
this.chromosomeSelectWidget.show()
}


await this.updateViews()

return this.genome
Expand All @@ -803,20 +771,9 @@ class Browser {
* @returns {Promise<void>}
*/
async loadTrackHub(options) {

const hub = await Hub.loadHub(options.url, options)
const genomeConfig = hub.getGenomeConfig()
const initialLocus = hub.getDefaultPosition()
if (initialLocus) {
const session = {
locus: initialLocus,
reference: genomeConfig
}
return this.loadSessionObject(session)

} else {
return this.loadGenome(genomeConfig)
}
const genomeConfig = setDefaults(hub.getGenomeConfig())
return this.loadGenome(genomeConfig)
}

/**
Expand Down Expand Up @@ -1473,12 +1430,12 @@ class Browser {
referenceFrame.end = referenceFrame.start + referenceFrame.bpPerPixel * width
}

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

if (this.chromosomeSelectWidget) {
this.chromosomeSelectWidget.select.value = referenceFrameList.length === 1 ? this.referenceFrameList[0].chr : ''
}

const loc = this.referenceFrameList.map(rf => rf.getLocusString()).join(' ')


this.$searchInput.val(loc)

this.fireEvent('locuschange', [this.referenceFrameList])
Expand Down Expand Up @@ -1570,6 +1527,22 @@ class Browser {
await this.updateViews(true)
}

createCenterLineList(columnContainer) {

const centerLines = columnContainer.querySelectorAll('.igv-center-line')
for (let i = 0; i < centerLines.length; i++) {
centerLines[i].remove()
}

const centerLineList = []
const viewportColumns = columnContainer.querySelectorAll('.igv-column')
for (let i = 0; i < viewportColumns.length; i++) {
centerLineList.push(new ViewportCenterLine(this, this.referenceFrameList[i], viewportColumns[i]))
}

return centerLineList
}

async removeMultiLocusPanel(referenceFrame) {

// find the $column corresponding to this referenceFrame and remove it
Expand Down Expand Up @@ -2268,14 +2241,6 @@ function mouseUpOrLeave(e) {
}


function getInitialLocus(locus, genome) {
if (locus) {
return Array.isArray(locus) ? locus.join(' ') : locus
} else {
return genome.getHomeChromosomeName()
}
}

function logo() {

return $(
Expand Down
22 changes: 10 additions & 12 deletions js/genome/genome.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class Genome {
return Object.assign({}, this.config, {tracks: undefined})
}

getInitialLocus() {

get initialLocus() {
return this.config.locus ? this.config.locus : this.getHomeChromosomeName()
}

getHomeChromosomeName() {
Expand Down Expand Up @@ -141,21 +141,19 @@ class Genome {

async loadChromosome(chr) {

let chromAliasRecord
if (this.chromAlias) {
chromAliasRecord = await this.chromAlias.search(chr)
chr = chromAliasRecord.chr
}

if (!this.chromosomes.has(chr)) {
let chromosome
let sequenceRecord = await this.sequence.getSequenceRecord(chr)
const sequenceRecord = await this.sequence.getSequenceRecord(chr)
if (sequenceRecord) {
chromosome = new Chromosome(chr, 0, sequenceRecord.bpLength)
} else {
// Try alias
if (this.chromAlias) {
const chromAliasRecord = await this.chromAlias.search(chr)
if (chromAliasRecord) {
sequenceRecord = await this.sequence.getSequenceRecord(chromAliasRecord.chr)
chromosome = new Chromosome(chromAliasRecord.chr, 0, sequenceRecord.bpLength)
}
}
}

this.chromosomes.set(chr, chromosome) // <= chromosome might be undefined, setting it prevents future attempts
}

Expand Down
Loading

0 comments on commit 724bbcf

Please sign in to comment.