diff --git a/src/main/java/org/broad/igv/ucsc/bb/BBDataSource.java b/src/main/java/org/broad/igv/ucsc/bb/BBDataSource.java index 74c8c165b4..0016d3f351 100644 --- a/src/main/java/org/broad/igv/ucsc/bb/BBDataSource.java +++ b/src/main/java/org/broad/igv/ucsc/bb/BBDataSource.java @@ -131,8 +131,6 @@ private void initMinMax() { // dataMax = 100; // } // } - - public double getDataMax() { return dataMax; } @@ -197,7 +195,7 @@ protected List getPrecomputedSummaryScores(String chr, int start, in Chromosome chromosome = genome.getChromosome(chr); - if(chromosome == null) { + if (chromosome == null) { throw new RuntimeException("Unexpected chromosome name: " + chr); } @@ -210,11 +208,11 @@ protected List getPrecomputedSummaryScores(String chr, int start, in return null; } else { long rTreeOffset = zlHeader.indexOffset; + int chrIdx = reader.getIdForChr(chr); List chunks = this.reader.getLeafChunks(chr, start, chr, end, rTreeOffset); - List features = new ArrayList<>(); for (byte[] c : chunks) { - reader.decodeZoomData(c, windowFunction, features); + reader.decodeZoomData(c, chrIdx, start, end, windowFunction, features); } return features; } @@ -272,7 +270,7 @@ private List getWholeGenomeScores() { List features = new ArrayList<>(); for (byte[] c : chunks) { - reader.decodeZoomData(c, windowFunction, features); + reader.decodeZoomData(c, -1, -1, -1, windowFunction, features); } for (LocusScore s : features) { diff --git a/src/main/java/org/broad/igv/ucsc/bb/BBFeatureSource.java b/src/main/java/org/broad/igv/ucsc/bb/BBFeatureSource.java index 0ff3ad588a..38a46bcfd7 100644 --- a/src/main/java/org/broad/igv/ucsc/bb/BBFeatureSource.java +++ b/src/main/java/org/broad/igv/ucsc/bb/BBFeatureSource.java @@ -95,10 +95,11 @@ public void close() { public Iterator getFeatures(String chr, int start, int end) throws IOException { long rTreeOffset = reader.header.fullIndexOffset; + int chrIdx = reader.getIdForChr(chr); List chunks = this.reader.getLeafChunks(chr, start, chr, end, rTreeOffset); List features = new ArrayList<>(); for (byte[] c : chunks) { - features.addAll(reader.decodeFeatures(c)); + features.addAll(reader.decodeFeatures(c, chrIdx, start, end)); } return new FeatureIterator(features, start, end); } diff --git a/src/main/java/org/broad/igv/ucsc/bb/BBFile.java b/src/main/java/org/broad/igv/ucsc/bb/BBFile.java index 32e2dda292..b573c81d6f 100644 --- a/src/main/java/org/broad/igv/ucsc/bb/BBFile.java +++ b/src/main/java/org/broad/igv/ucsc/bb/BBFile.java @@ -411,7 +411,7 @@ public BasicFeature search(String term) throws IOException { byte[] buffer = new byte[size]; is.seek(start); is.readFully(buffer); - List features = decodeFeatures(buffer); + List features = decodeFeatures(buffer, -1, -1, -1); BasicFeature largest = features.stream().reduce((f1, f2) -> { int l1 = f1.getEnd() - f1.getStart(); int l2 = f2.getEnd() - f2.getStart(); @@ -423,7 +423,7 @@ public BasicFeature search(String term) throws IOException { return null; } - List decodeFeatures(byte[] buffer) { + List decodeFeatures(byte[] buffer, int chrIdx, int start, int end) { List features = new ArrayList<>(); byte[] uncompressed; if (this.header.uncompressBuffSize > 0) { @@ -440,8 +440,13 @@ List decodeFeatures(byte[] buffer) { int chromStart = bb.getInt(); int chromEnd = bb.getInt(); String restOfFields = bb.getString(); - String chr = getChrForId(chromId); + if (chrIdx > 0) { + if (chromId < chrIdx || (chromId == chrIdx && chromEnd < start)) continue; + else if (chromId > chrIdx || (chromId == chrIdx && chromStart >= end)) break; + } + + String chr = getChrForId(chromId); final BedData bedData = new BedData(chr, chromStart, chromEnd, restOfFields); final BasicFeature feature = bedCodec.decode(bedData); features.add(feature); @@ -449,7 +454,7 @@ List decodeFeatures(byte[] buffer) { return features; } - List decodeZoomData(byte[] buffer, WindowFunction windowFunction, List features) { + List decodeZoomData(byte[] buffer, int chrIdx, int start, int end, WindowFunction windowFunction, List features) { byte[] uncompressed; if (header.uncompressBuffSize > 0) { @@ -470,6 +475,11 @@ List decodeZoomData(byte[] buffer, WindowFunction windowFunction, Li float sumData = bb.getFloat(); float sumSquares = bb.getFloat(); + if (chrIdx > 0) { + if (chromId < chrIdx || (chromId == chrIdx && chromEnd < start)) continue; + else if (chromId > chrIdx || (chromId == chrIdx && chromStart >= end)) break; + } + String chr = getChrForId(chromId); float value;