diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index a7f631629d..71a57b0719 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -1,4 +1,4 @@ -name: pypi +name: pypi upload on: create: diff --git a/.github/workflows/planemo.yml b/.github/workflows/test_planemo.yml similarity index 98% rename from .github/workflows/planemo.yml rename to .github/workflows/test_planemo.yml index 1eb242f423..dd5d0a413b 100644 --- a/.github/workflows/planemo.yml +++ b/.github/workflows/test_planemo.yml @@ -1,4 +1,4 @@ -name: Planemo +name: tests_planemo on: [push, pull_request, workflow_dispatch] env: diff --git a/.github/workflows/test.yml b/.github/workflows/test_pytest.yml similarity index 95% rename from .github/workflows/test.yml rename to .github/workflows/test_pytest.yml index f994faa306..4e9322f40e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test_pytest.yml @@ -1,4 +1,4 @@ -name: Test +name: tests_pytest on: [push, pull_request, workflow_dispatch] defaults: @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9','3.10', '3.11', '3.12'] + python-version: ['3.9','3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -73,7 +73,7 @@ jobs: runs-on: macOS-latest strategy: matrix: - python-version: ['3.9','3.10', '3.11', '3.12'] + python-version: ['3.9','3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/.github/workflows/cargo_test.yml b/.github/workflows/test_rust.yml similarity index 95% rename from .github/workflows/cargo_test.yml rename to .github/workflows/test_rust.yml index a785be5401..47728e18b5 100644 --- a/.github/workflows/cargo_test.yml +++ b/.github/workflows/test_rust.yml @@ -1,4 +1,4 @@ -name: Cargo +name: tests_rust on: [push, pull_request, workflow_dispatch] jobs: diff --git a/.github/workflows/maturin.yml b/.github/workflows/wheels.yml similarity index 99% rename from .github/workflows/maturin.yml rename to .github/workflows/wheels.yml index 023e0a5e81..76c439767b 100644 --- a/.github/workflows/maturin.yml +++ b/.github/workflows/wheels.yml @@ -1,11 +1,10 @@ -name: Wheels +name: build wheels # maturin generate-ci github > .github/workflows/maturin.yml # Also, see: https://github.com/jackh726/bigtools/blob/master/.github/workflows/release-python.yml on: push: pull_request: - workflow_dispatch: permissions: contents: read diff --git a/src/lib.rs b/src/lib.rs index 44cc19cb75..47b39334a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ mod filtering; mod multibamsummary; mod normalization; #[cfg(test)] -mod test; +mod tests; #[pymodule] fn hp(m: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index edff9fa94c..0000000000 --- a/src/test.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::calc::median; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_median() { - let v: Vec = vec![1,2,3,4,5]; - assert_eq!(median(v), 3.0); - } -} \ No newline at end of file diff --git a/src/tests/mod.rs b/src/tests/mod.rs new file mode 100644 index 0000000000..d2112058d2 --- /dev/null +++ b/src/tests/mod.rs @@ -0,0 +1,2 @@ +pub mod test_calc; +pub mod test_normalization; diff --git a/src/tests/test_calc.rs b/src/tests/test_calc.rs new file mode 100644 index 0000000000..3972826209 --- /dev/null +++ b/src/tests/test_calc.rs @@ -0,0 +1,115 @@ +use crate::calc::*; +use ndarray::{Array1, Array2}; + +mod vector_calculations_tests{ + use super::*; + + #[test] + fn test_median() { + let v: Vec = vec![1,2,3,4,5]; + assert_eq!(median(v), 3.0); + } + + #[test] + fn test_mean_float() { + let v: Vec = vec![1.0, 2.0, 3.0, 4.0, 5.0]; + assert_eq!(mean_float(v.iter().collect()), 3.0); + } + + #[test] + fn test_median_float() { + let v: Vec = vec![1.0, 2.0, 3.0, 4.0, 5.0]; + assert_eq!(median_float(v.iter().collect()), 3.0); + } + + + #[test] + fn test_min_float() { + let v: Vec = vec![1.0, 2.0, 3.0, 4.0, 5.0]; + assert_eq!(min_float(v.iter().collect()), 1.0); + } + + #[test] + fn test_max_float() { + let v: Vec = vec![1.0, 2.0, 3.0, 4.0, 5.0]; + assert_eq!(max_float(v.iter().collect()), 5.0); + } + + #[test] + fn test_sum_float() { + let v: Vec = vec![1.0, 2.0, 3.0, 4.0, 5.0]; + assert_eq!(sum_float(v.iter().collect()), 15.0); + } + + #[test] + fn test_std_float() { + let v: Vec = vec![1.0, 2.0, 3.0, 4.0, 5.0]; + assert_eq!(std_float(v.iter().collect()), 1.5811388); + + let v: Vec = vec![1.0, 1.0, 1.0]; + assert_eq!(std_float(v.iter().collect()), 0.0); + + assert_eq!(std_float(vec![]), 0.0); + } +} + +mod scalefactor_calculations_tests{ + use super::*; + #[test] + fn test_calc_ratio() { + let cov1: f32 = 5.0; + let cov2: f32 = 10.0; + + let sf1: f32 = 1.0; + let sf2: f32 = 2.0; + + let pc1: f32 = 1.0; + let pc2: f32 = 2.0; + + let log2 = "log2"; + let ratio = "ratio"; + let reciprocal_ratio = "reciprocal_ratio"; + let subtract = "subtract"; + + let r1 = calc_ratio( + cov1, cov2, + &sf1, &sf2, + &pc1, &pc2, + log2 + ); + let r2 = calc_ratio( + cov1, cov2, + &sf1, &sf2, + &pc1, &pc2, + ratio + ); + let r3 = calc_ratio( + cov1, cov2, + &sf1, &sf2, + &pc1, &pc2, + reciprocal_ratio + ); + let r4 = calc_ratio( + cov1, cov2, + &sf1, &sf2, + &pc1, &pc2, + subtract + ); + assert_eq!(r1, -1.87); + assert_eq!(r2, 0.27); + assert_eq!(r3, -0.27); + assert_eq!(r4, -16.0); + } + + #[test] + fn test_deseq_scalefactors() { + let counts = Array2::from_shape_vec((3, 3), vec![ + 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, + 7.0, 8.0, 9.0 + ]).unwrap(); + let sf = deseq_scalefactors(&counts); + let expected_sf = Array1::from_vec(vec![1.233106, 0.9864848, 0.82207066]); + assert_eq!(sf, expected_sf); + } +} \ No newline at end of file diff --git a/src/tests/test_normalization.rs b/src/tests/test_normalization.rs new file mode 100644 index 0000000000..d16a3f3c92 --- /dev/null +++ b/src/tests/test_normalization.rs @@ -0,0 +1,84 @@ +use crate::normalization::*; + +mod scale_factor_tests { + use super::*; + + #[test] + fn test_scale_factor_rpkm() { + let nm = "RPKM"; + let sf = scale_factor( + nm, + 1000, 10, 10000, + 20.0, 20.0, + 1.0, &false + ); + assert_eq!(sf, 99999.99); + } + + #[test] + fn test_scale_factor_cpm() { + let nm = "CPM"; + let sf = scale_factor( + nm, + 1000, 10, 10000, + 20.0, 20.0, + 1.0, &false + ); + assert_eq!(sf, 999.99994); + } + + #[test] + fn test_scale_factor_bpm() { + let nm = "BPM"; + let sf = scale_factor( + nm, + 1000, 10, 10000, + 20.0, 20.0, + 1.0, &false + ); + assert_eq!(sf, 999.99994); + } + + #[test] + fn test_scale_factor_rpgc() { + let nm = "RPGC"; + let sf = scale_factor( + nm, + 1000, 10, 10000, + 20.0, 20.0, + 1.0, &false + ); + assert_eq!(sf, 0.5); + } + + #[test] + fn test_preset_scalefactor() { + let nm = "RPKM"; + let sf = scale_factor( + nm, + 1000, 10, 10000, + 20.0, 20.0, + 5.5, &false + ); + assert_eq!(sf, 5.5); + } +} + +mod bamcompare_scale_factor_tests{ + use super::*; + + #[test] + fn test_bamcompare_readcount() { + let nm = "readCount"; + let (sf1, sf2) = scale_factor_bamcompare( + nm, + 1000, 2000, + 10, 10000, + "RPKM", + 20.0, 20.0, + 1.0, 1.0 + ); + assert_eq!(sf1, 1.0); + assert_eq!(sf2, 0.5); + } +} \ No newline at end of file