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

Make rownames part of obs and var #171

Merged
merged 13 commits into from
Jul 8, 2024
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ Config/Needs/website: pkgdown, tibble, knitr, rprojroot, stringr, readr,
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
biocViews: SingleCell, DataImport, DataRepresentation
11 changes: 2 additions & 9 deletions R/AbstractAnnData.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
},
#' @description Number of observations in the AnnData object.
n_obs = function() {
length(self$obs_names)
nrow(self$obs)
},
#' @description Number of variables in the AnnData object.
n_vars = function() {
length(self$var_names)
nrow(self$var)
},
#' @description Keys ('column names') of `obs`.
obs_keys = function() {
Expand Down Expand Up @@ -284,13 +284,6 @@ AbstractAnnData <- R6::R6Class("AbstractAnnData", # nolint
))
}

if (has_row_names(df)) {
warning(wrap_message(
"'", label, "' should not have any rownames, removing them from the data frame."
))
rownames(df) <- NULL
}

df
},

Expand Down
24 changes: 8 additions & 16 deletions R/AnnData.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
#'
#' To read an AnnData file from disk, use [read_h5ad()] instead.
#'
#' @param obs_names A vector of unique identifiers
#' used to identify each row of `obs` and to act as an index into the
#' observation dimension of the AnnData object. The length of `obs_names`
#' defines the observation dimension of the AnnData object.
#' @param var_names A vector of unique identifiers used to identify each row
#' of `var` and to act as an index into the variable dimension of the
#' AnnData object. The length of `var_names` defines the variable
#' dimension of the AnnData object.
#' @param X Either `NULL` or a observation × variable matrix with
#' dimensions consistent with `obs` and `var`.
#' @param layers Either `NULL` or a named list, where each element is an
Expand All @@ -41,27 +33,27 @@
#' element is a sparse matrix where each dimension has length `n_vars`.
#' @param uns The uns slot is used to store unstructured annotation. It must
#' be either `NULL` or a named list.
#' @param shape Shape tuple (#observations, #variables). Can be provided
#' if `X` or `obs` and `var` are not provided.
#'
#' @export
#'
#' @examples
#' adata <- AnnData(
#' obs_names = paste0("obs", 1:3),
#' var_names = paste0("var", 1:4),
#' X = matrix(1:12, nrow = 3, ncol = 4),
#' obs = data.frame(
#' row.names = paste0("obs", 1:3),
#' n_counts = c(1, 2, 3),
#' n_cells = c(1, 2, 3)
#' ),
#' var = data.frame(
#' row.names = paste0("var", 1:4),
#' n_cells = c(1, 2, 3, 4)
#' )
#' )
#'
#' adata
AnnData <- function(
obs_names = NULL,
var_names = NULL,
X = NULL,
obs = NULL,
var = NULL,
Expand All @@ -70,10 +62,9 @@ AnnData <- function(
varm = NULL,
obsp = NULL,
varp = NULL,
uns = NULL) {
uns = NULL,
shape = shape) {
InMemoryAnnData$new(
obs_names = obs_names,
var_names = var_names,
X = X,
obs = obs,
var = var,
Expand All @@ -82,6 +73,7 @@ AnnData <- function(
varm = varm,
obsp = obsp,
varp = varp,
uns = uns
uns = uns,
shape = shape
)
}
Loading
Loading