Add t-SNE embedding to a MarchR object
add_tsne.RdComputes a t-SNE (t-distributed Stochastic Neighbor Embedding) embedding
from a previously computed dimensionality reduction (e.g. LSI, PCA, Harmony)
and stores the result in cell metadata. Uses the Rtsne package.
Usage
# Default S3 method
add_tsne(
x,
perplexity = 50,
max_iterations = 1000L,
n_components = 2L,
seed = 1L,
threads = get_threads(),
verbose = getOption("MarchR.verbose", FALSE),
tsne_params = list(),
...
)
# S3 method for class 'MarchRDataset'
add_tsne(
x,
embedding_name = character(0),
output_assay_name = "TSNE",
perplexity = 50,
max_iterations = 1000L,
n_components = 2L,
seed = 1L,
store_as_matrix = FALSE,
overwrite = FALSE,
threads = get_threads(),
verbose = getOption("MarchR.verbose", FALSE),
tsne_params = list(),
...
)
# S3 method for class 'MarchRProject'
add_tsne(
x,
embedding_name = character(0),
dataset_names = character(0),
output_assay_name = "TSNE",
perplexity = 50,
max_iterations = 1000L,
n_components = 2L,
seed = 1L,
store_as_matrix = FALSE,
overwrite = FALSE,
threads = get_threads(),
verbose = getOption("MarchR.verbose", FALSE),
tsne_params = list(),
...
)Arguments
- x
(MarchRProject) Project containing embedding assays.
- perplexity
(numeric) Perplexity parameter for t-SNE. Default is 50 (matching ArchR).
- max_iterations
(integer) Maximum number of iterations. Default is 1000 (matching ArchR).
- n_components
(integer) Number of t-SNE dimensions. Default is 2.
- seed
(integer) Random seed for reproducibility.
- threads
(integer) Number of threads.
- verbose
(logical) Print progress messages. Default
getOption("MarchR.verbose", FALSE).- tsne_params
(list) Additional parameters passed to
Rtsne::Rtsne(). These override any other arguments when there is a conflict.- ...
Additional arguments passed to specific methods.
- embedding_name
(character) Name of the embedding assay to use as input (e.g.
"PCA","LSI","Harmony"). Auto-selected if only one dimensionality reduction exists.- output_assay_name
(character) Prefix for the output columns stored in cell metadata. Default is
"TSNE", producing columnsTSNE_1,TSNE_2, etc. Also used as the assay name whenstore_as_matrix = TRUE.- store_as_matrix
(logical) If
TRUE, also store the t-SNE coordinates asIterableMatrixassays in addition to cell metadata. Default isFALSE.- overwrite
(logical) If
TRUE, overwrite existing metadata columns or assays.- dataset_names
(character) Names of datasets to include. Defaults to all datasets.
Value
A matrix of t-SNE coordinates (cells x n_components) with
rownames as cell names and colnames as TSNE_1, TSNE_2, etc.
The modified MarchRDataset with t-SNE coordinates added as cell metadata columns (and optionally as a matrix assay).
The modified MarchRProject with t-SNE coordinates added as cell metadata columns (and optionally as matrix assays) in each dataset.
Details
t-SNE is computed on a cells x dimensions dense matrix extracted from a
stored embedding assay (e.g. PCA or LSI output). The result is a 2D (or
n_components-dimensional) embedding stored as columns in cell
metadata (e.g. TSNE_1, TSNE_2). Optionally, the embedding
can also be stored as a matrix assay by setting store_as_matrix = TRUE.
The Rtsne package is used as the backend, matching ArchR's default.
The MarchRProject method extracts the joint embedding across all selected
datasets, computes t-SNE on the concatenated embedding (so coordinates are
comparable across datasets), then distributes results back to each dataset
as cell metadata columns. When store_as_matrix = TRUE, the
coordinates are additionally stored as matrix assays.
Methods (by class)
add_tsne(default): Compute t-SNE on a cells x dimensions matrixadd_tsne(MarchRDataset): Compute t-SNE for a MarchRDataset and store in cell metadataadd_tsne(MarchRProject): Compute t-SNE for a MarchRProject and store in cell metadata
ArchR correspondence
This function is analogous to ArchR's addTSNE().
ArchR defaults: perplexity = 50, maxIterations = 1000.
MarchR defaults match these values.