Skip to contents

Metadata that describes the samples.

Usage

sampleData(object, ...)

sampleData(object, ...) <- value

# S4 method for SingleCellExperiment
sampleData(
  object,
  clean = TRUE,
  ignoreCols = c("^description$", "^genomeBuild$", "^qualityFormat$", "^samRef$"),
  denylistCols = c("^ident$", "^g2mScore$", "^sScore$", "^phase$", "^oldIdent$",
    "^origIdent$", "^res[0-9]+")
)

# S4 method for SingleCellExperiment,DFrame
sampleData(object) <- value

Arguments

object

Object.

clean

logical(1). Only return factor columns. Useful when working with objects that contain quality control metrics in colData(). For example, bcbioRNASeq and DESeqDataSet objects often contain additional columns that aren't informative sample metadata.

ignoreCols

character or NULL. Only applies when clean = TRUE. Additional factor columns defined in colData to be ignored as sample-level metadata. Particularly useful for SingleCellExperiment objects, where cell-to-sample mappings are defined using the sampleId column.

denylistCols

character or NULL. Column names that should not be treated as sample-level metadata. Currently applicable only to SingleCellExperiment objects, which have cell-level columns that can be difficult to distinguish, especially when processed using Seurat, scater, etc.

value

Value to assign.

...

Additional arguments.

Value

DataFrame.

Details

This is a complement to the standard colData() function, but improves support for accessing sample metadata for datasets where multiple items in the columns map to a single sample (e.g. cells for a single-cell RNA-seq experiment).

Note

Updated 2023-03-27.

SingleCellExperiment

Recommended colData:

  • sampleId: factor defining cell-to-sample mappings. These mappings should use syntactically valid names. Note that this is not currently required as we're supporting SingleCellExperiment objects from 1 sample, but it's required for working with multiple samples in a single object.

Examples

data(SingleCellExperiment_splatter, package = "AcidTest")

## SingleCellExperiment ====
object <- SingleCellExperiment_splatter
sampleData(object)
#> DataFrame with 4 rows and 2 columns
#>         sampleName interestingGroups
#>           <factor>          <factor>
#> sample3    sample3           sample3
#> sample4    sample4           sample4
#> sample1    sample1           sample1
#> sample2    sample2           sample2

## Assignment support.
sampleData(object)[["batch"]] <- 1L
#> DataFrame with 400 rows and 3 columns
#>         sampleId sampleName     batch
#>         <factor>   <factor> <integer>
#> cell001  sample3    sample3         1
#> cell002  sample3    sample3         1
#> cell003  sample4    sample4         1
#> cell004  sample1    sample1         1
#> cell005  sample2    sample2         1
#> ...          ...        ...       ...
#> cell396  sample3    sample3         1
#> cell397  sample4    sample4         1
#> cell398  sample3    sample3         1
#> cell399  sample3    sample3         1
#> cell400  sample2    sample2         1
## `batch` column should be now defined.
sampleData(object)
#> DataFrame with 4 rows and 2 columns
#>         sampleName interestingGroups
#>           <factor>          <factor>
#> sample3    sample3           sample3
#> sample4    sample4           sample4
#> sample1    sample1           sample1
#> sample2    sample2           sample2