Repository: matchms/matchms
Pull request #786 (2025-03-27 11:50:52)

Added reference spectra
Comes from #781 by @LucaCappelletti94


Patch:
diff --git a/matchms/reference_spectra/__init__.py b/matchms/reference_spectra/__init__.py
new file mode 100644
index 00000000..fb977ae5
--- /dev/null
+++ b/matchms/reference_spectra/__init__.py
@@ -0,0 +1,18 @@
+"""Submodule providing reference spectra for tests, examples and tutorials."""
+
+from .aspirin import aspirin
+from .cocaine import cocaine
+from .glucose import glucose
+from .hydroxy_cholesterol import hydroxy_cholesterol
+from .phenylalanine import phenylalanine
+from .salicin import salicin
+
+
+__all__ = [
+    "aspirin",
+    "cocaine",
+    "glucose",
+    "hydroxy_cholesterol",
+    "phenylalanine",
+    "salicin",
+]
diff --git a/matchms/reference_spectra/aspirin.py b/matchms/reference_spectra/aspirin.py
new file mode 100644
index 00000000..213b4915
--- /dev/null
+++ b/matchms/reference_spectra/aspirin.py
@@ -0,0 +1,84 @@
+"""Submodule providing a reference spectrum for aspirin."""
+
+import numpy as np
+from ..Spectrum import Spectrum
+
+
+ASPIRIN_PRECURSOR_MZ: float = 181.0490
+
+ASPIRIN_MZ: np.ndarray = np.array(
+    [
+        50.0149,
+        51.0228,
+        53.0385,
+        55.0177,
+        65.0384,
+        77.0383,
+        79.054,
+        80.0254,
+        81.0334,
+        91.0541,
+        92.0254,
+        93.0333,
+        94.0411,
+        95.049,
+        98.0361,
+        105.0333,
+        105.0445,
+        107.0489,
+        111.0439,
+        120.0203,
+        121.0282,
+        121.0394,
+        133.0282,
+        135.0438,
+        138.0308,
+        149.0231,
+        163.0386,
+        167.0337,
+        181.0491,
+    ]
+)
+
+ASPIRIN_INTENSITIES: np.ndarray = np.array(
+    [
+        49377.4,
+        53422.1,
+        454244.5,
+        57881.0,
+        1997532.0,
+        825848.2,
+        1153465.5,
+        96202.8,
+        58626.8,
+        44573.8,
+        394779.8,
+        1129287.8,
+        56357.2,
+        1654496.5,
+        72487.3,
+        707899.4,
+        1119356.4,
+        207437.4,
+        587441.8,
+        166384.0,
+        9695889.0,
+        2506571.2,
+        5824675.0,
+        6124332.0,
+        78621.8,
+        34285450.0,
+        18191732.0,
+        69049.3,
+        120675.9,
+    ]
+)
+
+
+def aspirin() -> Spectrum:
+    """Return a reference spectrum for aspirin."""
+    return Spectrum(
+        mz=ASPIRIN_MZ,
+        intensities=ASPIRIN_INTENSITIES,
+        metadata={"precursor_mz": ASPIRIN_PRECURSOR_MZ},
+    )
diff --git a/matchms/reference_spectra/cocaine.py b/matchms/reference_spectra/cocaine.py
new file mode 100644
index 00000000..eeecd633
--- /dev/null
+++ b/matchms/reference_spectra/cocaine.py
@@ -0,0 +1,44 @@
+"""Submodule providing a reference spectrum for cocaine."""
+
+import numpy as np
+from ..Spectrum import Spectrum
+
+
+COCAINE_PRECURSOR_MZ: float = 304.153137
+
+COCAINE_MZ: np.ndarray = np.array(
+    [
+        82.064789,
+        105.033249,
+        109.213745,
+        119.04921,
+        150.0914,
+        182.117676,
+        185.804688,
+        226.579071,
+        304.153137,
+    ]
+)
+
+COCAINE_INTENSITIES: np.ndarray = np.array(
+    [
+        13342.493164,
+        3264.133545,
+        1584.27478,
+        2382.930908,
+        3257.366211,
+        133504.296875,
+        1849.140137,
+        1391.734497,
+        86052.375,
+    ]
+)
+
+
+def cocaine() -> Spectrum:
+    """Return a reference spectrum for cocaine."""
+    return Spectrum(
+        mz=COCAINE_MZ,
+        intensities=COCAINE_INTENSITIES,
+        metadata={"precursor_mz": COCAINE_PRECURSOR_MZ},
+    )
diff --git a/matchms/reference_spectra/glucose.py b/matchms/reference_spectra/glucose.py
new file mode 100644
index 00000000..cec85518
--- /dev/null
+++ b/matchms/reference_spectra/glucose.py
@@ -0,0 +1,54 @@
+"""Submodule providing a reference spectrum for glucose."""
+
+import numpy as np
+from ..Spectrum import Spectrum
+
+
+GLUCOSE_PRECURSOR_MZ: float = 203.05
+
+GLUCOSE_MZ: np.ndarray = np.array(
+    [
+        82.952148,
+        105.270447,
+        112.789398,
+        121.208,
+        129.116699,
+        131.104095,
+        131.990692,
+        135.007935,
+        142.50119,
+        143.102905,
+        158.092255,
+        160.235291,
+        173.100464,
+        185.152679,
+    ]
+)
+
+GLUCOSE_INTENSITIES: np.ndarray = np.array(
+    [
+        798.858887,
+        1257.253418,
+        3923.249023,
+        1952.965454,
+        169.587341,
+        412.055176,
+        309.939514,
+        520.569153,
+        555.742432,
+        13786.814453,
+        1758.816406,
+        408.889771,
+        892.346924,
+        9220.535156,
+    ]
+)
+
+
+def glucose() -> Spectrum:
+    """Return a reference spectrum for glucose."""
+    return Spectrum(
+        mz=GLUCOSE_MZ,
+        intensities=GLUCOSE_INTENSITIES,
+        metadata={"precursor_mz": GLUCOSE_PRECURSOR_MZ},
+    )
diff --git a/matchms/reference_spectra/hydroxy_cholesterol.py b/matchms/reference_spectra/hydroxy_cholesterol.py
new file mode 100644
index 00000000..1125c65c
--- /dev/null
+++ b/matchms/reference_spectra/hydroxy_cholesterol.py
@@ -0,0 +1,288 @@
+"""Submodule providing a reference spectrum for hydroxy-cholesterol."""
+
+import numpy as np
+from ..Spectrum import Spectrum
+
+
+HYDROXY_CHOLESTEROL_PRECURSOR_MZ: float = 385.345
+
+HYDROXY_CHOLESTEROL_MZ: np.ndarray = np.array(
+    [
+        79.306831,
+        81.036896,
+        83.170624,
+        95.116501,
+        97.141312,
+        103.330635,
+        105.13884,
+        107.099525,
+        109.088669,
+        111.171356,
+        117.067558,
+        119.17308,
+        121.166855,
+        123.211304,
+        125.549042,
+        129.067566,
+        131.025848,
+        133.06012,
+        135.10881,
+        137.158203,
+        139.159882,
+        143.095245,
+        144.09375,
+        145.11795,
+        147.135376,
+        149.237,
+        151.340973,
+        155.078186,
+        156.218506,
+        157.128006,
+        159.123199,
+        160.329163,
+        161.145004,
+        163.198151,
+        165.245865,
+        167.088364,
+        169.130753,
+        170.001282,
+        171.115753,
+        173.205078,
+        175.229889,
+        177.121674,
+        179.243744,
+        181.121948,
+        182.870956,
+        185.176254,
+        187.167389,
+        188.135376,
+        189.40036,
+        191.186417,
+        193.249725,
+        197.140747,
+        199.207489,
+        201.150269,
+        202.018677,
+        203.189331,
+        205.19397,
+        207.164642,
+        209.172241,
+        210.234711,
+        211.334076,
+        213.274597,
+        214.419525,
+        215.139832,
+        217.144775,
+        218.287445,
+        219.207062,
+        221.182129,
+        223.02652,
+        224.174591,
+        225.354797,
+        227.09613,
+        229.292114,
+        231.228241,
+        233.224274,
+        239.40976,
+        241.226135,
+        243.170807,
+        245.26358,
+        247.416382,
+        249.43924,
+        251.274628,
+        253.427612,
+        255.29483,
+        257.357147,
+        259.194214,
+        261.212494,
+        263.759247,
+        267.261414,
+        269.225983,
+        271.266144,
+        272.015472,
+        273.283508,
+        274.167114,
+        283.198181,
+        285.315887,
+        287.210297,
+        288.743622,
+        289.402252,
+        291.233917,
+        293.318817,
+        295.074127,
+        297.280762,
+        299.349792,
+        301.309204,
+        303.264313,
+        305.25528,
+        309.267731,
+        311.262543,
+        313.286377,
+        315.270203,
+        324.4086,
+        325.427856,
+        327.317963,
+        327.939636,
+        329.279388,
+        338.460541,
+        339.459991,
+        340.288177,
+        341.369415,
+        343.326355,
+        349.281647,
+        354.272034,
+        357.45163,
+        365.516479,
+        367.329041,
+        368.233795,
+        368.874878,
+        384.32431,
+        385.305664,
+        386.437317,
+    ]
+)
+
+HYDROXY_CHOLESTEROL_INTENSITIES: np.ndarray = np.array(
+    [
+        4.979912,
+        22.765455,
+        16.608736,
+        84.772972,
+        70.130226,
+        11.714973,
+        31.981926,
+        54.602894,
+        91.455025,
+        46.116692,
+        37.930031,
+        74.307091,
+        41.617023,
+        54.827194,
+        3.832052,
+        68.119186,
+        102.478645,
+        114.723343,
+        107.749023,
+        12.766851,
+        6.991966,
+        17.36504,
+        16.665106,
+        121.05883,
+        66.699089,
+        78.691193,
+        21.242491,
+        17.17906,
+        18.209969,
+        16.721523,
+        220.098206,
+        7.839384,
+        180.722809,
+        176.15947,
+        85.956116,
+        18.90317,
+        36.619061,
+        14.848515,
+        26.946314,
+        195.633636,
+        74.910393,
+        184.579041,
+        174.899841,
+        63.308514,
+        11.29303,
+        37.871227,
+        325.631165,
+        7.312701,
+        98.873009,
+        323.946899,
+        71.510201,
+        16.049942,
+        64.065384,
+        192.031296,
+        14.154707,
+        120.749435,
+        368.516785,
+        226.5923,
+        28.575651,
+        15.240299,
+        6.454416,
+        176.759491,
+        10.867487,
+        91.041054,
+        85.689346,
+        7.409761,
+        365.31958,
+        28.595486,
+        40.717285,
+        11.677838,
+        11.328114,
+        145.452393,
+        80.116074,
+        263.121277,
+        252.111954,
+        11.013158,
+        319.304626,
+        56.70892,
+        139.755737,
+        57.950039,
+        23.482685,
+        14.781034,
+        22.184134,
+        454.479736,
+        154.093491,
+        368.519592,
+        56.954346,
+        42.744823,
+        19.643261,
+        88.461494,
+        94.910172,
+        16.442837,
+        413.641632,
+        7.44519,
+        41.749924,
+        87.47644,
+        128.763336,
+        64.673119,
+        14.391298,
+        13.502331,
+        75.397293,
+        49.663109,
+        169.150269,
+        12.272851,
+        152.579407,
+        113.564987,
+        30.968838,
+        16.352489,
+        310.930267,
+        41.870014,
+        20.039595,
+        72.416031,
+        155.088058,
+        234.508896,
+        24.093281,
+        83.271744,
+        53.767117,
+        85.915543,
+        40.059822,
+        35.149338,
+        25.068996,
+        30.07332,
+        9.299104,
+        60.239254,
+        6.935501,
+        14848.887695,
+        179.36615,
+        46.81424,
+        46.517662,
+        447.72229,
+        12.113778,
+    ]
+)
+
+
+def hydroxy_cholesterol() -> Spectrum:
+    """Return a reference spectrum for hydroxy-cholesterol."""
+    return Spectrum(
+        mz=HYDROXY_CHOLESTEROL_MZ,
+        intensities=HYDROXY_CHOLESTEROL_INTENSITIES,
+        metadata={"precursor_mz": HYDROXY_CHOLESTEROL_PRECURSOR_MZ},
+    )
diff --git a/matchms/reference_spectra/phenylalanine.py b/matchms/reference_spectra/phenylalanine.py
new file mode 100644
index 00000000..97dc263b
--- /dev/null
+++ b/matchms/reference_spectra/phenylalanine.py
@@ -0,0 +1,72 @@
+"""Submodule providing a reference spectrum for phenylalanine."""
+
+import numpy as np
+from ..Spectrum import Spectrum
+
+
+PHENYLANINE_PRECURSOR_MZ: float = 166.086
+
+PHENYLANINE_MZ: np.ndarray = np.array(
+    [
+        84.329651,
+        95.261452,
+        104.255539,
+        107.151161,
+        108.493408,
+        120.354172,
+        121.332741,
+        122.174088,
+        123.061447,
+        123.876312,
+        125.26976,
+        127.950974,
+        131.030273,
+        131.898819,
+        132.987488,
+        133.966949,
+        135.217804,
+        136.683533,
+        138.050446,
+        148.049011,
+        149.007416,
+        149.634232,
+        150.754486,
+    ]
+)
+
+PHENYLANINE_INTENSITIES: np.ndarray = np.array(
+    [
+        802.63324,
+        527.747314,
+        232.556427,
+        297.472168,
+        113.401199,
+        8457614.0,
+        5223.298828,
+        1784.401855,
+        733.603821,
+        514.92334,
+        680.641602,
+        341.421326,
+        44541.625,
+        596.891602,
+        781.120422,
+        2167.02002,
+        130.054764,
+        264.539215,
+        1620.135986,
+        55389.789062,
+        364218.59375,
+        4676.80957,
+        590.623291,
+    ]
+)
+
+
+def phenylalanine() -> Spectrum:
+    """Return a reference spectrum for phenylalanine."""
+    return Spectrum(
+        mz=PHENYLANINE_MZ,
+        intensities=PHENYLANINE_INTENSITIES,
+        metadata={"precursor_mz": PHENYLANINE_PRECURSOR_MZ},
+    )
diff --git a/matchms/reference_spectra/salicin.py b/matchms/reference_spectra/salicin.py
new file mode 100644
index 00000000..c665806a
--- /dev/null
+++ b/matchms/reference_spectra/salicin.py
@@ -0,0 +1,68 @@
+"""Submodule providing a reference spectrum for salicin."""
+
+import numpy as np
+from ..Spectrum import Spectrum
+
+
+SALICIN_PRECURSOR_MZ: float = 321.0750
+
+SALICIN_MZ: np.ndarray = np.array(
+    [
+        52.27001,
+        55.74109,
+        57.76688,
+        60.32213,
+        64.12009,
+        82.39278,
+        87.02966,
+        91.02013,
+        92.37563,
+        93.13435,
+        112.07272,
+        116.92837,
+        123.04468,
+        138.61075,
+        140.95815,
+        146.96143,
+        174.95708,
+        184.95059,
+        238.55797,
+        305.44812,
+        321.07443,
+    ]
+)
+
+SALICIN_INTENSITIES: np.ndarray = np.array(
+    [
+        2309.0,
+        1977.0,
+        2003.0,
+        2102.0,
+        2177.0,
+        2127.0,
+        2376.0,
+        2380.0,
+        2703.0,
+        2200.0,
+        2232.0,
+        2923.0,
+        2173.0,
+        2257.0,
+        2367.0,
+        4363.0,
+        31526.0,
+        5119.0,
+        2252.0,
+        2233.0,
+        22755.0,
+    ]
+)
+
+
+def salicin() -> Spectrum:
+    """Return a reference spectrum for salicin."""
+    return Spectrum(
+        mz=SALICIN_MZ,
+        intensities=SALICIN_INTENSITIES,
+        metadata={"precursor_mz": SALICIN_PRECURSOR_MZ},
+    )


Test patch:
diff --git a/tests/test_reference_spectra.py b/tests/test_reference_spectra.py
new file mode 100644
index 00000000..9e612d0f
--- /dev/null
+++ b/tests/test_reference_spectra.py
@@ -0,0 +1,41 @@
+"""Simple test submodule to verify that all reference spectra can be instantiated."""
+
+from matchms.reference_spectra import (aspirin, cocaine, glucose,
+                                       hydroxy_cholesterol, phenylalanine,
+                                       salicin)
+
+
+def test_aspirin():
+    """Test if aspirin reference spectrum can be instantiated."""
+    aspirin_spectrum = aspirin()
+    assert aspirin_spectrum is not None
+
+
+def test_cocaine():
+    """Test if cocaine reference spectrum can be instantiated."""
+    cocaine_spectrum = cocaine()
+    assert cocaine_spectrum is not None
+
+
+def test_glucose():
+    """Test if glucose reference spectrum can be instantiated."""
+    glucose_spectrum = glucose()
+    assert glucose_spectrum is not None
+
+
+def test_hydroxy_cholesterol():
+    """Test if hydroxy-cholesterol reference spectrum can be instantiated."""
+    hydroxy_cholesterol_spectrum = hydroxy_cholesterol()
+    assert hydroxy_cholesterol_spectrum is not None
+
+
+def test_phenylalanine():
+    """Test if phenylalanine reference spectrum can be instantiated."""
+    phenylalanine_spectrum = phenylalanine()
+    assert phenylalanine_spectrum is not None
+
+
+def test_salicin():
+    """Test if salicin reference spectrum can be instantiated."""
+    salicin_spectrum = salicin()
+    assert salicin_spectrum is not None