From 21e6c4c6859eae3d67c63b97cd45eb0fbacdf677 Mon Sep 17 00:00:00 2001 From: lassedochreden Date: Mon, 12 Feb 2024 15:57:28 +0100 Subject: [PATCH 1/2] updated plotCells object scaling --- 10-image_visualization.Rmd | 37 ++++++++++++++++++++++--------------- CHANGELOG.md | 6 +++++- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/10-image_visualization.Rmd b/10-image_visualization.Rmd index 1584a81..9961eb4 100644 --- a/10-image_visualization.Rmd +++ b/10-image_visualization.Rmd @@ -31,7 +31,7 @@ spe <- readRDS("data/spe.rds") images <- readRDS("data/images.rds") masks <- readRDS("data/masks.rds") -# Sample images +# Sample images and masks set.seed(220517) cur_id <- sample(unique(spe$sample_id), 3) cur_images <- images[names(images) %in% cur_id] @@ -180,7 +180,7 @@ distribution of cell phenotypes, the visual assessment of morphological features and quality control in terms of cell segmentation and phenotyping. -### Visualzing metadata +### Visualizing metadata The `cytomapper` package provides the `plotCells` function that accepts a `CytoImageList` object containing segmentation masks. These are @@ -245,18 +245,22 @@ plotCells(cur_masks, In terms of visualizing metadata, any entry in the `colData(spe)` slot can be visualized. The `plotCells` function automatically detects if the -entry is continuous or discrete. In this fashion, we can now visualize -the area of each cell: +entry is continuous or discrete. For continuous features, `cytomapper` scales +across the whole `SpatialExperiment` object. Therefore, we will subset the +object to only contain the 3 visualized images. In this fashion, we can now +visualize the area of each cell: ```{r area} +cur_spe <- spe[,spe$sample_id %in% cur_id] + plotCells(cur_masks, - object = spe, + object = cur_spe, cell_id = "ObjectNumber", img_id = "sample_id", colour_by = "area") ``` -### Visualizating expression +### Visualizing expression Similar to visualizing single-cell metadata on segmentation masks, we can use the `plotCells` function to visualize the aggregated pixel @@ -264,14 +268,17 @@ intensities per cell. In the current dataset pixel intensities were aggregated by computing the mean pixel intensity per cell and per channel. The `plotCells` function accepts the `exprs_values` argument (default `counts`) that allows selecting the assay which stores the -expression values that should be visualized. +expression values that should be visualized. Similar to continuous +`colData(spe)` features, `cytomapper` scales the expression values across +the whole `SpatialExperiment` object. We will again subset the object +to only contain the 3 visualized images. In the following example, we visualize the asinh-transformed mean pixel intensities of the epithelial marker E-cadherin on segmentation masks. ```{r Ecad-expression} plotCells(cur_masks, - object = spe, + object = cur_spe, cell_id = "ObjectNumber", img_id = "sample_id", colour_by = "Ecad", @@ -286,7 +293,7 @@ spatial distribution of tumor cells (E-cadherin), T cells (CD3), B cells ```{r 6-channel-expression} plotCells(cur_masks, - object = spe, + object = cur_spe, cell_id = "ObjectNumber", img_id = "sample_id", colour_by = c("Ecad", "CD3", "CD20", "CD8a", "CD38", "Ki67"), @@ -304,7 +311,7 @@ argument: ```{r setting-expression-colors} plotCells(cur_masks, - object = spe, + object = cur_spe, cell_id = "ObjectNumber", img_id = "sample_id", colour_by = c("Ecad", "CD3", "CD20"), @@ -330,7 +337,7 @@ the cells' outlines by their cell phenotype. ```{r outlining-all-cells} plotPixels(image = cur_images, mask = cur_masks, - object = spe, + object = cur_spe, cell_id = "ObjectNumber", img_id = "sample_id", colour_by = c("Ecad", "CD3", "CD20"), @@ -338,14 +345,14 @@ plotPixels(image = cur_images, bcg = list(Ecad = c(0, 5, 1), CD3 = c(0, 5, 1), CD20 = c(0, 5, 1)), - colour = list(celltype = metadata(spe)$color_vectors$celltype), + colour = list(celltype = metadata(cur_spe)$color_vectors$celltype), thick = TRUE) ``` Distinguishing individual cell phenotypes is nearly impossible in the images above. -However, the `SpatialExperiment` object can be subsetted to only contain +However, the `SpatialExperiment` object can be further subsetted to only contain cells of a single or few phenotypes. This allows the selective visualization of cell outlines on composite images. @@ -353,7 +360,7 @@ Here, we select all CD8+ T cells from the dataset and outline them on a 2-channel composite image displaying the expression of CD3 and CD8a. ```{r outlining-CD8} -CD8 <- spe[,spe$celltype == "CD8"] +CD8 <- cur_spe[,cur_spe$celltype == "CD8"] plotPixels(image = cur_images, mask = cur_masks, @@ -467,7 +474,7 @@ out1 <- plotCells(cur_masks, return_plot = TRUE) out2 <- plotCells(cur_masks, - object = spe, + object = cur_spe, cell_id = "ObjectNumber", img_id = "sample_id", colour_by = c("Ecad", "CD3", "CD20"), diff --git a/CHANGELOG.md b/CHANGELOG.md index 50fd351..d31b204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,4 +13,8 @@ **Version 1.0.3** [2024-01-05] -- Updated cytoviewer citation and corresponding text \ No newline at end of file +- Updated cytoviewer citation and corresponding text + +**Version 1.0.4** [2024-02-12] + +- Updated cell-level visualization with subsetted object \ No newline at end of file From 34a534fbfa8a89a8f8b5e06d2da0ea7b41f3ded7 Mon Sep 17 00:00:00 2001 From: lassedochreden Date: Thu, 12 Jun 2025 09:19:23 +0200 Subject: [PATCH 2/2] trigger actions --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d31b204..f2b9836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,4 +17,4 @@ **Version 1.0.4** [2024-02-12] -- Updated cell-level visualization with subsetted object \ No newline at end of file +- Updated cell-level visualization with subsetted object - re-trigger actions \ No newline at end of file