## ----include = FALSE----------------------------------------------------------
library(BiocStyle)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----usage example------------------------------------------------------------
# Load the package
suppressPackageStartupMessages(library(LRDE))
set.seed(123)

# 1. Simulate a count matrix (Negative Binomial)
mat <- matrix(rnbinom(300, size = 5, mu = 5), nrow = 50)

# Define sample groups
grp <- factor(c("A", "A", "A", "B", "B", "B"))

# 2. Prepare the data object
y <- prepareDGE(mat, grp)

# 3. Estimate size factors for normalization
y <- sizeFactorsEst(y)

# 4. Estimate tag-wise dispersions
y <- tagwiseEst(y)

# 5a. Differential expression testing: Wald test
y <- hurdle_Wald_Test(y)

# 5b. Differential expression testing: Likelihood Ratio Test
y <- hurdle_LRT(y)

# 6. Inspect results
head(y$lrt_stats)        # LRT statistics per gene
head(y$wald_stats)       # Wald statistics per gene
head(y$p.values)         # p-values
head(y$tagwise.disp)     # estimated dispersions
str(y, max.level = 1)    # Data structure visualization

## -----------------------------------------------------------------------------
padj <- p.adjust(y$p.values, method = "BH")
head(padj)

## ----SE_input-----------------------------------------------------------------
# 1. Create a SummarizedExperiment object
suppressPackageStartupMessages(library(SummarizedExperiment))
set.seed(123)

# Simulate data
counts_mat <- matrix(rnbinom(300, size = 5, mu = 5), nrow = 50)
colnames(counts_mat) <- paste0("Sample", 1:6)
group_info <- factor(c("A", "A", "A", "B", "B", "B"))

# Construct SE with colData
se <- SummarizedExperiment(
    assays = list(counts = counts_mat),
    colData = data.frame(condition = group_info)
)

# 2. Start the LRDE pipeline using the SE object
# Extract the condition directly from colData
y_se <- prepareDGE(se, group = colData(se)$condition)

# 3. Standard downstream workflow
y_se <- sizeFactorsEst(y_se)
y_se <- tagwiseEst(y_se)
y_se <- hurdle_LRT(y_se)

# View results
head(y_se$lrt_stats)

## ----sessionInfo, echo=FALSE--------------------------------------------------
sessionInfo()

