From e70277d9634c274fa855efc389c124e7973f42ab Mon Sep 17 00:00:00 2001 From: Gert Hulselmans Date: Thu, 13 Jun 2024 16:28:18 +0200 Subject: [PATCH] Fix behaviour of names argument in bigWigAverageOverBed of pybigtools. 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). --- pybigtools/src/lib.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pybigtools/src/lib.rs b/pybigtools/src/lib.rs index afca2bc..f24ea59 100644 --- a/pybigtools/src/lib.rs +++ b/pybigtools/src/lib.rs @@ -1175,22 +1175,21 @@ fn bigWigAverageOverBed( Some(names) => match names.extract::(py) { Ok(b) => { if b { - (Name::Column(4), true) + (Name::Column(3), true) } else { (Name::None, true) } } Err(_) => match names.extract::(py) { Ok(col) => { - if col < 0 { - return Err(PyErr::new::( - "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::( + "Invalid names argument. Must be >= 0.", + )); + } } } Err(_) => {