sumCountsAcrossFeatures {scater} | R Documentation

## Sum counts across a feature set

### Description

Create a count matrix where counts for all features in a set are summed together.

### Usage

    sumCountsAcrossFeatures(object, ids, exprs_values = "counts",
      BPPARAM = SerialParam())

### Arguments

`object` | A SingleCellExperiment object or a count matrix.
`ids` | A factor specifying the set to which each feature in `object` belongs.
`exprs_values` | A string or integer scalar specifying the assay of `object` containing counts, if `object` is a SingleCellExperiment.
`BPPARAM` | A BiocParallelParam object specifying whether summation should be parallelized.

### Details

This function provides a convenient method for aggregating counts across multiple rows for each cell. For example, genes with multiple mapping locations in the reference will often manifest as multiple rows with distinct Ensembl/Entrez IDs. These counts can be aggregated into a single feature by setting the shared identifier (usually the gene symbol) as `ids`.

It is theoretically possible to aggregate transcript-level counts to gene-level counts with this function. However, it is often better to do so with dedicated functions (e.g., from the tximport or tximeta packages) that account for differences in length across isoforms.

Any `NA` values in `ids` are implicitly ignored and will not be considered or reported. This may be useful, e.g., to remove undesirable feature sets by setting their entries in `ids` to `NA`.

### Value

A count matrix where counts for all features in the same set are summed together within each cell.

### Author(s)

Aaron Lun

### Examples

    data("sc_example_counts")
    data("sc_example_cell_info")
    example_sce <- SingleCellExperiment(
        assays = list(counts = sc_example_counts),
        colData = sc_example_cell_info)

    ids <- sample(LETTERS, nrow(example_sce), replace=TRUE)
    out <- sumCountsAcrossFeatures(example_sce, ids)
    dimnames(out)

[Package scater version 1.12.2 Index]