This function enables you to easily calculate the percentage of all the counts belonging to a subset of the possible features for each cell. This is useful when trying to compute the percentage of transcripts that map to mitochondrial genes for example. The calculation here is simply the column sum of the matrix present in the counts slot for features belonging to the set divided by the column sum for all features times 100.
pattern = NULL,
features = NULL,
col.name = NULL,
assay = NULL
A Seurat object
A regex pattern to match features against
A defined feature set. If features provided, will ignore the pattern matching
Name in meta.data column to assign. If this is not null, returns a Seurat object with the proportion of the feature set stored in metadata.
Assay to use
Returns a vector with the proportion of the feature set or if md.name is set, returns a Seurat object with the proportion of the feature set stored in metadata.
# Calculate the proportion of transcripts mapping to mitochondrial genes
# NOTE: The pattern provided works for human gene names. You may need to adjust depending on your
# system of interest
pbmc_small[["percent.mt"]] <- PercentageFeatureSet(object = pbmc_small, pattern = "^MT-")