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

## ----installation, eval=FALSE-------------------------------------------------
# if (!requireNamespace("BiocManager", quietly = TRUE)) {
#   install.packages("BiocManager")
# }
# 
# BiocManager::install("RPBC")

## ----load-package-------------------------------------------------------------
library(RPBC)

## ----load-data----------------------------------------------------------------
data("haley_gbm_example", package = "RPBC")

haley_gbm_example
dim(haley_gbm_example)
SummarizedExperiment::assayNames(haley_gbm_example)

## ----inspect-design-----------------------------------------------------------
table(
  haley_gbm_example$patient_id,
  haley_gbm_example$region_type
)

## ----ordinary-rpbc------------------------------------------------------------
example_ordinary <- rpbc(
  object = haley_gbm_example,
  patient = "patient_id",
  region = "region_type",
  assay_name = "counts",
  transform = "asinh",
  cofactor = 5,
  adaptive = FALSE,
  output_assay = "rpbc"
)

SummarizedExperiment::assayNames(example_ordinary)

## ----ordinary-output----------------------------------------------------------
dim(
  SummarizedExperiment::assay(
    example_ordinary,
    "rpbc"
  )
)

## ----adaptive-rpbc------------------------------------------------------------
example_adaptive <- rpbc(
  object = haley_gbm_example,
  patient = "patient_id",
  region = "region_type",
  assay_name = "counts",
  transform = "asinh",
  cofactor = 5,
  adaptive = TRUE,
  output_assay = "rpbc_adaptive"
)

SummarizedExperiment::assayNames(example_adaptive)

## ----covariate-rpbc-----------------------------------------------------------
example_covariate <- rpbc(
  object = haley_gbm_example,
  patient = "patient_id",
  region = "region_type",
  assay_name = "counts",
  transform = "asinh",
  cofactor = 5,
  covariates = c("age", "sex"),
  adaptive = FALSE,
  output_assay = "rpbc_covariate"
)

SummarizedExperiment::assayNames(example_covariate)

## ----covariate-output---------------------------------------------------------
dim(
  SummarizedExperiment::assay(
    example_covariate,
    "rpbc_covariate"
  )
)

## ----access-output------------------------------------------------------------
rpbc_matrix <- SummarizedExperiment::assay(
  example_ordinary,
  "rpbc"
)

rpbc_matrix[1:5, 1:5]

## ----return-fit---------------------------------------------------------------
example_fit <- rpbc(
  object = haley_gbm_example,
  patient = "patient_id",
  region = "region_type",
  assay_name = "counts",
  transform = "asinh",
  cofactor = 5,
  adaptive = FALSE,
  output_assay = "rpbc_fit_example",
  return_fit = TRUE
)

names(example_fit)
all(example_fit$fit$converged)

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

