R/search_hmdb.R

#' Seach HMDB
#'
#' Search the current version of the Human Metabolome Database using database generic names
#'
#' @param query a generic compound name (ie, methyl histidine)
#' @return a \code{data.frame} containing the following for each results;
#' \itemize{
#'  \item{accession_id}
#'  \item{name}
#'  \item{molecular_formula}
#'  \item{monoisotopic_weight}
#'  \item{smiles}
#'  \item{inchikey}
#'  \item{inchi}
#' }
#'
#' @author Tom Wilson \email{tpw2@@aber.ac.uk}
#' @export
#' @examples \dontrun{
#'
#' res <- search_hmdb("anserine")
#' names(res)
#' [1] "accession_id"       "name"               "molecular_formula"
#' [4] "monisotopic_weight" "smiles"             "inchikey"
#' [7] "inchi"
#'
#' res$name
#' [1] Anserine     Homoanserine Mianserin
#'
#' res[1, "smiles"]
#' [1] CN1C=NC=C1C[C@H](NC(=O)CCN)C(O)=O
#'
#' res[1,"monisotopic_weight"]
#' [1] 240.1222
#'
#' #'
#' }
#' @export

search_hmdb <- function(query) #, local = FALSE)
  {
  if(!is.character(query)){stop("...Query must be a character string")}
      query_agrep <- agrep(query, hmdb[,"name"], max.distance = 0.1)
      search_results <- hmdb[query_agrep,]

  return(search_results)
  }
wilsontom/hmdbR documentation built on May 4, 2019, 6:29 a.m.