From c6f18c9be3f5f2f5ff41f835832afd30202af924 Mon Sep 17 00:00:00 2001 From: RalfG Date: Mon, 8 Apr 2024 16:09:32 +0200 Subject: [PATCH] Add tests for get_ms2_spectra --- tests/__init__.py | 0 tests/{ => data}/README.md | 0 tests/test.py | 38 ------------------- tests/test_lib.py | 78 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 tests/__init__.py rename tests/{ => data}/README.md (100%) delete mode 100644 tests/test.py create mode 100644 tests/test_lib.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/README.md b/tests/data/README.md similarity index 100% rename from tests/README.md rename to tests/data/README.md diff --git a/tests/test.py b/tests/test.py deleted file mode 100644 index 8910a47..0000000 --- a/tests/test.py +++ /dev/null @@ -1,38 +0,0 @@ -import pytest -from ms2rescore_rs import get_precursor_info - - -def test_mgf_precursor_reading(): - precursor = get_precursor_info("tests/data/test.mgf")["peptide1"] - assert precursor.mz == pytest.approx(475.137295, 0.0001) - assert precursor.charge == 2 - assert precursor.intensity == 0 - assert precursor.rt == pytest.approx(0.853, 0.001) - assert precursor.im == 42.42 - - -def test_mzml_precursor_reading(): - precursor = get_precursor_info("tests/data/test.mzML")["index=3"] - assert precursor.mz == pytest.approx(1007.8454316970522, 0.0001) - assert precursor.charge == 3 - assert precursor.intensity == 0 - assert precursor.rt == pytest.approx(40.01385810926034, 0.001) - assert precursor.im == 1.2507906843214256 - - -def test_bruker_tdf_reading(): - precursor = get_precursor_info("tests/data/dda_test.d")["2"] - assert precursor.mz == pytest.approx(502, 0.0001) - assert precursor.charge == 2 - assert precursor.intensity == 10 - assert precursor.rt == pytest.approx(0.4, 0.001) - assert precursor.im == 1.4989212513484358 - - -def test_bruker_minitdf_reading(): - precursor = get_precursor_info("tests/data/test.ms2")["3"] - assert precursor.mz == pytest.approx(502, 0.0001) - assert precursor.charge == 2 - assert precursor.intensity == 0 - assert precursor.rt == pytest.approx(0.3, 0.001) - assert precursor.im == 1.3 diff --git a/tests/test_lib.py b/tests/test_lib.py new file mode 100644 index 0000000..dea310f --- /dev/null +++ b/tests/test_lib.py @@ -0,0 +1,78 @@ +import pytest +from ms2rescore_rs import get_precursor_info, get_ms2_spectra + + +def test_get_precursor_info_mgf(): + precursor = get_precursor_info("tests/data/test.mgf")["peptide1"] + assert precursor.mz == pytest.approx(475.137295, 0.0001) + assert precursor.charge == 2 + assert precursor.intensity == 0 + assert precursor.rt == pytest.approx(0.853, 0.001) + assert precursor.im == 42.42 + + +def test_get_precursor_info_mzml(): + precursor = get_precursor_info("tests/data/test.mzML")["index=3"] + assert precursor.mz == pytest.approx(1007.8454316970522, 0.0001) + assert precursor.charge == 3 + assert precursor.intensity == 0 + assert precursor.rt == pytest.approx(40.01385810926034, 0.001) + assert precursor.im == 1.2507906843214256 + + +def test_get_precursor_info_bruker_tdf(): + precursor = get_precursor_info("tests/data/dda_test.d")["2"] + assert precursor.mz == pytest.approx(502, 0.0001) + assert precursor.charge == 2 + assert precursor.intensity == 10 + assert precursor.rt == pytest.approx(0.4, 0.001) + assert precursor.im == 1.4989212513484358 + + +def test_get_precursor_info_bruker_minitdf(): + precursor = get_precursor_info("tests/data/test.ms2")["3"] + assert precursor.mz == pytest.approx(502, 0.0001) + assert precursor.charge == 2 + assert precursor.intensity == 0 + assert precursor.rt == pytest.approx(0.3, 0.001) + assert precursor.im == 1.3 + + +def test_get_ms2_spectra_mgf(): + spectra = get_ms2_spectra("tests/data/test.mgf") + assert len(spectra) == 1 + spectrum = spectra[0] + assert spectrum.identifier == "peptide1" + assert spectrum.mz[0] == pytest.approx(72.04439, 0.0001) + assert spectrum.intensity[0] == pytest.approx(100.0, 0.0001) + assert spectrum.mz[-1] == pytest.approx(423.11802, 0.0001) + assert spectrum.intensity[-1] == pytest.approx(200.0, 0.0001) + + +def test_get_ms2_spectra_mzml(): + spectra = get_ms2_spectra("tests/data/test.mzML") + assert len(spectra) == 4 + spectrum = spectra[0] + assert spectrum.identifier == "index=2" + assert spectrum.mz[0] == pytest.approx(113.69136810302734, 0.0001) + assert spectrum.intensity[0] == pytest.approx(14.0, 0.0001) + assert spectrum.mz[-1] == pytest.approx(1699.74951171875, 0.0001) + assert spectrum.intensity[-1] == pytest.approx(15.0, 0.0001) + + +def test_get_ms2_spectra_bruker_tdf(): + spectra = get_ms2_spectra("tests/data/dda_test.d") + assert len(spectra) == 3 + spectrum = spectra[0] + assert spectrum.identifier == "0" + assert spectrum.mz[0] == pytest.approx(199.7633514404297, 0.0001) + assert spectrum.intensity[0] == pytest.approx(162.0, 0.0001) + + +def test_get_ms2_spectra_bruker_minitdf(): + spectra = get_ms2_spectra("tests/data/test.ms2") + assert len(spectra) == 3 + spectrum = spectra[0] + assert spectrum.identifier == "1" + assert spectrum.mz[0] == pytest.approx(190.1070556640625, 0.0001) + assert spectrum.intensity[0] == pytest.approx(350.0, 0.0001)