Last updated: 2019-12-16
Checks: 5 1
Knit directory: STUtility_web_site/
This reproducible R Markdown analysis was created with workflowr (version 1.3.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish
to commit the R Markdown file and build the HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20191031)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: analysis/.DS_Store
Ignored: analysis/about_cache/
Ignored: analysis/getting_started_cache/
Ignored: analysis/image_processing_cache/
Ignored: analysis/normalization_cache/
Ignored: docs/.DS_Store
Untracked files:
Untracked: analysis/3D_visualization.Rmd
Untracked: docs/figure/3D_visualization.Rmd/
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
There are no past versions. Publish this analysis with wflow_publish()
to start tracking its development.
STutility currently allows for visualization of features in 3D using a point cloud created from the nuclei detected in aligned HE images using the Create3DStack()
function. The cell nuclei coordinates are extracted based on color intensity as nuclei are typically darker in color than the surrounding tissue. This is not an exact cell segmentation but it will typically capture the density of nuclei well enough to define various morphological structures.
Once the nuclei coordinates have been extracted from each aligned section, a z value will be assigned to each section to create a 3D stack. Feature values can be interpolated across the points in the stack and then visualized in 3D by mapping the values to a colorscale. Below are a couple of criteria that has to be fulfilled for the method to work:
LoadImages()
, MaskImages()
and AlginImages()
(or ManualAlginImages()
) firstCreate3DStack()
will automatically reload the images in higher resolution if the image widths are lower than 400 pixels or you can run SwitchResolution()
to reload the images in higher resolution before running Create3DStack()
Once the stack has been created, a 2D grid will be created that covers the aligned tissue sections with its width determined by the nx
parameter. This grid will later be used to interpolate feature values over, so that we can assign a value to each point in the point cloud.
se <- Create3DStack(se)
We can plot the stacked coordinates in 2D to see what the point patterns look like. From the plot below you can see that a higher density of points is picked up in areas width darker color, which is typically the case for the tissue edges. However we can see that some structures such as the dentate gyrus have a higher density of nuclei as expected.
stack_3d <- setNames(GetStaffli(se)@scatter.data, c("x", "y", "z", "grid.cell"))
ggplot(stack_3d, aes(x, 2e3 - y)) +
geom_point(size = 0.1, color = "lightgray") +
facet_wrap(~z, ncol = 1) +
theme_void() +
theme(plot.background = element_rect(fill = "black"),
plot.title = element_text(colour = "white"),
legend.text = element_text(colour = "white"))
The next step to visualize features is to interpolate values across the point patterns. Since each point is assigned to a grid cell, we can interpolate values across the grid and assign an interpolated values back to the points. Remember that the width of the grid is determined by the nx
parameter and you can increase the resolution of the interpolation by setting nx
to a higher value when running the Create3DStack()
function. Increasing the value of this parameter will improve the “smoothness” of the colormap but will slow down the computation significantly.
interpolated.data <- FeaturePlot3D(se, features = "Mbp", return.data = TRUE)
ggplot(interpolated.data, aes(x, 2e3 - y, color = val)) +
geom_point(size = 0.1) +
facet_wrap(~z, ncol = 1) +
theme_void() +
ggtitle("Mbp") +
scale_color_gradientn(colours = c("black", "dark blue", "cyan", "yellow", "red", "dark red")) +
theme(plot.background = element_rect(fill = "black"),
plot.title = element_text(colour = "white"),
legend.text = element_text(colour = "white"))
To generate 3D plots you can use the visualization functions FeaturePlot3D()
, DimPlot3D()
, and HSVPlot3D()
. Each section will by default be assigned a z coordinate ranging from 1 to N where N is the number of samples. If you wish to change these z coordinates you can use the parameter zcoords
to map each section to a new value (note that you need to provide as many z coordinates as the number of samples in your Seurat object).
If you wish to force the sections closer to each other you can add margins to the z axis using the add.margins
parameter. This will essentially add empty space below and above the 3D stack and therefore push the sections closer.
Now we are ready to plot features in 3D. We’ll run the FeaturePlot3D()
function as above but with return.data = FALSE.
FeaturePlot3D(se, features = "Mbp", dark.theme = TRUE, pt.size = 0.6)
The 3D plots are drawn using the plotly
R package and you can specify a layout attribute called scene to the FeaturePlot3D()
to enable the visualization of multiple 3D plots at the same time. Below we plot the features “Mbp” and “Calb2” in two different scenes and we can then use subplot()
to visualize them side by side.
p1 <- FeaturePlot3D(se, features = "Mbp", scene = "scene", cols = c("black", "navyblue", "cyan", "white"), dark.theme = TRUE, add.margins = 1)
p2 <- FeaturePlot3D(se, features = "Calb2", scene = "scene2", cols = c("black", "navyblue", "cyan", "white"), dark.theme = TRUE, add.margins = 1)
plotly::subplot(p1, p2, margin = 0)
A work by Joseph Bergenstråhle and Ludvig Larsson
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] parallel stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] STutility_0.1.0 ggplot2_3.2.1
[3] SingleCellExperiment_1.6.0 SummarizedExperiment_1.14.1
[5] DelayedArray_0.10.0 BiocParallel_1.18.1
[7] matrixStats_0.55.0 Biobase_2.44.0
[9] GenomicRanges_1.36.1 GenomeInfoDb_1.20.0
[11] IRanges_2.18.3 S4Vectors_0.22.1
[13] BiocGenerics_0.30.0 Seurat_3.1.2
loaded via a namespace (and not attached):
[1] reticulate_1.13 R.utils_2.9.0
[3] tidyselect_0.2.5 htmlwidgets_1.5.1
[5] grid_3.6.1 Rtsne_0.15
[7] munsell_0.5.0 codetools_0.2-16
[9] ica_1.0-2 future_1.14.0
[11] miniUI_0.1.1.1 withr_2.1.2
[13] colorspace_1.4-1 knitr_1.25
[15] ROCR_1.0-7 tensor_1.5
[17] gbRd_0.4-11 listenv_0.7.0
[19] labeling_0.3 Rdpack_0.11-0
[21] git2r_0.26.1 GenomeInfoDbData_1.2.1
[23] mnormt_1.5-5 polyclip_1.10-0
[25] rprojroot_1.3-2 vctrs_0.2.0
[27] xfun_0.10 R6_2.4.0
[29] doParallel_1.0.15 rsvd_1.0.2
[31] Morpho_2.7 ggiraph_0.6.1
[33] manipulateWidget_0.10.0 bitops_1.0-6
[35] spatstat.utils_1.13-0 assertthat_0.2.1
[37] promises_1.1.0 SDMTools_1.1-221.1
[39] scales_1.0.0 imager_0.41.2
[41] gtable_0.3.0 npsurv_0.4-0
[43] globals_0.12.4 bmp_0.3
[45] goftest_1.1-1 workflowr_1.3.0
[47] rlang_0.4.1 zeallot_0.1.0
[49] akima_0.6-2 systemfonts_0.1.1
[51] splines_3.6.1 lazyeval_0.2.2
[53] rgl_0.100.30 yaml_2.2.0
[55] reshape2_1.4.3 abind_1.4-5
[57] crosstalk_1.0.0 backports_1.1.5
[59] httpuv_1.5.2 tools_3.6.1
[61] gplots_3.0.1.1 raster_3.0-7
[63] RColorBrewer_1.1-2 Rvcg_0.18
[65] ggridges_0.5.1 Rcpp_1.0.2
[67] plyr_1.8.4 zlibbioc_1.30.0
[69] purrr_0.3.2 RCurl_1.95-4.12
[71] rpart_4.1-15 deldir_0.1-23
[73] viridis_0.5.1 pbapply_1.4-2
[75] cowplot_1.0.0 zoo_1.8-6
[77] ggrepel_0.8.1 cluster_2.1.0
[79] colorRamps_2.3 fs_1.3.1
[81] magrittr_1.5 data.table_1.12.2
[83] magick_2.2 readbitmap_0.1.5
[85] lmtest_0.9-37 RANN_2.6.1
[87] fitdistrplus_1.0-14 shinyjs_1.0
[89] lsei_1.2-0 mime_0.7
[91] evaluate_0.14 xtable_1.8-4
[93] jpeg_0.1-8 gridExtra_2.3
[95] compiler_3.6.1 tibble_2.1.3
[97] KernSmooth_2.23-15 crayon_1.3.4
[99] R.oo_1.22.0 htmltools_0.4.0
[101] mgcv_1.8-29 later_1.0.0
[103] tiff_0.1-5 tidyr_1.0.0
[105] RcppParallel_4.4.4 lubridate_1.7.4
[107] MASS_7.3-51.4 Matrix_1.2-17
[109] R.methodsS3_1.7.1 gdata_2.18.0
[111] metap_1.1 igraph_1.2.4.1
[113] pkgconfig_2.0.3 sn_1.5-4
[115] numDeriv_2016.8-1.1 sp_1.3-1
[117] plotly_4.9.0 xml2_1.2.2
[119] foreach_1.4.7 webshot_0.5.1
[121] XVector_0.24.0 bibtex_0.4.2
[123] stringr_1.4.0 digest_0.6.22
[125] sctransform_0.2.0 RcppAnnoy_0.0.13
[127] tsne_0.1-3 spatstat.data_1.4-0
[129] rmarkdown_1.16 leiden_0.3.1
[131] uwot_0.1.5 gdtools_0.2.0
[133] shiny_1.4.0 gtools_3.8.1
[135] lifecycle_0.1.0 nlme_3.1-141
[137] jsonlite_1.6 viridisLite_0.3.0
[139] pillar_1.4.2 lattice_0.20-38
[141] fastmap_1.0.1 httr_1.4.1
[143] survival_2.44-1.1 glue_1.3.1
[145] spatstat_1.61-0 png_0.1-7
[147] iterators_1.0.12 stringi_1.4.3
[149] caTools_1.17.1.2 dplyr_0.8.3
[151] irlba_2.3.3 future.apply_1.3.0
[153] ape_5.3