## ----setup-options, include = FALSE-------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(AnnotationGx)

## ----aspirin-cid--------------------------------------------------------------
mapCompound2CID("aspirin")

## ----multi-cid----------------------------------------------------------------
drugs <- c(
  "Aspirin",
  "Erlotinib",
  "Acadesine",
  "Camptothecin",
  "Vincaleukoblastine",
  "Cisplatin"
)

mapCompound2CID(drugs)

## ----multi-cid-first----------------------------------------------------------
mapCompound2CID(drugs, first = TRUE)

## ----missing-cid--------------------------------------------------------------
(result <- mapCompound2CID(
  c(drugs, "non existent compound", "another bad compound"),
  first = TRUE
))

failed <- attributes(result)$failed

# get the list of failed inputs
names(failed)

# get the error message for the failed input
print(failed[1])

## ----pubchem-properties-------------------------------------------------------
getPubchemProperties()

## ----single-cid---------------------------------------------------------------
properties <- c("Title", "MolecularFormula", "InChIKey", "MolecularWeight")

# Need to remove NA values from the query as they will cause an error
result[!is.na(cids), mapCID2Properties(ids = cids, properties = properties)]

## ----annotation-headings------------------------------------------------------
getPubchemAnnotationHeadings()

## ----headings-by-type---------------------------------------------------------
getPubchemAnnotationHeadings(type = "Compound")

## ----headings-by-heading------------------------------------------------------
getPubchemAnnotationHeadings(heading = "ChEMBL ID")

## ----headings-by-type-heading-------------------------------------------------
getPubchemAnnotationHeadings(type = "Compound", heading = "CAS")

## ----single-cid-annotations---------------------------------------------------
result[!is.na(cids), CAS := annotatePubchemCompound(cids, "CAS")]
result

## ----session-info-------------------------------------------------------------
sessionInfo()

