This vignette introduces the cytoviewer
package for
interactive multi-channel image visualization. Images as well as
corresponding segmentation masks generated by imaging mass cytometry
(IMC) and other highly multiplexed imaging techniques can be
interactively visualized and explored.
The cytoviewer
package builds on top of the cytomapper
Bioconductor package (Eling et al. 2020)
and extends the static visualization strategies provided by
cytomapper
via an interactive Shiny
application. The cytoviewer
package leverages the
image handling, analysis and visualization strategies provided by the
EBImage
Bioconductor package and offers interactive image visualization
strategies in a similar fashion as iSEE for
single-cell data. In addition, building up on SingleCellExperiment,
SpatialExperiment
and cytomapper::CytoImageList
classes, the
cytoviewer
package integrates into the Bioconductor
framework for single-cell and image analysis.
Read the pre-print here.
Highly multiplexed imaging allows simultaneous spatially and single-cell resolved detection of dozens of biological molecules (e.g. proteins) in their native tissue context. As a result, these technologies allow an in-depth analysis of complex systems and diseases such as the tumor microenvironment (Jackson et al. 2020) and type 1 diabetes progression (Damond et al. 2019).
Imaging-based spatial proteomics methods (Moffitt, Lundberg, and Heyn 2022) can be broadly divided into fluorescent cyclic approaches such as tissue-based cyclic immunofluorescence (t-CyCIF) (Lin et al. 2018) and one-step mass-tag based approaches such as multiplexed ion beam imaging (MIBI) (Angelo et al. 2014) and IMC (Giesen et al. 2014).
Of note, the instructions below will focus on the visualization and
exploration of IMC data as an example. However, data
from other technologies such as t-CyCIF or MIBI, which produce
pixel-level intensities and (optionally) segmentation masks, can be
interactively visualized with cytoviewer
as long as they
have the appropriate input format (see Section Data input format).
IMC, an advancement of CyTOF, combines antibodies tagged with isotopically pure rare earth metals with laser ablation and mass-spectrometry-based detection to produce high-dimensional images (Giesen et al. 2014). It captures the spatial expression of over 40 proteins in parallel at a sub-cellular resolution of 1 μm. Thus, IMC is able to detect cytoplasmic and nuclear localization of proteins.
To fully leverage the information contained in IMC and multiplexed imaging data in general, computational tools are of key importance.
The main analysis steps, irrespective of the biological question, include 1) Visual inspection of images for quality control, 2) Image pre-processing and segmentation and 3) Single-cell and spatial analysis (Windhager, Bodenmiller, and Eling 2021).
A comprehensive end-to-end workflow for multiplexed image processing and analysis with detailed information for every analysis step can be found here.
Importantly, the cytoviewer
package can support,
simplify and improve any of these analysis steps with its easy-to-use
interactive visualization interface in R.
Below we will showcase an example
workflow that highlights the different functionality and potential
application fields of cytoviewer
.
The cytoviewer
interface is broadly divided into image-level (Composite and Channels) and cell-level visualization (Masks). It allows users
to overlay individual images with segmentation masks, integrates well
with SingleCellExperiment
and
SpatialExperiment
objects for metadata visualization and
supports image downloads (Figure
2B).
The cytoviewer
package combines objects of SingleCellExperiment,
SpatialExperiment
and cytomapper::CytoImageList
classes (from cytomapper)
to visualize image- and cell-level information.
The cytoviewer
function takes up to five
arguments.
Firstly, image
refers to a CytoImageList
object containing one or multiple multi-channel images where each
channel represents the pixel-intensities of one marker (proteins in
IMC).
Secondly, mask
refers to a CytoImageList
object containing one or multiple segmentation masks. Segmentation masks
are defined as one-channel images containing integer values, which
represent the cell ids or background.
Thirdly, the object
entry refers to a
SingleCellExperiment
or SpatialExperiment
class object that contains cell-specific metadata in the
colData
slot.
Lastly, to match information between the CytoImageList
objects and the
SingleCellExperiment
/SpatialExperiment
object,
two additional spots can be specified:
img_id
: a single character indicating the
colData
(of the
SingleCellExperiment
/SpatialExperiment
object)
and elementMetadata
(of the CytoImageList
object) entry that contains the image identifiers. These image ids have
to match between the SingleCellExperiment
/
SpatialExperiment
object and the CytoImageList
objects.
cell_id
: a single character indicating the
colData
entry that contains the cell identifiers. These
should be integer values corresponding to pixel-values in the
segmentation masks.
For more detailed information on the input objects, please refer to the respective documentation (e.g. the vignettes of the cytomapper or SingleCellExperiment/ SpatialExperiment packages).
In the Read in data section, we provide
example code to directly read in images and masks (e.g. in .tiff format)
into a CytoImageList
object and create a
SingleCellExperiment
object from them, which we can then
visualize with cytoviewer
.
The functionality of cytoviewer
depends on which input
objects are user-provided. Below we describe the four use
cases in respect to input objects and functionality.
1. Usage of cytoviewer with images, masks and object
The full functionality of cytoviewer can be leveraged when
image
, mask
and object
are
provided, which is the main intended use case.
This allows image-level visualization (Composite and Channels), cell-level visualization, overlaying images with segmentation masks as well as metadata visualization.
2. Usage of cytoviewer with images only
If only the image
object is specified, image-level visualization (Composite and
Channels) is possible.
3. Usage of cytoviewer with images and masks
Image-level visualization (Composite and
Channels), overlaying of images with segmentation masks and cell-level visualization is feasible when
image
and mask
objects are provided.
4. Usage of cytoviewer with masks and object
If mask
and object
are specified, cell-level visualization as well as metadata
visualization is possible.
The cytoviewer
package can be installed from
Bioconductor
via:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("cytoviewer")
The development version of cytoviewer
can be installed
from Github via:
if (!requireNamespace("remotes", quietly = TRUE))
install.packages("remotes")
remotes::install_github("BodenmillerGroup/cytoviewer")
To load the package in your R session, type the following:
For visualization purposes, we will use a toy dataset provided by the cytomapper package.
The dataset contains 3 images of 100μm x 100μm dimensions with 362 segmented cells and pixel-intensities for 5 proteins: H3, CD99, PIN, CD8a, and CDH. It is a small subset from a Type 1 Diabetes dataset (Damond et al. 2019).
Pixel-level intensities for all 5 markers (5 channels) are stored in
the pancreasImages
object.
The corresponding segmentation masks are stored in the
pancreasMasks
object.
All cell-specific metadata are stored in the colData
slot of the corresponding SingleCellExperiment
object:
pancreasSCE
.
For more detailed information on the dataset, please refer to the
respective documentation (e.g. via ?pancreasImages
or the
vignette of the cytomapper
package).
We also provide example code to directly read in images and masks
(e.g. in .tiff format) into a CytoImageList
object and
create a SingleCellExperiment
object from them in the Read in data section.
# Load example datasets
library(cytomapper)
data("pancreasImages")
data("pancreasMasks")
data("pancreasSCE")
pancreasImages
## CytoImageList containing 3 image(s)
## names(3): E34_imc G01_imc J02_imc
## Each image contains 5 channel(s)
## channelNames(5): H3 CD99 PIN CD8a CDH
## CytoImageList containing 3 image(s)
## names(3): E34_mask G01_mask J02_mask
## Each image contains 1 channel
## class: SingleCellExperiment
## dim: 5 362
## metadata(0):
## assays(2): counts exprs
## rownames(5): H3 CD99 PIN CD8a CDH
## rowData names(4): MetalTag Target clean_Target frame
## colnames(362): E34_824 E34_835 ... J02_4190 J02_4209
## colData names(9): ImageName Pos_X ... MaskName Pattern
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
Here as an example, we call cytoviewer
with
image
, mask
and object
data to
leverage all provided functionality.
This setting allows image-level visualization (Composite and Channels), cell-level visualization, overlaying images with segmentation masks as well as metadata visualization.
For further details, please refer to the ?cytoviewer
manual or the Help page
within the shiny application.
The cytoviewer
interface is divided into a
Header, Sidebar and
Body section (see Figure below).
The Header includes package version information, access to session information and the help page as well as a dropdown-menu for image downloads.
The Body features a Tabset-Panel layout allowing the user to switch between three image modes: Image-level (Composite and Channels) and Cell-level (Mask). Furthermore, the Composite and Mask tabs have zoom controls.
The Sidebar panel is subdivided into four sections: Sample selection, Image-level, Cell-level and General controls.
Image visualization control is split into basic and advanced controls.
Basic controls supports the selection of up to six
markers/channels for image
display. Each marker has color
control settings that allow the user to set contrast, brightness, gamma
and select a channel color.
In the advanced controls part, the user can choose to
overlay the displayed images with provided segmentation
masks
. Outline color and mask thickness can be adjusted by
the user. Moreover, the masks can be outlined by cell-specific metadata
provided in colData
slot of the object
.
Of note, for categorical and continuous metadata entries the user can choose between discrete colors and continuous color palettes (viridis, inferno, plasma), respectively.
Cell visualization has basic controls.
Here, the user can choose to display the provided segmentation
masks
. If an object
is provided, the masks can
be colored by cell-specific metadata.
Please note again that for categorical and continuous metadata entries the user can choose between discrete colors and continuous color palettes (viridis, inferno, plasma), respectively.
General controls is subdivided into an Image appearance and Image filters part.
In the Image appearance section, the user can adjust the scale bar length and include legend/image titles, while the Image filters section allows to control pixel-wise interpolation (default) and apply a Gaussian filter.
The cytoviewer
package supports fast and uncomplicated
image downloads.
Download controls are part of the Header (see Section Interface).
The user can specify a file name, select the image of interest (Composite, Channels, Mask) and the file format (pdf, png). Upon clicking the download button, a pop-window should appear where the user can specify the download location.
To conveniently read in images and segmentation masks into a
CytoImageList
object and then visualize these using
cytoviewer
, the cytomapper
package provides
the loadImages
function.
The loadImages
function returns a
CytoImageList
object containing the multi-channel images or
segmentation masks. Refer to the ?loadImages
function to
see the full functionality.
As an example, we will read in multi-channel images and segmentation
masks provided by the cytomapper
package.
To correctly scale pixel values of the segmentation masks when
reading them in, we will need to set as.is = TRUE
. Users
needs to take care that pixel values are scaled correctly in more
complex cases.
library(cytomapper)
# Data directory that stores images and masks in tiff format
data_path <- system.file("extdata", package = "cytomapper")
# Read in images
cur_images <- loadImages(data_path, pattern = "_imc.tiff")
cur_images
## CytoImageList containing 3 image(s)
## names(3): E34_imc G01_imc J02_imc
## Each image contains 5 channel(s)
## CytoImageList containing 3 image(s)
## names(3): E34_mask G01_mask J02_mask
## Each image contains 1 channel
To link images between the two CytoImageList
objects and
the corresponding SingleCellExperiment
object, the image
ids need to be added to the elementMetadata
slot of the
CytoImageList
objects.
## [1] "E34_imc" "G01_imc" "J02_imc"
## [1] "E34_mask" "G01_mask" "J02_mask"
To access the correct images in the multi-channel
CytoImageList
object, the user needs to set the correct
channel names. For this, the cytomapper
package provides
the ?channelNames
getter and setter function:
Based on the processed segmentation masks and multi-channel images,
cytomapper
can be used to measure cell-specific intensities
and morphological features. Here, these features are stored in form of a
SingleCellExperiment
object.
## class: SingleCellExperiment
## dim: 5 362
## metadata(0):
## assays(1): counts
## rownames(5): H3 CD99 PIN CD8a CDH
## rowData names(0):
## colnames: NULL
## colData names(8): ImageNb object_id ... m.majoraxis m.eccentricity
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
Next, we can again call cytoviewer
with the generated
image
, mask
and object
data and
leverage all provided functionality.
# Use cytoviewer with images, masks and object
app_1 <- cytoviewer(image = cur_images,
mask = cur_masks,
object = cur_sce,
img_id = "ImageNb",
cell_id = "object_id")
if (interactive()) {
shiny::runApp(app_1, launch.browser = TRUE)
}
For more detailed information on the input objects, please refer to the respective documentation (the vignettes of the cytomapper or SingleCellExperiment/ SpatialExperiment packages).
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] cytomapper_1.19.0 SingleCellExperiment_1.29.1
## [3] SummarizedExperiment_1.37.0 Biobase_2.67.0
## [5] GenomicRanges_1.59.1 GenomeInfoDb_1.43.2
## [7] IRanges_2.41.1 S4Vectors_0.45.2
## [9] BiocGenerics_0.53.3 generics_0.1.3
## [11] MatrixGenerics_1.19.0 matrixStats_1.4.1
## [13] EBImage_4.49.0 cytoviewer_1.7.0
## [15] BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] bitops_1.0-9 gridExtra_2.3 rlang_1.1.4
## [4] magrittr_2.0.3 svgPanZoom_0.3.4 shinydashboard_0.7.2
## [7] compiler_4.4.2 png_0.1-8 systemfonts_1.1.0
## [10] fftwtools_0.9-11 vctrs_0.6.5 pkgconfig_2.0.3
## [13] SpatialExperiment_1.17.0 crayon_1.5.3 fastmap_1.2.0
## [16] magick_2.8.5 XVector_0.47.0 fontawesome_0.5.3
## [19] utf8_1.2.4 promises_1.3.2 rmarkdown_2.29
## [22] UCSC.utils_1.3.0 ggbeeswarm_0.7.2 xfun_0.49
## [25] zlibbioc_1.52.0 cachem_1.1.0 jsonlite_1.8.9
## [28] later_1.4.1 rhdf5filters_1.19.0 DelayedArray_0.33.2
## [31] Rhdf5lib_1.29.0 BiocParallel_1.41.0 jpeg_0.1-10
## [34] tiff_0.1-12 terra_1.7-83 parallel_4.4.2
## [37] R6_2.5.1 bslib_0.8.0 RColorBrewer_1.1-3
## [40] jquerylib_0.1.4 Rcpp_1.0.13-1 knitr_1.49
## [43] httpuv_1.6.15 Matrix_1.7-1 nnls_1.6
## [46] tidyselect_1.2.1 viridis_0.6.5 abind_1.4-8
## [49] yaml_2.3.10 codetools_0.2-20 miniUI_0.1.1.1
## [52] lattice_0.22-6 tibble_3.2.1 shiny_1.9.1
## [55] evaluate_1.0.1 archive_1.1.10 shinycssloaders_1.1.0
## [58] pillar_1.9.0 BiocManager_1.30.25 sp_2.1-4
## [61] RCurl_1.98-1.16 ggplot2_3.5.1 munsell_0.5.1
## [64] scales_1.3.0 xtable_1.8-4 glue_1.8.0
## [67] maketools_1.3.1 tools_4.4.2 sys_3.4.3
## [70] colourpicker_1.3.0 locfit_1.5-9.10 buildtools_1.0.0
## [73] rhdf5_2.51.0 grid_4.4.2 colorspace_2.1-1
## [76] GenomeInfoDbData_1.2.13 raster_3.6-30 beeswarm_0.4.0
## [79] HDF5Array_1.35.1 vipor_0.4.7 cli_3.6.3
## [82] fansi_1.0.6 viridisLite_0.4.2 S4Arrays_1.7.1
## [85] svglite_2.1.3 dplyr_1.1.4 gtable_0.3.6
## [88] sass_0.4.9 digest_0.6.37 SparseArray_1.7.2
## [91] rjson_0.2.23 htmlwidgets_1.6.4 memoise_2.0.1
## [94] htmltools_0.5.8.1 lifecycle_1.0.4 httr_1.4.7
## [97] mime_0.12