Skip to contents

This function calculates a tSNE embedding using single-cell data from a `tof_tibble`.

Usage

tof_reduce_tsne(
  tof_tibble,
  tsne_cols = where(tof_is_numeric),
  num_comp = 2,
  perplexity = 30,
  theta = 0.5,
  max_iterations = 1000,
  verbose = FALSE,
  ...
)

Arguments

tof_tibble

A `tof_tbl` or `tibble`.

tsne_cols

Unquoted column names indicating which columns in `tof_tibble` to use in computing the tSNE embedding. Defaults to all numeric columns in `tof_tibble`. Supports tidyselect helpers.

num_comp

The number of tSNE components to calculate for the embedding. Defaults to 2.

perplexity

A positive numeric value that represents represents the rough balance between the input data’s local and global structure emphasized in the embedding. Smaller values emphasize local structure; larger values emphasize global structure. The recommended range is generally 5-50. Defaults to 30.

theta

A numeric value representing the speed/accuracy tradeoff for the embedding. Set to 0 for the exact tSNE; increase for a faster approximation. Defaults to 0.5

max_iterations

An integer number of iterations to use during embedding calculation. Defaults to 1000.

verbose

A boolean value indicating whether progress updates should be printed during embedding calculation. Default is FALSE.

...

Additional arguments to pass to Rtsne.

Value

A tibble with the same number of rows as `tof_tibble`, each representing a single cell. Each of the `num_comp` columns represents each cell's embedding in the calculated tSNE space.

See also

Other dimensionality reduction functions: tof_reduce_dimensions(), tof_reduce_pca(), tof_reduce_umap()

Examples

# simulate single-cell data
sim_data <-
    dplyr::tibble(
        cd45 = rnorm(n = 200),
        cd38 = rnorm(n = 200),
        cd34 = rnorm(n = 200),
        cd19 = rnorm(n = 200)
    )

# calculate tsne
tof_reduce_tsne(tof_tibble = sim_data)
#> # A tibble: 200 × 2
#>    .tsne1 .tsne2
#>     <dbl>  <dbl>
#>  1 -5.23   0.651
#>  2  0.253 -4.95 
#>  3 -3.33   5.10 
#>  4 -6.28  -2.15 
#>  5  4.39   0.355
#>  6 -2.62   0.632
#>  7 -3.55  -9.00 
#>  8  0.862 -2.13 
#>  9 -2.39  -0.260
#> 10 -5.35  -5.82 
#> # ℹ 190 more rows

# calculate tsne with only 2 columns
tof_reduce_tsne(tof_tibble = sim_data, tsne_cols = c(cd34, cd38))
#> # A tibble: 200 × 2
#>    .tsne1 .tsne2
#>     <dbl>  <dbl>
#>  1 -6.55  -3.80 
#>  2 -5.35   1.96 
#>  3  0.900  0.330
#>  4 -3.09  -5.67 
#>  5  2.06  -1.33 
#>  6 -0.282 -6.70 
#>  7 -5.48   4.56 
#>  8 -1.71  -1.26 
#>  9 -0.977 -6.83 
#> 10 -4.52  -1.36 
#> # ℹ 190 more rows