compound_tbl_sdf: Extract compound data from a file in SDF format

View source: R/createCompDbPackage.R

compound_tbl_sdfR Documentation

Extract compound data from a file in SDF format


compound_tbl_sdf extracts basic compound annotations from a file in SDF format (structure-data file). The function currently supports SDF files from:

  • HMDB (Human Metabolome Database):

  • ChEBI (Chemical Entities of Biological Interest):

  • LMSD (LIPID MAPS Structure Database):

  • PubChem:

  • MoNa: (see notes below!)


compound_tbl_sdf(file, collapse, onlyValid = TRUE, nonStop = TRUE)



character(1) with the name of the SDF file.


optional character(1) to be used to collapse multiple values in the columns "synonyms". See examples for details.


logical(1) to import only valid or all elements (defaults to onlyValid = TRUE)


logical(1) whether file content specific errors should only reported as warnings and not break the full import process. The value of this parameter is passed to parameter skipErrors of the read.SDFset() function.


Column "name" reports for HMDB files the "GENERIC_NAME", for ChEBI the "ChEBI Name", for PubChem the "PUBCHEM_IUPAC_TRADITIONAL_NAME", and for Lipid Maps the "COMMON_NAME", if that is not available, the first of the compounds synonyms and, if that is also not provided, the "SYSTEMATIC_NAME".


A tibble::tibble with general compound information (one row per compound):

  • compound_id: the ID of the compound.

  • name: the compound's name.

  • inchi: the InChI of the compound.

  • inchikey: the InChI key.

  • formula: the chemical formula.

  • exactmass: the compound's (monoisotopic exact) mass.

  • synonyms: the compound's synonyms (aliases). This type of this column is by default a list to support multiple aliases per compound, unless argument collapse is provided, in which case multiple synonyms are pasted into a single element separated by the value of collapse.

  • smiles: the compound's SMILES (if provided).


compound_tbl_sdf supports also to read/process gzipped files.

MoNa SDF files organize the data by individual spectra (i.e. each element is one spectrum) and individual compounds can not easily and consistently defined (i.e. not all entries have an InChI ID or other means to uniquely identify compounds). Thus, the function returns a highly redundant compound table. Feedback on how to reduce this redundancy would be highly welcome!

LIPID MAPS was tested August 2020. Older SDF files might not work as the field names were changed.


Johannes Rainer and Jan Stanstrup

See Also

createCompDb() for a function to create a SQLite-based compound database.

Other compound table creation functions: compound_tbl_lipidblast()


## Read compound information from a subset of HMDB
fl <- system.file("sdf/HMDB_sub.sdf.gz", package = "CompoundDb")
cmps <- compound_tbl_sdf(fl)

## Column synonyms contains a list

## If we provide the optional argument collapse, multiple entries will be
## collapsed.
cmps <- compound_tbl_sdf(fl, collapse = "|")

EuracBiomedicalResearch/CompoundDb documentation built on March 17, 2023, 3:47 p.m.