makePerFeatureDF {scater} | R Documentation |
Create a per-feature data.frame (i.e., where each row represents a feature) from a SingleCellExperiment, most typically for creating custom ggplot2 plots.
makePerFeatureDF( x, cells = NULL, exprs_values = "logcounts", check_names = FALSE )
x |
A SingleCellExperiment object.
This is expected to have non- |
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. |
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:
Columns named according to values in cells
represent the expression values across features for the specified cell in the exprs_values
assay.
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
.
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
.
Aaron Lun
ggfeatures
, which uses this function under the hood.
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)