Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method glmmTMB #296

Merged
merged 13 commits into from
Sep 17, 2023
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Suggests:
pbapply,
pbmcapply,
lme4,
glmmTMB,
MASS
VignetteBuilder:
knitr
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ importFrom(stats,median)
importFrom(stats,model.matrix)
importFrom(stats,na.omit)
importFrom(stats,p.adjust)
importFrom(stats,pchisq)
importFrom(stats,plogis)
importFrom(stats,prcomp)
importFrom(stats,qlogis)
Expand Down
16 changes: 8 additions & 8 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ get_differential_transcript_abundance_glmmSeq <- function(.data,
.abundance = enquo(.abundance)
.sample_total_read_count = enquo(.sample_total_read_count)
.dispersion = enquo(.dispersion)

# Check if omit_contrast_in_colnames is correctly setup
if(omit_contrast_in_colnames & length(.contrasts) > 1){
warning("tidybulk says: you can omit contrasts in column names only when maximum one contrast is present")
Expand Down Expand Up @@ -757,33 +757,33 @@ get_differential_transcript_abundance_glmmSeq <- function(.data,

# Reorder counts
counts = counts[,rownames(metadata),drop=FALSE]

if(quo_is_symbolic(.dispersion))
dispersion = .data |> pivot_transcript(!!.transcript) |> select(!!.transcript, !!.dispersion) |> deframe()
else
dispersion = setNames(edgeR::estimateDisp(counts)$tagwise.dispersion, rownames(counts))

# # Check dispersion
# if(!names(dispersion) |> sort() |> identical(
# rownames(counts) |>
# sort()
# )) stop("tidybulk says: The features in the dispersion vector do not overlap with the feature in the assay")

# Make sure the order matches the counts
dispersion = dispersion[rownames(counts)]
glmmSeq_object =

glmmSeq_object =
glmmSeq( .formula,
countdata = counts ,
metadata = metadata,
dispersion = dispersion,
progress = TRUE,
progress = TRUE,
method = method |> str_remove("(?i)^glmmSeq_"),
...
)

glmmSeq_object |>
summary() |>
summary_lmmSeq() |>
as_tibble(rownames = "gene") |>
mutate(across(starts_with("P_"), list(adjusted = function(x) p.adjust(x, method="BH")), .names = "{.col}_{.fn}")) |>

Expand Down
2 changes: 1 addition & 1 deletion R/functions_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ get_differential_transcript_abundance_glmmSeq_SE <- function(.data,
)

glmmSeq_object |>
summary() |>
summary_lmmSeq() |>
as_tibble(rownames = "transcript") |>
mutate(across(starts_with("P_"), list(adjusted = function(x) p.adjust(x, method="BH")), .names = "{.col}_{.fn}")) |>

Expand Down
Loading
Loading