From 683cb54573feebf700b82b4c2f05081dc2848605 Mon Sep 17 00:00:00 2001 From: RalfG Date: Mon, 16 Sep 2024 10:37:44 +0200 Subject: [PATCH 1/9] Add test for predict-single --- tests/test_core.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/test_core.py b/tests/test_core.py index d2759476..771521f9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,6 +1,9 @@ +import numpy as np +from psm_utils import PSM, Peptidoform import pandas as pd -from ms2pip.core import get_training_data +from ms2pip.core import get_training_data, predict_single +from ms2pip.result import ProcessingResult def _test_get_training_data(): @@ -13,3 +16,33 @@ def _test_get_training_data(): processes=1 ) pd.testing.assert_frame_equal(expected_df, output_df) + +def test_predict_single(): + pep = Peptidoform("ACDE/2") + result = predict_single(pep) + + expected = ProcessingResult( + psm_index=0, + psm=PSM(peptidoform=pep, spectrum_id=0), + theoretical_mz={ + "b": np.array([72.04435, 175.05354, 290.08047], dtype=np.float32), + "y": np.array([148.0604, 263.0873, 366.0965], dtype=np.float32), + }, + predicted_intensity={ + "b": np.array([-9.14031, -7.6102686, -7.746709], dtype=np.float32), + "y": np.array([-5.8988147, -5.811797, -7.069088], dtype=np.float32), + }, + observed_intensity=None, + correlation=None, + feature_vectors=None, + ) + + assert result.psm_index == expected.psm_index + assert result.psm == expected.psm + np.testing.assert_array_almost_equal(result.theoretical_mz["b"], expected.theoretical_mz["b"]) + np.testing.assert_array_almost_equal(result.theoretical_mz["y"], expected.theoretical_mz["y"]) + np.testing.assert_array_almost_equal(result.predicted_intensity["b"], expected.predicted_intensity["b"]) + np.testing.assert_array_almost_equal(result.predicted_intensity["y"], expected.predicted_intensity["y"]) + assert result.observed_intensity == expected.observed_intensity + assert result.correlation == expected.correlation + assert result.feature_vectors == expected.feature_vectors From d65dde7d53bdeea66fc9b9e62c814c668c6e419d Mon Sep 17 00:00:00 2001 From: RalfG Date: Mon, 16 Sep 2024 10:42:18 +0200 Subject: [PATCH 2/9] Build with backwards-compatible Numpy v2, allow newer versions of Numpy, Pandas, and XGBoost at runtime --- pyproject.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ce3540ea..ebdf79b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,14 +33,14 @@ classifiers = [ ] requires-python = ">=3.8" dependencies = [ - "numpy>=1.16,<2", - "pandas>=1,<2", + "numpy>=1.25,<3", + "pandas>=1,<3", "pyarrow", "pyteomics>=3.5,<5", "tomlkit>=0.5,<1", "sqlalchemy>=1.3,<2", "click>=7,<9", - "xgboost>=1.3,<2", + "xgboost>=1.3", "lxml>=4", "rich>=13", "pydantic>=2", @@ -75,7 +75,7 @@ publication = "https://doi.org/10.1093/nar/gkad335/" ms2pip = "ms2pip.__main__:main" [build-system] -requires = ["setuptools", "cython", "oldest-supported-numpy"] +requires = ["setuptools", "cython", "numpy>=2.0"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] From b0aacd8127dfd1f192d592170013d9550a620bd6 Mon Sep 17 00:00:00 2001 From: RalfG Date: Mon, 16 Sep 2024 11:19:00 +0200 Subject: [PATCH 3/9] Remove Python 3.8 builds (EOL soon; no Numpy v2) --- .github/workflows/test.yml | 3 ++- .readthedocs.yml | 2 +- docs/source/installation.rst | 2 +- pyproject.toml | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 133da30e..b06442ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,8 +12,9 @@ jobs: runs-on: ubuntu-latest strategy: max-parallel: 4 + fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/.readthedocs.yml b/.readthedocs.yml index 8badf360..d5cd59ce 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -3,7 +3,7 @@ version: 2 build: os: "ubuntu-20.04" tools: - python: "3.8" + python: "3.11" jobs: post_checkout: # Download and uncompress the binary diff --git a/docs/source/installation.rst b/docs/source/installation.rst index e530b455..5ca4efbd 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -6,7 +6,7 @@ Pip package .. image:: https://flat.badgen.net/badge/install%20with/pip/green :target: https://pypi.org/project/ms2pip/ -With Python 3.8 or higher, run: +With Python 3.9 or higher, run: .. code-block:: bash diff --git a/pyproject.toml b/pyproject.toml index ebdf79b2..114f9b01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ classifiers = [ "Topic :: Scientific/Engineering :: Bio-Informatics", "Development Status :: 5 - Production/Stable", ] -requires-python = ">=3.8" +requires-python = ">=3.9" dependencies = [ "numpy>=1.25,<3", "pandas>=1,<3", @@ -83,15 +83,15 @@ include = ["ms2pip*"] [tool.black] line-length = 99 -target-version = ['py38'] +target-version = ['py39'] [tool.ruff] line-length = 99 -target-version = 'py38' +target-version = 'py39' [tool.cibuildwheel] build = "cp3*-manylinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" -skip = "cp36-* cp37-* cp312-*" # EOL / no Numpy wheels available yet for Python 3.12 +skip = "cp36-* cp37-* cp38-*" manylinux-x86_64-image = "manylinux2014" # test-command = "pytest {package}/tests" test-command = "ms2pip --help" From 5327e433c186ee67e86746988b4f3374d58dc86f Mon Sep 17 00:00:00 2001 From: RalfG Date: Mon, 30 Sep 2024 16:54:37 +0200 Subject: [PATCH 4/9] Update build CI: Upgrade cibuildwheel version (adding Python 3.12?), add musllinux builds, add pytest for built wheels --- .github/workflows/build_and_publish.yml | 18 +++--------------- pyproject.toml | 6 ++---- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index e4ee0050..768ab13d 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -12,20 +12,16 @@ jobs: - uses: actions/checkout@v4 with: lfs: "true" - - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.11" - - name: Install dependencies run: | python -m pip install --upgrade pip pip install build - - name: Build sdist run: python -m build --sdist --outdir dist - - uses: actions/upload-artifact@v4 with: name: dist-source @@ -41,18 +37,10 @@ jobs: - uses: actions/checkout@v4 with: lfs: "true" - - - uses: actions/setup-python@v5 - name: Set up Python - with: - python-version: "3.11" - - - name: Install cibuildwheel - run: python -m pip install cibuildwheel>=2 - - name: Build wheels - run: python -m cibuildwheel --output-dir dist - + uses: pypa/cibuildwheel@v2.21.1 + with: + output-dir: dist - uses: actions/upload-artifact@v4 with: name: dist-${{ matrix.os }} diff --git a/pyproject.toml b/pyproject.toml index 114f9b01..6e6767cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,11 +90,9 @@ line-length = 99 target-version = 'py39' [tool.cibuildwheel] -build = "cp3*-manylinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" +build = "cp3*-manylinux_x86_64 cp3*-musllinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" skip = "cp36-* cp37-* cp38-*" -manylinux-x86_64-image = "manylinux2014" -# test-command = "pytest {package}/tests" -test-command = "ms2pip --help" +test-command = "pytest {package}/tests && ms2pip --help" [tool.cibuildwheel.macos] before-all = "brew install libomp" From 39426cd2c84c53f211cd630957f209a979430ede Mon Sep 17 00:00:00 2001 From: RalfG Date: Tue, 1 Oct 2024 15:14:36 +0200 Subject: [PATCH 5/9] Test publish workflow --- .github/workflows/build_and_publish.yml | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 768ab13d..de369779 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -3,6 +3,7 @@ name: Build and publish to PyPI on: release: types: [created] + pull_request: # for testing jobs: build-sdist: @@ -46,18 +47,18 @@ jobs: name: dist-${{ matrix.os }} path: dist - publish-to-pypi: - needs: [build-sdist, build-wheels] - runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/p/ms2pip - permissions: - id-token: write - steps: - - uses: actions/download-artifact@v4 - - name: Move wheels to dist - run: | - mv wheels-*/*.whl dist/ - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + # publish-to-pypi: + # needs: [build-sdist, build-wheels] + # runs-on: ubuntu-latest + # environment: + # name: pypi + # url: https://pypi.org/p/ms2pip + # permissions: + # id-token: write + # steps: + # - uses: actions/download-artifact@v4 + # - name: Move wheels to dist + # run: | + # mv wheels-*/*.whl dist/ + # - name: Publish to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1 From 691f048d9f7e3a1ce39c2bc1dac2cd49d485b7f0 Mon Sep 17 00:00:00 2001 From: RalfG Date: Tue, 1 Oct 2024 15:21:22 +0200 Subject: [PATCH 6/9] Add test-requires option for cibuildwheel --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 6e6767cf..318669a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,6 +92,7 @@ target-version = 'py39' [tool.cibuildwheel] build = "cp3*-manylinux_x86_64 cp3*-musllinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" skip = "cp36-* cp37-* cp38-*" +test-requires = "pytest" test-command = "pytest {package}/tests && ms2pip --help" [tool.cibuildwheel.macos] From 68414ca800572d323b675890f0e8c798dca83d4e Mon Sep 17 00:00:00 2001 From: RalfG Date: Tue, 1 Oct 2024 15:30:13 +0200 Subject: [PATCH 7/9] Add before-test option for cibuildwheel --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 318669a0..939a3de4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,6 +92,7 @@ target-version = 'py39' [tool.cibuildwheel] build = "cp3*-manylinux_x86_64 cp3*-musllinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" skip = "cp36-* cp37-* cp38-*" +before-test = "cd {project} && rm ms2pip" # Remove the ms2pip dir to avoid conflicts with the built wheel test-requires = "pytest" test-command = "pytest {package}/tests && ms2pip --help" From 4851b67d255fa0e2fe79e2f6396648ac18558e3b Mon Sep 17 00:00:00 2001 From: RalfG Date: Tue, 1 Oct 2024 15:33:50 +0200 Subject: [PATCH 8/9] Fix stupid mistake --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 939a3de4..97e0731f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,7 +92,7 @@ target-version = 'py39' [tool.cibuildwheel] build = "cp3*-manylinux_x86_64 cp3*-musllinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" skip = "cp36-* cp37-* cp38-*" -before-test = "cd {project} && rm ms2pip" # Remove the ms2pip dir to avoid conflicts with the built wheel +before-test = "cd {project} && rm -r ms2pip" # Remove the ms2pip dir to avoid conflicts with the built wheel test-requires = "pytest" test-command = "pytest {package}/tests && ms2pip --help" From 1d85f90a4385cf65a9b2f660430704592d05c13b Mon Sep 17 00:00:00 2001 From: RalfG Date: Tue, 1 Oct 2024 16:04:20 +0200 Subject: [PATCH 9/9] Fix stupid mistake --- pyproject.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 97e0731f..cd78362e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,9 +92,7 @@ target-version = 'py39' [tool.cibuildwheel] build = "cp3*-manylinux_x86_64 cp3*-musllinux_x86_64 cp3*-win_amd64 cp3*-macosx_x86_64 cp3*-macosx_arm64" skip = "cp36-* cp37-* cp38-*" -before-test = "cd {project} && rm -r ms2pip" # Remove the ms2pip dir to avoid conflicts with the built wheel -test-requires = "pytest" -test-command = "pytest {package}/tests && ms2pip --help" +test-command = "ms2pip --help" [tool.cibuildwheel.macos] before-all = "brew install libomp"