Skip to content

Commit

Permalink
* Add support for user settable window function (wig track) (igvteam#…
Browse files Browse the repository at this point in the history
…1734)

* Summarize wig track with "mean" by default -- this was the case for bigwig until zoomed in, then "raw" values, now mean is used consistently
  • Loading branch information
jrobinso authored and arpanda committed Apr 2, 2024
1 parent 081ac2f commit a500e2d
Show file tree
Hide file tree
Showing 11 changed files with 128,353 additions and 196 deletions.
52 changes: 0 additions & 52 deletions dev/wig/encode.html

This file was deleted.

83 changes: 83 additions & 0 deletions dev/wig/windowFunctions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IGV-JB</title>
<!-- Font Awesome CSS-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">

<!-- Juicebox CSS-->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/juicebox.js@2.2.2/dist/css/juicebox.css">

</head>
<body>


<div id="igvDiv" style="flex-grow:0;flex-shrink:0;flex-basis: 950px"></div>


<script type="module">

import igv from "../../js"


// Start igv.js and create regions
const igvConfig =
{
genome: "hg19",
locus: "chr8:61,424,086-62,080,568",
"tracks": [
{
"url": "https://www.encodeproject.org/files/ENCFF000ARZ/@@download/ENCFF000ARZ.bigWig",
"name": "H3K4me1 bigwig",
"autoscaleGroup": "1"
},
{
"url": "../../test/data/tdf/ENCFF000ARZ.wig.tdf",
"name": "H3K4me1 tdf",
"autoscaleGroup": "1"
},
{
"url": "../../test/data/wig/ENCFF000ARZ.wig",
"name": "H3K4me1 mean",
"autoscaleGroup": "1"
},
{
"url": "../../test/data/wig/ENCFF000ARZ.wig",
"name": "H3K4me1 min",
"windowFunction": "min",
"autoscaleGroup": "1"
},
{
"url": "../../test/data/wig/ENCFF000ARZ.wig",
"name": "H3K4me1 max",
"windowFunction": "max",
"autoscaleGroup": "1"
},
{
"url": "../../test/data/wig/ENCFF000ARZ.wig",
"name": "H3K4me1 none",
"windowFunction": "none",
"autoscaleGroup": "1"
},
{
"url": "../../test/data/wig/ENCFF000ARZ.wig",
"name": "H3K4me1 points",
"graphType": "points",
"autoscaleGroup": "1"
}
]
}

igv.createBrowser(document.getElementById("igvDiv"), igvConfig)

.then(async function (igvBrowser) {


})


</script>

</body>
</html>
17 changes: 4 additions & 13 deletions js/bigwig/bwReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {BGZip, igvxhr, StringUtils} from "../../node_modules/igv-utils/src/index
import {buildOptions, isDataURL} from "../util/igvUtils.js"
import getDecoder from "./bbDecoders.js"
import {parseAutoSQL} from "../util/ucscUtils.js"
import summarizeWigData from "./summarizeWigData.js"
import Trix from "./trix.js"
import BPTree from "./bpTree.js"

Expand Down Expand Up @@ -131,7 +130,7 @@ class BWReader {
}))

// Parse data and return features
const allFeatures = []
const features = []
for (let item of leafItems) {
const uint8Array = new Uint8Array(arrayBuffer, item.dataOffset - start, item.dataSize)
let plain
Expand All @@ -141,22 +140,14 @@ class BWReader {
} else {
plain = uint8Array
}
decodeFunction.call(this, new DataView(plain.buffer), chrIdx1, bpStart, chrIdx2, bpEnd, allFeatures, this.chromTree.idToName, windowFunction)
decodeFunction.call(this, new DataView(plain.buffer), chrIdx1, bpStart, chrIdx2, bpEnd, features, this.chromTree.idToName, windowFunction)
}

allFeatures.sort(function (a, b) {
features.sort(function (a, b) {
return a.start - b.start
})

// If we are reading "raw" wig data optionally summarize it with window function.
// Zoom level data is already summarized
if (decodeFunction === decodeWigData &&
bpPerPixel &&
("mean" === windowFunction || "min" === windowFunction || "max" === windowFunction)) {
return summarizeWigData(allFeatures, bpPerPixel, windowFunction)
} else {
return allFeatures
}
return features
}
}

Expand Down
6 changes: 4 additions & 2 deletions js/bigwig/bwSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import pack from "../feature/featurePacker.js"

class BWSource {

queryable = true
wgValues = {}
windowFunctions = ["mean", "min", "max"]

constructor(config, genome) {
this.reader = new BWReader(config, genome)
this.genome = genome
this.format = config.format || "bigwig"
this.wgValues = {}
this.queryable = true
}

async getFeatures({chr, start, end, bpPerPixel, windowFunction}) {
Expand Down
69 changes: 0 additions & 69 deletions js/bigwig/summarizeWigData.js

This file was deleted.

3 changes: 3 additions & 0 deletions js/feature/textFeatureSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class TextFeatureSource {
const queryChr = genome ? genome.getChromosomeName(chr) : chr
const isWholeGenome = ("all" === queryChr.toLowerCase())

start = start || 0
end = end || Number.MAX_SAFE_INTEGER

// Various conditions that can require a feature load
// * view is "whole genome" but no features are loaded
// * cache is disabled
Expand Down
Loading

0 comments on commit a500e2d

Please sign in to comment.