Skip to content

Instantly share code, notes, and snippets.

@sneumann
Last active September 19, 2022 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sneumann/959a6d205ea4ac73eaf1393da0ec0673 to your computer and use it in GitHub Desktop.
Save sneumann/959a6d205ea4ac73eaf1393da0ec0673 to your computer and use it in GitHub Desktop.
Install and benchmark a number of
install.packages("microbenchmark")
install.packages("plyr")
install.packages("rcdk")
install.packages("OrgMassSpecR")
install.packages("CHNOSZ")
BiocManager::install("Rdisop")
BiocManager::install("MetaboCoreUtils")
BiocManager::install("ChemmineR")
BiocManager::install("ChemmineOB")
BiocManager::install("enviPat")
## These require loading the packages explicitly
library(plyr)
library(CHNOSZ)
library(enviPat)
library(MetaboCoreUtils)
library(rcdk)
library(ChemmineR)
library(ChemmineOB)
library(OrgMassSpecR)
library(Rdisop)
## enviPat
data(isotopes)
benchmark <- microbenchmark::microbenchmark(
MetaboCoreUtils = MetaboCoreUtils::calculateMass("C2H6O"),
rcdk = rcdk::get.formula("C2H6O", charge = 0)@mass,
Rdisop = Rdisop::getMolecule("C2H6O")$exactmass,
ChemmineR = ChemmineR::exactMassOB(ChemmineR::smiles2sdf("CCO")),
OrgMassSpecR = OrgMassSpecR::MonoisotopicMass(formula = OrgMassSpecR::ListFormula("C2H6O)"), charge = 0),
CHNOSZ = CHNOSZ::mass("C2H6O"),
enviPat = enviPat::isopattern(isotopes, "C2H6O", charge=FALSE, verbose=FALSE)[[1]][1,1]
, times=1000L)
masses <- c(
MetaboCoreUtils=MetaboCoreUtils::calculateMass("C2H6O"),
rcdk=rcdk::get.formula("C2H6O", charge = 0)@mass,
Rdisop=Rdisop::getMolecule("C2H6O")$exactmass,
ChemmineR=ChemmineR::exactMassOB(ChemmineR::smiles2sdf("CCO")),
OrgMassSpecR=OrgMassSpecR::MonoisotopicMass(formula = OrgMassSpecR::ListFormula("C2H6O)"), charge = 0),
CHNOSZ=CHNOSZ::mass("C2H6O"),
enviPat=enviPat::isopattern(isotopes, "C2H6O", charge=FALSE, verbose=FALSE)[[1]][1,1]
)
options(digits=10)
t(t(sort(masses)))
summary(benchmark)[order(summary(benchmark)[,"median"]) , ]
clipr::write_clip(as.data.frame(summary(benchmark)[order(summary(benchmark)[,"median"]) , ] ))
@stanstrup
Copy link

stanstrup commented Sep 18, 2022

  • install.packages("microbenchmark") to make it runable on vanilla R
    • BiocManager::install("enviPat") was missing
  • smiles2sdf --> ChemmineR::smiles2sdf since it was not found before when the package was not loaded
  • t(t(sort(masses))) to make it easier to read
  • name benchmark entries
  • OrgMassSpecR had an unfair advantage since the heavy lifting is converting the formula to its components. Added OrgMassSpecR::ListFormula that does that.

RESULTS:
image

install.packages("microbenchmark")
install.packages("plyr")

install.packages("rcdk")
install.packages("OrgMassSpecR")
install.packages("CHNOSZ")

BiocManager::install("Rdisop")
BiocManager::install("MetaboCoreUtils")

BiocManager::install("ChemmineR")
BiocManager::install("ChemmineOB")

BiocManager::install("enviPat")


## These require loading the packages explicitly
library(plyr)

library(CHNOSZ)
library(enviPat)
library(MetaboCoreUtils)
library(rcdk)
library(ChemmineR)
library(ChemmineOB)
library(OrgMassSpecR)
library(Rdisop)

data(isotopes)


benchmark <- microbenchmark::microbenchmark(
              MetaboCoreUtils = MetaboCoreUtils::calculateMass("C2H6O"),
              rcdk = rcdk::get.formula("C2H6O", charge = 0)@mass,
              Rdisop = Rdisop::getMolecule("C2H6O")$exactmass,
              ChemmineR = ChemmineR::exactMassOB(ChemmineR::smiles2sdf("CCO")),
              OrgMassSpecR = OrgMassSpecR::MonoisotopicMass(formula = OrgMassSpecR::ListFormula("C2H6O)"), charge = 0),

              CHNOSZ = CHNOSZ::mass("C2H6O"),
              enviPat = enviPat::isopattern(isotopes, "C2H6O", charge=FALSE, verbose=FALSE)[[1]][1,1]
            , times=1000L)


masses <- c(
  MetaboCoreUtils=MetaboCoreUtils::calculateMass("C2H6O"),
  rcdk=rcdk::get.formula("C2H6O", charge = 0)@mass,
  Rdisop=Rdisop::getMolecule("C2H6O")$exactmass,
  ChemmineR=ChemmineR::exactMassOB(ChemmineR::smiles2sdf("CCO")),
  OrgMassSpecR=OrgMassSpecR::MonoisotopicMass(formula = OrgMassSpecR::ListFormula("C2H6O)"), charge = 0),
  CHNOSZ=CHNOSZ::mass("C2H6O"),
  enviPat=enviPat::isopattern(isotopes, "C2H6O", charge=FALSE, verbose=FALSE)[[1]][1,1]
)



options(digits=10)

t(t(sort(masses)))


summary(benchmark)[order(summary(benchmark)[,"median"]) , ]


clipr::write_clip(as.data.frame(summary(benchmark)[order(summary(benchmark)[,"median"]) , ] ))

@sneumann
Copy link
Author

Cool, thanks ! If this continues like this, maybe that turns into a section in the etaRbolomics-book one day :-) Yours, Steffen

@stanstrup
Copy link

Yeah. I think what this needs is some testing of what happens if you throw them odd things they might not be expecting like HCOOH, C3H2S0, Na+Cl-, H3O+, +H2O-, Fe4+, Cp3UCl, 2H2O (isotope notation I guess would vary), D2O.

@zachcp
Copy link

zachcp commented Sep 19, 2022

Updated code with some improvements to RCDK: https://gist.github.com/zachcp/ac410b900d67264ffb8061d2b8fa45bf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment