Skip to content

Commit

Permalink
Merge pull request #254 from jr-leary7/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jr-leary7 authored Oct 15, 2024
2 parents 2516d8a + 62b3803 commit 0f8f9fd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0009-0004-8821-3269")),
person(given = "Rhonda", family = "Bacher", email = "[email protected]", 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.
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 6 additions & 1 deletion R/getFittedValues.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -44,6 +46,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",
Expand Down Expand Up @@ -104,7 +109,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))
}
Expand Down
6 changes: 3 additions & 3 deletions R/sortObservations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions man/getFittedValues.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sortObservations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f8f9fd

Please sign in to comment.