Skip to content

Commit

Permalink
updated tests and such
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-leary7 committed Oct 10, 2023
1 parent 82973ab commit 6132e8d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(enrichDynamicGenes)
export(extractBreakpoints)
export(fitGLMM)
export(getFittedValues)
export(getKnotDist)
export(getResultsDE)
export(marge2)
export(modelLRT)
Expand Down Expand Up @@ -86,10 +87,10 @@ importFrom(glmmTMB,nbinom2)
importFrom(parallel,clusterEvalQ)
importFrom(parallel,clusterExport)
importFrom(parallel,clusterSetRNGStream)
importFrom(parallel,detectCores)
importFrom(parallel,makeCluster)
importFrom(parallel,stopCluster)
importFrom(purrr,discard)
importFrom(purrr,imap)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_chr)
Expand Down
6 changes: 5 additions & 1 deletion R/summarizeModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ summarizeModel <- function(marge.model = NULL, pt = NULL) {
Trend.Segment = NA_real_)
} else {
# extract model equation, slopes, & covariances
coef_vcov <- vcov(marge.model$final_mod)
if (marge.model$model_type == "GEE") {
coef_vcov <- as.matrix(marge.model$final_mod$var)
} else {
coef_vcov <- vcov(marge.model$final_mod)
}
coef_df <- data.frame(coef_name = names(coef(marge.model$final_mod)),
coef_value = unname(coef(marge.model$final_mod)),
coef_var = unname(diag(coef_vcov)))
Expand Down
17 changes: 8 additions & 9 deletions R/testDynamic.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @importFrom bigstatsr as_FBM
#' @importFrom foreach foreach %dopar% registerDoSEQ
#' @importFrom doParallel registerDoParallel
#' @importFrom parallel makeCluster detectCores stopCluster clusterEvalQ clusterExport clusterSetRNGStream
#' @importFrom parallel makeCluster stopCluster clusterEvalQ clusterExport clusterSetRNGStream
#' @importFrom withr with_output_sink
#' @importFrom MASS glm.nb negative.binomial theta.mm
#' @importFrom dplyr rename mutate relocate
Expand Down Expand Up @@ -93,6 +93,9 @@ testDynamic <- function(expr.mat = NULL,
if (is.null(expr.mat) || is.null(pt)) { stop("You forgot some inputs to testDynamic().") }

# get raw counts from SingleCellExperiment or Seurat object & transpose to cell x gene dense matrix
if (is.null(genes)) {
genes <- rownames(expr.mat)
}
if (inherits(expr.mat, "SingleCellExperiment")) {
expr.mat <- BiocGenerics::counts(expr.mat)[genes, ]
expr.mat <- as.matrix(expr.mat)
Expand All @@ -102,15 +105,12 @@ testDynamic <- function(expr.mat = NULL,
assay = Seurat::DefaultAssay(expr.mat))
expr.mat <- as.matrix(expr.mat[genes, ])
} else if (inherits(expr.mat, "dgCMatrix")) {
expr.mat <- as.matrix(expr.mat)
expr.mat <- as.matrix(expr.mat[genes, ])
} else {
expr.mat <- expr.mat[genes, ]
}
if (!(inherits(expr.mat, "matrix") || inherits(expr.mat, "array"))) { stop("Input expr.mat must be coerceable to a matrix of integer counts.") }
expr.mat <- t(expr.mat) # transpose to cell x gene matrix
if (is.null(genes)) {
genes <- colnames(expr.mat)
} else {
expr.mat <- expr.mat[, genes]
}

# extract pseudotime dataframe if input is results from Slingshot
if (inherits(pt, "SlingshotDataSet")) {
Expand Down Expand Up @@ -165,8 +165,7 @@ testDynamic <- function(expr.mat = NULL,
package_list <- c("glm2", "scLANE", "MASS", "bigstatsr", "broom.mixed", "dplyr", "stats")
if (is.gee) {
package_list <- c(package_list, "geeM")
}
if (is.glmm) {
} else if (is.glmm) {
package_list <- c(package_list, "glmmTMB")
}

Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test_scLANE.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ withr::with_output_sink(tempfile(), {
size.factor.offset = cell_offset,
n.cores = 2,
track.time = TRUE)
gee_gene_stats <- testDynamic(sim_data,
gee_gene_stats <- testDynamic(expr.mat = sim_data,
pt = pt_test,
genes = genes_to_test,
n.potential.basis.fns = 5,
Expand All @@ -53,7 +53,7 @@ withr::with_output_sink(tempfile(), {
glmm.adaptive = TRUE,
id.vec = sim_data$subject,
n.cores = 2,
track.time = TRUE)
track.time = FALSE)
# get results tables overall
glm_test_results <- getResultsDE(glm_gene_stats)
gee_test_results <- getResultsDE(gee_gene_stats)
Expand Down Expand Up @@ -191,6 +191,7 @@ withr::with_output_sink(tempfile(), {
gsea_res <- enrichDynamicGenes(glm_test_results, species = "hsapiens")
coef_summary_glm <- summarizeModel(marge_mod_offset, pt = pt_test)
coef_summary_gee <- summarizeModel(marge_mod_GEE_offset, pt = pt_test)
knot_df <- getKnotDist(glm_gene_stats)
})

# run tests
Expand Down Expand Up @@ -359,3 +360,8 @@ test_that("summarizeModels() output", {
expect_type(coef_summary_glm$Slope.Segment, "double")
expect_type(coef_summary_gee$Slope.Segment, "double")
})

test_that("getKnotDist() output", {
expect_s3_class(knot_df, "data.frame")
expect_equal(ncol(knot_df), 3)
})

0 comments on commit 6132e8d

Please sign in to comment.