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

Preserve row and column names when creating an Assay #4

Merged
merged 3 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: SeuratObject
Type: Package
Title: Data Structures for Single Cell Data
Version: 4.0.0.9001
Date: 2021-01-19
Version: 4.0.0.9002
Date: 2021-02-12
Authors@R: c(
person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
person(given = 'Andrew', family = 'Butler', email = 'abutler@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0003-3608-0463')),
Expand Down
6 changes: 4 additions & 2 deletions R/assay.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Assay <- setClass(
#' new object with a lower cutoff.
#' @param min.features Include cells where at least this many features are
#' detected.
#' @param ... Arguments passed to \code{\link{as.sparse}}
#'
#' @return A \code{\link{Assay}} object
#'
Expand All @@ -91,7 +92,8 @@ CreateAssayObject <- function(
counts,
data,
min.cells = 0,
min.features = 0
min.features = 0,
...
) {
if (missing(x = counts) && missing(x = data)) {
stop("Must provide either 'counts' or 'data'")
Expand Down Expand Up @@ -125,7 +127,7 @@ CreateAssayObject <- function(
stop("No feature names (rownames) names present in the input matrix")
}
if (!inherits(x = counts, what = 'dgCMatrix')) {
counts <- as(object = as.matrix(x = counts), Class = 'dgCMatrix')
counts <- as.sparse(x = counts, ...)
}
# Filter based on min.features
if (min.features > 0) {
Expand Down
8 changes: 7 additions & 1 deletion R/seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ Command.Seurat <- function(object, command = NULL, value = NULL, ...) {
return(params[[value]])
}

#' @param row.names When \code{counts} is a \code{data.frame} or
#' \code{data.frame}-derived object: an optional vector of feature names to be
#' used
#'
#' @rdname CreateSeuratObject
#' @method CreateSeuratObject default
#' @export
Expand All @@ -922,6 +926,7 @@ CreateSeuratObject.default <- function(
meta.data = NULL,
min.cells = 0,
min.features = 0,
row.names = NULL,
...
) {
if (!is.null(x = meta.data)) {
Expand All @@ -932,7 +937,8 @@ CreateSeuratObject.default <- function(
assay.data <- CreateAssayObject(
counts = counts,
min.cells = min.cells,
min.features = min.features
min.features = min.features,
row.names = row.names
)
if (!is.null(x = meta.data)) {
common.cells <- intersect(
Expand Down
11 changes: 10 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,21 @@ RowMergeSparseMatrices <- function(mat1, mat2) {
# Methods for Seurat-defined generics
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#' @param row.names \code{NULL} or a character vector giving the row names for
#' the data; missing values are not allowed
#'
#' @rdname as.sparse
#' @export
#' @method as.sparse data.frame
#'
as.sparse.data.frame <- function(x, ...) {
as.sparse.data.frame <- function(x, row.names = NULL, ...) {
CheckDots(...)
dnames <- list(row.names %||% rownames(x = x), colnames(x = x))
if (length(x = dnames[[1]]) != nrow(x = x)) {
stop("Differing numbers of rownames and rows", call. = FALSE)
}
x <- as.data.frame(x = x)
dimnames(x = x) <- dnames
return(as.sparse(x = as.matrix(x = x)))
}

Expand Down
4 changes: 3 additions & 1 deletion man/CreateAssayObject.Rd

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

5 changes: 5 additions & 0 deletions man/CreateSeuratObject.Rd

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

5 changes: 4 additions & 1 deletion man/as.sparse.Rd

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