makeSummarizedExperiment: Make a SummarizedExperiment object

View source: R/makeSummarizedExperiment.R

makeSummarizedExperimentR Documentation

Make a SummarizedExperiment object

Description

This function is a utility wrapper for SummarizedExperiment that provides automatic subsetting for row and column data, as well as automatic handling of transgenes and spike-ins.

Usage

makeSummarizedExperiment(
  assays = S4Vectors::SimpleList(),
  rowRanges = GenomicRanges::GRanges(),
  rowData = NULL,
  colData = S4Vectors::DataFrame(),
  metadata = list(),
  transgeneNames = NULL,
  denylist = TRUE,
  sort = TRUE,
  sessionInfo = TRUE
)

Arguments

assays

SimpleList. Count matrices, which must have matching dimensions. Counts can be passed in as either a dense matrix (matrix) or sparse matrix (sparseMatrix).

rowRanges

GenomicRanges or GenomicRangesList. Genomic ranges (e.g. genome annotations). Metadata describing the assay rows.

rowData

DataFrame. Metadata describing the assay rows, if genomic ranges are not available. Use rowRanges (GenomicRanges) instead, if possible.

colData

DataFrame. Metadata describing the assay columns. For bulk RNA-seq, this data describes the samples. For single-cell RNA-seq, this data describes the cells.

metadata

list. Metadata.

transgeneNames

character. Vector indicating which assay rows denote transgenes (e.g. EGFP, TDTOMATO).

denylist

logical(1). Apply a denylist check on illegal column names defined in colData. This is useful for catching names that are not considered best practice, and other values that may conflict with Acid Genomics packages. Refer to metadataDenylist for the current list of offending values.

sort

logical(1). Ensure all row and column names are sorted alphabetically. This includes columns inside rowData and colData, and metadata slot names. Assay names are required to contain counts as the first assay.

sessionInfo

logical(1). Slot session information into metadata.

Value

  • Providing rowRanges: RangedSummarizedExperiment.

  • Providing rowData: SummarizedExperiment.

Session information

This function improves upon the standard constructor by slotting useful session information into the metadata slot by default:

  • date: Today's date, returned from Sys.Date.

  • sessionInfo: sessioninfo::session_info() return. This behavior can be disabled by setting sessionInfo = FALSE.

  • wd: Working directory, returned from getwd.

Note

Updated 2022-09-20.

See Also

  • SummarizedExperiment().

  • help("RangedSummarizedExperiment-class", "SummarizedExperiment").

  • help("SummarizedExperiment-class", "SummarizedExperiment").

Examples

## Rows (genes)
genes <- c(
    sprintf("gene%02d", seq_len(3L)),
    "EGFP" # transgene
)
print(genes)

## Columns (samples)
samples <- sprintf("sample%02d", seq_len(4L))
print(samples)

## Counts (assay)
counts <- matrix(
    data = seq_len(length(genes) * length(samples)),
    nrow = length(genes),
    ncol = length(samples),
    dimnames = list(genes, samples)
)
## Primary assay must be named "counts".
assays <- S4Vectors::SimpleList("counts" = counts)
print(assays)

## Row data (genomic ranges)
## Note that we haven't defined the transgene here.
## It will be handled automatically in the function call.
rowRanges <- AcidGenomes::emptyRanges(head(genes, n = length(genes) - 1L))
print(rowRanges)

## Column data
colData <- S4Vectors::DataFrame(
    "age" = rep(
        x = c(3L, 6L),
        times = length(samples) / 2L
    ),
    "genotype" = rep(
        x = c("wildtype", "knockout"),
        times = 1L,
        each = length(samples) / 2L
    ),
    row.names = samples
)
print(colData)

## Minimal mode.
x <- makeSummarizedExperiment(assays = assays)
print(x)

x <- makeSummarizedExperiment(
    assays = assays,
    rowRanges = rowRanges,
    colData = colData,
    transgeneNames = "EGFP"
)
print(x)

acidgenomics/r-acidexperiment documentation built on Jan. 17, 2024, 7:56 p.m.