rformassspectrometry / CompoundDb

Creating and using (chemical) compound databases
https://rformassspectrometry.github.io/CompoundDb/index.html
17 stars 16 forks source link

Getter for synonyms #46

Closed stanstrup closed 4 years ago

stanstrup commented 4 years ago

Is there an interface for accessing the synonyms? I could find one apart form direct DB access.

jorainer commented 4 years ago

You can do it that way:

> library(CompDb.Hsapiens.HMDB.4.0)
> cdb <- CompDb.Hsapiens.HMDB.4.0
> compounds(cdb, columns = c("compound_id", "compound_name", "synonym"), filter = ~ compound_id == "HMDB0001471")
  compound_id   compound_name                                   synonym
1 HMDB0001471 Epipregnanolone 3-Deoxo-3b-hydroxy-5b-dihydroprogesterone
2 HMDB0001471 Epipregnanolone                        3b,5b-Pregnanolone
3 HMDB0001471 Epipregnanolone              3b-Hydroxy-5b-pregnan-20-one
4 HMDB0001471 Epipregnanolone             3b-Hydroxy-5b-pregnane-20-one
5 HMDB0001471 Epipregnanolone      3b-Hydroxy-5b-tetrahydroprogesterone
6 HMDB0001471 Epipregnanolone                   5b-Pregnan-3b-ol-20-one
7 HMDB0001471 Epipregnanolone             5b-Pregnane-3b-hydroxy-20-one
8 HMDB0001471 Epipregnanolone                  5b-Pregnane-3b-ol-20-one
9 HMDB0001471 Epipregnanolone                            Pregnanolone I

With the parameter columns you can specify any columns from the database and the compounds function will make the necessary joins of the database tables. Note that without the filter you would get all synonyms for all compounds - a huge data frame.

get the database I used from here - just install with R CMD INSTALL.

stanstrup commented 4 years ago

Great! Didn't realize you could do this. Very useful for inserting all kinds of things in the database.