Skip to content

Commit

Permalink
Fix behaviour of names argument in bigWigAverageOverBed of pybigtools.
Browse files Browse the repository at this point in the history
Fix behaviour of names argument in bigWigAverageOverBed of pybigtools
for `True` and `1+` as values passed to `Name::Column()` were off by one.

Before for a 4 column BED file, you would get the following error
for `True` or `4`:

    Exception: Invalid name column option. Number of columns (4) is less than the value specified (5).
  • Loading branch information
ghuls committed Jun 13, 2024
1 parent 42fdb15 commit e70277d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pybigtools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,22 +1175,21 @@ fn bigWigAverageOverBed(
Some(names) => match names.extract::<bool>(py) {
Ok(b) => {
if b {
(Name::Column(4), true)
(Name::Column(3), true)
} else {
(Name::None, true)
}
}
Err(_) => match names.extract::<isize>(py) {
Ok(col) => {
if col < 0 {
return Err(PyErr::new::<exceptions::PyException, _>(
"Invalid names argument. Must be >= 0.",
));
}
if col == 0 {
(Name::None, true)
} else {
(Name::Column(col as usize), true)
match col {
0 => (Name::None, true),
1.. => (Name::Column((col - 1) as usize), true),
_ => {
return Err(PyErr::new::<exceptions::PyException, _>(
"Invalid names argument. Must be >= 0.",
));
}
}
}
Err(_) => {
Expand Down

0 comments on commit e70277d

Please # to comment.