makePerFeatureDF {scater} | R Documentation

## Create a per-feature data.frame from a SingleCellDataFrame

### Description

Create a per-feature data.frame (i.e., where each row represents a feature) from a SingleCellExperiment, most typically for creating custom ggplot2 plots.

### Usage

    makePerFeatureDF(
      x,
      cells = NULL,
      exprs_values = "logcounts",
      check_names = FALSE
    )

### Arguments

`x` | A SingleCellExperiment object. This is expected to have non-`NULL` row names.
`cells` | Character vector specifying the features for which to extract expression profiles across cells.
`exprs_values` | String or integer scalar indicating the assay to use to obtain expression values. Must refer to a matrix-like object with integer or numeric values.
`check_names` | Logical scalar indicating whether the column names of the output data.frame should be made syntactically valid and unique.

### Details

This function enables us to conveniently create a per-feature data.frame from a SingleCellExperiment. Each row of the returned data.frame corresponds to a row in `x`, while each column of the data.frame corresponds to one aspect of the (meta)data in `x`. Columns are provided in the following order:

1. Columns named according to values in `cells` represent the expression values across features for the specified cell in the `exprs_values` assay.

2. Columns named according to the columns of `rowData(x)` represent the row metadata variables.

By default, nothing is done to resolve syntactically invalid or duplicated column names; this will often lead (correctly) to an error in downstream functions like `ggplot`. If `check_names=TRUE`, this is resolved by passing the column names through `make.names`. Of course, as a result, some columns may not have the same names as the original fields in `x`.

### Value

A data.frame containing one field per aspect of data in `x` - see Details. Each row corresponds to a feature (i.e., row) of `x`.

### Author(s)

Aaron Lun

### See Also

`ggfeatures`, which uses this function under the hood.

### Examples

    example_sce <- mockSCE()
    example_sce <- logNormCounts(example_sce)
    rowData(example_sce)$Length <- runif(nrow(example_sce))

    df <- makePerFeatureDF(example_sce, cells="Cell_001")
    head(colnames(df))
    tail(colnames(df))

    head(df$Cell_001)
    head(df$Length)

[Package scater version 1.16.2 Index]