rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
34 stars 24 forks source link

Add documentation on MS entropy-based similarity calculation #301

Closed jorainer closed 10 months ago

jorainer commented 11 months ago

Add an example to the vignette how the entropy-based similarity score from the msentropy package can be used with Spectra's compareSpectra (using the function introduced by https://github.com/YuanyueLi/MSEntropy/pull/2 ).

This closes also https://github.com/rformassspectrometry/MsCoreUtils/issues/116 in MsCoreUtils (no need to implement the similarity score ourselfs).

jorainer commented 10 months ago

I did a little performance evaluation and what puzzled me a bit is that the default is quite faster (test Spectra are from SpectraTutorials):

sps <- setBackend(sps, MsBackendMemory())
sps <- reset(sps)
mbank <- setBackend(mbank, MsBackendMemory())
mbank <- reset(mbank)
length(sps)
[1] 6
length(mbank)
[1] 86576

First comparison:

library(microbenchmark)
library(msentropy)
register(SerialParam())
microbenchmark(
    compareSpectra(sps, mbank, ppm = 50),
    compareSpectra(sps, mbank, MAPFUN = joinPeaksNone,
                   FUN = msentropy_similarity, ms2_tolerance_in_ppm = 50,
                   ms2_tolerance_in_da = -1),
    times = 7)
Unit: seconds
       min        lq      mean    median        uq       max neval cld
  34.13611  34.50067  35.36888  35.38705  35.88188  37.29387     7  a 
 211.89302 214.32614 215.05660 215.40014 216.28642 216.87790     7   b

Disabling the spectra cleaning in msentropy: the C-based code from msentropy is now faster.

microbenchmark(
    compareSpectra(sps, mbank, ppm = 50),
    compareSpectra(sps, mbank, MAPFUN = joinPeaksNone,
                   FUN = msentropy_similarity, ms2_tolerance_in_ppm = 50,
                   ms2_tolerance_in_da = -1, clean_spectra = FALSE),
    times = 7)
Unit: seconds
      min       lq     mean   median       uq      max neval cld
 34.00032 34.54637 35.48093 35.01858 36.16561 37.92366     7  a 
 11.13546 11.21656 11.39383 11.42869 11.47468 11.81019     7   b
jorainer commented 10 months ago

FYI @YuanyueLi

jorainer commented 10 months ago

Example is here

YuanyueLi commented 10 months ago

Cool! Thanks for the example!