diff --git a/pybigtools/src/lib.rs b/pybigtools/src/lib.rs index ac7ade8..b0c30d5 100644 --- a/pybigtools/src/lib.rs +++ b/pybigtools/src/lib.rs @@ -285,7 +285,7 @@ fn intervals_to_array( .convert_err()?; to_array(start, end, iter, missing, array.as_array_mut()).convert_err()?; - (end - start) as f64 + 1.0 } }; @@ -301,7 +301,7 @@ fn intervals_to_array( 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; @@ -421,7 +421,7 @@ fn entries_to_array( .convert_err()?; to_entry_array(start, end, iter, missing, array.as_array_mut()).convert_err()?; - (end - start) as f64 + 1.0 } }; @@ -437,7 +437,7 @@ fn entries_to_array( 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; diff --git a/pybigtools/tests/test_api.py b/pybigtools/tests/test_api.py index 189536f..4f7c933 100644 --- a/pybigtools/tests/test_api.py +++ b/pybigtools/tests/test_api.py @@ -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, ) + 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