Repository: matchms/matchms
Pull request #620 (2024-04-08 09:40:49)

Renamed repair_adduct_based_on_smiles.py to repair_adduct_and_parent_…
Changed the name of repair_adduct_based_on_smiles to repair_adduct_and_parent_mass_based_on_smiles, since that is a better description. 


Patch:
diff --git a/matchms/filtering/__init__.py b/matchms/filtering/__init__.py
index 07fe8186..ffbe02b4 100644
--- a/matchms/filtering/__init__.py
+++ b/matchms/filtering/__init__.py
@@ -106,8 +106,8 @@ from matchms.filtering.metadata_processing.interpret_pepmass import \
     interpret_pepmass
 from matchms.filtering.metadata_processing.make_charge_int import \
     make_charge_int
-from matchms.filtering.metadata_processing.repair_adduct_based_on_smiles import \
-    repair_adduct_based_on_smiles
+from matchms.filtering.metadata_processing.repair_adduct_and_parent_mass_based_on_smiles import \
+    repair_adduct_and_parent_mass_based_on_smiles
 from matchms.filtering.metadata_processing.repair_inchi_inchikey_smiles import \
     repair_inchi_inchikey_smiles
 from matchms.filtering.metadata_processing.repair_not_matching_annotation import \
@@ -179,7 +179,7 @@ __all__ = [
     "reduce_to_number_of_peaks",
     "remove_peaks_around_precursor_mz",
     "remove_peaks_outside_top_k",
-    "repair_adduct_based_on_smiles",
+    "repair_adduct_and_parent_mass_based_on_smiles",
     "require_correct_ionmode",
     "repair_inchi_inchikey_smiles",
     "repair_parent_mass_is_molar_mass",
diff --git a/matchms/filtering/default_pipelines.py b/matchms/filtering/default_pipelines.py
index 9d0c1628..c01a1506 100644
--- a/matchms/filtering/default_pipelines.py
+++ b/matchms/filtering/default_pipelines.py
@@ -34,7 +34,7 @@ REQUIRE_COMPLETE_METADATA = [msfilters.require_precursor_mz,
 REPAIR_ANNOTATION = [
     (msfilters.repair_smiles_of_salts, {'mass_tolerance': 0.1}),
     (msfilters.repair_parent_mass_is_molar_mass, {'mass_tolerance': 0.1}),
-    (msfilters.repair_adduct_based_on_smiles, {'mass_tolerance': 0.1}),
+    (msfilters.repair_adduct_and_parent_mass_based_on_smiles, {'mass_tolerance': 0.1}),
     msfilters.repair_not_matching_annotation,
     (msfilters.derive_annotation_from_compound_name, {"mass_tolerance": 0.1}),
 ]
diff --git a/matchms/filtering/filter_order.py b/matchms/filtering/filter_order.py
index 1b75089b..1f2f4fe9 100644
--- a/matchms/filtering/filter_order.py
+++ b/matchms/filtering/filter_order.py
@@ -29,7 +29,7 @@ ALL_FILTERS = [msfilters.make_charge_int,
                msfilters.derive_inchikey_from_inchi,
                msfilters.repair_smiles_of_salts,
                msfilters.repair_parent_mass_is_molar_mass,
-               msfilters.repair_adduct_based_on_smiles,
+               msfilters.repair_adduct_and_parent_mass_based_on_smiles,
                msfilters.repair_parent_mass_match_smiles_wrapper,
                msfilters.repair_not_matching_annotation,
                msfilters.require_valid_annotation,
diff --git a/matchms/filtering/metadata_processing/repair_adduct_based_on_smiles.py b/matchms/filtering/metadata_processing/repair_adduct_and_parent_mass_based_on_smiles.py
similarity index 91%
rename from matchms/filtering/metadata_processing/repair_adduct_based_on_smiles.py
rename to matchms/filtering/metadata_processing/repair_adduct_and_parent_mass_based_on_smiles.py
index b59df60e..80818b2f 100644
--- a/matchms/filtering/metadata_processing/repair_adduct_based_on_smiles.py
+++ b/matchms/filtering/metadata_processing/repair_adduct_and_parent_mass_based_on_smiles.py
@@ -8,10 +8,10 @@ from ..filter_utils.load_known_adducts import load_known_adducts
 logger = logging.getLogger("matchms")
 
 
-def repair_adduct_based_on_smiles(spectrum_in: Spectrum,
-                                  mass_tolerance: float):
+def repair_adduct_and_parent_mass_based_on_smiles(spectrum_in: Spectrum,
+                                                  mass_tolerance: float):
     """
-    Corrects the adduct of a spectrum based on its SMILES representation and the precursor m/z.
+    Corrects the adduct and parent mass of a spectrum based on its SMILES representation and the precursor m/z.
 
     Given a spectrum, this function tries to match the spectrum's parent mass, derived from its
     precursor m/z and known adducts, to the neutral monoisotopic mass of the molecule derived
diff --git a/matchms/filtering/metadata_processing/repair_parent_mass_match_smiles_wrapper.py b/matchms/filtering/metadata_processing/repair_parent_mass_match_smiles_wrapper.py
index fb52f3f3..ccc3c562 100644
--- a/matchms/filtering/metadata_processing/repair_parent_mass_match_smiles_wrapper.py
+++ b/matchms/filtering/metadata_processing/repair_parent_mass_match_smiles_wrapper.py
@@ -1,7 +1,7 @@
 import logging
 from typing import Optional
-from matchms.filtering.metadata_processing.repair_adduct_based_on_smiles import \
-    repair_adduct_based_on_smiles
+from matchms.filtering.metadata_processing.repair_adduct_and_parent_mass_based_on_smiles import \
+    repair_adduct_and_parent_mass_based_on_smiles
 from matchms.typing import SpectrumType
 from .repair_parent_mass_is_molar_mass import repair_parent_mass_is_molar_mass
 from .repair_smiles_of_salts import repair_smiles_of_salts
@@ -21,7 +21,7 @@ def repair_parent_mass_match_smiles_wrapper(spectrum_in: SpectrumType,
 
     filters_to_apply = [repair_smiles_of_salts,
                         repair_parent_mass_is_molar_mass,
-                        repair_adduct_based_on_smiles,
+                        repair_adduct_and_parent_mass_based_on_smiles,
                         ]
     for filter_function in filters_to_apply:
         if _check_smiles_and_parent_mass_match(smiles=spectrum.get("smiles"),


Test patch:
diff --git a/tests/filtering/test_all_filter_order.py b/tests/filtering/test_all_filter_order.py
index 3e20fda7..7fcba459 100644
--- a/tests/filtering/test_all_filter_order.py
+++ b/tests/filtering/test_all_filter_order.py
@@ -11,7 +11,7 @@ from matchms.filtering.filter_order import ALL_FILTERS
 REPAIR_PARENT_MASS_SMILES_FILTERS = \
     [msfilters.repair_smiles_of_salts,
      msfilters.repair_parent_mass_is_molar_mass,
-     msfilters.repair_adduct_based_on_smiles,
+     msfilters.repair_adduct_and_parent_mass_based_on_smiles,
      msfilters.repair_parent_mass_match_smiles_wrapper, ]
 DERIVE_ANNOTATION_FILTERS = [msfilters.derive_smiles_from_inchi,
                              msfilters.derive_inchi_from_smiles,
diff --git a/tests/filtering/test_repair_adduct/test_repair_adduct_based_on_smiles.py b/tests/filtering/test_repair_adduct/test_repair_adduct_based_on_smiles.py
index a89dd9d6..2f06b440 100644
--- a/tests/filtering/test_repair_adduct/test_repair_adduct_based_on_smiles.py
+++ b/tests/filtering/test_repair_adduct/test_repair_adduct_based_on_smiles.py
@@ -1,6 +1,6 @@
 import pytest
-from matchms.filtering.metadata_processing.repair_adduct_based_on_smiles import \
-    repair_adduct_based_on_smiles
+from matchms.filtering.metadata_processing.repair_adduct_and_parent_mass_based_on_smiles import \
+    repair_adduct_and_parent_mass_based_on_smiles
 from tests.builder_Spectrum import SpectrumBuilder
 
 
@@ -19,7 +19,7 @@ def test_repair_adduct_based_on_smiles_not_mol_wt(precursor_mz, expected_adduct,
     spectrum_in = SpectrumBuilder().with_metadata({"smiles": "C",
                                                    "precursor_mz": precursor_mz,
                                                    "ionmode": ionmode}).build()
-    spectrum_out = repair_adduct_based_on_smiles(spectrum_in, mass_tolerance=0.1)
+    spectrum_out = repair_adduct_and_parent_mass_based_on_smiles(spectrum_in, mass_tolerance=0.1)
     assert spectrum_out.get("adduct") == expected_adduct
     assert abs(spectrum_out.get("parent_mass") - 15.9589) < 0.1
 
@@ -40,5 +40,5 @@ def test_repair_adduct_based_on_smiles_not_repaired(precursor_mz, ionmode):
     spectrum_in = SpectrumBuilder().with_metadata({"smiles": "C",
                                                    "precursor_mz": precursor_mz,
                                                    "ionmode": ionmode}).build()
-    spectrum_out = repair_adduct_based_on_smiles(spectrum_in, mass_tolerance=0.1)
+    spectrum_out = repair_adduct_and_parent_mass_based_on_smiles(spectrum_in, mass_tolerance=0.1)
     assert spectrum_out.get("adduct") is None