## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.crop = FALSE)
set.seed(1)

## ----demo---------------------------------------------------------------------
library(path2path)
data(demo_z)
data(demo_pathways)
dim(demo_z)

## ----pipeline-----------------------------------------------------------------
res <- path2path(demo_z, demo_pathways,
    stage1 = list(nperm = 200, min_size = 5),
    stage2 = list(min_pu = 5),
    BPPARAM = BiocParallel::SerialParam(RNGseed = 1))
round(res$M, 2)

## ----planted------------------------------------------------------------------
res$M["PATHWAY_A", "PATHWAY_B"]   # planted activation, > 0
res$M["PATHWAY_C", "PATHWAY_D"]   # planted suppression, < 0
res$padj["PATHWAY_A", "PATHWAY_B"]
res$padj["PATHWAY_C", "PATHWAY_D"]

## ----plot, fig.width = 6, fig.height = 5--------------------------------------
plot_map(res, padj_cutoff = 0.05)

## ----entry, fig.width = 6, fig.height = 3.5-----------------------------------
plot_entry(res, demo_pathways, "PATHWAY_A", "PATHWAY_B")

## ----real---------------------------------------------------------------------
f <- system.file("extdata", "zscore_demo.csv.gz", package = "path2path")
z <- read_input_matrix(f)  # your screen: "zscore_myscreen.csv.gz"
all.equal(z, demo_z)       # the demo matrix, up to CSV round-trip precision
write_result(res, dir = file.path(tempdir(), "results"),
    tag = "demo", collection = "demo")
list.files(file.path(tempdir(), "results"))

## ----routeb-------------------------------------------------------------------
cal <- calibrate_pvalues(res, demo_z, demo_pathways, B = 50, seed_base = 42)
unlist(cal$gpd[c("u", "xi", "beta", "n_exc", "q_used")])
cal$pval_gpd["PATHWAY_A", "PATHWAY_B"]
cal$pval_pool["PATHWAY_A", "PATHWAY_B"]

## ----calplot, fig.width = 7, fig.height = 3.5---------------------------------
plot_calibration(cal)

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

