### R code from vignette source 'bioIOT.Rnw'

###################################################
### code chunk number 1: setup
###################################################
library(bioIOT)
set.seed(1)
sim <- simulate_iot_states(K = 6, seed = 1)
names(sim)


###################################################
### code chunk number 2: fit
###################################################
fit <- fit_iot(sim$phi, sim$a, sim$b, sim$T_true,
               n_restart = 2, epochs = 150, seed = 1)
fit
summary(fit)


###################################################
### code chunk number 3: transitions
###################################################
Q <- transition_matrix(fit)
round(Q, 2)
pseudotime_from_transition(Q, root = "S1")


###################################################
### code chunk number 4: heatmap
###################################################
plot_transition_heatmap(Q)


###################################################
### code chunk number 5: flow
###################################################
plot_transition_flow(Q, sim$embedding, threshold = 0.04)


###################################################
### code chunk number 6: theta
###################################################
plot_theta(fit)


###################################################
### code chunk number 7: matrix
###################################################
res <- runIOT(sim$cell_embedding, sim$cell_state,
              from = sim$cell_time == "t0", to = sim$cell_time == "t1",
              root = "S1")
round(res$Q[1:3, 1:3], 2)
res$pseudotime


###################################################
### code chunk number 8: bulk
###################################################
expr <- matrix(rnorm(200 * 12), nrow = 200)
rownames(expr) <- paste0("G", 1:200)
colnames(expr) <- paste0("S", 1:12)
rownames(expr)[1] <- "VIM"
rownames(expr)[2] <- "CDH2"
rownames(expr)[3] <- "MKI67"
pw <- score_pathways(expr)
print(plot_pathway_trend(pw, time = sort(runif(12))))
