This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ReporteR.scRNAseq/inst/content/05-dimension-reduction-B-tsne-dist.Rmd
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
72 lines (56 sloc)
3.53 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r parameters-and-defaults, include = FALSE} | |
module <- "scRNAseq" | |
section <- "dimension_reduction" | |
``` | |
```{r parameter-merge, include = FALSE} | |
local_params <- module %>% | |
options() %>% | |
magrittr::extract2(module) %>% | |
magrittr::extract2(section) %>% | |
ReporteR.base::validate_params(parameters_and_defaults) | |
``` | |
```{r scRNAseq-dimension-reduction-B-tsne-dist-checks, include = FALSE} | |
assertive.sets::assert_is_subset(local_params$features, colnames(SummarizedExperiment::colData(object_filtered))) | |
``` | |
### t-SNE based on cell-to-cell correlation | |
**t**-**S**tochastic **N**eighbor **E**mbedding[@maaten_tsne_2008] (t-SNE) converts a high-dimensional data set into a low-dimensional representation using pairwise similarity between objects of the data set. t-SNE claims to be able to capture much of the local structure in a data set, while also revealing global structures like *clusters*. t-SNE adapts to the data by applying different transformations on different regions in the data space, using many iterations over the data. Further, t-SNE allows to balance the importance of local vs. global structures via an important *perplexity* parameter, which has, together with the data adaptation step, complex effects on the resulting dimensionality reduction. | |
```{r scRNAseq-dimension-reduction-B-tsne-dist-processing, include=FALSE, echo=FALSE} | |
input <- SummarizedExperiment::assay(object_filtered, local_params$assay) | |
if (local_params$subset_het) { | |
input <- input[SummarizedExperiment::rowData(object_filtered)$is_het, ] | |
} | |
dissimilarity <- (1 - WGCNA::cor(input, method = local_params$wgcna_cor_method)) / local_params$wgcna_cor_denominator | |
if (local_params$tsne_dist) { | |
di <- as.dist(dissimilarity) | |
} else { | |
di <- dissimilarity | |
} | |
# Allow choosing perplexity automatically | |
if (local_params$tsne_perplexity < 0) { | |
perplexity <- floor(ncol(as.matrix(di))/5) | |
} else { | |
perplexity <- local_params$tsne_perplexity | |
} | |
tsne <- Rtsne::Rtsne(as.matrix(di), dims = local_params$dims, is_distance = local_params$tsne_dist, perplexity = perplexity, max_iter = local_params$maxiter) | |
SingleCellExperiment::reducedDim(object_filtered, "tsne-dist") <- tsne$Y | |
``` | |
```{r scRNAseq-dimension-reduction-B-tsne-dist-figure-params, include = FALSE, echo = FALSE} | |
fig_height <- ReporteR.base::estimate_figure_height( | |
height_in_panels = 1, | |
panel_height_in_in = params$formatting_defaults$figures$panel_height_in, | |
axis_space_in_in = params$formatting_defaults$figures$axis_space_in, | |
mpf_row_space = as.numeric(grid::convertUnit(grid::unit(5, 'mm'), 'in')), | |
max_height_in_in = params$formatting_defaults$figures$max_height_in) | |
caption_tsne <- glue::glue("Dimensionality reduction using t-SNE [@maaten_tsne_2008] on a dissimilarity structure (calculated as *1 - {local_params$wgcna_cor_method} correlation*) with a perplexity value of {perplexity} and {local_params$tsne_iter} epochs of learning.") | |
``` | |
```{r scRNAseq-dimension-reduction-B-tsne-dist-figure, echo = FALSE, message=FALSE, warning=FALSE, fig.height = fig_height$global, fig.cap = caption_tsne} | |
figure_dimred_tsne_dist <- multipanelfigure::multi_panel_figure(height = fig_height$sub, columns = min(3, length(local_params$features)), rows = 1, unit = "in") | |
for(i in 1:min(3, length(local_params$features))) { | |
tmp_plot <- object_filtered %>% | |
scater::plotReducedDim(use_dimred = "tsne-dist", colour_by = local_params$features[i], add_ticks = FALSE) + | |
ggplot2::guides(colour = FALSE) + | |
theme_dimred_scatter | |
figure_dimred_tsne_dist <- multipanelfigure::fill_panel(figure_dimred_tsne_dist, tmp_plot) | |
} | |
figure_dimred_tsne_dist | |
``` |