From afe05002539312942412090e68dd83c03df84f15 Mon Sep 17 00:00:00 2001 From: Jim Robinson Date: Sat, 20 Oct 2018 21:58:23 -0700 Subject: [PATCH] Support queries for "all" in straw. See #236 --- js/hicStraw.js | 24 +++++++++++++++--------- test/runTests.html | 13 +++++++++---- test/testStraw.js | 27 ++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/js/hicStraw.js b/js/hicStraw.js index ab26925e..025e3e05 100644 --- a/js/hicStraw.js +++ b/js/hicStraw.js @@ -39,16 +39,20 @@ var hic = (function (hic) { var self = this, chr1 = region1.chr, chr2 = region2.chr, - x1 = region1.start / binsize, - x2 = region1.end / binsize, - y1 = region2.start / binsize, - y2 = region2.end / binsize; + x1 = (region1.start === undefined) ? undefined : region1.start / binsize, + x2 = (region1.end === undefined) ? undefined : region1.end / binsize, + y1 = (region2.start === undefined) ? undefined : region2.start / binsize, + y2 = (region2.end === undefined) ? undefined : region2.end / binsize; return getDataset.call(self) + .then(function (dataset) { self.dataset = dataset; + if("ALL" === chr1.toUpperCase()) chr1 = chr1.toUpperCase(); + if("ALL" === chr2.toUpperCase()) chr2 = chr2.toUpperCase(); + var chr1idx = dataset.getChrIndexFromName(chr1), chr2idx = dataset.getChrIndexFromName(chr2); @@ -59,8 +63,9 @@ var hic = (function (hic) { return dataset.getMatrix(chr1idx, chr2idx) }) .then(function (matrix) { + // Find the requested resolution - var z = self.dataset.getZoomIndexForBinSize(binsize, units); + var z = undefined === binsize ? 0 : self.dataset.getZoomIndexForBinSize(binsize, units); if (z === -1) { throw new Error("Invalid bin size"); } @@ -69,8 +74,8 @@ var hic = (function (hic) { blockBinCount = zd.blockBinCount, // Dimension in bins of a block (width = height = blockBinCount) col1 = x1 === undefined ? 0 : Math.floor(x1 / blockBinCount), col2 = x1 === undefined ? zd.blockColumnCount : Math.floor(x2 / blockBinCount), - row1 = Math.floor(y1 / blockBinCount), - row2 = Math.floor(y2 / blockBinCount), + row1 = y1 === undefined ? 0 : Math.floor(y1 / blockBinCount), + row2 = y2 === undefined ? zd.blockColumnCount : Math.floor(y2 / blockBinCount), row, column, sameChr, blockNumber, promises = []; @@ -91,15 +96,16 @@ var hic = (function (hic) { return Promise.all(promises); }) .then(function (blocks) { + var contactRecords = []; blocks.forEach(function (block) { - if (block === null) { // This is most likely caused by a base pair range outside the chromosome + if (!block) { // This is most likely caused by a base pair range outside the chromosome return; } block.records.forEach(function(rec) { // TODO -- transpose? - if(rec.bin1 >= x1 && rec.bin1 <= x2 && rec.bin2 >= y1 && rec.bin2 <= y2) { + if(x1 === undefined || (rec.bin1 >= x1 && rec.bin1 <= x2 && rec.bin2 >= y1 && rec.bin2 <= y2)) { contactRecords.push(rec); } }); diff --git a/test/runTests.html b/test/runTests.html index 74285be6..b75f14df 100644 --- a/test/runTests.html +++ b/test/runTests.html @@ -41,6 +41,11 @@ + + + + + @@ -53,11 +58,11 @@
diff --git a/test/testStraw.js b/test/testStraw.js index de8ab4d7..dbdb6851 100644 --- a/test/testStraw.js +++ b/test/testStraw.js @@ -29,7 +29,6 @@ function runStrawTests() { } - asyncTest("Version 7 file", function () { var url = "https://data.broadinstitute.org/igvdata/test/data/hic/inter.hic", @@ -51,6 +50,32 @@ function runStrawTests() { start(); }) .catch(function (error) { + ok(false); + console.error(error); + start(); + }) + }); + + asyncTest("All chromosome", function () { + + var url = "https://data.broadinstitute.org/igvdata/test/data/hic/inter.hic", + normalization = "NONE", + units = "BP", + region1 = { + chr: "all" + }, + binSize = undefined, + straw; + + straw = new hic.Straw({url: url}); + + straw.getContactRecords(normalization,region1, region1, units, binSize) + .then( function(records) { + ok(records.length > 0); + start(); + }) + .catch(function (error) { + ok(false); console.error(error); start(); })