matchms 0.34.0__tar.gz → 1.0.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- matchms-1.0.0.dev1/PKG-INFO +1368 -0
- matchms-1.0.0.dev1/README.rst +1324 -0
- matchms-1.0.0.dev1/matchms/__init__.py +42 -0
- matchms-1.0.0.dev1/matchms/_parquet.py +132 -0
- matchms-1.0.0.dev1/matchms/calculate_scores.py +31 -0
- matchms-1.0.0.dev1/matchms/cli/__init__.py +15 -0
- matchms-1.0.0.dev1/matchms/cli/commands/filter_info.py +75 -0
- matchms-1.0.0.dev1/matchms/cli/commands/filter_list.py +58 -0
- matchms-1.0.0.dev1/matchms/cli/commands/filter_pipelines.py +162 -0
- matchms-1.0.0.dev1/matchms/cli/commands/filter_run.py +371 -0
- matchms-1.0.0.dev1/matchms/cli/commands/info.py +100 -0
- matchms-1.0.0.dev1/matchms/cli/commands/similarity_build_index.py +198 -0
- matchms-1.0.0.dev1/matchms/cli/commands/similarity_info.py +90 -0
- matchms-1.0.0.dev1/matchms/cli/commands/similarity_list.py +126 -0
- matchms-1.0.0.dev1/matchms/cli/commands/similarity_matrix.py +569 -0
- matchms-1.0.0.dev1/matchms/cli/commands/similarity_search.py +648 -0
- matchms-1.0.0.dev1/matchms/cli/commands/spectra_convert.py +134 -0
- matchms-1.0.0.dev1/matchms/cli/commands/spectra_describe.py +97 -0
- matchms-1.0.0.dev1/matchms/cli/constants.py +70 -0
- matchms-1.0.0.dev1/matchms/cli/errors.py +426 -0
- matchms-1.0.0.dev1/matchms/cli/files.py +162 -0
- matchms-1.0.0.dev1/matchms/cli/introspection.py +304 -0
- matchms-1.0.0.dev1/matchms/cli/main.py +834 -0
- matchms-1.0.0.dev1/matchms/cli/output.py +137 -0
- matchms-1.0.0.dev1/matchms/cli/params.py +158 -0
- matchms-1.0.0.dev1/matchms/cli/parser.py +180 -0
- matchms-1.0.0.dev1/matchms/cli/similarity.py +264 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/data/example_pipelines/library_cleaning.yaml +2 -3
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/data/export_key_conversions.csv +114 -114
- matchms-1.0.0.dev1/matchms/exporting/__init__.py +19 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/exporting/metadata_export.py +11 -19
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/exporting/save_as_json.py +7 -7
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/exporting/save_as_mgf.py +4 -6
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/exporting/save_as_msp.py +136 -150
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/exporting/save_as_mzspeclib.py +51 -44
- matchms-1.0.0.dev1/matchms/exporting/save_as_parquet.py +301 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/exporting/save_spectra.py +20 -7
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/__init__.py +177 -65
- matchms-1.0.0.dev1/matchms/filtering/_dispatch.py +377 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/default_filters.py +18 -3
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/default_pipelines.py +12 -14
- matchms-1.0.0.dev1/matchms/filtering/filter_effects.py +70 -0
- matchms-1.0.0.dev1/matchms/filtering/filter_order.py +68 -0
- matchms-1.0.0.dev1/matchms/filtering/filter_utils/derive_precursor_mz_and_parent_mass.py +109 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/filter_utils/get_neutral_mass_from_smiles.py +4 -24
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/filter_utils/interpret_unknown_adduct.py +25 -41
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/filter_utils/load_known_adducts.py +8 -9
- matchms-1.0.0.dev1/matchms/filtering/filter_utils/metadata_conversions.py +216 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/filter_utils/smile_inchi_inchikey_conversions.py +11 -44
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/add_compound_name.py +41 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/add_parent_mass.py +135 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/add_precursor_formula.py +105 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/add_precursor_mz.py +111 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/add_retention.py +142 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/metadata_processing/clean_adduct.py +47 -44
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/metadata_processing/clean_compound_name.py +27 -33
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/correct_charge.py +82 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_adduct_from_name.py +130 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_annotation_from_compound_name.py +322 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_formula_from_name.py +82 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_formula_from_smiles.py +75 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_inchi_from_smiles.py +33 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_inchikey_from_inchi.py +32 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_ionmode.py +83 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/derive_smiles_from_inchi.py +33 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/harmonize_missing_entries.py +70 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/harmonize_undefined_inchi.py +28 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/harmonize_undefined_inchikey.py +28 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/harmonize_undefined_smiles.py +28 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/metadata_processing/interpret_pepmass.py +84 -27
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/make_charge_int.py +66 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_adduct_and_parent_mass_based_on_smiles.py +90 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_adduct_based_on_parent_mass.py +73 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_inchi_inchikey_smiles.py +43 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/metadata_processing/repair_not_matching_annotation.py +17 -9
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_parent_mass_from_smiles.py +33 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_parent_mass_is_molar_mass.py +44 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_parent_mass_match_smiles_wrapper.py +124 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/repair_smiles_of_salts.py +96 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_compound_name.py +36 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_correct_ionmode.py +57 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_correct_ms_level.py +30 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_formula.py +43 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_matching_adduct_and_ionmode.py +46 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_matching_adduct_precursor_mz_parent_mass.py +96 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_parent_mass_match_smiles.py +52 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_precursor_mz.py +263 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_retention_index.py +26 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_retention_time.py +63 -0
- matchms-1.0.0.dev1/matchms/filtering/metadata_processing/require_valid_annotation.py +82 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/normalize_intensities.py +175 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/reduce_to_number_of_peaks.py +160 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/remove_noise_below_frequent_intensities.py +204 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/remove_peaks_around_precursor_mz.py +75 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/peak_processing/remove_peaks_outside_top_k.py +12 -5
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/remove_peaks_relative_to_precursor_mz.py +115 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/remove_profiled_spectra.py +206 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/require_maximum_number_of_peaks.py +74 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/require_minimum_number_of_high_peaks.py +98 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/require_minimum_number_of_peaks.py +100 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/select_by_intensity.py +76 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/select_by_mz.py +77 -0
- matchms-1.0.0.dev1/matchms/filtering/peak_processing/select_by_relative_intensity.py +92 -0
- matchms-0.34.0/matchms/filtering/SpeciesString.py → matchms-1.0.0.dev1/matchms/filtering/species_string.py +32 -10
- matchms-1.0.0.dev1/matchms/filtering/spectra_processor.py +745 -0
- matchms-1.0.0.dev1/matchms/filtering/spectrum_processor.py +15 -0
- matchms-1.0.0.dev1/matchms/fingerprints.py +423 -0
- matchms-1.0.0.dev1/matchms/fragment_collection.py +735 -0
- matchms-0.34.0/matchms/Fragments.py → matchms-1.0.0.dev1/matchms/fragments.py +12 -6
- matchms-1.0.0.dev1/matchms/hashing.py +170 -0
- matchms-1.0.0.dev1/matchms/importing/__init__.py +54 -0
- matchms-1.0.0.dev1/matchms/importing/collection_builder.py +145 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/load_from_json.py +7 -8
- matchms-1.0.0.dev1/matchms/importing/load_from_mgf.py +111 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/load_from_msp.py +9 -9
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/load_from_mzml.py +5 -5
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/load_from_mzxml.py +5 -5
- matchms-1.0.0.dev1/matchms/importing/load_from_parquet.py +241 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/load_from_pickle.py +2 -3
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/load_from_usi.py +5 -3
- matchms-1.0.0.dev1/matchms/importing/load_spectra.py +147 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/importing/parsing_utils.py +5 -5
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/logging_functions.py +10 -22
- matchms-0.34.0/matchms/Metadata.py → matchms-1.0.0.dev1/matchms/metadata.py +80 -31
- matchms-1.0.0.dev1/matchms/metadata_collection.py +398 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/networking/__init__.py +3 -5
- matchms-1.0.0.dev1/matchms/networking/networking_functions.py +194 -0
- matchms-1.0.0.dev1/matchms/networking/similarity_network.py +242 -0
- matchms-1.0.0.dev1/matchms/pipeline.py +462 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/plotting/__init__.py +3 -3
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/plotting/spectrum_plots.py +29 -36
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/aspirin.py +1 -1
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/cocaine.py +1 -1
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/glucose.py +1 -1
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/hydroxy_cholesterol.py +1 -1
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/phenylalanine.py +1 -1
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/salicin.py +1 -1
- matchms-1.0.0.dev1/matchms/scores.py +466 -0
- matchms-1.0.0.dev1/matchms/similarity/__init__.py +185 -0
- matchms-1.0.0.dev1/matchms/similarity/_entropy_search_topk.py +262 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_cosine.py +457 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_cosine_topk.py +489 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_entropy.py +225 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_entropy_topk.py +291 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_prepared.py +139 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_tolerance.py +48 -0
- matchms-1.0.0.dev1/matchms/similarity/_flash_topk_common.py +107 -0
- matchms-1.0.0.dev1/matchms/similarity/_topk.py +120 -0
- matchms-0.34.0/matchms/similarity/BaseEmbeddingSimilarity.py → matchms-1.0.0.dev1/matchms/similarity/base_embedding_similarity.py +137 -96
- matchms-1.0.0.dev1/matchms/similarity/base_similarity.py +525 -0
- matchms-1.0.0.dev1/matchms/similarity/binned_embedding_similarity.py +100 -0
- matchms-1.0.0.dev1/matchms/similarity/cosine.py +313 -0
- matchms-0.34.0/matchms/similarity/BlinkCosine.py → matchms-1.0.0.dev1/matchms/similarity/cosine_blink.py +102 -112
- matchms-0.34.0/matchms/similarity/CosineGreedy.py → matchms-1.0.0.dev1/matchms/similarity/cosine_greedy.py +69 -22
- matchms-0.34.0/matchms/similarity/CosineHungarian.py → matchms-1.0.0.dev1/matchms/similarity/cosine_hungarian.py +67 -33
- matchms-1.0.0.dev1/matchms/similarity/cosine_linear.py +199 -0
- matchms-1.0.0.dev1/matchms/similarity/cosine_linear_functions.py +385 -0
- matchms-1.0.0.dev1/matchms/similarity/default_parameters.py +12 -0
- matchms-1.0.0.dev1/matchms/similarity/entropy.py +101 -0
- matchms-1.0.0.dev1/matchms/similarity/entropy_greedy.py +336 -0
- matchms-1.0.0.dev1/matchms/similarity/entropy_search.py +1079 -0
- matchms-1.0.0.dev1/matchms/similarity/fingerprint_similarity.py +261 -0
- matchms-1.0.0.dev1/matchms/similarity/flash_index.py +622 -0
- matchms-1.0.0.dev1/matchms/similarity/flash_similarity.py +922 -0
- matchms-1.0.0.dev1/matchms/similarity/flash_utils.py +587 -0
- matchms-1.0.0.dev1/matchms/similarity/metadata_match.py +342 -0
- matchms-1.0.0.dev1/matchms/similarity/modified_cosine.py +189 -0
- matchms-1.0.0.dev1/matchms/similarity/modified_cosine_greedy.py +139 -0
- matchms-0.34.0/matchms/similarity/ModifiedCosineHungarian.py → matchms-1.0.0.dev1/matchms/similarity/modified_cosine_hungarian.py +63 -21
- matchms-1.0.0.dev1/matchms/similarity/modified_cosine_linear.py +122 -0
- matchms-0.34.0/matchms/similarity/NeutralLossesCosine.py → matchms-1.0.0.dev1/matchms/similarity/neutral_losses_cosine.py +52 -26
- matchms-1.0.0.dev1/matchms/similarity/parent_mass_match.py +19 -0
- matchms-1.0.0.dev1/matchms/similarity/precursor_mz_match.py +27 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/similarity/spectrum_similarity_functions.py +145 -27
- matchms-1.0.0.dev1/matchms/similarity/topk_results.py +116 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/similarity/vector_similarity_functions.py +6 -4
- matchms-1.0.0.dev1/matchms/spectra_collection.py +854 -0
- matchms-0.34.0/matchms/Spectrum.py → matchms-1.0.0.dev1/matchms/spectrum.py +44 -35
- matchms-1.0.0.dev1/matchms/typing.py +16 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/utils.py +14 -8
- matchms-1.0.0.dev1/matchms/yaml_file_functions.py +59 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/pyproject.toml +58 -34
- matchms-1.0.0.dev1/pyproject.toml.orig +176 -0
- matchms-0.34.0/LICENSE +0 -204
- matchms-0.34.0/PKG-INFO +0 -476
- matchms-0.34.0/README.rst +0 -435
- matchms-0.34.0/matchms/Fingerprints.py +0 -456
- matchms-0.34.0/matchms/Pipeline.py +0 -413
- matchms-0.34.0/matchms/Scores.py +0 -497
- matchms-0.34.0/matchms/__init__.py +0 -53
- matchms-0.34.0/matchms/calculate_scores.py +0 -64
- matchms-0.34.0/matchms/exporting/__init__.py +0 -22
- matchms-0.34.0/matchms/filtering/SpectrumProcessor.py +0 -405
- matchms-0.34.0/matchms/filtering/filter_order.py +0 -66
- matchms-0.34.0/matchms/filtering/filter_utils/derive_precursor_mz_and_parent_mass.py +0 -129
- matchms-0.34.0/matchms/filtering/metadata_processing/add_compound_name.py +0 -40
- matchms-0.34.0/matchms/filtering/metadata_processing/add_fingerprint.py +0 -151
- matchms-0.34.0/matchms/filtering/metadata_processing/add_parent_mass.py +0 -104
- matchms-0.34.0/matchms/filtering/metadata_processing/add_precursor_formula.py +0 -81
- matchms-0.34.0/matchms/filtering/metadata_processing/add_precursor_mz.py +0 -82
- matchms-0.34.0/matchms/filtering/metadata_processing/add_retention.py +0 -148
- matchms-0.34.0/matchms/filtering/metadata_processing/correct_charge.py +0 -73
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_adduct_from_name.py +0 -107
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_annotation_from_compound_name.py +0 -218
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_formula_from_name.py +0 -71
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_formula_from_smiles.py +0 -59
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_inchi_from_smiles.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_inchikey_from_inchi.py +0 -44
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_ionmode.py +0 -95
- matchms-0.34.0/matchms/filtering/metadata_processing/derive_smiles_from_inchi.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/harmonize_undefined_inchi.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/harmonize_undefined_inchikey.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/harmonize_undefined_smiles.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/make_charge_int.py +0 -62
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_adduct_and_parent_mass_based_on_smiles.py +0 -82
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_adduct_based_on_parent_mass.py +0 -81
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_inchi_inchikey_smiles.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_parent_mass_from_smiles.py +0 -42
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_parent_mass_is_molar_mass.py +0 -63
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_parent_mass_match_smiles_wrapper.py +0 -50
- matchms-0.34.0/matchms/filtering/metadata_processing/repair_smiles_of_salts.py +0 -78
- matchms-0.34.0/matchms/filtering/metadata_processing/require_compound_name.py +0 -20
- matchms-0.34.0/matchms/filtering/metadata_processing/require_correct_ionmode.py +0 -46
- matchms-0.34.0/matchms/filtering/metadata_processing/require_correct_ms_level.py +0 -10
- matchms-0.34.0/matchms/filtering/metadata_processing/require_formula.py +0 -26
- matchms-0.34.0/matchms/filtering/metadata_processing/require_matching_adduct_and_ionmode.py +0 -21
- matchms-0.34.0/matchms/filtering/metadata_processing/require_matching_adduct_precursor_mz_parent_mass.py +0 -53
- matchms-0.34.0/matchms/filtering/metadata_processing/require_parent_mass_match_smiles.py +0 -45
- matchms-0.34.0/matchms/filtering/metadata_processing/require_precursor_mz.py +0 -82
- matchms-0.34.0/matchms/filtering/metadata_processing/require_retention_index.py +0 -33
- matchms-0.34.0/matchms/filtering/metadata_processing/require_retention_time.py +0 -56
- matchms-0.34.0/matchms/filtering/metadata_processing/require_valid_annotation.py +0 -52
- matchms-0.34.0/matchms/filtering/peak_processing/normalize_intensities.py +0 -71
- matchms-0.34.0/matchms/filtering/peak_processing/reduce_to_number_of_peaks.py +0 -76
- matchms-0.34.0/matchms/filtering/peak_processing/remove_noise_below_frequent_intensities.py +0 -67
- matchms-0.34.0/matchms/filtering/peak_processing/remove_peaks_around_precursor_mz.py +0 -50
- matchms-0.34.0/matchms/filtering/peak_processing/remove_peaks_relative_to_precursor_mz.py +0 -51
- matchms-0.34.0/matchms/filtering/peak_processing/remove_profiled_spectra.py +0 -93
- matchms-0.34.0/matchms/filtering/peak_processing/require_maximum_number_of_peaks.py +0 -43
- matchms-0.34.0/matchms/filtering/peak_processing/require_minimum_number_of_high_peaks.py +0 -49
- matchms-0.34.0/matchms/filtering/peak_processing/require_minimum_number_of_peaks.py +0 -54
- matchms-0.34.0/matchms/filtering/peak_processing/select_by_intensity.py +0 -41
- matchms-0.34.0/matchms/filtering/peak_processing/select_by_mz.py +0 -39
- matchms-0.34.0/matchms/filtering/peak_processing/select_by_relative_intensity.py +0 -44
- matchms-0.34.0/matchms/hashing.py +0 -34
- matchms-0.34.0/matchms/importing/__init__.py +0 -40
- matchms-0.34.0/matchms/importing/load_from_mgf.py +0 -53
- matchms-0.34.0/matchms/importing/load_scores.py +0 -30
- matchms-0.34.0/matchms/importing/load_spectra.py +0 -68
- matchms-0.34.0/matchms/networking/SimilarityNetwork.py +0 -224
- matchms-0.34.0/matchms/networking/networking_functions.py +0 -100
- matchms-0.34.0/matchms/similarity/BaseSimilarity.py +0 -168
- matchms-0.34.0/matchms/similarity/BinnedEmbeddingSimilarity.py +0 -96
- matchms-0.34.0/matchms/similarity/CosineLinear.py +0 -146
- matchms-0.34.0/matchms/similarity/FingerprintSimilarity.py +0 -173
- matchms-0.34.0/matchms/similarity/FlashSimilarity.py +0 -1109
- matchms-0.34.0/matchms/similarity/IntersectMz.py +0 -60
- matchms-0.34.0/matchms/similarity/MetadataMatch.py +0 -183
- matchms-0.34.0/matchms/similarity/ModifiedCosineGreedy.py +0 -91
- matchms-0.34.0/matchms/similarity/ParentMassMatch.py +0 -130
- matchms-0.34.0/matchms/similarity/PrecursorMzMatch.py +0 -147
- matchms-0.34.0/matchms/similarity/__init__.py +0 -85
- matchms-0.34.0/matchms/similarity/cosine_linear_functions.py +0 -195
- matchms-0.34.0/matchms/similarity/flash_utils.py +0 -372
- matchms-0.34.0/matchms/typing.py +0 -10
- matchms-0.34.0/matchms/yaml_file_functions.py +0 -37
- matchms-0.34.0/tests/__init__.py +0 -1
- matchms-0.34.0/tests/builder_Spectrum.py +0 -53
- matchms-0.34.0/tests/cosine_linear_reference.json +0 -2679
- matchms-0.34.0/tests/exporting/__init__.py +0 -1
- matchms-0.34.0/tests/exporting/test_exporting_metadata.py +0 -105
- matchms-0.34.0/tests/exporting/test_save_as_json_load_from_json.py +0 -132
- matchms-0.34.0/tests/exporting/test_save_as_mgf.py +0 -196
- matchms-0.34.0/tests/exporting/test_save_as_msp.py +0 -203
- matchms-0.34.0/tests/exporting/test_save_as_mzspeclib.py +0 -96
- matchms-0.34.0/tests/exporting/test_save_spectra.py +0 -123
- matchms-0.34.0/tests/filtering/__init__.py +0 -1
- matchms-0.34.0/tests/filtering/test_add_compound_name.py +0 -33
- matchms-0.34.0/tests/filtering/test_add_fingerprint.py +0 -104
- matchms-0.34.0/tests/filtering/test_add_parent_mass.py +0 -113
- matchms-0.34.0/tests/filtering/test_add_precursor_formula.py +0 -99
- matchms-0.34.0/tests/filtering/test_add_precursor_mz.py +0 -86
- matchms-0.34.0/tests/filtering/test_add_retention.py +0 -71
- matchms-0.34.0/tests/filtering/test_all_filter_order.py +0 -236
- matchms-0.34.0/tests/filtering/test_clean_compound_name.py +0 -27
- matchms-0.34.0/tests/filtering/test_correct_charge.py +0 -50
- matchms-0.34.0/tests/filtering/test_derive_adduct_from_name.py +0 -87
- matchms-0.34.0/tests/filtering/test_derive_annotation_from_compound_name.py +0 -278
- matchms-0.34.0/tests/filtering/test_derive_formula_from_name.py +0 -57
- matchms-0.34.0/tests/filtering/test_derive_formula_from_smiles.py +0 -21
- matchms-0.34.0/tests/filtering/test_derive_inchi_from_inchikey.py +0 -27
- matchms-0.34.0/tests/filtering/test_derive_inchi_from_smiles.py +0 -30
- matchms-0.34.0/tests/filtering/test_derive_ionmode.py +0 -27
- matchms-0.34.0/tests/filtering/test_derive_smiles_from_inchi.py +0 -38
- matchms-0.34.0/tests/filtering/test_filter_utils/__init__.py +0 -0
- matchms-0.34.0/tests/filtering/test_filter_utils/test_derive_precursor_mz_and_parent_mass.py +0 -51
- matchms-0.34.0/tests/filtering/test_filter_utils/test_interpret_unknown_adduct.py +0 -21
- matchms-0.34.0/tests/filtering/test_filter_utils/test_smiles_inchi_inchikey_conversions.py +0 -129
- matchms-0.34.0/tests/filtering/test_harmonize_undefined_inchi.py +0 -28
- matchms-0.34.0/tests/filtering/test_harmonize_undefined_inchikey.py +0 -29
- matchms-0.34.0/tests/filtering/test_harmonize_undefined_smiles.py +0 -29
- matchms-0.34.0/tests/filtering/test_interpret_pepmass.py +0 -146
- matchms-0.34.0/tests/filtering/test_load_adducts.py +0 -23
- matchms-0.34.0/tests/filtering/test_make_charge_int.py +0 -37
- matchms-0.34.0/tests/filtering/test_normalize_intensities.py +0 -125
- matchms-0.34.0/tests/filtering/test_predefined_pipelines.py +0 -16
- matchms-0.34.0/tests/filtering/test_reduce_to_number_of_peaks.py +0 -121
- matchms-0.34.0/tests/filtering/test_remove_noise_below_frequent_intensities.py +0 -43
- matchms-0.34.0/tests/filtering/test_remove_peaks_around_precursor_mz.py +0 -74
- matchms-0.34.0/tests/filtering/test_remove_peaks_outside_top_k.py +0 -92
- matchms-0.34.0/tests/filtering/test_remove_peaks_relative_to_precursor_mz.py +0 -136
- matchms-0.34.0/tests/filtering/test_remove_profiled_spectra.py +0 -42
- matchms-0.34.0/tests/filtering/test_repair_adduct/test_clean_adduct.py +0 -80
- matchms-0.34.0/tests/filtering/test_repair_adduct/test_repair_adduct_and_parent_mass_based_on_smiles.py +0 -73
- matchms-0.34.0/tests/filtering/test_repair_adduct/test_repair_adduct_based_on_parent_mass.py +0 -29
- matchms-0.34.0/tests/filtering/test_repair_inchi_inchikey_smiles.py +0 -71
- matchms-0.34.0/tests/filtering/test_repair_not_matching_annotation.py +0 -105
- matchms-0.34.0/tests/filtering/test_repair_parent_mass_from_smiles/test_repair_parent_mass_from_smiles.py +0 -18
- matchms-0.34.0/tests/filtering/test_repair_parent_mass_from_smiles/test_repair_parent_mass_is_molar_mass.py +0 -32
- matchms-0.34.0/tests/filtering/test_repair_parent_mass_from_smiles/test_repair_parent_mass_match_smiles_wrapper.py +0 -57
- matchms-0.34.0/tests/filtering/test_repair_parent_mass_from_smiles/test_repair_smiles_of_salts.py +0 -29
- matchms-0.34.0/tests/filtering/test_repair_parent_mass_from_smiles/test_require_parent_mass_match_smiles.py +0 -22
- matchms-0.34.0/tests/filtering/test_require_compound_name.py +0 -19
- matchms-0.34.0/tests/filtering/test_require_correct_ionmode.py +0 -26
- matchms-0.34.0/tests/filtering/test_require_correct_ms_level.py +0 -25
- matchms-0.34.0/tests/filtering/test_require_formula.py +0 -22
- matchms-0.34.0/tests/filtering/test_require_matching_adduct_and_ionmode.py +0 -25
- matchms-0.34.0/tests/filtering/test_require_matching_adduct_precursor_mz_parent_mass.py +0 -29
- matchms-0.34.0/tests/filtering/test_require_maximum_number_of_peaks.py +0 -17
- matchms-0.34.0/tests/filtering/test_require_minimum_number_of_high_peaks.py +0 -58
- matchms-0.34.0/tests/filtering/test_require_minimum_number_of_peaks.py +0 -88
- matchms-0.34.0/tests/filtering/test_require_precursor_below_mz.py +0 -60
- matchms-0.34.0/tests/filtering/test_require_precursor_mz.py +0 -60
- matchms-0.34.0/tests/filtering/test_require_retention_index.py +0 -47
- matchms-0.34.0/tests/filtering/test_require_retention_time.py +0 -61
- matchms-0.34.0/tests/filtering/test_require_valid_annotation.py +0 -25
- matchms-0.34.0/tests/filtering/test_select_by_intensity.py +0 -49
- matchms-0.34.0/tests/filtering/test_select_by_mz.py +0 -49
- matchms-0.34.0/tests/filtering/test_select_by_relative_intensity.py +0 -50
- matchms-0.34.0/tests/filtering/test_spectrum_processor.py +0 -567
- matchms-0.34.0/tests/importing/__init__.py +0 -1
- matchms-0.34.0/tests/importing/test_load_from_mgf.py +0 -115
- matchms-0.34.0/tests/importing/test_load_from_msp.py +0 -332
- matchms-0.34.0/tests/importing/test_load_from_mzml.py +0 -19
- matchms-0.34.0/tests/importing/test_load_from_mzxml.py +0 -33
- matchms-0.34.0/tests/importing/test_load_from_usi.py +0 -53
- matchms-0.34.0/tests/importing/test_load_spectra.py +0 -31
- matchms-0.34.0/tests/networking/__init__.py +0 -1
- matchms-0.34.0/tests/networking/test_SimilarityNetwork.py +0 -220
- matchms-0.34.0/tests/networking/test_networking_functions.py +0 -80
- matchms-0.34.0/tests/plotting/__init__.py +0 -1
- matchms-0.34.0/tests/plotting/test_spectrum_plots.py +0 -142
- matchms-0.34.0/tests/similarity/__init__.py +0 -1
- matchms-0.34.0/tests/similarity/test_base_embedding_similarity.py +0 -80
- matchms-0.34.0/tests/similarity/test_bench_matrix.py +0 -57
- matchms-0.34.0/tests/similarity/test_binned_embedding_similarity.py +0 -198
- matchms-0.34.0/tests/similarity/test_blink_cosine.py +0 -262
- matchms-0.34.0/tests/similarity/test_cosine_greedy.py +0 -101
- matchms-0.34.0/tests/similarity/test_cosine_hungarian.py +0 -372
- matchms-0.34.0/tests/similarity/test_cosine_linear.py +0 -374
- matchms-0.34.0/tests/similarity/test_fingerprint_similarity.py +0 -101
- matchms-0.34.0/tests/similarity/test_flash_similarity.py +0 -447
- matchms-0.34.0/tests/similarity/test_flash_similarity_ms_entropy_parity.py +0 -106
- matchms-0.34.0/tests/similarity/test_flash_utils.py +0 -236
- matchms-0.34.0/tests/similarity/test_intersect_mz.py +0 -18
- matchms-0.34.0/tests/similarity/test_metadata_match.py +0 -92
- matchms-0.34.0/tests/similarity/test_modified_cosine_greedy.py +0 -187
- matchms-0.34.0/tests/similarity/test_modified_cosine_hungarian.py +0 -227
- matchms-0.34.0/tests/similarity/test_modified_cosine_hungarian_reference.py +0 -76
- matchms-0.34.0/tests/similarity/test_modified_cosine_message_consistency.py +0 -62
- matchms-0.34.0/tests/similarity/test_neutral_losses_cosine.py +0 -153
- matchms-0.34.0/tests/similarity/test_parentmass_match.py +0 -62
- matchms-0.34.0/tests/similarity/test_precursormz_match.py +0 -63
- matchms-0.34.0/tests/similarity/test_spectrum_similarity_functions.py +0 -132
- matchms-0.34.0/tests/similarity/test_vector_similarity_functions.py +0 -217
- matchms-0.34.0/tests/test_fingerprints.py +0 -283
- matchms-0.34.0/tests/test_fragments.py +0 -113
- matchms-0.34.0/tests/test_hashing.py +0 -72
- matchms-0.34.0/tests/test_key_conversion.py +0 -23
- matchms-0.34.0/tests/test_logging.py +0 -114
- matchms-0.34.0/tests/test_metadata.py +0 -126
- matchms-0.34.0/tests/test_pipeline.py +0 -289
- matchms-0.34.0/tests/test_pipeline.yaml +0 -29
- matchms-0.34.0/tests/test_reference_spectra.py +0 -39
- matchms-0.34.0/tests/test_scores.py +0 -377
- matchms-0.34.0/tests/test_scores_read_write.py +0 -134
- matchms-0.34.0/tests/test_scoring_method_consistency.py +0 -97
- matchms-0.34.0/tests/test_spectrum.py +0 -310
- matchms-0.34.0/tests/test_spectrum_builder.py +0 -33
- matchms-0.34.0/tests/test_spectrum_peak_comments.py +0 -35
- matchms-0.34.0/tests/test_utils.py +0 -49
- matchms-0.34.0/tests/test_version_string_consistency.py +0 -19
- matchms-0.34.0/tests/testdata/Hydrogen_chloride.msp +0 -11
- matchms-0.34.0/tests/testdata/Hydrogen_chloride.mzspeclib +0 -17
- matchms-0.34.0/tests/testdata/JL_2021_V2.msl +0 -14
- matchms-0.34.0/tests/testdata/MoNA-export-GC-MS-first10.msp +0 -603
- matchms-0.34.0/tests/testdata/comments_with_quotes.msp +0 -262
- matchms-0.34.0/tests/testdata/edge_golm.msp +0 -39
- matchms-0.34.0/tests/testdata/expected_metadata.csv +0 -11
- matchms-0.34.0/tests/testdata/expected_metadata.json +0 -252
- matchms-0.34.0/tests/testdata/expected_metadata.tsv +0 -11
- matchms-0.34.0/tests/testdata/gnps_spectra.json +0 -495
- matchms-0.34.0/tests/testdata/golm.msp +0 -118
- matchms-0.34.0/tests/testdata/massbank_five_spectra.msp +0 -139
- matchms-0.34.0/tests/testdata/multiline_semicolon.msp +0 -10
- matchms-0.34.0/tests/testdata/pesticides.mgf +0 -6393
- matchms-0.34.0/tests/testdata/rcx_gc-ei_ms_20201028_perylene.msp +0 -39
- matchms-0.34.0/tests/testdata/riken_style_five_spectra.msp +0 -100
- matchms-0.34.0/tests/testdata/save_as_msp_from_mgf.mgf +0 -27
- matchms-0.34.0/tests/testdata/save_as_msp_from_mgf.msp +0 -25
- matchms-0.34.0/tests/testdata/test_remove_fingerprint.json +0 -280
- matchms-0.34.0/tests/testdata/test_remove_fingerprint.mgf +0 -150
- matchms-0.34.0/tests/testdata/test_spectra_collection.msp +0 -86
- matchms-0.34.0/tests/testdata/testdata.mgf +0 -1562
- matchms-0.34.0/tests/testdata/testdata.mzXML +0 -111
- matchms-0.34.0/tests/testdata/testdata.mzml +0 -623
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/__version__.py +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/constants.py +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/data/known_adduct_conversions.csv +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/data/known_adducts_table.csv +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/data/known_key_conversions.csv +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/filter_utils/__init__.py +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/metadata_processing/__init__.py +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/filtering/peak_processing/__init__.py +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/reference_spectra/__init__.py +0 -0
- {matchms-0.34.0 → matchms-1.0.0.dev1}/matchms/similarity/_precursor_validation.py +0 -0
|
@@ -0,0 +1,1368 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matchms
|
|
3
|
+
Version: 1.0.0.dev1
|
|
4
|
+
Summary: Python library for large-scale comparisons and processing of tandem mass spectral data
|
|
5
|
+
Keywords: fuzzy matching,fuzzy search,mass spectrometry,similarity measures
|
|
6
|
+
Author: matchms developer team
|
|
7
|
+
Author-email: matchms developer team <florian.huber@hs-duesseldorf.de>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Requires-Dist: deprecated>=1.3.1
|
|
19
|
+
Requires-Dist: lxml>=6.0.2
|
|
20
|
+
Requires-Dist: matplotlib>=3.10.8
|
|
21
|
+
Requires-Dist: networkx>=3.5
|
|
22
|
+
Requires-Dist: numba>=0.61.2
|
|
23
|
+
Requires-Dist: numpy>=2.0.0
|
|
24
|
+
Requires-Dist: pandas>=2.2.3
|
|
25
|
+
Requires-Dist: pickydict>=0.5.0
|
|
26
|
+
Requires-Dist: psims>=1.3.2
|
|
27
|
+
Requires-Dist: pubchempy>=1.0.5
|
|
28
|
+
Requires-Dist: pyarrow>=16,!=26.0.1
|
|
29
|
+
Requires-Dist: pynndescent>=0.6.0
|
|
30
|
+
Requires-Dist: pyteomics>=4.7.5
|
|
31
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
32
|
+
Requires-Dist: rdkit>=2024.3.5
|
|
33
|
+
Requires-Dist: requests>=2.32.5
|
|
34
|
+
Requires-Dist: scipy>=1.16.1,<2.0
|
|
35
|
+
Requires-Dist: tqdm>=4.67.1
|
|
36
|
+
Requires-Dist: chemap>=0.3.5 ; extra == 'all'
|
|
37
|
+
Requires-Dist: chemap>=0.3.5 ; extra == 'fingerprints'
|
|
38
|
+
Requires-Python: >=3.11, <3.15
|
|
39
|
+
Project-URL: documentation, https://matchms.readthedocs.io/en/latest/
|
|
40
|
+
Project-URL: repository, https://github.com/matchms/matchms
|
|
41
|
+
Provides-Extra: all
|
|
42
|
+
Provides-Extra: fingerprints
|
|
43
|
+
Description-Content-Type: text/x-rst
|
|
44
|
+
|
|
45
|
+
|GitHub Badge|
|
|
46
|
+
|License Badge|
|
|
47
|
+
|Conda Badge| |Pypi Badge| |Research Software Directory Badge|
|
|
48
|
+
|Zenodo Badge|
|
|
49
|
+
|CII Best Practices Badge| |Howfairis Badge|
|
|
50
|
+
|
|
51
|
+
Code quality checks:
|
|
52
|
+
|
|
53
|
+
|CI First Code Checks| |CI Build|
|
|
54
|
+
|ReadTheDocs Badge|
|
|
55
|
+
|Sonarcloud Quality Gate Badge| |Sonarcloud Coverage Badge|
|
|
56
|
+
|
|
57
|
+
.. image:: readthedocs/_static/matchms_header.png
|
|
58
|
+
:target: readthedocs/_static/matchms.png
|
|
59
|
+
:align: left
|
|
60
|
+
:alt: matchms
|
|
61
|
+
|
|
62
|
+
matchms
|
|
63
|
+
=======
|
|
64
|
+
|
|
65
|
+
Matchms is an open-source Python package for importing, processing, cleaning,
|
|
66
|
+
exporting, and comparing tandem mass spectrometry data (MS/MS). It supports
|
|
67
|
+
reproducible workflows that transform raw spectra from common file formats into
|
|
68
|
+
cleaned, harmonized, and comparable spectral datasets.
|
|
69
|
+
|
|
70
|
+
The preferred way to work with matchms is now through
|
|
71
|
+
`SpectraCollection`: a collection-level representation for complete MS/MS
|
|
72
|
+
datasets. A `SpectraCollection` keeps metadata and fragment peak data
|
|
73
|
+
synchronized, supports table-like inspection and filtering, and provides a
|
|
74
|
+
natural basis for scalable dataset-level processing and similarity computation.
|
|
75
|
+
|
|
76
|
+
Matchms supports popular spectral data formats including mzML, mzXML, MSP, MGF,
|
|
77
|
+
metabolomics-USI, JSON, pickle, and Parquet. It provides tools for metadata
|
|
78
|
+
harmonization, metadata validation, peak filtering, spectrum processing,
|
|
79
|
+
collection processing, export, and large-scale spectral similarity calculations.
|
|
80
|
+
|
|
81
|
+
The classic ``Spectrum`` API, which was the default in matchms < 1.0, remains supported.
|
|
82
|
+
Individual spectra are still represented as ``Spectrum`` objects, and existing workflows
|
|
83
|
+
that process lists of spectra continue to work.
|
|
84
|
+
For new workflows, however, ``SpectraCollection`` is recommended whenever a
|
|
85
|
+
complete dataset is imported, cleaned, filtered, exported, or compared.
|
|
86
|
+
|
|
87
|
+
For changes from matchms 0.x, see the `changelog <CHANGELOG.md>`_ and the
|
|
88
|
+
`development documentation <https://matchms.readthedocs.io/en/development/>`_.
|
|
89
|
+
|
|
90
|
+
.. image:: readthedocs/_static/matchms_modular_design_v1_0.png
|
|
91
|
+
:target: readthedocs/_static/matchms_modular_design_v1_0.png
|
|
92
|
+
:align: left
|
|
93
|
+
:alt: matchms code design
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
Citation
|
|
97
|
+
========
|
|
98
|
+
|
|
99
|
+
If you use matchms in your research, please cite the following software papers:
|
|
100
|
+
|
|
101
|
+
F Huber, S. Verhoeven, C. Meijer, H. Spreeuw, E. M. Villanueva Castilla, C. Geng, J.J.J. van der Hooft, S. Rogers, A. Belloum, F. Diblen, J.H. Spaaks, (2020). matchms - processing and similarity evaluation of mass spectrometry data. Journal of Open Source Software, 5(52), 2411, https://doi.org/10.21105/joss.02411
|
|
102
|
+
|
|
103
|
+
de Jonge NF, Hecht H, Michael Strobel, Mingxun Wang, van der Hooft JJJ, Huber F. (2024). Reproducible MS/MS library cleaning pipeline in matchms. Journal of Cheminformatics, 2024, https://jcheminf.biomedcentral.com/articles/10.1186/s13321-024-00878-1
|
|
104
|
+
|
|
105
|
+
Quick start: collection-first workflow
|
|
106
|
+
======================================
|
|
107
|
+
|
|
108
|
+
A typical matchms workflow starts by loading an MS/MS dataset directly as a
|
|
109
|
+
``SpectraCollection``:
|
|
110
|
+
|
|
111
|
+
.. code-block:: python
|
|
112
|
+
|
|
113
|
+
from matchms.importing import load_ms2_dataset
|
|
114
|
+
|
|
115
|
+
collection = load_ms2_dataset("my_spectra.mgf")
|
|
116
|
+
|
|
117
|
+
print(collection)
|
|
118
|
+
print(collection.metadata.head())
|
|
119
|
+
print(collection.n_spectra)
|
|
120
|
+
|
|
121
|
+
Filters can then be applied directly to the collection:
|
|
122
|
+
|
|
123
|
+
.. code-block:: python
|
|
124
|
+
|
|
125
|
+
from matchms.filtering import (
|
|
126
|
+
harmonize_missing_entries,
|
|
127
|
+
select_by_relative_intensity,
|
|
128
|
+
require_minimum_number_of_peaks,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
collection = harmonize_missing_entries(collection)
|
|
132
|
+
collection = select_by_relative_intensity(
|
|
133
|
+
collection,
|
|
134
|
+
intensity_from=0.01,
|
|
135
|
+
intensity_to=1.0,
|
|
136
|
+
)
|
|
137
|
+
collection = require_minimum_number_of_peaks(collection, n_required=5)
|
|
138
|
+
|
|
139
|
+
The processed collection can be exported again:
|
|
140
|
+
|
|
141
|
+
.. code-block:: python
|
|
142
|
+
|
|
143
|
+
collection.to_mgf("processed_spectra.mgf")
|
|
144
|
+
collection.to_msp("processed_spectra.msp")
|
|
145
|
+
collection.to_json("processed_spectra.json")
|
|
146
|
+
|
|
147
|
+
Similarity scores can be computed directly from the processed collection:
|
|
148
|
+
|
|
149
|
+
.. code-block:: python
|
|
150
|
+
|
|
151
|
+
from matchms.similarity import ModifiedCosine
|
|
152
|
+
|
|
153
|
+
similarity = ModifiedCosine(tolerance=0.01)
|
|
154
|
+
scores = similarity.matrix(collection)
|
|
155
|
+
|
|
156
|
+
For repeated searches against a fixed reference library, build the library
|
|
157
|
+
index once and reuse it. For large libraries, request only the best hits:
|
|
158
|
+
|
|
159
|
+
.. code-block:: python
|
|
160
|
+
|
|
161
|
+
query_collection = load_ms2_dataset("my_queries.mgf")
|
|
162
|
+
library_index = similarity.build_index(collection)
|
|
163
|
+
|
|
164
|
+
top_hits = similarity.search_topk(
|
|
165
|
+
query_collection, library_index, k=10, min_score=0.1, n_jobs=1
|
|
166
|
+
)
|
|
167
|
+
reference_indices, similarities = top_hits.get_hits(0)
|
|
168
|
+
|
|
169
|
+
Use ``similarity.search(query_collection, library_index)`` when the complete
|
|
170
|
+
query-by-reference score matrix is needed.
|
|
171
|
+
|
|
172
|
+
The index can also be saved and loaded again later:
|
|
173
|
+
|
|
174
|
+
.. code-block:: python
|
|
175
|
+
|
|
176
|
+
similarity.save_index(
|
|
177
|
+
library_index,
|
|
178
|
+
"modified_cosine_index.npz",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
library_index = similarity.load_index(
|
|
182
|
+
"modified_cosine_index.npz"
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
Core concepts
|
|
187
|
+
=============
|
|
188
|
+
|
|
189
|
+
SpectraCollection
|
|
190
|
+
-----------------
|
|
191
|
+
|
|
192
|
+
``SpectraCollection`` is the central matchms representation for complete MS/MS
|
|
193
|
+
datasets. It stores many spectra in a synchronized collection layout and keeps
|
|
194
|
+
spectrum-level metadata aligned with fragment peak data.
|
|
195
|
+
|
|
196
|
+
A collection separates dataset storage into:
|
|
197
|
+
|
|
198
|
+
- ``MetadataCollection``: a pandas-based table where each row corresponds to one
|
|
199
|
+
spectrum.
|
|
200
|
+
- ``FragmentCollection``: a backend for storing all fragment peaks. The default
|
|
201
|
+
backend is ``CSRFragmentCollection``, which stores peaks in a sparse matrix
|
|
202
|
+
with spectra as rows and binned m/z values as columns.
|
|
203
|
+
|
|
204
|
+
The central invariant is:
|
|
205
|
+
|
|
206
|
+
.. code-block:: text
|
|
207
|
+
|
|
208
|
+
len(collection.metadata) == len(collection.fragments) == collection.n_spectra
|
|
209
|
+
|
|
210
|
+
Metadata row ``i`` and fragment row ``i`` always describe the same spectrum.
|
|
211
|
+
Operations such as slicing, filtering, sorting, dropping, and deduplication
|
|
212
|
+
preserve this alignment.
|
|
213
|
+
|
|
214
|
+
Example:
|
|
215
|
+
|
|
216
|
+
.. code-block:: python
|
|
217
|
+
|
|
218
|
+
from matchms.importing import load_ms2_dataset
|
|
219
|
+
|
|
220
|
+
collection = load_ms2_dataset("my_spectra.mgf")
|
|
221
|
+
|
|
222
|
+
print(collection)
|
|
223
|
+
print(collection.metadata.head())
|
|
224
|
+
print(collection.describe())
|
|
225
|
+
|
|
226
|
+
first_spectrum = collection[0]
|
|
227
|
+
|
|
228
|
+
``SpectraCollection`` supports dataset-level selection while keeping metadata
|
|
229
|
+
and fragment data synchronized:
|
|
230
|
+
|
|
231
|
+
.. code-block:: python
|
|
232
|
+
|
|
233
|
+
# Select spectra by metadata
|
|
234
|
+
positive = collection.filter(collection.metadata["ionmode"] == "positive")
|
|
235
|
+
|
|
236
|
+
# Sort spectra by metadata
|
|
237
|
+
sorted_collection = collection.sort("precursor_mz")
|
|
238
|
+
|
|
239
|
+
# Select spectra and restrict m/z range
|
|
240
|
+
selected = collection[:100, 50.0:500.0]
|
|
241
|
+
|
|
242
|
+
# Drop spectra without peaks
|
|
243
|
+
collection = collection.drop_empty_spectra()
|
|
244
|
+
|
|
245
|
+
# Drop duplicate spectra
|
|
246
|
+
collection = collection.drop_duplicates()
|
|
247
|
+
|
|
248
|
+
Individual rows can still be accessed as regular ``Spectrum`` objects:
|
|
249
|
+
|
|
250
|
+
.. code-block:: python
|
|
251
|
+
|
|
252
|
+
spectrum = collection[0]
|
|
253
|
+
|
|
254
|
+
print(spectrum.peaks.mz)
|
|
255
|
+
print(spectrum.get("precursor_mz"))
|
|
256
|
+
|
|
257
|
+
It is also possible to run a simple for loop: ``for spectrum in collection:``
|
|
258
|
+
|
|
259
|
+
Spectrum
|
|
260
|
+
--------
|
|
261
|
+
|
|
262
|
+
``Spectrum`` represents one mass spectrum. It contains:
|
|
263
|
+
|
|
264
|
+
- ``Fragments``: the m/z and intensity arrays of one spectrum.
|
|
265
|
+
- ``Metadata``: one spectrum-level metadata dictionary.
|
|
266
|
+
|
|
267
|
+
``Spectrum`` is useful for individual spectra, custom spectrum-wise algorithms,
|
|
268
|
+
and backward-compatible workflows (e.g., for projects partly using matchms < 1.0).
|
|
269
|
+
|
|
270
|
+
Example:
|
|
271
|
+
|
|
272
|
+
.. code-block:: python
|
|
273
|
+
|
|
274
|
+
import numpy as np
|
|
275
|
+
from matchms import Spectrum
|
|
276
|
+
|
|
277
|
+
spectrum = Spectrum(
|
|
278
|
+
mz=np.array([100.0, 150.0, 200.0]),
|
|
279
|
+
intensities=np.array([0.1, 0.5, 1.0]),
|
|
280
|
+
metadata={
|
|
281
|
+
"precursor_mz": 201.1,
|
|
282
|
+
"ionmode": "positive",
|
|
283
|
+
"smiles": "CCCO",
|
|
284
|
+
},
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
print(spectrum.peaks.mz)
|
|
288
|
+
print(spectrum.get("precursor_mz"))
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
Importing datasets
|
|
292
|
+
==================
|
|
293
|
+
|
|
294
|
+
For new workflows, use ``load_ms2_dataset`` to import a complete dataset as a
|
|
295
|
+
``SpectraCollection``:
|
|
296
|
+
|
|
297
|
+
.. code-block:: python
|
|
298
|
+
|
|
299
|
+
from matchms.importing import load_ms2_dataset
|
|
300
|
+
|
|
301
|
+
collection = load_ms2_dataset("my_spectra.mgf")
|
|
302
|
+
|
|
303
|
+
The file type is detected automatically from the file extension. Supported
|
|
304
|
+
types include ``mzML``, ``mzXML``, ``mgf``, ``msp``, ``json``, and
|
|
305
|
+
``pickle``. Parquet datasets can be loaded directly with
|
|
306
|
+
``matchms.importing.load_from_parquet`` (requires ``pyarrow``).
|
|
307
|
+
|
|
308
|
+
If needed, the file type can be specified explicitly:
|
|
309
|
+
|
|
310
|
+
.. code-block:: python
|
|
311
|
+
|
|
312
|
+
collection = load_ms2_dataset("my_file.txt", ftype="mgf")
|
|
313
|
+
|
|
314
|
+
Metadata harmonization is enabled by default:
|
|
315
|
+
|
|
316
|
+
.. code-block:: python
|
|
317
|
+
|
|
318
|
+
collection = load_ms2_dataset(
|
|
319
|
+
"my_spectra.mgf",
|
|
320
|
+
metadata_harmonization=True,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
For lower-level workflows, individual importers remain available:
|
|
324
|
+
|
|
325
|
+
.. code-block:: python
|
|
326
|
+
|
|
327
|
+
from matchms.importing import load_from_mgf
|
|
328
|
+
|
|
329
|
+
spectra = list(load_from_mgf("my_spectra.mgf"))
|
|
330
|
+
|
|
331
|
+
The helper ``load_spectra`` returns spectra as ``Spectrum`` objects or iterables
|
|
332
|
+
of ``Spectrum`` objects:
|
|
333
|
+
|
|
334
|
+
.. code-block:: python
|
|
335
|
+
|
|
336
|
+
from matchms.importing import load_spectra
|
|
337
|
+
|
|
338
|
+
spectra = list(load_spectra("my_spectra.mgf"))
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
Exporting datasets
|
|
342
|
+
==================
|
|
343
|
+
|
|
344
|
+
``SpectraCollection`` objects can be exported directly:
|
|
345
|
+
|
|
346
|
+
.. code-block:: python
|
|
347
|
+
|
|
348
|
+
collection.to_mgf("processed_spectra.mgf")
|
|
349
|
+
collection.to_msp("processed_spectra.msp")
|
|
350
|
+
collection.to_json("processed_spectra.json")
|
|
351
|
+
|
|
352
|
+
MGF and MSP export support appending to an existing file:
|
|
353
|
+
|
|
354
|
+
.. code-block:: python
|
|
355
|
+
|
|
356
|
+
collection.to_mgf("combined_spectra.mgf", append=True)
|
|
357
|
+
collection.to_msp("combined_spectra.msp", append=True)
|
|
358
|
+
|
|
359
|
+
The export style can be selected where supported:
|
|
360
|
+
|
|
361
|
+
.. code-block:: python
|
|
362
|
+
|
|
363
|
+
collection.to_mgf("processed_spectra.mgf", export_style="gnps")
|
|
364
|
+
collection.to_msp("processed_spectra.msp", export_style="nist")
|
|
365
|
+
|
|
366
|
+
Parquet datasets can also be exported using
|
|
367
|
+
``matchms.exporting.save_as_parquet``. The Parquet import/export API is
|
|
368
|
+
separate from the collection ``to_mgf``/``to_msp``/``to_json`` methods.
|
|
369
|
+
|
|
370
|
+
The classic ``save_spectra`` wrapper remains available for workflows that work
|
|
371
|
+
with individual ``Spectrum`` objects or lists of spectra:
|
|
372
|
+
|
|
373
|
+
.. code-block:: python
|
|
374
|
+
|
|
375
|
+
from matchms.exporting import save_spectra
|
|
376
|
+
|
|
377
|
+
save_spectra(spectra, "processed_spectra.mgf")
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
Filtering and processing
|
|
381
|
+
========================
|
|
382
|
+
|
|
383
|
+
Many matchms filters support both ``Spectrum`` and ``SpectraCollection`` input.
|
|
384
|
+
When a filter receives a collection, it operates on all rows while preserving
|
|
385
|
+
the alignment between metadata and fragment data.
|
|
386
|
+
|
|
387
|
+
.. code-block:: python
|
|
388
|
+
|
|
389
|
+
from matchms.filtering import (
|
|
390
|
+
harmonize_missing_entries,
|
|
391
|
+
select_by_relative_intensity,
|
|
392
|
+
require_minimum_number_of_peaks,
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
collection = harmonize_missing_entries(collection)
|
|
396
|
+
collection = select_by_relative_intensity(collection, intensity_from=0.01)
|
|
397
|
+
collection = require_minimum_number_of_peaks(collection, n_required=5)
|
|
398
|
+
|
|
399
|
+
For filters that remove spectra, the behavior depends on the input type:
|
|
400
|
+
|
|
401
|
+
- For ``Spectrum`` input, a failing spectrum returns ``None``.
|
|
402
|
+
- For ``SpectraCollection`` input, failing rows are removed from both metadata
|
|
403
|
+
and fragments.
|
|
404
|
+
|
|
405
|
+
This keeps the collection synchronized throughout the workflow.
|
|
406
|
+
|
|
407
|
+
SpectraProcessor
|
|
408
|
+
----------------
|
|
409
|
+
|
|
410
|
+
``SpectraProcessor`` provides a single processing pipeline for both individual
|
|
411
|
+
``Spectrum`` objects and complete ``SpectraCollection`` objects.
|
|
412
|
+
|
|
413
|
+
The processor uses the same ordered list of filters for both execution paths,
|
|
414
|
+
but provides explicit methods for choosing how the pipeline is applied:
|
|
415
|
+
|
|
416
|
+
- ``process_spectrum()`` applies all filters sequentially to one ``Spectrum``.
|
|
417
|
+
- ``process_collection()`` applies each filter to the complete
|
|
418
|
+
``SpectraCollection``, allowing collection-native and vectorized filter
|
|
419
|
+
implementations to be used.
|
|
420
|
+
|
|
421
|
+
For collection-based workflows:
|
|
422
|
+
|
|
423
|
+
.. code-block:: python
|
|
424
|
+
|
|
425
|
+
from matchms import SpectraProcessor
|
|
426
|
+
from matchms.importing import load_ms2_dataset
|
|
427
|
+
|
|
428
|
+
collection = load_ms2_dataset("my_spectra.mgf")
|
|
429
|
+
|
|
430
|
+
processor = SpectraProcessor(
|
|
431
|
+
filters=[
|
|
432
|
+
"harmonize_missing_entries",
|
|
433
|
+
("select_by_relative_intensity", {"intensity_from": 0.01}),
|
|
434
|
+
("require_minimum_number_of_peaks", {"n_required": 5}),
|
|
435
|
+
]
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
processed_collection = processor.process_collection(collection)
|
|
439
|
+
|
|
440
|
+
For individual spectra, the same processor and filter configuration can be
|
|
441
|
+
used:
|
|
442
|
+
|
|
443
|
+
.. code-block:: python
|
|
444
|
+
|
|
445
|
+
from matchms import SpectraProcessor
|
|
446
|
+
from matchms.filtering.default_pipelines import BASIC_FILTERS
|
|
447
|
+
from matchms.importing import load_spectra
|
|
448
|
+
|
|
449
|
+
spectra = list(load_spectra("my_spectra.mgf"))
|
|
450
|
+
processor = SpectraProcessor(BASIC_FILTERS)
|
|
451
|
+
|
|
452
|
+
processed_spectra = [
|
|
453
|
+
processed
|
|
454
|
+
for spectrum in spectra
|
|
455
|
+
if (processed := processor.process_spectrum(spectrum)) is not None
|
|
456
|
+
]
|
|
457
|
+
|
|
458
|
+
Both processing methods copy the input once before applying the pipeline, so the
|
|
459
|
+
original ``Spectrum`` or ``SpectraCollection`` is not modified.
|
|
460
|
+
|
|
461
|
+
``SpectraProcessor`` accepts filter descriptions in several forms:
|
|
462
|
+
|
|
463
|
+
.. code-block:: python
|
|
464
|
+
|
|
465
|
+
filters = [
|
|
466
|
+
"harmonize_missing_entries",
|
|
467
|
+
("select_by_intensity", {"intensity_from": 10.0, "intensity_to": 1000.0}),
|
|
468
|
+
custom_filter_function,
|
|
469
|
+
(custom_filter_with_parameters, {"parameter": "value"}),
|
|
470
|
+
]
|
|
471
|
+
|
|
472
|
+
Known matchms filters are ordered according to the matchms filter order. Custom
|
|
473
|
+
filters are appended unless a specific position is supplied.
|
|
474
|
+
|
|
475
|
+
Processing reports
|
|
476
|
+
------------------
|
|
477
|
+
|
|
478
|
+
``SpectraProcessor`` can optionally collect a processing report that summarizes
|
|
479
|
+
how much each filter changed the data.
|
|
480
|
+
|
|
481
|
+
.. code-block:: python
|
|
482
|
+
|
|
483
|
+
processor = SpectraProcessor(
|
|
484
|
+
filters=[
|
|
485
|
+
"harmonize_missing_entries",
|
|
486
|
+
("select_by_relative_intensity", {"intensity_from": 0.01}),
|
|
487
|
+
("require_minimum_number_of_peaks", {"n_required": 5}),
|
|
488
|
+
]
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
report = processor.create_processing_report()
|
|
492
|
+
|
|
493
|
+
processed_collection = processor.process_collection(
|
|
494
|
+
collection,
|
|
495
|
+
processing_report=report,
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
print(report.to_dataframe())
|
|
499
|
+
|
|
500
|
+
The report also exposes ``report.missing_metadata`` to identify metadata
|
|
501
|
+
entries that remain missing after processing.
|
|
502
|
+
|
|
503
|
+
The report records, for each filter:
|
|
504
|
+
|
|
505
|
+
- the number of input spectra,
|
|
506
|
+
- the number of output spectra,
|
|
507
|
+
- the number of removed spectra,
|
|
508
|
+
- the number of spectra with changed metadata,
|
|
509
|
+
- the number of spectra with changed fragments.
|
|
510
|
+
|
|
511
|
+
Changes are detected using metadata and fragment hashes, so reporting does not
|
|
512
|
+
require keeping full copies of the data before every processing step.
|
|
513
|
+
|
|
514
|
+
The same reporting mechanism can also be used with ``process_spectrum()``:
|
|
515
|
+
|
|
516
|
+
.. code-block:: python
|
|
517
|
+
|
|
518
|
+
report = processor.create_processing_report()
|
|
519
|
+
|
|
520
|
+
processed_spectrum = processor.process_spectrum(
|
|
521
|
+
spectrum,
|
|
522
|
+
processing_report=report,
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
Metadata handling
|
|
527
|
+
=================
|
|
528
|
+
|
|
529
|
+
For collections, metadata is stored in ``MetadataCollection``, a pandas-based
|
|
530
|
+
table. Each row corresponds to one spectrum, and columns correspond to metadata
|
|
531
|
+
fields.
|
|
532
|
+
|
|
533
|
+
.. code-block:: python
|
|
534
|
+
|
|
535
|
+
print(collection.metadata.head())
|
|
536
|
+
print(collection.metadata.columns)
|
|
537
|
+
|
|
538
|
+
Metadata column names can be harmonized using matchms key conventions:
|
|
539
|
+
|
|
540
|
+
.. code-block:: python
|
|
541
|
+
|
|
542
|
+
collection = collection.harmonize_metadata_columns()
|
|
543
|
+
|
|
544
|
+
For example:
|
|
545
|
+
|
|
546
|
+
.. code-block:: text
|
|
547
|
+
|
|
548
|
+
"Precursor MZ" -> "precursor_mz"
|
|
549
|
+
"Compound Name" -> "compound_name"
|
|
550
|
+
|
|
551
|
+
Missing metadata values can be harmonized with:
|
|
552
|
+
|
|
553
|
+
.. code-block:: python
|
|
554
|
+
|
|
555
|
+
from matchms.filtering import harmonize_missing_entries
|
|
556
|
+
|
|
557
|
+
collection = harmonize_missing_entries(collection)
|
|
558
|
+
|
|
559
|
+
By default, common aliases for missing values such as ``""``, ``"N/A"``,
|
|
560
|
+
``"NA"``, ``"n/a"``, ``"NaN"``, ``"None"``, and ``"no data"`` are interpreted
|
|
561
|
+
as missing entries.
|
|
562
|
+
|
|
563
|
+
Older specialized filters such as ``harmonize_undefined_inchi``,
|
|
564
|
+
``harmonize_undefined_inchikey``, and ``harmonize_undefined_smiles`` are kept for
|
|
565
|
+
backward compatibility but are deprecated in favor of
|
|
566
|
+
``harmonize_missing_entries``.
|
|
567
|
+
|
|
568
|
+
For individual spectra, metadata is stored in a ``Metadata`` object and can be
|
|
569
|
+
accessed with:
|
|
570
|
+
|
|
571
|
+
.. code-block:: python
|
|
572
|
+
|
|
573
|
+
spectrum.get("precursor_mz")
|
|
574
|
+
spectrum.set("compound_name", "example")
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
Peak data handling
|
|
578
|
+
==================
|
|
579
|
+
|
|
580
|
+
For collections, peak data is stored in a ``FragmentCollection`` backend. The
|
|
581
|
+
default backend is ``CSRFragmentCollection``, which stores peaks in a sparse
|
|
582
|
+
matrix.
|
|
583
|
+
|
|
584
|
+
This enables efficient dataset-level operations such as:
|
|
585
|
+
|
|
586
|
+
- counting peaks per spectrum,
|
|
587
|
+
- selecting peaks by intensity,
|
|
588
|
+
- selecting peaks by relative intensity,
|
|
589
|
+
- filtering spectra by number of peaks,
|
|
590
|
+
- slicing m/z ranges,
|
|
591
|
+
- computing fragment hashes,
|
|
592
|
+
- computing summary statistics.
|
|
593
|
+
|
|
594
|
+
Example:
|
|
595
|
+
|
|
596
|
+
.. code-block:: python
|
|
597
|
+
|
|
598
|
+
peak_counts = collection.fragments.count(axis=1)
|
|
599
|
+
intensity_sums = collection.fragments.sum(axis=1)
|
|
600
|
+
|
|
601
|
+
selected = collection[:, 50.0:500.0]
|
|
602
|
+
|
|
603
|
+
Because the default collection backend uses binned sparse storage, spectra
|
|
604
|
+
reconstructed from a ``SpectraCollection`` may contain m/z values corresponding
|
|
605
|
+
to bin centers rather than the exact original m/z values. This is important when
|
|
606
|
+
testing for exact m/z equality; use numerical tolerances where appropriate.
|
|
607
|
+
|
|
608
|
+
For individual spectra, peak data is available through ``spectrum.peaks``:
|
|
609
|
+
|
|
610
|
+
.. code-block:: python
|
|
611
|
+
|
|
612
|
+
spectrum.peaks.mz
|
|
613
|
+
spectrum.peaks.intensities
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
Similarity measures
|
|
617
|
+
===================
|
|
618
|
+
|
|
619
|
+
Matchms provides several similarity measures in ``matchms.similarity`` for
|
|
620
|
+
comparing mass spectra, spectrum metadata, and molecular structures.
|
|
621
|
+
|
|
622
|
+
For most peak-based spectral comparisons, start with one of the high-level
|
|
623
|
+
classes ``Cosine``, ``ModifiedCosine``, ``Entropy``, or ``EntropySearch``.
|
|
624
|
+
These classes provide a common interface for comparing individual spectra,
|
|
625
|
+
computing complete similarity matrices, and, where applicable, repeatedly
|
|
626
|
+
searching a fixed reference library using a reusable index.
|
|
627
|
+
|
|
628
|
+
.. list-table:: Similarity measures at a glance
|
|
629
|
+
:header-rows: 1
|
|
630
|
+
:widths: 18 22 42 32
|
|
631
|
+
|
|
632
|
+
* - Similarity
|
|
633
|
+
- Recommended class
|
|
634
|
+
- Typical use
|
|
635
|
+
- Specialized implementations
|
|
636
|
+
* - Cosine
|
|
637
|
+
- ``Cosine``
|
|
638
|
+
- Standard peak-based spectral similarity with one-to-one peak matching.
|
|
639
|
+
Supports reusable library indices for repeated searches.
|
|
640
|
+
- ``CosineGreedy``,
|
|
641
|
+
``CosineHungarian``,
|
|
642
|
+
``CosineLinear``,
|
|
643
|
+
``CosineFlash``,
|
|
644
|
+
``CosineBlink``
|
|
645
|
+
* - Modified cosine
|
|
646
|
+
- ``ModifiedCosine``
|
|
647
|
+
- Cosine similarity allowing both direct fragment matches and matches
|
|
648
|
+
shifted by the difference in precursor m/z. Supports reusable library
|
|
649
|
+
indices for repeated searches.
|
|
650
|
+
- ``ModifiedCosineGreedy``,
|
|
651
|
+
``ModifiedCosineHungarian``,
|
|
652
|
+
``ModifiedCosineLinear``;
|
|
653
|
+
``CosineFlash`` with ``matching_mode="hybrid"``
|
|
654
|
+
* - Spectral entropy
|
|
655
|
+
- ``Entropy``
|
|
656
|
+
- General-purpose spectral entropy similarity with explicit one-to-one
|
|
657
|
+
matching. Supports fragment, neutral-loss, and hybrid matching as well
|
|
658
|
+
as reusable library indices.
|
|
659
|
+
- ``EntropyGreedy``,
|
|
660
|
+
``EntropyFlash``
|
|
661
|
+
* - Search-optimized spectral entropy
|
|
662
|
+
- ``EntropySearch``
|
|
663
|
+
- High-throughput fragment-only entropy searches against large reference
|
|
664
|
+
libraries. Requires sufficiently separated peaks and can optionally
|
|
665
|
+
merge close peaks during preparation.
|
|
666
|
+
- -
|
|
667
|
+
* - Neutral-loss cosine
|
|
668
|
+
- ``NeutralLossesCosine``
|
|
669
|
+
- Compare spectra based on neutral-loss rather than fragment m/z patterns.
|
|
670
|
+
- -
|
|
671
|
+
* - Binned spectra
|
|
672
|
+
- ``BinnedEmbeddingSimilarity``
|
|
673
|
+
- Compare fixed-width binned spectrum representations using cosine or
|
|
674
|
+
Euclidean similarity.
|
|
675
|
+
- -
|
|
676
|
+
* - Molecular structure
|
|
677
|
+
- ``FingerprintSimilarity``
|
|
678
|
+
- Compare molecular fingerprints derived from structure metadata.
|
|
679
|
+
- -
|
|
680
|
+
* - Metadata
|
|
681
|
+
- ``MetadataMatch``
|
|
682
|
+
- Compare arbitrary metadata fields using exact or tolerance-based matching.
|
|
683
|
+
- -
|
|
684
|
+
* - Precursor or parent mass
|
|
685
|
+
- ``PrecursorMzMatch``,
|
|
686
|
+
``ParentMassMatch``
|
|
687
|
+
- Simple matching based on precursor m/z or parent mass.
|
|
688
|
+
- -
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
Default preprocessing for spectral similarities
|
|
692
|
+
-----------------------------------------------
|
|
693
|
+
|
|
694
|
+
The high-level cosine and entropy implementations remove precursor-region
|
|
695
|
+
peaks by default (``remove_precursor=True``) and ignore peaks below a relative
|
|
696
|
+
intensity threshold (``noise_cutoff=0.01``). These settings are part of
|
|
697
|
+
*similarity preparation*; they do not modify the input collection in place.
|
|
698
|
+
For reproducible comparisons with older workflows, configure both explicitly:
|
|
699
|
+
|
|
700
|
+
.. code-block:: python
|
|
701
|
+
|
|
702
|
+
from matchms.similarity import ModifiedCosine
|
|
703
|
+
|
|
704
|
+
similarity = ModifiedCosine(
|
|
705
|
+
tolerance=0.01,
|
|
706
|
+
remove_precursor=False,
|
|
707
|
+
noise_cutoff=None,
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
Keep preprocessing settings consistent when constructing and reusing an index.
|
|
711
|
+
The exact available options can differ for specialized scoring classes.
|
|
712
|
+
|
|
713
|
+
Pair and matrix comparisons
|
|
714
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
715
|
+
|
|
716
|
+
Similarity matrices can be computed directly from a ``SpectraCollection``:
|
|
717
|
+
|
|
718
|
+
.. code-block:: python
|
|
719
|
+
|
|
720
|
+
from matchms.similarity import Entropy
|
|
721
|
+
|
|
722
|
+
similarity = Entropy(tolerance=0.02)
|
|
723
|
+
scores = similarity.matrix(collection)
|
|
724
|
+
|
|
725
|
+
The same API can be used to compare two collections:
|
|
726
|
+
|
|
727
|
+
.. code-block:: python
|
|
728
|
+
|
|
729
|
+
from matchms.similarity import ModifiedCosine
|
|
730
|
+
|
|
731
|
+
similarity = ModifiedCosine(tolerance=0.01)
|
|
732
|
+
scores = similarity.matrix(references, queries)
|
|
733
|
+
|
|
734
|
+
Rows of the resulting matrix correspond to the first input collection and
|
|
735
|
+
columns to the second.
|
|
736
|
+
|
|
737
|
+
Pairwise scoring of individual spectra is also supported:
|
|
738
|
+
|
|
739
|
+
.. code-block:: python
|
|
740
|
+
|
|
741
|
+
from matchms.similarity import Cosine
|
|
742
|
+
|
|
743
|
+
similarity = Cosine(tolerance=0.01)
|
|
744
|
+
score = similarity.pair(spectrum_1, spectrum_2)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
Working with Scores results
|
|
748
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
749
|
+
|
|
750
|
+
``pair()`` returns the score fields for one spectrum pair. ``matrix()`` and
|
|
751
|
+
``search()`` return a lightweight ``Scores`` container with fields such as
|
|
752
|
+
``"score"`` and (for cosine) ``"matches"``. It stores results but does not
|
|
753
|
+
perform score computations itself.
|
|
754
|
+
|
|
755
|
+
.. code-block:: python
|
|
756
|
+
|
|
757
|
+
score_matrix = scores["score"].to_array()
|
|
758
|
+
high_similarity = scores["score"] > 0.7
|
|
759
|
+
|
|
760
|
+
Some pair-oriented similarity implementations also support
|
|
761
|
+
``sparse_matrix()`` for calculations where only selected pairs should be
|
|
762
|
+
stored. ``search_topk()`` instead returns a dedicated ``TopKResults`` object
|
|
763
|
+
and should not be treated as a sparse representation of the full matrix.
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
Repeated library searches with reusable indices
|
|
767
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
768
|
+
|
|
769
|
+
``Cosine``, ``ModifiedCosine``, ``Entropy``, and ``EntropySearch`` support
|
|
770
|
+
repeated searches against a fixed reference library.
|
|
771
|
+
|
|
772
|
+
For this workflow, construct the library index once with ``build_index`` and
|
|
773
|
+
then use ``search`` for one or more query collections:
|
|
774
|
+
|
|
775
|
+
.. code-block:: python
|
|
776
|
+
|
|
777
|
+
from matchms.similarity import Cosine
|
|
778
|
+
|
|
779
|
+
similarity = Cosine(tolerance=0.01)
|
|
780
|
+
|
|
781
|
+
library_index = similarity.build_index(reference_library)
|
|
782
|
+
|
|
783
|
+
scores = similarity.search(
|
|
784
|
+
query_collection,
|
|
785
|
+
library_index,
|
|
786
|
+
)
|
|
787
|
+
|
|
788
|
+
Unlike ``matrix``, ``search`` always treats the input spectra as queries.
|
|
789
|
+
The returned score matrix therefore has query spectra as rows and reference
|
|
790
|
+
library spectra as columns.
|
|
791
|
+
|
|
792
|
+
The same workflow is available for modified cosine:
|
|
793
|
+
|
|
794
|
+
.. code-block:: python
|
|
795
|
+
|
|
796
|
+
from matchms.similarity import ModifiedCosine
|
|
797
|
+
|
|
798
|
+
similarity = ModifiedCosine(tolerance=0.01)
|
|
799
|
+
|
|
800
|
+
library_index = similarity.build_index(reference_library)
|
|
801
|
+
scores = similarity.search(query_collection, library_index)
|
|
802
|
+
|
|
803
|
+
and for general spectral entropy similarity:
|
|
804
|
+
|
|
805
|
+
.. code-block:: python
|
|
806
|
+
|
|
807
|
+
from matchms.similarity import Entropy
|
|
808
|
+
|
|
809
|
+
similarity = Entropy(
|
|
810
|
+
matching_mode="fragment",
|
|
811
|
+
tolerance=0.01,
|
|
812
|
+
)
|
|
813
|
+
|
|
814
|
+
library_index = similarity.build_index(reference_library)
|
|
815
|
+
scores = similarity.search(query_collection, library_index)
|
|
816
|
+
|
|
817
|
+
Building the index separately is especially useful when many query batches are
|
|
818
|
+
searched against the same reference library, because the reference spectra do
|
|
819
|
+
not need to be prepared and indexed again for every search.
|
|
820
|
+
|
|
821
|
+
.. image:: readthedocs/_static/matchms_similarity_implementations.png
|
|
822
|
+
:target: readthedocs/_static/matchms_similarity_implementations.png
|
|
823
|
+
:align: left
|
|
824
|
+
:alt: matchms similarity implementations and class inheritances
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
Saving and loading similarity indices
|
|
828
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
829
|
+
|
|
830
|
+
A built index can be stored on disk and reused in a later Python session:
|
|
831
|
+
|
|
832
|
+
.. code-block:: python
|
|
833
|
+
|
|
834
|
+
similarity.save_index(
|
|
835
|
+
library_index,
|
|
836
|
+
"library_index.npz",
|
|
837
|
+
)
|
|
838
|
+
|
|
839
|
+
Load it again with a similarity object using the same scoring and preprocessing
|
|
840
|
+
configuration:
|
|
841
|
+
|
|
842
|
+
.. code-block:: python
|
|
843
|
+
|
|
844
|
+
from matchms.similarity import Cosine
|
|
845
|
+
|
|
846
|
+
similarity = Cosine(tolerance=0.01)
|
|
847
|
+
|
|
848
|
+
library_index = similarity.load_index(
|
|
849
|
+
"library_index.npz"
|
|
850
|
+
)
|
|
851
|
+
|
|
852
|
+
scores = similarity.search(
|
|
853
|
+
query_collection,
|
|
854
|
+
library_index,
|
|
855
|
+
)
|
|
856
|
+
|
|
857
|
+
Index compatibility is checked when the index is loaded or used. An index
|
|
858
|
+
should therefore be loaded with a similarity configuration matching the one
|
|
859
|
+
used to create it.
|
|
860
|
+
|
|
861
|
+
The same ``build_index``, ``save_index``, ``load_index``, and ``search``
|
|
862
|
+
workflow is available for ``Cosine``, ``ModifiedCosine``, ``Entropy``, and
|
|
863
|
+
``EntropySearch``.
|
|
864
|
+
|
|
865
|
+
For ``Cosine`` and ``ModifiedCosine``, persistent indexed searching uses the
|
|
866
|
+
default indexed greedy implementation. It is not available when
|
|
867
|
+
``use_hungarian=True``.
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
Exact top-k library search
|
|
871
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
872
|
+
|
|
873
|
+
For large libraries, a dense ``search()`` result can be expensive even when
|
|
874
|
+
only a few high-scoring references are needed. Indexed cosine, modified
|
|
875
|
+
cosine, ``Entropy``, and ``EntropySearch`` therefore provide ``search_topk()``
|
|
876
|
+
and ``search_prepared_topk()``. These methods return the **exact best k hits**
|
|
877
|
+
under the selected similarity scorer, without allocating a dense
|
|
878
|
+
query-by-reference score matrix.
|
|
879
|
+
|
|
880
|
+
.. code-block:: python
|
|
881
|
+
|
|
882
|
+
from matchms.similarity import ModifiedCosine
|
|
883
|
+
|
|
884
|
+
similarity = ModifiedCosine(tolerance=0.01)
|
|
885
|
+
library_index = similarity.build_index(reference_library)
|
|
886
|
+
|
|
887
|
+
hits = similarity.search_topk(
|
|
888
|
+
query_collection,
|
|
889
|
+
library_index,
|
|
890
|
+
k=100,
|
|
891
|
+
min_score=0.1,
|
|
892
|
+
n_jobs=1,
|
|
893
|
+
)
|
|
894
|
+
|
|
895
|
+
# Reference positions (zero-based) and similarity values for query 0.
|
|
896
|
+
library_ids, values = hits.get_hits(0)
|
|
897
|
+
|
|
898
|
+
``TopKResults`` provides ``indices``, ``scores``, and ``valid_counts`` arrays
|
|
899
|
+
with shape ``(n_queries, k)`` for the first two. Each query's hits are sorted
|
|
900
|
+
by decreasing similarity, breaking equal scores by ascending reference ID.
|
|
901
|
+
Only scores *strictly greater* than ``min_score`` are kept (default: ``0``).
|
|
902
|
+
If fewer than ``k`` references qualify, unused entries are padded with
|
|
903
|
+
reference ID ``-1`` and score ``0``; ``get_hits()`` excludes the padding.
|
|
904
|
+
Excluded references must not be interpreted as having a zero similarity.
|
|
905
|
+
|
|
906
|
+
Cosine and modified-cosine hits can also report accepted peak-match counts:
|
|
907
|
+
|
|
908
|
+
.. code-block:: python
|
|
909
|
+
|
|
910
|
+
library_ids, values, matched_peaks = hits.get_hits_with_matches(0)
|
|
911
|
+
|
|
912
|
+
These counts are available by default for cosine; specify
|
|
913
|
+
``score_fields=("score",)`` if they are not needed. Entropy top-k results do
|
|
914
|
+
not contain match counts. Top-k retrieval returns ``TopKResults``, **not** a
|
|
915
|
+
truncated ``Scores`` matrix.
|
|
916
|
+
|
|
917
|
+
The output arrays scale with ``n_queries * k`` instead of
|
|
918
|
+
``n_queries * n_references``. Workers still use library-sized scratch arrays;
|
|
919
|
+
``n_jobs=-1`` can therefore use substantially more memory than ``n_jobs=1``.
|
|
920
|
+
Top-k can also take longer than dense scoring, depending on the workload.
|
|
921
|
+
For repeated searches, ``prepare_queries()`` followed by
|
|
922
|
+
``search_prepared_topk()`` avoids repeating query preprocessing.
|
|
923
|
+
|
|
924
|
+
Entropy and EntropySearch
|
|
925
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
926
|
+
|
|
927
|
+
``Entropy`` and ``EntropySearch`` calculate spectral entropy similarity but
|
|
928
|
+
make different assumptions about peak matching.
|
|
929
|
+
|
|
930
|
+
``Entropy`` is the general-purpose implementation. It explicitly resolves
|
|
931
|
+
competing one-to-one peak matches and supports ``"fragment"``,
|
|
932
|
+
``"neutral_loss"``, and ``"hybrid"`` matching. Use ``Entropy`` when general
|
|
933
|
+
matching behavior is required, when tolerance windows may overlap, or when
|
|
934
|
+
neutral-loss or hybrid matching is needed.
|
|
935
|
+
|
|
936
|
+
Example:
|
|
937
|
+
|
|
938
|
+
.. code-block:: python
|
|
939
|
+
|
|
940
|
+
from matchms.similarity import Entropy
|
|
941
|
+
|
|
942
|
+
similarity = Entropy(
|
|
943
|
+
matching_mode="hybrid",
|
|
944
|
+
tolerance=0.01,
|
|
945
|
+
)
|
|
946
|
+
|
|
947
|
+
scores = similarity.matrix(collection)
|
|
948
|
+
|
|
949
|
+
``EntropySearch`` is optimized for repeated fragment-only searches against
|
|
950
|
+
large reference libraries. It requires peaks within each prepared spectrum to
|
|
951
|
+
be sufficiently separated so that candidate matches do not compete for the
|
|
952
|
+
same physical peak. This avoids the additional bookkeeping required by the
|
|
953
|
+
general ``Entropy`` implementation.
|
|
954
|
+
|
|
955
|
+
By default, close peaks are merged during preparation:
|
|
956
|
+
|
|
957
|
+
.. code-block:: python
|
|
958
|
+
|
|
959
|
+
from matchms.similarity import EntropySearch
|
|
960
|
+
|
|
961
|
+
similarity = EntropySearch(
|
|
962
|
+
tolerance=0.01,
|
|
963
|
+
peak_separation="merge",
|
|
964
|
+
)
|
|
965
|
+
|
|
966
|
+
library_index = similarity.build_index(reference_library)
|
|
967
|
+
|
|
968
|
+
scores = similarity.search(
|
|
969
|
+
query_collection,
|
|
970
|
+
library_index,
|
|
971
|
+
)
|
|
972
|
+
|
|
973
|
+
Merging close peaks changes the prepared spectrum and can therefore lead to
|
|
974
|
+
scores that differ from ``Entropy``.
|
|
975
|
+
|
|
976
|
+
If the input spectra are already sufficiently separated, use
|
|
977
|
+
``peak_separation="raise"`` to keep the input peak representation unchanged
|
|
978
|
+
and raise an error when the separation requirement is violated:
|
|
979
|
+
|
|
980
|
+
.. code-block:: python
|
|
981
|
+
|
|
982
|
+
similarity = EntropySearch(
|
|
983
|
+
tolerance=0.01,
|
|
984
|
+
peak_separation="raise",
|
|
985
|
+
)
|
|
986
|
+
|
|
987
|
+
``EntropySearch`` currently supports fragment matching with an absolute Da
|
|
988
|
+
tolerance. Use ``Entropy`` instead when ppm tolerances, neutral-loss matching,
|
|
989
|
+
hybrid matching, or general one-to-one matching semantics are required.
|
|
990
|
+
|
|
991
|
+
Like the other indexed similarity classes, an ``EntropySearch`` index can be
|
|
992
|
+
saved and reused:
|
|
993
|
+
|
|
994
|
+
.. code-block:: python
|
|
995
|
+
|
|
996
|
+
similarity.save_index(
|
|
997
|
+
library_index,
|
|
998
|
+
"entropy_search_index.npz",
|
|
999
|
+
)
|
|
1000
|
+
|
|
1001
|
+
library_index = similarity.load_index(
|
|
1002
|
+
"entropy_search_index.npz"
|
|
1003
|
+
)
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
Specialized similarity implementations
|
|
1007
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1008
|
+
|
|
1009
|
+
The specialized classes are useful when a particular scoring implementation is
|
|
1010
|
+
required.
|
|
1011
|
+
|
|
1012
|
+
``CosineGreedy`` provides a simple pair-oriented greedy cosine implementation,
|
|
1013
|
+
while ``CosineHungarian`` uses optimal peak assignment. ``CosineLinear`` and
|
|
1014
|
+
``CosineBlink`` provide alternative cosine implementations, and ``CosineFlash``
|
|
1015
|
+
exposes the indexed Flash-based cosine implementation directly.
|
|
1016
|
+
|
|
1017
|
+
For spectral entropy, ``EntropyGreedy`` provides a compact pair-oriented
|
|
1018
|
+
implementation and ``EntropyFlash`` exposes the general indexed implementation
|
|
1019
|
+
used by ``Entropy``.
|
|
1020
|
+
|
|
1021
|
+
For most applications, the high-level ``Cosine``, ``ModifiedCosine``,
|
|
1022
|
+
``Entropy``, and ``EntropySearch`` classes are preferred.
|
|
1023
|
+
|
|
1024
|
+
Molecular fingerprints are handled through the ``Fingerprints`` class, which
|
|
1025
|
+
uses the optional ``chemap`` package for fingerprint generation. The old
|
|
1026
|
+
``add_fingerprint`` filter was removed. Install the optional fingerprint
|
|
1027
|
+
support with ``pip install 'matchms[fingerprints]'`` when needed.
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
Command-line interface
|
|
1031
|
+
======================
|
|
1032
|
+
|
|
1033
|
+
matchms also provides a CLI for dataset inspection, conversion, filtering,
|
|
1034
|
+
similarity matrices, library index creation, and spectral library searches.
|
|
1035
|
+
Run ``matchms --help`` or a subcommand with ``--help`` for all options.
|
|
1036
|
+
|
|
1037
|
+
.. code-block:: console
|
|
1038
|
+
|
|
1039
|
+
matchms info --table
|
|
1040
|
+
matchms spectra describe my_spectra.mgf
|
|
1041
|
+
matchms spectra convert my_spectra.mgf converted_spectra.msp
|
|
1042
|
+
|
|
1043
|
+
For an indexed modified-cosine search from the command line:
|
|
1044
|
+
|
|
1045
|
+
.. code-block:: console
|
|
1046
|
+
|
|
1047
|
+
matchms similarity build-index library.mgf --method ModifiedCosine -o library.index.npz
|
|
1048
|
+
matchms similarity search queries.mgf library.index.npz --method ModifiedCosine --top-k 10 -o hits.tsv
|
|
1049
|
+
|
|
1050
|
+
Use the same similarity settings when building and querying an index.
|
|
1051
|
+
The CLI supports output as tabular text or machine-readable JSON.
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
Installation
|
|
1055
|
+
============
|
|
1056
|
+
|
|
1057
|
+
Prerequisites:
|
|
1058
|
+
|
|
1059
|
+
- A compatible Python version (check ``requires-python`` in
|
|
1060
|
+
``pyproject.toml`` for the development branch). Python 3.13 is used in
|
|
1061
|
+
the examples below.
|
|
1062
|
+
|
|
1063
|
+
Install the published matchms release with uv (recommended). Create a
|
|
1064
|
+
virtual environment before using ``uv pip install``:
|
|
1065
|
+
|
|
1066
|
+
.. code-block:: console
|
|
1067
|
+
|
|
1068
|
+
uv venv --python 3.13
|
|
1069
|
+
uv pip install matchms
|
|
1070
|
+
|
|
1071
|
+
To try the upcoming matchms 1.0 development version instead, use a fresh
|
|
1072
|
+
virtual environment:
|
|
1073
|
+
|
|
1074
|
+
.. code-block:: console
|
|
1075
|
+
|
|
1076
|
+
uv venv --python 3.13
|
|
1077
|
+
uv pip install "git+https://github.com/matchms/matchms.git@development"
|
|
1078
|
+
|
|
1079
|
+
The default ``uv pip install matchms`` command installs the latest
|
|
1080
|
+
published version, which may not yet contain the APIs shown above.
|
|
1081
|
+
|
|
1082
|
+
Install matchms with conda:
|
|
1083
|
+
|
|
1084
|
+
.. code-block:: console
|
|
1085
|
+
|
|
1086
|
+
conda create --name matchms python=3.13
|
|
1087
|
+
conda activate matchms
|
|
1088
|
+
conda install --channel bioconda --channel conda-forge matchms
|
|
1089
|
+
|
|
1090
|
+
Install matchms with pip:
|
|
1091
|
+
|
|
1092
|
+
.. code-block:: console
|
|
1093
|
+
|
|
1094
|
+
python -m venv matchms
|
|
1095
|
+
source matchms/bin/activate
|
|
1096
|
+
pip install matchms
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
Documentation for users
|
|
1100
|
+
=======================
|
|
1101
|
+
|
|
1102
|
+
For more extensive documentation, see:
|
|
1103
|
+
|
|
1104
|
+
- `Development API documentation <https://matchms.readthedocs.io/en/development/>`_
|
|
1105
|
+
- `Latest published documentation <https://matchms.readthedocs.io/en/latest/>`_
|
|
1106
|
+
- `matchms introduction tutorial <https://blog.esciencecenter.nl/build-your-own-mass-spectrometry-analysis-pipeline-in-python-using-matchms-part-i-d96c718c68ee>`_
|
|
1107
|
+
- `user documentation <https://matchms.github.io/matchms-docs/intro.html>`_
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
matchms ecosystem
|
|
1111
|
+
=================
|
|
1112
|
+
|
|
1113
|
+
Additional packages can complement matchms functionality:
|
|
1114
|
+
|
|
1115
|
+
- `Spec2Vec <https://github.com/iomega/spec2vec>`_: machine-learning spectral
|
|
1116
|
+
similarity scoring.
|
|
1117
|
+
- `MS2DeepScore <https://github.com/matchms/ms2deepscore>`_: supervised
|
|
1118
|
+
deep-learning-based spectral similarity scoring.
|
|
1119
|
+
- `matchmsextras <https://github.com/matchms/matchmsextras>`_: additional tools
|
|
1120
|
+
for networks, PubChem search, and plotting.
|
|
1121
|
+
- `MS2Query <https://github.com/iomega/ms2query>`_: MS/MS spectral analogue
|
|
1122
|
+
search.
|
|
1123
|
+
- `memo <https://github.com/mandelbrot-project/memo>`_: retention-time agnostic
|
|
1124
|
+
alignment of metabolomics samples.
|
|
1125
|
+
- `RIAssigner <https://github.com/RECETOX/RIAssigner>`_: retention index
|
|
1126
|
+
calculation for GC-MS data.
|
|
1127
|
+
- `MSMetaEnhancer <https://github.com/RECETOX/MSMetaEnhancer>`_: metadata
|
|
1128
|
+
enrichment using web services and computational chemistry packages.
|
|
1129
|
+
- `SimMS <https://github.com/PangeAI/SimMS>`_: GPU-based implementations of
|
|
1130
|
+
common similarity classes.
|
|
1131
|
+
|
|
1132
|
+
If you know of another package that is compatible with matchms, let us know.
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
Ecosystem compatibility
|
|
1136
|
+
-----------------------
|
|
1137
|
+
|
|
1138
|
+
.. compatibility matrix start
|
|
1139
|
+
|
|
1140
|
+
.. list-table::
|
|
1141
|
+
:header-rows: 1
|
|
1142
|
+
|
|
1143
|
+
* - NumPy Version
|
|
1144
|
+
- spec2vec Status
|
|
1145
|
+
- ms2deepscore Status
|
|
1146
|
+
- ms2query Status
|
|
1147
|
+
* - .. image:: https://img.shields.io/badge/numpy-1.25-lightgrey?logo=numpy
|
|
1148
|
+
:alt: numpy
|
|
1149
|
+
- .. image:: https://img.shields.io/badge/spec2vec-0.9.1-green
|
|
1150
|
+
- .. image:: https://img.shields.io/badge/ms2deepscore-2.7.2-green
|
|
1151
|
+
- .. image:: https://img.shields.io/badge/ms2query-1.5.4-red
|
|
1152
|
+
* - .. image:: https://img.shields.io/badge/numpy-2.1-lightgrey?logo=numpy
|
|
1153
|
+
:alt: numpy
|
|
1154
|
+
- .. image:: https://img.shields.io/badge/spec2vec-0.9.1-green
|
|
1155
|
+
- .. image:: https://img.shields.io/badge/ms2deepscore-2.7.2-green
|
|
1156
|
+
- .. image:: https://img.shields.io/badge/ms2query-1.5.4-red
|
|
1157
|
+
|
|
1158
|
+
.. compatibility matrix end
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
Documentation for developers
|
|
1162
|
+
============================
|
|
1163
|
+
|
|
1164
|
+
Development installation
|
|
1165
|
+
------------------------
|
|
1166
|
+
|
|
1167
|
+
.. code-block:: console
|
|
1168
|
+
|
|
1169
|
+
git clone https://github.com/matchms/matchms.git
|
|
1170
|
+
cd matchms
|
|
1171
|
+
|
|
1172
|
+
# Create environment and install all dependencies with uv (recommended)
|
|
1173
|
+
uv sync --frozen
|
|
1174
|
+
|
|
1175
|
+
# Alternatively, install with conda
|
|
1176
|
+
conda create --name matchms-dev python=3.13
|
|
1177
|
+
conda activate matchms-dev
|
|
1178
|
+
pip install -e ".[dev]"
|
|
1179
|
+
|
|
1180
|
+
# Alternatively, install with pip
|
|
1181
|
+
pip install -r dev-requirements.txt
|
|
1182
|
+
pip install --editable .
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
Code quality
|
|
1186
|
+
------------
|
|
1187
|
+
|
|
1188
|
+
Run the linter and formatter:
|
|
1189
|
+
|
|
1190
|
+
.. code-block:: console
|
|
1191
|
+
|
|
1192
|
+
uv run ruff check --fix matchms/YOUR-MODIFIED-FILE.py
|
|
1193
|
+
uv run ruff format matchms/YOUR-MODIFIED-FILE.py
|
|
1194
|
+
|
|
1195
|
+
Install pre-commit hooks:
|
|
1196
|
+
|
|
1197
|
+
.. code-block:: console
|
|
1198
|
+
|
|
1199
|
+
uv run pre-commit install
|
|
1200
|
+
|
|
1201
|
+
Run tests:
|
|
1202
|
+
|
|
1203
|
+
.. code-block:: console
|
|
1204
|
+
|
|
1205
|
+
uv run pytest
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
Developer notes: collection-first design
|
|
1209
|
+
----------------------------------------
|
|
1210
|
+
|
|
1211
|
+
When adding new functionality, prefer ``SpectraCollection`` support from the
|
|
1212
|
+
start. New filters should ideally support both ``Spectrum`` and
|
|
1213
|
+
``SpectraCollection`` inputs.
|
|
1214
|
+
|
|
1215
|
+
For filters with separate spectrum and collection implementations, use
|
|
1216
|
+
``collection_filter``:
|
|
1217
|
+
|
|
1218
|
+
.. code-block:: python
|
|
1219
|
+
|
|
1220
|
+
def _my_filter_spectrum(spectrum_in, *, clone=True):
|
|
1221
|
+
...
|
|
1222
|
+
|
|
1223
|
+
def _my_filter_collection(collection, *, clone=True):
|
|
1224
|
+
...
|
|
1225
|
+
|
|
1226
|
+
my_filter = collection_filter(
|
|
1227
|
+
_my_filter_spectrum,
|
|
1228
|
+
collection_impl=_my_filter_collection,
|
|
1229
|
+
)
|
|
1230
|
+
|
|
1231
|
+
For metadata-only filters, prefer metadata-level implementations and dispatch
|
|
1232
|
+
helpers:
|
|
1233
|
+
|
|
1234
|
+
.. code-block:: python
|
|
1235
|
+
|
|
1236
|
+
def _my_metadata_filter(metadata):
|
|
1237
|
+
...
|
|
1238
|
+
|
|
1239
|
+
my_filter = metadata_update_filter(_my_metadata_filter)
|
|
1240
|
+
|
|
1241
|
+
For requirement filters that keep or remove spectra, use a predicate-style
|
|
1242
|
+
metadata implementation:
|
|
1243
|
+
|
|
1244
|
+
.. code-block:: python
|
|
1245
|
+
|
|
1246
|
+
def _require_my_metadata(metadata) -> bool:
|
|
1247
|
+
...
|
|
1248
|
+
|
|
1249
|
+
require_my_metadata = metadata_requirement_filter(_require_my_metadata)
|
|
1250
|
+
|
|
1251
|
+
General recommendations:
|
|
1252
|
+
|
|
1253
|
+
- Prefer collection-native implementations for new filters.
|
|
1254
|
+
- Metadata-only filters should operate on ``MetadataCollection`` or metadata rows.
|
|
1255
|
+
- Peak-only filters should operate on ``FragmentCollection``.
|
|
1256
|
+
- Filters that drop spectra should return ``None`` for failing ``Spectrum``
|
|
1257
|
+
inputs and should drop rows for ``SpectraCollection`` inputs.
|
|
1258
|
+
- Filters should preserve alignment between metadata rows and fragment rows.
|
|
1259
|
+
- Avoid introducing pandas-specific missing values into reconstructed
|
|
1260
|
+
``Spectrum`` metadata.
|
|
1261
|
+
- Prefer ``ValueError`` over ``assert`` for user-facing validation.
|
|
1262
|
+
- Add tests for both ``Spectrum`` and ``SpectraCollection`` behavior whenever a
|
|
1263
|
+
public filter supports both input types.
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
Conda package
|
|
1267
|
+
=============
|
|
1268
|
+
|
|
1269
|
+
The conda packaging is handled by a `recipe at Bioconda <https://github.com/bioconda/bioconda-recipes/blob/master/recipes/matchms/meta.yaml>`_.
|
|
1270
|
+
|
|
1271
|
+
Publishing to PyPI will trigger the creation of a pull request on the Bioconda
|
|
1272
|
+
recipes repository. Once the pull request is merged, the new version of matchms
|
|
1273
|
+
will appear on `Anaconda <https://anaconda.org/bioconda/matchms>`_.
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
Agent skill
|
|
1277
|
+
===========
|
|
1278
|
+
A ``SKILL.md`` for AI coding agents is available at
|
|
1279
|
+
``.agents/skills/matchms/SKILL.md``.
|
|
1280
|
+
Copy it into your agent's skills directory to help it use ``matchms`` correctly.
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
Support
|
|
1284
|
+
=======
|
|
1285
|
+
|
|
1286
|
+
To get support, join the public
|
|
1287
|
+
`Slack channel <https://join.slack.com/t/matchms/shared_invite/zt-2l0t61651-Svv0d5hwl~P5jwV4ZCNFXg>`_.
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
Contributing
|
|
1291
|
+
============
|
|
1292
|
+
|
|
1293
|
+
If you want to contribute to matchms development, see the
|
|
1294
|
+
`contribution guidelines <CONTRIBUTING.md>`_.
|
|
1295
|
+
|
|
1296
|
+
|
|
1297
|
+
License
|
|
1298
|
+
=======
|
|
1299
|
+
|
|
1300
|
+
Copyright (c) 2026, Düsseldorf University of Applied Sciences
|
|
1301
|
+
|
|
1302
|
+
Licensed under the Apache License, Version 2.0. You may not use this file except
|
|
1303
|
+
in compliance with the License. You may obtain a copy of the License at:
|
|
1304
|
+
|
|
1305
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
1306
|
+
|
|
1307
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
1308
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
1309
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
1310
|
+
specific language governing permissions and limitations under the License.
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
.. |GitHub Badge| image:: https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue
|
|
1315
|
+
:target: https://github.com/matchms/matchms
|
|
1316
|
+
:alt: GitHub Badge
|
|
1317
|
+
|
|
1318
|
+
.. |License Badge| image:: https://img.shields.io/github/license/matchms/matchms
|
|
1319
|
+
:target: https://github.com/matchms/matchms
|
|
1320
|
+
:alt: License Badge
|
|
1321
|
+
|
|
1322
|
+
.. |Conda Badge| image:: https://anaconda.org/bioconda/matchms/badges/version.svg
|
|
1323
|
+
:target: https://anaconda.org/bioconda/matchms
|
|
1324
|
+
:alt: Conda Badge
|
|
1325
|
+
|
|
1326
|
+
.. |Pypi Badge| image:: https://img.shields.io/pypi/v/matchms?color=blue
|
|
1327
|
+
:target: https://pypi.org/project/matchms/
|
|
1328
|
+
:alt: Pypi Badge
|
|
1329
|
+
|
|
1330
|
+
.. |Research Software Directory Badge| image:: https://img.shields.io/badge/rsd-matchms-00a3e3.svg
|
|
1331
|
+
:target: https://www.research-software.nl/software/matchms
|
|
1332
|
+
:alt: Research Software Directory Badge
|
|
1333
|
+
|
|
1334
|
+
.. |Zenodo Badge| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3859772.svg
|
|
1335
|
+
:target: https://doi.org/10.5281/zenodo.3859772
|
|
1336
|
+
:alt: Zenodo Badge
|
|
1337
|
+
|
|
1338
|
+
.. |JOSS Badge| image:: https://joss.theoj.org/papers/10.21105/joss.02411/status.svg
|
|
1339
|
+
:target: https://doi.org/10.21105/joss.02411
|
|
1340
|
+
:alt: JOSS Badge
|
|
1341
|
+
|
|
1342
|
+
.. |CII Best Practices Badge| image:: https://bestpractices.coreinfrastructure.org/projects/3792/badge
|
|
1343
|
+
:target: https://bestpractices.coreinfrastructure.org/projects/3792
|
|
1344
|
+
:alt: CII Best Practices Badge
|
|
1345
|
+
|
|
1346
|
+
.. |Howfairis Badge| image:: https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F-green
|
|
1347
|
+
:target: https://fair-software.eu
|
|
1348
|
+
:alt: Howfairis badge
|
|
1349
|
+
|
|
1350
|
+
.. |CI First Code Checks| image:: https://github.com/matchms/matchms/actions/workflows/CI_first_code_check.yml/badge.svg
|
|
1351
|
+
:alt: Continuous integration workflow
|
|
1352
|
+
:target: https://github.com/matchms/matchms/actions/workflows/CI_first_code_check.yml
|
|
1353
|
+
|
|
1354
|
+
.. |CI Build| image:: https://github.com/matchms/matchms/actions/workflows/CI_build.yml/badge.svg?branch=master
|
|
1355
|
+
:alt: Continuous integration workflow
|
|
1356
|
+
:target: https://github.com/matchms/matchms/actions/workflows/CI_build.yml?query=branch%3Amaster
|
|
1357
|
+
|
|
1358
|
+
.. |ReadTheDocs Badge| image:: https://readthedocs.org/projects/matchms/badge/?version=latest
|
|
1359
|
+
:alt: Documentation Status
|
|
1360
|
+
:target: https://matchms.readthedocs.io/en/latest/?badge=latest
|
|
1361
|
+
|
|
1362
|
+
.. |Sonarcloud Quality Gate Badge| image:: https://sonarcloud.io/api/project_badges/measure?project=matchms_matchms&metric=alert_status
|
|
1363
|
+
:target: https://sonarcloud.io/dashboard?id=matchms_matchms
|
|
1364
|
+
:alt: Sonarcloud Quality Gate
|
|
1365
|
+
|
|
1366
|
+
.. |Sonarcloud Coverage Badge| image:: https://sonarcloud.io/api/project_badges/measure?project=matchms_matchms&metric=coverage
|
|
1367
|
+
:target: https://sonarcloud.io/component_measures?id=matchms_matchms&metric=Coverage&view=list
|
|
1368
|
+
:alt: Sonarcloud Coverage
|