Skip to content

Commit

Permalink
bin_size when no bins are specified is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed Jun 29, 2024
1 parent cb690ad commit cda114f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pybigtools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ fn intervals_to_array<R: BBIFileRead>(
.convert_err()?;
to_array(start, end, iter, missing, array.as_array_mut()).convert_err()?;

(end - start) as f64
1.0
}
};

Expand All @@ -301,7 +301,7 @@ fn intervals_to_array<R: BBIFileRead>(
array[i] = oob;
}
}
if end >= length {
if end > length {
let interval_start = (length as i32) - start;
let interval_end = end - start;
let bin_start = ((interval_start as f64) / bin_size) as usize;
Expand Down Expand Up @@ -421,7 +421,7 @@ fn entries_to_array<R: BBIFileRead>(
.convert_err()?;
to_entry_array(start, end, iter, missing, array.as_array_mut()).convert_err()?;

(end - start) as f64
1.0
}
};

Expand All @@ -437,7 +437,7 @@ fn entries_to_array<R: BBIFileRead>(
array[i] = oob;
}
}
if end >= length {
if end > length {
let interval_start = (length as i32) - start;
let interval_end = end - start;
let bin_start = ((interval_start as f64) / bin_size) as usize;
Expand Down
9 changes: 9 additions & 0 deletions pybigtools/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ def test_zoom_records(bw, bb):
assert pytest.raises(KeyError, bw.zoom_records, 10, "chr11")
assert pytest.raises(KeyError, bb.zoom_records, 3911, "chr11")

def test_values_no_end(bw, bb):
# (chrom, None, None) => all values on chrom
assert len(bw.values("chr17")) == 83_257_441
assert len(bb.values("chr21")) == 48_129_895
# (chrom, start, None) => all values from (start, <chrom_end>)
assert len(bw.values("chr17", 0)) == 83_257_441
assert len(bw.values("chr17", 10)) == 83_257_441 - 10
assert len(bb.values("chr21", 0)) == 48_129_895
assert len(bb.values("chr21", 10)) == 48_129_895 - 10

def test_values(bw, bb):
assert len(bw.values("chr17", 100_000, 110_000)) == 10_000
Expand Down

0 comments on commit cda114f

Please sign in to comment.