## ----knitr-options, include = FALSE-------------------------------------------
# CoreGx and PharmacoGx are suggested, not imported, so this vignette has to build
# without them - the code is shown but not evaluated when they are absent.
pset_pkgs_available <- requireNamespace("CoreGx", quietly = TRUE) &&
  requireNamespace("PharmacoGx", quietly = TRUE)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  eval = pset_pkgs_available
)

## ----pset-pkgs-note, echo = FALSE, eval = TRUE, results = "asis"--------------
if (!pset_pkgs_available) {
  cat("**Note:** this vignette needs the suggested packages `CoreGx` and `PharmacoGx`.",
      "They are not installed, so the code below is shown but not run.\n")
}

## ----load-libraries, include=FALSE--------------------------------------------
library(PharmacoGx)
library(gDRimport)
library(MultiAssayExperiment)

## ----load-mae-data------------------------------------------------------------
(mae <- qs2::qs_read(
    system.file("extdata", "kyung2022mae", "MAE_E2.qs2", package = "gDRimport")
  )
)

## ----inspect-mae-assays-------------------------------------------------------
gDRutils::MAEpply(mae, assays)

## ----convert-mae-to-pset, warning=FALSE---------------------------------------
pset <- convert_MAE_to_PSet(mae, pset_name="Kyung2022")

## ----display-pset-object------------------------------------------------------
pset

## ----inspect-metadata---------------------------------------------------------
head(treatmentInfo(pset))

head(sampleInfo(pset))


## ----inspect-tre-rows, echo=TRUE----------------------------------------------
tre <- treatmentResponse(pset)
head(rownames(tre))
head(rowData(tre))

## ----inspect-tre-cols, echo=TRUE----------------------------------------------
head(colnames(tre))
head(colData(tre))

## ----subset-tre-data-table, echo=TRUE-----------------------------------------
tre[
  .(treatmentid=="G02967907_GDC-0077_PI3K-A_168"), # query on row
  .(sampleid=="CL131891_EFM-19_Breast_EFM-19_unknown_64") # query on column
]

## ----invert-subset-tre, echo=TRUE---------------------------------------------
tre[
  .(treatmentid!="G02967907_GDC-0077_PI3K-A_168"), # query on row
  .(sampleid!="CL131891_EFM-19_Breast_EFM-19_unknown_64") # query on column
]

## ----view-tre-assays----------------------------------------------------------
lapply(assays(tre), head)

## ----view-tre-assay-names-----------------------------------------------------
assayNames(tre)

## ----inspect-metrics-assay----------------------------------------------------
head(assay(tre, "Metrics"),3)

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

