matchms.similarity.spectrum_similarity_functions module

matchms.similarity.spectrum_similarity_functions.collect_peak_pairs(spec1: numpy.ndarray, spec2: numpy.ndarray, tolerance: float, shift: float = 0, mz_power: float = 0.0, intensity_power: float = 1.0)[source]

Find matching pairs between two spectra.

Parameters
  • spec1 – Spectrum peaks and intensities as numpy array.

  • spec2 – Spectrum peaks and intensities as numpy array.

  • tolerance – Peaks will be considered a match when <= tolerance appart.

  • shift – Shift spectra peaks by shift. The default is 0.

  • mz_power – The power to raise mz to in the cosine function. The default is 0, in which case the peak intensity products will not depend on the m/z ratios.

  • intensity_power – The power to raise intensity to in the cosine function. The default is 1.

Returns

matching_pairs – Array of found matching peaks.

Return type

numpy array

matchms.similarity.spectrum_similarity_functions.find_matches(spec1_mz: numpy.ndarray, spec2_mz: numpy.ndarray, tolerance: float, shift: float = 0) List[Tuple[int, int]][source]

Faster search for matching peaks. Makes use of the fact that spec1 and spec2 contain ordered peak m/z (from low to high m/z).

Parameters
  • spec1_mz – Spectrum peak m/z values as numpy array. Peak mz values must be ordered.

  • spec2_mz – Spectrum peak m/z values as numpy array. Peak mz values must be ordered.

  • tolerance – Peaks will be considered a match when <= tolerance appart.

  • shift – Shift peaks of second spectra by shift. The default is 0.

Returns

List containing entries of type (idx1, idx2).

Return type

matches

matchms.similarity.spectrum_similarity_functions.score_best_matches(matching_pairs: numpy.ndarray, spec1: numpy.ndarray, spec2: numpy.ndarray, mz_power: float = 0.0, intensity_power: float = 1.0) Tuple[float, int][source]

Calculate cosine-like score by multiplying matches. Does require a sorted list of matching peaks (sorted by intensity product).