Skip to content

Commit

Permalink
* Add script to create an igv genome config from a hub.txt file
Browse files Browse the repository at this point in the history
* general cleanup
  • Loading branch information
jrobinso committed Jul 24, 2024
1 parent 27e2afa commit 530dd97
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 102 deletions.
61 changes: 2 additions & 59 deletions dev/ucsc/genome.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,19 @@

<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>
<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
</option>
<option value="">T2T</option>
</select>

<label>
Enter full URL to hub.txt file
<input id="hub-input" type="text" style="width: 600px">
</label>

<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">

import igv from "../../js/index.js"
import Hub from "../../js/ucsc/ucscHub.js"


const hubOptions = {
includeTracks: true
}

const hub = await Hub.loadHub("https://hgdownload.soe.ucsc.edu/hubs/GCF/002/006/095/GCF_002006095.1/hub.txt", hubOptions)

const igvConfig = {
reference: hub.getGenomeConfig(),
listeners: {
'genomechange': ({genome, trackConfigurations}) => {
console.log('genomechange')
console.log(genome)
console.log(trackConfigurations)
}
}
const igvConfig = {
genome: "GCA_000002305.1"
}


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", async () => {
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>

</body>
Expand Down
7 changes: 0 additions & 7 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1467,13 +1467,6 @@ class Browser {
return this.trackViews.map(tv => tv.track).filter(t => t !== undefined)
}

getTrackURLs() {
return new Set(this.tracks
.filter(track => track.config && StringUtils.isString(track.config.url))
.map(track => track.config.url))
}


/**
* Set the track height globally for all tracks. (Note: Its not clear why this is useful).
* @param newHeight
Expand Down
2 changes: 1 addition & 1 deletion js/feature/wigTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class WigTrack extends TrackBase {
}

} else {

// Default graph type (bar)
const height = Math.min(pixelHeight, y - y0)
IGVGraphics.fillRect(ctx, x, y0, width, height, {fillStyle: color})
if (f.value > this.dataRange.max) {
Expand Down
25 changes: 11 additions & 14 deletions js/ucsc/ucscHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
https://genome.ucsc.edu/goldenpath/help/trackDb/trackDbHub.html
*/

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

class Hub {

Expand Down Expand Up @@ -110,7 +109,7 @@ transBlat dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
isPcr dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
*/

getGenomeConfig(includeTrackGroups = "all") {
getGenomeConfig(options = {}) {
// TODO -- add blat? htmlPath?

const id = this.genomeStanza.getProperty("genome")
Expand Down Expand Up @@ -156,11 +155,11 @@ isPcr dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
if (this.genomeStanza.hasProperty("twoBitBptUrl")) {
config.twoBitBptURL = this.baseURL + this.genomeStanza.getProperty("twoBitBptUrl")
}
// chromSizes can take a very long time to load, and is not useful with the default WGV = off
// if (this.genomeStanza.hasProperty("chromSizes")) {
// config.chromSizes = this.baseURL + this.genomeStanza.getProperty("chromSizes")
// }

// chromSizes can take a very long time to load, and is not useful with the default WGV = off
if (options.includeChromSizes && this.genomeStanza.hasProperty("chromSizes")) {
config.chromSizesURL = this.baseURL + this.genomeStanza.getProperty("chromSizes")
}

if (this.hubStanza.hasProperty("longLabel")) {
config.description = this.hubStanza.getProperty("longLabel").replace("/", "\n")
Expand Down Expand Up @@ -196,13 +195,10 @@ isPcr dynablat-01.soe.ucsc.edu 4040 dynamic GCF/000/186/305/GCF_000186305.1
config.cytobandBbURL = this.baseURL + cytoStanza[0].getProperty("bigDataUrl")
}

// Tracks. To prevent loading tracks set `includeTrackGroups`to false or "none"
if (includeTrackGroups && "none" !== includeTrackGroups) {
const filter = (t) => !Hub.filterTracks.has(t.name) &&
"hide" !== t.getProperty("visibility") &&
("all" === includeTrackGroups || t.getProperty("group") === includeTrackGroups)
config.tracks = this.#getTracksConfigs(filter)
}
// Tracks.
const filter = (t) => !Hub.filterTracks.has(t.name) && "hide" !== t.getProperty("visibility")
config.tracks = this.#getTracksConfigs(filter)


return config
}
Expand Down Expand Up @@ -430,7 +426,8 @@ class Stanza {
*/
async function loadStanzas(url) {

const data = await igvxhr.loadString(url)
const response = await fetch(url)
const data = await response.text()
const lines = data.split(/\n|\r\n|\r/g)

const nodes = []
Expand Down
3 changes: 0 additions & 3 deletions scripts/embedCssTemplate.js

This file was deleted.

36 changes: 36 additions & 0 deletions scripts/hubToGenomeConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Creates an IGV genome configuration json from a UCSC genark assembly hub. It might also work with other
* UCSC hubs but has not been tested.
*
* Example use
* node hubToGenomeConfig.js GCF_002006095.1
* node hubToGenomeConfig.js https://hgdownload.soe.ucsc.edu/hubs/GCF/002/006/095/GCF_002006095.1/hub.txt
*/

import Hub from "../js/ucsc/ucscHub.js"
import {convertToHubURL} from "../js/ucsc/ucscUtils.js"

if (process.argv.length !== 3) {
console.log("Usage: node hubToGenomeConfig.js <hub accession or url to hub.text>")
}

const hubAccensionOrURL = process.argv[2]

let url
if (hubAccensionOrURL.startsWith("http://") || hubAccensionOrURL.startsWith("https://")) {
url = hubAccensionOrURL
} else {
url = convertToHubURL(hubAccensionOrURL)
}

if (!url) {
console.error(`Could not convert input "${hubAccensionOrURL}" to genark hub url`)

}

const hub = await Hub.loadHub(url)

const config = hub.getGenomeConfig({includeChromSizes: true})

process.stdout.write(JSON.stringify(config, null, 2))

18 changes: 0 additions & 18 deletions scripts/updateVersion.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ const pj = require.resolve('../package.json');
const jsonText = fs.readFileSync(pj, 'utf-8');
const version = JSON.parse(jsonText).version;


// Try to get git commit hash
// let githash = "";
// try {
// const headPath = require.resolve('../.git/HEAD');
// const rev = fs.readFileSync(headPath).toString().trim().split(/.*[: ]/).slice(-1)[0];
// if (rev.indexOf('/') === -1) {
// githash = rev;
// } else {
// const revpath = require.resolve('../.git/' + rev);
// githash = fs.readFileSync(revpath).toString().trim();
// }
// } catch (e) {
// console.error("Error determining git hash")
// }


const versionJS = require.resolve('../js/version.js')
let ping = fs.readFileSync(versionJS, 'utf-8');
const lines = ping.split(/\r?\n/);
Expand All @@ -29,7 +12,6 @@ var fd = fs.openSync(versionJS, 'w');
for (let line of lines) {
if(!line) continue;
if(line.startsWith("const _version")) {
//fs.writeSync(fd, `const _version = "${version} (${githash})"\n`, null, 'utf-8')
fs.writeSync(fd, `const _version = "${version}"\n`, null, 'utf-8')
foundVersionLine = true;
} else {
Expand Down

0 comments on commit 530dd97

Please sign in to comment.