Skip to content

Commit

Permalink
bb bug when zoomed out -- out of chromosome features not filtered.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Nov 28, 2023
1 parent 133b8f2 commit e3eb05e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/main/java/org/broad/igv/ucsc/bb/BBDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ private void initMinMax() {
// dataMax = 100;
// }
// }


public double getDataMax() {
return dataMax;
}
Expand Down Expand Up @@ -197,7 +195,7 @@ protected List<LocusScore> getPrecomputedSummaryScores(String chr, int start, in


Chromosome chromosome = genome.getChromosome(chr);
if(chromosome == null) {
if (chromosome == null) {
throw new RuntimeException("Unexpected chromosome name: " + chr);
}

Expand All @@ -210,11 +208,11 @@ protected List<LocusScore> getPrecomputedSummaryScores(String chr, int start, in
return null;
} else {
long rTreeOffset = zlHeader.indexOffset;
int chrIdx = reader.getIdForChr(chr);
List<byte[]> chunks = this.reader.getLeafChunks(chr, start, chr, end, rTreeOffset);

List<LocusScore> features = new ArrayList<>();
for (byte[] c : chunks) {
reader.decodeZoomData(c, windowFunction, features);
reader.decodeZoomData(c, chrIdx, start, end, windowFunction, features);
}
return features;
}
Expand Down Expand Up @@ -272,7 +270,7 @@ private List<LocusScore> getWholeGenomeScores() {

List<LocusScore> features = new ArrayList<>();
for (byte[] c : chunks) {
reader.decodeZoomData(c, windowFunction, features);
reader.decodeZoomData(c, -1, -1, -1, windowFunction, features);
}

for (LocusScore s : features) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/ucsc/bb/BBFeatureSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ public void close() {
public Iterator<BasicFeature> getFeatures(String chr, int start, int end) throws IOException {

long rTreeOffset = reader.header.fullIndexOffset;
int chrIdx = reader.getIdForChr(chr);
List<byte[]> 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);
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/broad/igv/ucsc/bb/BBFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public BasicFeature search(String term) throws IOException {
byte[] buffer = new byte[size];
is.seek(start);
is.readFully(buffer);
List<BasicFeature> features = decodeFeatures(buffer);
List<BasicFeature> 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();
Expand All @@ -423,7 +423,7 @@ public BasicFeature search(String term) throws IOException {
return null;
}

List<BasicFeature> decodeFeatures(byte[] buffer) {
List<BasicFeature> decodeFeatures(byte[] buffer, int chrIdx, int start, int end) {
List<BasicFeature> features = new ArrayList<>();
byte[] uncompressed;
if (this.header.uncompressBuffSize > 0) {
Expand All @@ -440,16 +440,21 @@ List<BasicFeature> 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);
}
return features;
}

List<LocusScore> decodeZoomData(byte[] buffer, WindowFunction windowFunction, List<LocusScore> features) {
List<LocusScore> decodeZoomData(byte[] buffer, int chrIdx, int start, int end, WindowFunction windowFunction, List<LocusScore> features) {

byte[] uncompressed;
if (header.uncompressBuffSize > 0) {
Expand All @@ -470,6 +475,11 @@ List<LocusScore> 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;
Expand Down

0 comments on commit e3eb05e

Please sign in to comment.