convertTo {scran} | R Documentation

## Convert to other classes

### Description

Convert a SingleCellExperiment object into other classes for entry into other analysis pipelines.

### Usage

    ## S4 method for signature 'SingleCellExperiment'
    convertTo(x, type=c("edgeR", "DESeq2", "monocle"),
        row.fields=NULL, col.fields=NULL, ..., assay.type,
        use.all.sf=TRUE, subset.row=NULL, get.spikes=FALSE)

### Arguments

`x` | A SingleCellExperiment object.
`type` | A string specifying the analysis for which the object should be prepared.
`row.fields` | Any set of indices specifying which columns of `rowData(x)` should be retained in the returned object.
`col.fields` | Any set of indices specifying which columns of `colData(x)` should be retained.
`...` | Other arguments to be passed to pipeline-specific constructors.
`assay.type` | A string specifying which assay of `x` should be put in the returned object.
`use.all.sf` | A logical scalar indicating whether multiple size factors should be used to generate the returned object.
`subset.row` | A logical, integer or character scalar indicating the rows of `x` to return.
`get.spikes` | A logical scalar specifying whether rows corresponding to spike-in transcripts should be returned.

### Details

This function converts an SingleCellExperiment object into various other classes in preparation for entry into other analysis pipelines, as specified by `type`. Gene- and cell-specific data fields can be retained in the output object by setting `row.fields` and `col.fields`, respectively. Other arguments can be passed to the relevant constructors through the ellipsis.

By default, `assay.type` is set to `"counts"` such that count data is stored in the output object. This is consistent with the required inputs to analyses using count-based (e.g., negative binomial) models. Information about normalization is instead transmitted via size or normalization factors in the output object.

In all cases, rows corresponding to spike-in transcripts are removed from the output object by default. As such, rows in the returned object may not correspond directly to rows in `x`. Users should consider this when retrieving analysis results from these pipelines, e.g., match on row names in `x` before comparing to other results. This behaviour can be turned off by setting `get.spikes=TRUE`, such that all rows are retrieved in the output object. Users can also set `subset.row` to extract specific rows, in which case `get.spikes` is ignored.

For edgeR and DESeq2, different size factors for different rows (e.g., for spike-in sets) will be respected. For edgeR, an offset matrix will be constructed containing mean-centred log-size factors for each row. For DESeq2, a similar matrix will be constructed containing size factors scaled to have a geometric mean of unity. This behaviour can be turned off with `use.all.sf=FALSE`, such that only `sizeFactors(x)` is used for normalization for all `type`. (These matrices are not generated if all rows correspond to `sizeFactors(x)`, as this information is already stored in the object.)

### Value

For `type="edgeR"`, a DGEList object is returned containing the count matrix. Size factors are converted to normalization factors. Gene-specific `rowData` is stored in the `genes` element, and cell-specific `colData` is stored in the `samples` element.

For `type="DESeq2"`, a DESeqDataSet object is returned containing the count matrix and size factors. Additional gene- and cell-specific data is stored in the `mcols` and `colData` respectively.

For `type="monocle"`, a CellDataSet object is returned containing the count matrix and size factors. Additional gene- and cell-specific data is stored in the `rowData` and `colData` respectively.

### Author(s)

Aaron Lun

### See Also

`DGEList`, `DESeqDataSetFromMatrix`, `newCellDataSet`

### Examples

    example(computeSpikeFactors) # Using the mocked up data 'y' from this example.
    sizeFactors(y) <- 2^rnorm(ncells) # Adding some additional embellishments.
    rowData(y)$SYMBOL <- paste0("X", seq_len(nrow(y)))
    y$other <- sample(LETTERS, ncells, replace=TRUE)

    # Converting to various objects.
    convertTo(y, type="edgeR")
    convertTo(y, type="DESeq2")
    convertTo(y, type="monocle")

[Package scran version 1.8.4 Index]