get_celltype_mapping: get_celltype_mapping

View source: R/get_celltype_mapping.R

get_celltype_mappingR Documentation

get_celltype_mapping

Description

For each cell, returns an estimate of its cell type based on cell type labels of neighbors in Selection graph. Requires at least 2 genes for the Selection graph. If cell type mapping for the Selection graph is not possible, returns NULL.

Usage

get_celltype_mapping(
  sce,
  genes.selection,
  celltype.id = "celltype",
  batch = NULL,
  n.neigh = 5,
  nPC.selection = NULL,
  cosine = F,
  return.stat = T,
  which_genes_to_use = "all",
  ...
)

Arguments

sce

SingleCellExperiment object containing gene counts matrix (stored in 'logcounts' assay).

genes.selection

Character vector specifying genes (at least 2 genes) to be used for the construction of Selection kNN-graph.

celltype.id

Character specifying which field in colData(sce) should be used as celltype. Default celltype.id="celltype".

batch

Name of the field in colData(sce) to specify batch. Default batch=NULL if no batch is applied.

n.neigh

Positive integer > 1, specifying number of neighbors to use for kNN-graph. Default n.neigh=5.

nPC.selection

Positive integer (or NULL, if no PCA to be applied) specifying number of PCs to use for construction of True kNN-graph. Default nPC.selection=NULL. We advise to set it to 50 if length(genes.selection) > 50.

cosine

Boolean specifying if cosine normalization should be applied prior to constructing kNN-graph. Default cosine=FALSE.

return.stat

Boolean specifying if stat for the mapping (= diagonal values for the cell type confusion matrix) should be returned alongside the mapping.

which_genes_to_use

String specifying whether cell type mapping should be performed only on differentially expressed (between cell types) genes (= 'DE') or all selected genes (= 'all'). Default which_genes_to_use="all".

...

Additional arguments (e.g. the ones you can pass to get_DE_genes).

Value

List, containing field 'mapping' - data.frame with cell IDs (column 'cell'), originally assigned cell type labels (column 'celltype') and estimated cell type labels (column 'mapped_celltype'). If return.stat == TRUE, also returns field 'stat' - data.frame with cell type IDs (column 'celltype') and fraction of cells from this cell type that mapped correctly (column 'frac_correctly_mapped')

Examples

require(SingleCellExperiment)
n_row = 1000
n_col = 100
sce = SingleCellExperiment(assays = list(logcounts = matrix(rnorm(n_row*n_col), ncol=n_col)))
rownames(sce) = as.factor(1:n_row)
colnames(sce) = c(1:n_col)
sce$cell = colnames(sce)
sce$celltype = as.character(sample.int(5, n_col, replace = TRUE))
genes.selection = sample( rownames(sce) , 20)
out = get_celltype_mapping(sce, genes.selection = genes.selection)


MarioniLab/geneBasisR documentation built on June 30, 2023, 2:04 p.m.