From 41c1b4d99de0fd7a9ff9b92acc08d03e7dddfc78 Mon Sep 17 00:00:00 2001 From: Florian Huber <36473328+florian-huber@users.noreply.github.com> Date: Fri, 24 May 2024 21:31:09 +0200 Subject: [PATCH 1/4] Create basic_ci.yml Add first CI --- .github/workflows/basic_ci.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/basic_ci.yml diff --git a/.github/workflows/basic_ci.yml b/.github/workflows/basic_ci.yml new file mode 100644 index 0000000..6aeaf98 --- /dev/null +++ b/.github/workflows/basic_ci.yml @@ -0,0 +1,29 @@ +name: Basic CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + basic_tests: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install dependencies via pip + run: | + pip install -e . + + - name: Run tests + run: | + pytest From b8d1e29c55a7b84c5ce9cc3969ca69912338e920 Mon Sep 17 00:00:00 2001 From: Florian Huber <36473328+florian-huber@users.noreply.github.com> Date: Fri, 24 May 2024 21:39:04 +0200 Subject: [PATCH 2/4] add dev dependencies --- setup.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.py b/setup.py index c78383b..caa0704 100644 --- a/setup.py +++ b/setup.py @@ -28,4 +28,9 @@ "seaborn", "standardizeUtils @ git+https://github.com/boecker-lab/standardizeUtils/#egg=standardizeUtils" ], + extras_require={"dev": ["black", + "pytest", + "pytest-cov", + ], + } ) From 22cca16880bb14a0f2de2bf0e4f81d7c89f45609 Mon Sep 17 00:00:00 2001 From: Florian Huber <36473328+florian-huber@users.noreply.github.com> Date: Fri, 24 May 2024 21:40:59 +0200 Subject: [PATCH 3/4] Update basic_ci.yml --- .github/workflows/basic_ci.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/basic_ci.yml b/.github/workflows/basic_ci.yml index 6aeaf98..b10ab0d 100644 --- a/.github/workflows/basic_ci.yml +++ b/.github/workflows/basic_ci.yml @@ -14,16 +14,21 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Python uses: actions/setup-python@v4 with: python-version: 3.11 - - - name: Install dependencies via pip + - name: Python info run: | - pip install -e . - + which python + python --version + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e .[dev] + - name: Show pip list + run: | + pip list - name: Run tests run: | pytest From 85ddb44d28b17e34d792bd80c4814fbff8a9e645 Mon Sep 17 00:00:00 2001 From: Florian Huber Date: Fri, 24 May 2024 21:50:27 +0200 Subject: [PATCH 4/4] split test in two files --- tests/test_tokenizer.py | 41 ++++++++++++++++++++++++++++++++ tests/{test.py => test_utils.py} | 38 ----------------------------- 2 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 tests/test_tokenizer.py rename tests/{test.py => test_utils.py} (62%) diff --git a/tests/test_tokenizer.py b/tests/test_tokenizer.py new file mode 100644 index 0000000..a2443ce --- /dev/null +++ b/tests/test_tokenizer.py @@ -0,0 +1,41 @@ +import numpy as np +import matchms +from massspecgym.transforms import SpecTokenizer + + +def test_spec_tokenizer(): + spec = matchms.Spectrum( + mz=np.array( + [ + 45.134823, + 45.13699, + 110.096245, + 130.064972, + 136.111862, + 277.16571, + 289.165924, + 307.177856, + 406.223083, + ] + ), + intensities=np.array( + [ + 0.01082, + 0.01064, + 0.17184, + 0.1397, + 0.00874, + 1.0, + 0.52842, + 0.00793, + 0.43696 + ] + ), + metadata={"precursor_mz": 406.22}, + ) + + tokenizer = SpecTokenizer(n_peaks=60) + spec_np = tokenizer(spec) + assert spec_np.shape == (60, 2) + assert (spec_np[:spec.peaks.mz.shape[0], 0] == spec.peaks.mz).all() + assert (spec_np[:spec.peaks.intensities.shape[0], 1] == spec.peaks.intensities).all() diff --git a/tests/test.py b/tests/test_utils.py similarity index 62% rename from tests/test.py rename to tests/test_utils.py index 3284d68..a61b6e1 100644 --- a/tests/test.py +++ b/tests/test_utils.py @@ -51,44 +51,6 @@ def test_pad_spectrum(): assert False -def test_spec_tokenizer(): - spec = matchms.Spectrum( - mz=np.array( - [ - 45.134823, - 45.13699, - 110.096245, - 130.064972, - 136.111862, - 277.16571, - 289.165924, - 307.177856, - 406.223083, - ] - ), - intensities=np.array( - [ - 0.01082, - 0.01064, - 0.17184, - 0.1397, - 0.00874, - 1.0, - 0.52842, - 0.00793, - 0.43696 - ] - ), - metadata={"precursor_mz": 406.22}, - ) - - tokenizer = SpecTokenizer(n_peaks=60) - spec_np = tokenizer(spec) - assert spec_np.shape == (60, 2) - assert (spec_np[:spec.peaks.mz.shape[0], 0] == spec.peaks.mz).all() - assert (spec_np[:spec.peaks.intensities.shape[0], 1] == spec.peaks.intensities).all() - - def test_morgan_fp(): mol = Chem.MolFromSmiles("Cn1cnc2c1c(=O)n(C)c(=O)n2C") for i in [2048, 4096]: