bioalpha.singlecell.tools.tsne
- bioalpha.singlecell.tools.tsne(adata: AnnData, n_pcs: int | None = None, use_rep: str | None = None, rep_name: str = 'X_tsne', perplexity: float = 30, early_exaggeration: float = 12, learning_rate: float | None = None, random_state: None | int | RandomState = 0, copy: bool = False, **kwargs) AnnData | None
Run t-SNE t-distributed stochastic neighborhood embedding (tSNE).
- Parameters:
adata (
AnnData
) – The annotated data matrix of shapen_obs
xn_vars
. Rows correspond to cells and columns to genes.n_pcs (Optional[
int
], default =None
,) – Use this many PCs. Ifn_pcs==0
use.X
ifuse_rep is None
.use_rep (Optional[
str
]) – Use the indicated representation."X"
or any key for.obsm
is valid. IfNone
, the representation is chosen automatically: For.n_vars
< 50,.X
is used, otherwise “X_pca” is used. If “X_pca” is not present, it’s computed with default parameters.rep_name (
str
, default ="X_tsne"
) – Representation name that will be saved inadata.obsm
perplexity (
float
, default =30
) – The perplexity is related to the number of nearest neighbors that is used in other manifold learning algorithms. Larger datasets usually require a larger perplexity. Consider selecting a value between5
and50
. The choice is not extremely critical since t-SNE is quite insensitive to this parameter.early_exaggeration (
float
, default =12
) – Controls how tight natural clusters in the original space are in the embedded space and how much space will be between them. For larger values, the space between natural clusters will be larger in the embedded space. Again, the choice of this parameter is not very critical. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high.learning_rate (Optional[
float
], default =None
) – Note that the R-package “Rtsne” uses a default of200
. The learning rate can be a critical parameter. It should be between100
and1000
. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high. If the cost function gets stuck in a bad local minimum increasing the learning rate helps sometimes.random_state (Optional[Union[
int
,RandomState
]], default =0
) – Change this to use different intial states for the optimization. IfNone
, the initial state is not reproducible.copy (
bool
, default =False
) – Whether to copyadata
or modify it inplace.kwargs (
dict
) – Any additional arguments will be passed to_sctools.dimred.tsne
.
- Returns:
adata – If
copy=True
it returns or else adds fields toadata
:.obsm[
rep_name
] tSNE coordinates of data.
- Return type:
AnnData