cell_metadata_to_metacell | R Documentation |
Summarise cell metadata for each metacell. Metadata fields can be either numeric and then the summary function func
is applied for the values of each field, or categorical metadata fields which are expanded to multiple
metadata columns with the fraction of cells (in each metacell) for every category. Variables that are either character,
factor or are explicitly set at categorical
are treated as categorical.
cell_metadata_to_metacell
converts cell metadata to metacell metadata from data frames.
cell_metadata_to_metacell_from_h5ad
extracts metadata fields and cell_to_metacell from cells h5ad file and
then runs cell_metadata_to_metacell
.
cell_metadata_to_metacell_from_metacell1
extracts metadata fields and cell_to_metacell from metacell1 scdb and
then runs cell_metadata_to_metacell
.
cell_metadata_to_metacell(
cell_metadata,
cell_to_metacell,
func = mean,
categorical = c()
)
cell_metadata_to_metacell_from_metacell1(
scdb,
matrix,
mc,
metadata_fields,
func = mean,
categorical = c()
)
cell_metadata_to_metacell_from_h5ad(
anndata_file,
metadata_fields,
func = mean,
categorical = c(),
rm_outliers = TRUE
)
cell_metadata |
data frame with a column named "cell_id" with the cell id and other metadata columns, or a name of a delimited file which contains such data frame. |
cell_to_metacell |
data frame with a column named "cell_id" with cell id and another column named "metacell" with the metacell the cell is part of, or a name of a delimited file which contains such data frame. |
func |
summary function for the cell metadata for non categorical metadata columns (e.g. mean, median, sum) |
categorical |
a vector with names of categorical variables. The returned data frame would have a column for each category where the values are the fraction of cells with the category in each metacell. |
scdb , matrix , mc |
scdb, matrix and mc objects from metacell1. See |
metadata_fields |
names of fields in the anndata |
anndata_file |
path to |
rm_outliers |
do not calculate statistics for cells that are marked as outliers ( |
A data frame with a column named "metacell" and
the metadata columns from cell_metadata
summarized for each metacell using
func
for non-categorical variables, and a column for each category of the categorical metadata variables
incell_metadata
, where the values are the fraction of cells with the category in each metacell.
cell_metadata_to_metacell_from_metacell1()
:
cell_metadata_to_metacell_from_h5ad()
:
set.seed(60427)
n_cells <- 5e6
cell_metadata <- tibble::tibble(
cell_id = 1:n_cells,
md1 = sample(1:5, size = n_cells, replace = TRUE),
md2 = rnorm(n = n_cells),
md_categorical1 = sample(paste0("batch", 1:5), size = n_cells, replace = TRUE),
md_categorical2 = sample(1:5, size = n_cells, replace = TRUE)
)
cell_to_metacell <- tibble::tibble(
cell_id = 1:n_cells,
metacell = sample(0:1535, size = n_cells, replace = TRUE)
)
metadata <- cell_metadata_to_metacell(
cell_metadata[, 1:3],
cell_to_metacell
)
head(metadata)
metadata1 <- cell_metadata_to_metacell(
cell_metadata[, 1:3], cell_to_metacell,
func = function(x) x * 2
)
head(metadata1)
metadata3 <- cell_metadata_to_metacell(
cell_metadata,
cell_to_metacell,
categorical = c("md_categorical1", "md_categorical2")
)
head(metadata3)
## Not run:
cell_metadata_to_metacell_from_h5ad("cells.h5ad", c("pile", "age", "batch"), categorical = "batch")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.