Skip to content

Commit

Permalink
Handle edge cases for Group Autoscale.
Browse files Browse the repository at this point in the history
  • Loading branch information
turner committed Oct 13, 2023
1 parent fcf5a4e commit 04bc5c0
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 42 deletions.
219 changes: 218 additions & 1 deletion dev/multi-select/multi-select-examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,224 @@
]
};

igv.createBrowser(document.getElementById("myDiv"), config).then(function (browser) {})
const whole_lotta_wigs_config =
{
"version": "2.16.0",
"showSampleNames": false,
"reference": {
"id": "hg19",
"name": "Human (GRCh37/hg19)",
"fastaURL": "https://igv-genepattern-org.s3.amazonaws.com/genomes/seq/hg19/hg19.fasta",
"indexURL": "https://igv-genepattern-org.s3.amazonaws.com/genomes/seq/hg19/hg19.fasta.fai",
"cytobandURL": "https://igv-genepattern-org.s3.amazonaws.com/genomes/seq/hg19/cytoBand.txt",
"aliasURL": "https://s3.amazonaws.com/igv.org.genomes/hg19/hg19_alias.tab",
"chromosomeOrder": "chr1, chr2, chr3, chr4, chr5, chr6, chr7, chr8, chr9, chr10, chr11, chr12, chr13, chr14, chr15, chr16, chr17, chr18, chr19, chr20, chr21, chr22, chrX, chrY"
},
"locus": "chr8:128,745,581-128,755,100",
"gtexSelections": {
"chr8:128,745,581-128,755,100": {
"gene": "MYC",
"snp": null
}
},
"roi": [],
"tracks": [
{
"type": "sequence",
"order": -9007199254740991
},
{
"name": "Homo sapiens HepG2 PRPF4 ",
"url": "https://www.encodeproject.org/files/ENCFF059CKF/@@download/ENCFF059CKF.bigWig",
"metadata": {
"Biosample": "Homo sapiens HepG2",
"AssayType": "ChIP-seq",
"Target": "PRPF4 ",
"BioRep": "1,2",
"TechRep": "1_1,2_1",
"OutputType": "fold change over control",
"Format": "bigWig",
"Lab": "Xiang-Dong Fu, UCSD",
"Accession": "ENCFF059CKF",
"Experiment": "ENCSR243LNQ"
},
"order": 0,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean",
"color": "rgb(255, 41, 135)"
},
{
"name": "Homo sapiens GM13977 CTCF ",
"url": "https://www.encodeproject.org/files/ENCFF000RQI/@@download/ENCFF000RQI.bigWig",
"metadata": {
"Biosample": "Homo sapiens GM13977",
"AssayType": "ChIP-seq",
"Target": "CTCF ",
"BioRep": "1",
"TechRep": "1_1",
"OutputType": "base overlap signal",
"Format": "bigWig",
"Lab": "Vishwanath Iyer, UTA",
"Accession": "ENCFF000RQI",
"Experiment": "ENCSR000DLB"
},
"order": 1,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean",
"color": "rgb(5, 248, 2)"
},
{
"name": "Homo sapiens GM12878 BCLAF1 ",
"url": "https://www.encodeproject.org/files/ENCFF036IRJ/@@download/ENCFF036IRJ.bigWig",
"metadata": {
"Biosample": "Homo sapiens GM12878",
"AssayType": "ChIP-seq",
"Target": "BCLAF1 ",
"BioRep": "2",
"TechRep": "2_1",
"OutputType": "fold change over control",
"Format": "bigWig",
"Lab": "Richard Myers, HAIB",
"Accession": "ENCFF036IRJ",
"Experiment": "ENCSR000BJZ"
},
"order": 2,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean",
"color": "rgb(0, 46, 255)"
},
{
"name": "Homo sapiens K562 ZNF274 ",
"url": "https://www.encodeproject.org/files/ENCFF555CQE/@@download/ENCFF555CQE.bigWig",
"metadata": {
"Biosample": "Homo sapiens K562",
"AssayType": "ChIP-seq",
"Target": "ZNF274 ",
"BioRep": "2",
"TechRep": "2_1",
"OutputType": "fold change over control",
"Format": "bigWig",
"Lab": "Peggy Farnham, USC",
"Accession": "ENCFF555CQE",
"Experiment": "ENCSR000EWE"
},
"order": 3,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean",
"color": "rgb(106, 207, 255)"
},
{
"name": "Homo sapiens 22Rv1 ZFX ",
"url": "https://www.encodeproject.org/files/ENCFF420XMW/@@download/ENCFF420XMW.bigWig",
"metadata": {
"Biosample": "Homo sapiens 22Rv1",
"AssayType": "ChIP-seq",
"Target": "ZFX ",
"BioRep": "2",
"TechRep": "2_1",
"OutputType": "signal p-value",
"Format": "bigWig",
"Lab": "Michael Snyder, Stanford",
"Accession": "ENCFF420XMW",
"Experiment": "ENCSR246MLJ"
},
"order": 4,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean",
"color": "rgb(137, 30, 136)"
},
{
"name": "Homo sapiens A549 CHD4 ",
"url": "https://www.encodeproject.org/files/ENCFF725AXM/@@download/ENCFF725AXM.bigWig",
"metadata": {
"Biosample": "Homo sapiens A549",
"AssayType": "ChIP-seq",
"Target": "CHD4 ",
"BioRep": "1",
"TechRep": "1_1",
"OutputType": "fold change over control",
"Format": "bigWig",
"Lab": "Bradley Bernstein, Broad",
"Accession": "ENCFF725AXM",
"Experiment": "ENCSR550SCU"
},
"order": 5,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean",
"color": "rgb(255, 114, 110)"
},
{
"name": "Homo sapiens aorta tissue male adult (34 years) H3K27ac ",
"url": "https://www.encodeproject.org/files/ENCFF162CIW/@@download/ENCFF162CIW.bigWig",
"color": "rgb(200,0,0)",
"metadata": {
"Biosample": "Homo sapiens aorta tissue male adult (34 years)",
"AssayType": "ChIP-seq",
"Target": "H3K27ac ",
"BioRep": "2",
"TechRep": "2_1",
"OutputType": "signal p-value",
"Format": "bigWig",
"Lab": "Bing Ren, UCSD",
"Accession": "ENCFF162CIW",
"Experiment": "ENCSR519CFV"
},
"order": 6,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean"
},
{
"name": "Homo sapiens with nonobstructive coronary artery disease; liver tissue male adult (32 years) H3K9me3 ",
"url": "https://www.encodeproject.org/files/ENCFF566FON/@@download/ENCFF566FON.bigWig",
"color": "rgb(100,0,0)",
"metadata": {
"Biosample": "Homo sapiens with nonobstructive coronary artery disease; liver tissue male adult (32 years)",
"AssayType": "ChIP-seq",
"Target": "H3K9me3 ",
"BioRep": "1",
"TechRep": "1_1",
"OutputType": "fold change over control",
"Format": "bigWig",
"Lab": "Bing Ren, UCSD",
"Accession": "ENCFF566FON",
"Experiment": "ENCSR563YGF"
},
"order": 8,
"format": "bigwig",
"type": "wig",
"height": 128,
"windowFunction": "mean"
},
{
"name": "Refseq Genes",
"format": "refgene",
"id": "hg19_genes",
"url": "https://hgdownload.soe.ucsc.edu/goldenPath/hg19/database/ncbiRefSeq.txt.gz",
"indexed": false,
"removable": false,
"order": 1000000,
"infoURL": "https://www.ncbi.nlm.nih.gov/gene/?term=$$",
"type": "annotation",
"height": 70
}
]
};

igv.createBrowser(document.getElementById("myDiv"), group_autoscale_config).then(function (browser) {})


</script>
Expand Down
68 changes: 30 additions & 38 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,58 +1384,50 @@ class Browser {
}
} else {
// Group autoscale
const groupAutoscaleTracks = {}
const otherTracks = []
for (let trackView of trackViews) {
const group = trackView.track.autoscaleGroup
if (group) {
var l = groupAutoscaleTracks[group]
if (!l) {
l = []
groupAutoscaleTracks[group] = l
const groupAutoscaleTrackViews = {}
const otherTrackViews = []

// Isolate group autoscale trackViews
for (const trackView of trackViews) {
if (trackView.track.autoscaleGroup) {
const autoscaleGroup = trackView.track.autoscaleGroup
if (!groupAutoscaleTrackViews[autoscaleGroup]) {
groupAutoscaleTrackViews[autoscaleGroup] = []
}
l.push(trackView)
groupAutoscaleTrackViews[autoscaleGroup].push(trackView)
} else {
otherTracks.push(trackView)
otherTrackViews.push(trackView)
}
}

if (Object.entries(groupAutoscaleTracks).length > 0) {

const keys = Object.keys(groupAutoscaleTracks)
for (let group of keys) {

const groupTrackViews = groupAutoscaleTracks[group]
const promises = []

for (let trackView of groupTrackViews) {
promises.push(trackView.getInViewFeatures())
}

const featureArray = await Promise.all(promises)

var allFeatures = [], dataRange
// An autoscaleGroup of only one (1) trackView has the lone trackView removed from group autoscale mode
const singleTonKeys = Object.keys(groupAutoscaleTrackViews).filter(key => 1 === groupAutoscaleTrackViews[ key ].length)

for (let features of featureArray) {
allFeatures = allFeatures.concat(features)
if (singleTonKeys.length > 0) {
// Look for any single trackView groupAutoscale groups and move the single trackView to otherTrackViews list
for (const key of singleTonKeys) {
for (const trackView of groupAutoscaleTrackViews[ key ]) {
trackView.track.autoscaleGroup = undefined
}
dataRange = doAutoscale(allFeatures)
otherTrackViews.push(...groupAutoscaleTrackViews[ key ])
delete groupAutoscaleTrackViews[ key ]
}
}

const p = []
for (let trackView of groupTrackViews) {
// Calculate group autoscale dataRange
if (Object.entries(groupAutoscaleTrackViews).length > 0) {
for (const [ group, trackViews] of Object.entries(groupAutoscaleTrackViews)) {
const featureArray = await Promise.all(trackViews.map(trackView => trackView.getInViewFeatures()))
const dataRange = doAutoscale(featureArray.flat())
for (const trackView of trackViews) {
trackView.track.dataRange = Object.assign({}, dataRange)
trackView.track.autoscale = false
p.push(trackView.updateViews())
}
await Promise.all(p)
await Promise.all(trackViews.map(trackView => trackView.updateViews()))
}

}

await Promise.all(otherTracks.map(tv => tv.updateViews()))
// for (let trackView of otherTracks) {
// await trackView.updateViews(force);
// }
await Promise.all(otherTrackViews.map(tv => tv.updateViews()))
}

}
Expand Down
2 changes: 1 addition & 1 deletion js/trackBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class TrackBase {
function autoScaleHandler() {
this.autoscaleGroup = undefined
this.autoscale = !this.autoscale
this.trackView.updateViews()
this.browser.updateViews()
}

menuItems.push({ object, click:autoScaleHandler })
Expand Down
3 changes: 1 addition & 2 deletions js/trackView.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ class TrackView {
if (1 === list.length) {
list[ 0 ].track.autoscale = false
list[ 0 ].track.autoscaleGroup = undefined
list[ 0 ].repaintViews()
}

this.repaintViews()
this.browser.updateViews()

}

Expand Down

0 comments on commit 04bc5c0

Please sign in to comment.