From f4a950b7ed0d9115c701c6c3f530b91ac8ed2f96 Mon Sep 17 00:00:00 2001 From: Jack Leary Date: Mon, 14 Oct 2024 13:32:25 -0400 Subject: [PATCH 1/4] fixed GEE preds in getFittedValues() -- closes #252 --- R/getFittedValues.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/getFittedValues.R b/R/getFittedValues.R index 9b22af3..5fa78ee 100644 --- a/R/getFittedValues.R +++ b/R/getFittedValues.R @@ -44,6 +44,9 @@ getFittedValues <- function(test.dyn.res = NULL, if (inherits(expr.mat, "SingleCellExperiment")) { expr.mat <- BiocGenerics::counts(expr.mat)[genes, , drop = FALSE] expr.mat <- as.matrix(expr.mat) + } else if (inherits(expr.mat, "cell_data_set")) { + expr.mat <- BiocGenerics::counts(expr.mat)[genes, , drop = FALSE] + expr.mat <- as.matrix(expr.mat) } else if (inherits(expr.mat, "Seurat")) { expr.mat <- Seurat::GetAssayData(expr.mat, slot = "counts", @@ -104,7 +107,7 @@ getFittedValues <- function(test.dyn.res = NULL, scLANE_pred = exp(scLANE_pred_link), scLANE_ci_ll = exp(scLANE_pred_link - Z * scLANE_se_link), scLANE_ci_ul = exp(scLANE_pred_link + Z * scLANE_se_link)) - if (!is.null(size.factor.offset)) { + if (!is.null(size.factor.offset) & !is.gee) { gene_df <- dplyr::mutate(gene_df, dplyr::across(c(rna, scLANE_pred, scLANE_ci_ll, scLANE_ci_ul), \(m) m * size_factor)) } From b3530a0ecffc05071da381e013e14520afbedbcb Mon Sep 17 00:00:00 2001 From: Jack Leary Date: Mon, 14 Oct 2024 13:32:50 -0400 Subject: [PATCH 2/4] added more CDS support -- closes #250 --- R/sortObservations.R | 6 +++--- man/sortObservations.Rd | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/sortObservations.R b/R/sortObservations.R index decf2f1..4a82673 100644 --- a/R/sortObservations.R +++ b/R/sortObservations.R @@ -4,14 +4,14 @@ #' @author Jack R. Leary #' @importFrom dplyr arrange #' @description Since the GEE & GLMM modes require data to be sorted by sample ID and pseudotime, this function provides a simple way to do so for a range of inputs. -#' @param expr.mat Either a \code{SingleCellExperiment} or \code{Seurat} object from which counts can be extracted, or a matrix of integer-valued counts with genes as rows & cells as columns. Defaults to NULL. +#' @param expr.mat Either a \code{SingleCellExperiment}, \code{Seurat}, or \code{cell_data_set} object from which cell-level metadata can be extracted, or a matrix of integer-valued counts with genes as rows & cells as columns. Defaults to NULL. #' @param pt.vec A vector of pseudotime values used to sort the observations. May contain NA values. Defaults to NULL. #' @param id.vec A vector of subject IDs used to sort the observations. Defaults to NULL. #' @return An object of the same class as the input \code{expr.mat}, but sorted by sample ID & pseudotime. #' @details #' \itemize{ #' \item If the input is a matrix, it is assumed that the columns are cells - and are named as such - and the rows are genes. -#' \item If the input is a Seurat object, sorting requires converting to \code{SingleCellExperiment} object first, then ordering, then converting back toa \code{Seurat} object. Some information might be lost, so it is recommended not to overwrite your original \code{Seurat} object. +#' \item If the input is a \code{Seurat} object, sorting requires converting to \code{SingleCellExperiment} object first, then ordering, then converting back to a \code{Seurat} object. Some information might be lost, so it is recommended not to overwrite your original \code{Seurat} object. #' } #' @export #' @examples @@ -36,7 +36,7 @@ sortObservations <- function(expr.mat = NULL, ID, PT) # sort object by cells - if (inherits(expr.mat, "SingleCellExperiment") || inherits(expr.mat, "matrix") || inherits(expr.mat, "dgCMatrix")) { + if (inherits(expr.mat, "SingleCellExperiment") || inherits(expr.mat, "cell_data_set") || inherits(expr.mat, "matrix") || inherits(expr.mat, "dgCMatrix")) { expr.mat <- expr.mat[, subj_df$Cell] } else if (inherits(expr.mat, "Seurat")) { warning("Ordering a Seurat object requires conversion to SingleCellExperiment, and some information might be lost.") diff --git a/man/sortObservations.Rd b/man/sortObservations.Rd index 1c279a2..0d7b654 100644 --- a/man/sortObservations.Rd +++ b/man/sortObservations.Rd @@ -7,7 +7,7 @@ sortObservations(expr.mat = NULL, pt.vec = NULL, id.vec = NULL) } \arguments{ -\item{expr.mat}{Either a \code{SingleCellExperiment} or \code{Seurat} object from which counts can be extracted, or a matrix of integer-valued counts with genes as rows & cells as columns. Defaults to NULL.} +\item{expr.mat}{Either a \code{SingleCellExperiment}, \code{Seurat}, or \code{cell_data_set} object from which cell-level metadata can be extracted, or a matrix of integer-valued counts with genes as rows & cells as columns. Defaults to NULL.} \item{pt.vec}{A vector of pseudotime values used to sort the observations. May contain NA values. Defaults to NULL.} @@ -22,7 +22,7 @@ Since the GEE & GLMM modes require data to be sorted by sample ID and pseudotime \details{ \itemize{ \item If the input is a matrix, it is assumed that the columns are cells - and are named as such - and the rows are genes. -\item If the input is a Seurat object, sorting requires converting to \code{SingleCellExperiment} object first, then ordering, then converting back toa \code{Seurat} object. Some information might be lost, so it is recommended not to overwrite your original \code{Seurat} object. +\item If the input is a \code{Seurat} object, sorting requires converting to \code{SingleCellExperiment} object first, then ordering, then converting back to a \code{Seurat} object. Some information might be lost, so it is recommended not to overwrite your original \code{Seurat} object. } } \examples{ From 1f8d56751fb7a7f0d2171ca6d4c5d0dc664ef2f7 Mon Sep 17 00:00:00 2001 From: Jack Leary Date: Mon, 14 Oct 2024 13:33:04 -0400 Subject: [PATCH 3/4] bumped to v0.8.5 --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1b793c5..5cbd8f8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: scLANE Type: Package Title: Model Gene Expression Dynamics with Spline-Based NB GLMs, GEEs, & GLMMs -Version: 0.8.4 +Version: 0.8.5 Authors@R: c(person(given = c("Jack", "R."), family = "Leary", email = "j.leary@ufl.edu", role = c("aut", "cre"), comment = c(ORCID = "0009-0004-8821-3269")), person(given = "Rhonda", family = "Bacher", email = "rbacher@ufl.edu", role = c("ctb", "fnd"), comment = c(ORCID = "0000-0001-5787-476X"))) Description: Our scLANE model uses truncated power basis spline models to build flexible, interpretable models of single cell gene expression over pseudotime or latent time. diff --git a/NEWS.md b/NEWS.md index 3eda8ec..085dbd7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# Changes in v0.8.5 + ++ Minor bug fixes. ++ More improved matrix operations using `RcppEigen`. ++ Improved support for `cell_data_set` objects from `monocle3`. + # Changes in v0.8.4 + Minor bug fixes. From 62b380331892f442ee97840b8772a93ad499a066 Mon Sep 17 00:00:00 2001 From: Jack Leary Date: Mon, 14 Oct 2024 18:03:19 -0400 Subject: [PATCH 4/4] fixed bug in getFittedValues() -- closes #253 --- R/getFittedValues.R | 2 ++ man/getFittedValues.Rd | 3 +++ 2 files changed, 5 insertions(+) diff --git a/R/getFittedValues.R b/R/getFittedValues.R index 5fa78ee..1a3a1af 100644 --- a/R/getFittedValues.R +++ b/R/getFittedValues.R @@ -14,6 +14,7 @@ #' @param size.factor.offset (Optional) An offset to be used to rescale the fitted values. Can be generated easily with \code{\link{createCellOffset}}. No need to provide if the GEE backend was used. Defaults to NULL. #' @param log1p.norm (Optional) Should log1p-normalized versions of expression & model predictions be returned as well? Defaults to TRUE. #' @param cell.meta.data (Optional) A data.frame of metadata values for each cell (celltype label, subject characteristics, tissue type, etc.) that will be included in the result table. Defaults to NULL. +#' @param is.gee Was the GEE mode used to fit the models? Defaults to FALSE. #' @param id.vec (Optional) A vector of subject IDs used in fitting GEE or GLMM models. Defaults to NULL. #' @param ci.alpha (Optional) The pre-specified Type I Error rate used in generating (\eqn{1 - \alpha})\% CIs. Defaults to good old 0.05. #' @param filter.lineage (Optional) A character vector of lineages to filter out before generating the final plot. Should be letters, i.e. lineage "A" or "B". Defaults to NULL. @@ -35,6 +36,7 @@ getFittedValues <- function(test.dyn.res = NULL, size.factor.offset = NULL, log1p.norm = TRUE, cell.meta.data = NULL, + is.gee = FALSE, id.vec = NULL, ci.alpha = 0.05, filter.lineage = NULL) { diff --git a/man/getFittedValues.Rd b/man/getFittedValues.Rd index f8234b9..0ddf96d 100644 --- a/man/getFittedValues.Rd +++ b/man/getFittedValues.Rd @@ -12,6 +12,7 @@ getFittedValues( size.factor.offset = NULL, log1p.norm = TRUE, cell.meta.data = NULL, + is.gee = FALSE, id.vec = NULL, ci.alpha = 0.05, filter.lineage = NULL @@ -32,6 +33,8 @@ getFittedValues( \item{cell.meta.data}{(Optional) A data.frame of metadata values for each cell (celltype label, subject characteristics, tissue type, etc.) that will be included in the result table. Defaults to NULL.} +\item{is.gee}{Was the GEE mode used to fit the models? Defaults to FALSE.} + \item{id.vec}{(Optional) A vector of subject IDs used in fitting GEE or GLMM models. Defaults to NULL.} \item{ci.alpha}{(Optional) The pre-specified Type I Error rate used in generating (\eqn{1 - \alpha})\% CIs. Defaults to good old 0.05.}