runDR {CATALYST} | R Documentation

## Perform dim. reduction on a `daFrame`

### Description

Wrapper function to perform dimensionality reduction methods on a `daFrame` object using `scater`.

### Usage

    runDR(x, ...)

    ## S4 method for signature 'daFrame'
    runDR(x, dr = c("TSNE", "PCA", "MDS", "UMAP",
      "DiffusionMap"), rows_to_use = 1000, cols_to_use = NULL,
      overwrite = FALSE, ...)

### Arguments

`x` | a `daFrame`.
`...` | additional parameters passed to the dim. reduction method (see `runTSNE`, `runPCA`, `runMDS`, `runUMAP`, and `runDiffusionMap`).
`dr` | character string specifying the dimensionaly reduction method.
`rows_to_use` | numeric vector of row indices (cells) to use. If NULL, all cells will be used. If a single integer value N, (default 1000) a subset of N cells will be drawn from each sample.
`cols_to_use` | character vector in `colnames(x)` or numeric vector of column indices to use for computing reduced dimensions.
`overwrite` | logical. Whether to force overwriting any existing dimension reduction of type `dr`.

### Value

a `daFrame` with an additional entry titled "`dr`" in the `reducedDims` slot of the input `daFrame`.

### Author(s)

Helena L. Crowell helena.crowell@uzh.ch

### Examples

    data(PBMC_fs, PBMC_panel, PBMC_md)
    daf <- daFrame(PBMC_fs, PBMC_panel, PBMC_md)
    daf <- cluster(daf)

    # PCA on all cells
    daf <- runDR(daf, "PCA")

    # UMAP on 1000 random cells
    daf <- runDR(daf, "UMAP", rows_to_use = sample(nrow(daf), 1e3))

    reducedDims(daf)
    head(reducedDim(daf, "UMAP"))

    # PCA on 200 cells per sample
    set.seed(1)
    daf <- runDR(daf, "PCA", rows_to_use = 200, overwrite = TRUE)

    # re-using PCA for t-SNE will fail when using different cells
    ## Not run:
    daf <- runDR(daf, "TSNE", rows_to_use = 1:500, use_dimred = "PCA")
    ## End(Not run)

    # use same seed to assure the same subset of cells is sampled
    set.seed(1)
    daf <- runDR(daf, "TSNE", rows_to_use = 200, use_dimred = "PCA")

    # number of rows used for each DR:
    vapply(reducedDims(daf), nrow, numeric(1))

    # running on subset can be done 2-ways
    daf2 <- runDR(daf, "MDS", 1:100)
    daf3 <- runDR(daf[1:100, ], "MDS")

    # option 1 keeps object-dimensions
    identical(dim(daf2), dim(daf))

    # option 2 keeps only specified rows
    all.equal(dim(daf3), c(100, ncol(daf)))

    # reduced dimension are identical
    identical(reducedDim(daf2), reducedDim(daf2))

    # run t-SNE on B-cell clusters only
    data(merging_table)
    daf <- mergeClusters(daf, "meta20", merging_table, "merging")
    cells_use <- grep("B-cells", cluster_ids(daf, "merging"))
    daf <- runDR(daf, "TSNE", cells_use, overwrite = TRUE)
    plotDR(daf, "TSNE", "merging")

[Package CATALYST version 1.6.7 Index]