Calculate similarity between spectra

Description

Efficiently calculates similarity scores between query and target spectra using either entropy or GNPS methods

Usage

calculate_similarity(
  method,
  query_spectrum,
  target_spectrum,
  query_precursor,
  target_precursor,
  dalton,
  ppm,
  return_matched_peaks = FALSE,
  ...
)

Arguments

method Method ("entropy" or "gnps")
query_spectrum Query spectrum matrix
target_spectrum Target spectrum matrix
query_precursor Query precursor
target_precursor Target precursor
dalton Dalton tolerance
ppm PPM tolerance
return_matched_peaks Return matched peaks. Not compatible with ‘entropy’. Default: FALSE
Not documented for now

Value

Similarity score or NA_real_ if calculation fails

Examples

library("tima")

sp_1 <- cbind(
  mz = c(10, 36, 63, 91, 93),
  intensity = c(14, 15, 999, 650, 1)
)
precursor_1 <- 123.4567
precursor_2 <- precursor_1 + 14
sp_2 <- cbind(
  mz = c(10, 12, 50, 63, 105),
  intensity = c(35, 5, 16, 999, 450)
)
calculate_similarity(
  method = "entropy",
  query_spectrum = sp_1,
  target_spectrum = sp_2,
  query_precursor = precursor_1,
  target_precursor = precursor_2,
  dalton = 0.005,
  ppm = 10.0
)
[1] 0.5427377
calculate_similarity(
  method = "gnps",
  query_spectrum = sp_1,
  target_spectrum = sp_2,
  query_precursor = precursor_1,
  target_precursor = precursor_2,
  dalton = 0.005,
  ppm = 10.0,
  return_matched_peaks = TRUE
)
$score
[1] 0.9923501

$matches
[1] 4