## ----setup, include=FALSE-----------------------------------------------------
library(ExpoRiskR)
library(BiocStyle)

## ----se-align-----------------------------------------------------------------
set.seed(7)
d <- generate_dummy_exporisk(
  n = 12, p_micro = 5, p_metab = 6, p_expo = 3
)

aligned <- align_omics_se(
  microbiome = d$microbiome,
  metabolome = d$metabolome,
  exposures  = d$exposures,
  meta       = d$meta,
  id_col     = "sample_id",
  strict     = TRUE
)

aligned$se_microbiome
aligned$se_metabolome

## ----se-prep------------------------------------------------------------------
prepped <- prep_omics_se(aligned)
prepped

## ----se-network, message=FALSE, warning=FALSE, fig.width=7, fig.height=5------
X <- prepped$X
Y <- prepped$Y
E <- prepped$E

net <- build_exposure_network(
  X = X, Y = Y, E = E,
  fdr = 0.8, # relaxed for vignette speed / non-empty illustration
  max_pairs = 1500,
  seed = 1
)

plot_exposure_network(net)

## ----se-ranking, message=FALSE, warning=FALSE, fig.width=7, fig.height=4------
scores <- exposure_perturbation_score(
  X = X, Y = Y, E = E,
  fdr = 0.8,
  max_pairs = 1500,
  seed = 1
)

print(plot_exposure_ranking(scores, top_n = 15))

## ----se-importance, message=FALSE, warning=FALSE, fig.width=7, fig.height=4----
outcome <- d$meta$outcome
names(outcome) <- d$meta$sample_id

print(plot_feature_importance(
  E = E,
  outcome = outcome,
  top_n = 15
))

## ----se-roc, message=FALSE, warning=FALSE, fig.width=6, fig.height=4----------
print(plot_risk_roc(
  X = X, Y = Y, E = E,
  outcome = outcome,
  edges = net$edges,
  top_edges = 80
))

## -----------------------------------------------------------------------------
sessionInfo()

