From f48ff6253d8b6a80778c7546d1ad0c47d5aa28aa Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 14 Feb 2024 09:57:56 +0100 Subject: [PATCH 1/8] Update dependencies Update all dependencies to latest versions. This might be necessary to support Windows. --- Cargo.toml | 13 +++++-------- pyproject.toml | 2 +- src/lib.rs | 33 +++++++++++++++++---------------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 26dfff7..de56b7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,8 @@ name = "pycoverm" crate-type = ["cdylib"] [dependencies] -coverm = "0.6.0" -ndarray = "0.13.1" -numpy = "0.12.1" -pyo3 = { version = "0.12.4", features = ["extension-module"] } -rust-htslib = "0.36.0" - -[package.metadata.maturin] -requires-dist = ["numpy"] +coverm = "0.7.0" +ndarray = "0.15.6" +numpy = "0.20.0" +pyo3 = { version = "0.20", features = ["extension-module"] } +rust-htslib = "0.45.0" diff --git a/pyproject.toml b/pyproject.toml index 9a2f56d..28236c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["maturin>=0.10,<0.11"] +requires = ["maturin>=1.4.0,<2.0", "numpy==0.20.0"] build-backend = "maturin" diff --git a/src/lib.rs b/src/lib.rs index 22cd7cf..92e856e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,8 @@ use coverm::{ FlagFilter, }; use ndarray::Array; -use numpy::convert::ToPyArray; +use numpy::pyo3::IntoPy; +use numpy::ToPyArray; use pyo3::{prelude::*, wrap_pyfunction}; use rust_htslib::{bam, bam::Read}; use std::collections::HashSet; @@ -83,14 +84,16 @@ fn is_bam_sorted(bam_file: &str) -> PyResult { /// tuple /// A tuple whose fist element is a list of the contig names and the second /// one is a numpy matrix of contig coverages in the input BAM files. -#[pyfunction( - contig_end_exclusion = "75", - min_identity = "0.97", - trim_lower = "0.", - trim_upper = "0.", - contig_set = "None", - threads = "1" -)] +#[pyfunction] +#[pyo3(signature = ( + bam_list, + contig_end_exclusion = 75, + min_identity = 0.97, + trim_lower = 0., + trim_upper = 0., + contig_set = None, + threads = 1 +))] fn get_coverages_from_bam( py: Python, bam_list: Vec<&str>, @@ -99,7 +102,7 @@ fn get_coverages_from_bam( trim_lower: f32, trim_upper: f32, contig_set: Option>, - threads: usize, + threads: u16, ) -> (PyObject, PyObject) { let trim_upper = 1. - trim_upper; let min_fraction_covered_bases = 0.; @@ -166,7 +169,7 @@ fn get_coverages_from_bam( &mut estimators_and_taker.taker, &mut estimators_and_taker.estimators, true, - filter_params.flag_filters, + &filter_params.flag_filters, threads, ); @@ -200,9 +203,7 @@ fn get_coverages_from_bam( } ( headers.into_py(py), - matrix - .to_pyarray(Python::acquire_gil().python()) - .into_py(py), + matrix.to_pyarray(py).into() ) } @@ -210,8 +211,8 @@ fn default_return_value(py: Python, n_files: usize) -> (Py, Py) { ( Vec::::new().into_py(py), Array::from_elem((0, n_files), 0f32) - .to_pyarray(Python::acquire_gil().python()) - .into_py(py), + .to_pyarray(py) + .into(), ) } From 3f56c57cf8a91560bab3ffe382e6c2abde876d59 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Sat, 10 Feb 2024 16:12:13 +0100 Subject: [PATCH 2/8] Add Windows build to CI --- .github/workflows/build_wheels.yaml | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index c020d67..9d79bd9 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -6,6 +6,41 @@ on: workflow_dispatch: jobs: + macos: + name: Build Windows + runs-on: windows-latest + strategy: + matrix: + python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: rust-toolchain + uses: actions-rs/toolchain@v1.0.6 + with: + profile: minimal + toolchain: stable + default: true + - name: Setup Python ${{ matrix.python-version }} environment + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Build wheels (x86_64) + uses: messense/maturin-action@v1 + with: + target: x86_64 + maturin-version: v0.10.6 + args: --interpreter python${{ matrix.python-version }} --release --out dist + - name: Install built wheel (x86_64) + run: | + pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies + python -c "import pycoverm" + - name: Upload wheels + uses: actions/upload-artifact@v2 + with: + name: wheels + path: dist + macos: name: Build macOS runs-on: macos-latest From e8729f80737542fa091f96b43778e4fa5cdb0892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Camargo?= Date: Sat, 10 Feb 2024 10:14:01 -0800 Subject: [PATCH 3/8] Rename windows build CI --- .github/workflows/build_wheels.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index 9d79bd9..9e2b136 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -6,7 +6,7 @@ on: workflow_dispatch: jobs: - macos: + windows: name: Build Windows runs-on: windows-latest strategy: From eec9dae3c886681952b5319b3c3fa0816e2c0e52 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 14 Feb 2024 09:07:08 +0100 Subject: [PATCH 4/8] Try making Windows work --- .github/workflows/build_wheels.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index 9e2b136..500c593 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -27,10 +27,13 @@ jobs: python-version: ${{ matrix.python-version }} - name: Build wheels (x86_64) uses: messense/maturin-action@v1 + env: + PYO3_PYTHON: python3.11 + PYO3_PRINT_CONFIG: 1 with: target: x86_64 maturin-version: v0.10.6 - args: --interpreter python${{ matrix.python-version }} --release --out dist + args: --release --out dist - name: Install built wheel (x86_64) run: | pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies From 9cf00e9f2547f4d1c73afa13e59762b948a613f6 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 14 Feb 2024 09:17:22 +0100 Subject: [PATCH 5/8] Another try --- .github/workflows/build_wheels.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index 500c593..4a8df8c 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -25,15 +25,11 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Build wheels (x86_64) - uses: messense/maturin-action@v1 - env: - PYO3_PYTHON: python3.11 - PYO3_PRINT_CONFIG: 1 + + - name: Build wheels + uses: PyO3/maturin-action@v1 with: - target: x86_64 - maturin-version: v0.10.6 - args: --release --out dist + args: --release --out dist -m python/Cargo.toml - name: Install built wheel (x86_64) run: | pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies From 7182996aa5cfbbc07ce5179c49c7f48c97261347 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 14 Feb 2024 09:22:28 +0100 Subject: [PATCH 6/8] Another try --- .github/workflows/build_wheels.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index 4a8df8c..d343166 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -29,7 +29,7 @@ jobs: - name: Build wheels uses: PyO3/maturin-action@v1 with: - args: --release --out dist -m python/Cargo.toml + args: --release --out dist - name: Install built wheel (x86_64) run: | pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies From 210710455e33bc9a7f4361c09ee5f5b29dc24ca8 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 14 Feb 2024 09:28:25 +0100 Subject: [PATCH 7/8] Final try --- .github/workflows/build_wheels.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index d343166..a87e73f 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -29,7 +29,7 @@ jobs: - name: Build wheels uses: PyO3/maturin-action@v1 with: - args: --release --out dist + args: -i python --release --out dist - name: Install built wheel (x86_64) run: | pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies From 5fb1da77f4ed6ce1453b3cf948453c58c58628e1 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 14 Feb 2024 11:00:10 +0100 Subject: [PATCH 8/8] Try again --- .github/workflows/build_wheels.yaml | 154 ++++++++++++++-------------- Cargo.toml | 3 +- 2 files changed, 79 insertions(+), 78 deletions(-) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index a87e73f..3b7402d 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -11,7 +11,7 @@ jobs: runs-on: windows-latest strategy: matrix: - python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] + python-version: [ '3.10' ] # TODO: Restore! steps: - name: Checkout uses: actions/checkout@v3 @@ -40,79 +40,79 @@ jobs: name: wheels path: dist - macos: - name: Build macOS - runs-on: macos-latest - strategy: - matrix: - python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: rust-toolchain - uses: actions-rs/toolchain@v1.0.6 - with: - profile: minimal - toolchain: stable - default: true - - name: Setup Python ${{ matrix.python-version }} environment - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Build wheels (x86_64) - uses: messense/maturin-action@v1 - with: - target: x86_64 - maturin-version: v0.10.6 - args: --interpreter python${{ matrix.python-version }} --release --out dist - - name: Install built wheel (x86_64) - run: | - pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies - python -c "import pycoverm" - - name: Upload wheels - uses: actions/upload-artifact@v2 - with: - name: wheels - path: dist - - linux: - name: Build Linux - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - architecture: x64 - - name: Build Wheels - uses: messense/maturin-action@v1 - with: - target: x86_64 - maturin-version: v0.10.6 - manylinux: auto - args: --interpreter python${{ matrix.python-version }} --release --out dist - before-script-linux: | - # If we're running on rhel centos, install needed packages. - if command -v yum &> /dev/null; then - yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic - # If we're running on i686 we need to symlink libatomic - # in order to build openssl with -latomic flag. - if [[ ! -d "/usr/lib64" ]]; then - ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so - fi - else - # If we're running on debian-based system. - apt update -y && apt-get install -y libssl-dev openssl pkg-config - fi - - name: Install built wheel - run: | - pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies - python -c "import pycoverm" - - name: Upload wheels - uses: actions/upload-artifact@v2 - with: - name: wheels - path: dist +# macos: +# name: Build macOS +# runs-on: macos-latest +# strategy: +# matrix: +# python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] +# steps: +# - name: Checkout +# uses: actions/checkout@v3 +# - name: rust-toolchain +# uses: actions-rs/toolchain@v1.0.6 +# with: +# profile: minimal +# toolchain: stable +# default: true +# - name: Setup Python ${{ matrix.python-version }} environment +# uses: actions/setup-python@v4 +# with: +# python-version: ${{ matrix.python-version }} +# - name: Build wheels (x86_64) +# uses: messense/maturin-action@v1 +# with: +# target: x86_64 +# maturin-version: v0.10.6 +# args: --interpreter python${{ matrix.python-version }} --release --out dist +# - name: Install built wheel (x86_64) +# run: | +# pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies +# python -c "import pycoverm" +# - name: Upload wheels +# uses: actions/upload-artifact@v2 +# with: +# name: wheels +# path: dist +# +# linux: +# name: Build Linux +# runs-on: ubuntu-latest +# strategy: +# matrix: +# python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: ${{ matrix.python-version }} +# architecture: x64 +# - name: Build Wheels +# uses: messense/maturin-action@v1 +# with: +# target: x86_64 +# maturin-version: v0.10.6 +# manylinux: auto +# args: --interpreter python${{ matrix.python-version }} --release --out dist +# before-script-linux: | +# # If we're running on rhel centos, install needed packages. +# if command -v yum &> /dev/null; then +# yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic +# # If we're running on i686 we need to symlink libatomic +# # in order to build openssl with -latomic flag. +# if [[ ! -d "/usr/lib64" ]]; then +# ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so +# fi +# else +# # If we're running on debian-based system. +# apt update -y && apt-get install -y libssl-dev openssl pkg-config +# fi +# - name: Install built wheel +# run: | +# pip install pycoverm --no-index --find-links dist --force-reinstall --no-dependencies +# python -c "import pycoverm" +# - name: Upload wheels +# uses: actions/upload-artifact@v2 +# with: +# name: wheels +# path: dist diff --git a/Cargo.toml b/Cargo.toml index de56b7c..f4a377b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pycoverm" -version = "0.6.0" +version = "0.6.1" authors = ["Antonio Camargo "] edition = "2021" readme = "README.md" @@ -17,3 +17,4 @@ ndarray = "0.15.6" numpy = "0.20.0" pyo3 = { version = "0.20", features = ["extension-module"] } rust-htslib = "0.45.0" +openssl = { version = "0.10", features = ["vendored"] }