vignettes/cell-colocalisation.Rmd
cell-colocalisation.Rmd
With SPIAT we can quantify cell colocalisation, which refers to how much two cell types are colocalising and thus potentially interacting.
In this vignette we will use an inForm data file that’s already been
formatted for SPIAT with format_image_to_spe()
, which we
can load with data()
. We will use
define_celltypes()
to define the cells with certain
combinations of markers.
data("simulated_image")
# define cell types
formatted_image <- define_celltypes(
simulated_image,
categories = c("Tumour_marker","Immune_marker1,Immune_marker2",
"Immune_marker1,Immune_marker3",
"Immune_marker1,Immune_marker2,Immune_marker4", "OTHER"),
category_colname = "Phenotype",
names = c("Tumour", "Immune1", "Immune2", "Immune3", "Others"),
new_colname = "Cell.Type")
We can calculate the average percentage of cells of one cell type
(target) within a radius of another cell type (reference) using
average_percentage_of_cells_within_radius()
.
average_percentage_of_cells_within_radius(spe_object = formatted_image,
reference_celltype = "Immune1",
target_celltype = "Immune2",
radius=100, feature_colname="Cell.Type")
## [1] 4.768123
Alternatively, this analysis can also be performed based on marker
intensities rather than cell types. Here, we use
average_marker_intensity_within_radius()
to calculate the
average intensity of the target_marker within a radius from the cells
positive for the reference marker. Note that it pools all cells with the
target marker that are within the specific radius of any reference cell.
Results represent the average intensities within a radius.
average_marker_intensity_within_radius(spe_object = formatted_image,
reference_marker ="Immune_marker3",
target_marker = "Immune_marker2",
radius=30)
## [1] 0.5995357
To help identify suitable radii for
average_percentage_of_cells_within_radius()
and
average_marker_intensity_within_radius()
users can use
plot_average_intensity()
. This function calculates the
average intensity of a target marker for a number of user-supplied radii
values, and plots the intensity level at each specified radius as a line
graph. The radius unit is microns.
plot_average_intensity(spe_object=formatted_image, reference_marker="Immune_marker3",
target_marker="Immune_marker2", radii=c(30, 35, 40, 45, 50, 75, 100))
This plot shows low levels of Immune_marker3 were observed in cells near Immune_marker2+ cells and these levels increased at larger radii. This suggests Immune_marker2+ and Immune_marker3+ cells may not be closely interacting and are actually repelled.
This score was originally defined as the number of immune-tumour
interactions divided by the number of immune-immune interactions (Keren et al. 2018). SPIAT generalises this
method for any user-defined pair of cell types.
mixing_score_summary()
returns the mixing score between a
reference cell type and a target cell type. This mixing score is defined
as the number of target-reference interactions/number of
reference-reference interactions within a specified radius. The higher
the score the greater the mixing of the two cell types. The normalised
score is normalised for the number of target and reference cells in the
image.
mixing_score_summary(spe_object = formatted_image, reference_celltype = "Immune1",
target_celltype = "Immune2", radius=100, feature_colname ="Cell.Type")
## Reference Target Number_of_reference_cells Number_of_target_cells
## 2 Immune1 Immune2 338 178
## Reference_target_interaction Reference_reference_interaction Mixing_score
## 2 583 592 0.9847973
## Normalised_mixing_score
## 2 0.9322379
Cross K function calculates the number of target cell types across a range of radii from a reference cell type, and compares the behaviour of the input image with an image of randomly distributed points using a Poisson point process. There are four patterns that can be distinguished from K-cross function, as illustrated in the plots below. (taken from here in April 2021).
Here, the black line represents the input image, the red line represents a randomly distributed point pattern.
We can calculate the cross K-function using SPIAT. Here, we need to define which are the cell types of interest. In this example, we are using Tumour cells as the reference population, and Immune3 cells as the target population.
df_cross <- calculate_cross_functions(formatted_image, method = "Kcross",
cell_types_of_interest = c("Tumour","Immune2"),
feature_colname ="Cell.Type",
dist = 100)
The results shows similar pattern as the 4th plot in the cross K diagram. This means “Tumour” cells and “Immune2” cells are not colocalised (or form separate clusters).
We can calculate the area under the curve (AUC) of the cross K-function. In general, this tells us the two types of cells are:
AUC_of_cross_function(df_cross)
## [1] -0.2836735
The AUC score is close to zero so this tells us that the two types of cells either do not have a relationship or they form a ring surrounding a cluster.
There is another pattern in cross K curve which has not been previously appreciated, which is when there is a “ring” of one cell type, generally immune cells, surrounding the area of another cell type, generally tumour cells. For this pattern, the observed and expected curves in cross K function cross or intersect, such as the cross K plot above.
We note that crossing is not exclusively present in cases where there is an immune ring. When separate clusters of two cell types are close, there can be a crossing at a small radius. In images with infiltration, crossing may also happen at an extremely low distances due to randomness. To use the CKI to detect a ring pattern, users need to determine a threshold for when there is a true immune ring. Based on our tests, these generally fall within at a quarter to half of the image size, but users are encouraged to experiment with their datasets.
Here we use the colocalisation of “Tumour” and “Immune3” cells as an example. Let’s revisit the example image.
Compute the cross K function between “Tumour” and “Immune3”:
df_cross <- calculate_cross_functions(formatted_image, method = "Kcross",
cell_types_of_interest = c("Tumour","Immune3"),
feature_colname ="Cell.Type",
dist = 100)
Then find the intersection of the observed and expected cross K curves.
crossing_of_crossK(df_cross)
## [1] "Crossing of cross K function is detected for this image, indicating a potential immune ring."
## [1] "The crossing happens at the 50% of the specified distance."
## [1] 0.5
The result shows that the crossing happens at 50% of the specified distance (100) of the cross K function, which is very close to the edge of the tumour cluster. This means that the crossing is not due to the randomness in cell distribution, nor due to two close located immune and tumour clusters. This result aligns with the observation that there is an immune ring surrounding the tumour cluster.
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 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.20.so; LAPACK version 3.10.0
##
## locale:
## [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
## [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
## [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
##
## time zone: UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] SPIAT_1.6.3 SpatialExperiment_1.14.0
## [3] SingleCellExperiment_1.26.0 SummarizedExperiment_1.34.0
## [5] Biobase_2.64.0 GenomicRanges_1.56.1
## [7] GenomeInfoDb_1.40.1 IRanges_2.38.1
## [9] S4Vectors_0.42.1 BiocGenerics_0.50.0
## [11] MatrixGenerics_1.16.0 matrixStats_1.3.0
## [13] BiocStyle_2.32.1
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.1 farver_2.1.2 dplyr_1.1.4
## [4] fastmap_1.2.0 pracma_2.4.4 spatstat.geom_3.3-2
## [7] spatstat.explore_3.3-1 digest_0.6.36 lifecycle_1.0.4
## [10] spatstat.data_3.1-2 magrittr_2.0.3 dbscan_1.2-0
## [13] compiler_4.4.1 rlang_1.1.4 sass_0.4.9
## [16] tools_4.4.1 utf8_1.2.4 yaml_2.3.10
## [19] knitr_1.48 labeling_0.4.3 S4Arrays_1.4.1
## [22] htmlwidgets_1.6.4 DelayedArray_0.30.1 abind_1.4-5
## [25] withr_3.0.1 desc_1.4.3 grid_4.4.1
## [28] polyclip_1.10-7 fansi_1.0.6 colorspace_2.1-1
## [31] ggplot2_3.5.1 scales_1.3.0 spatstat.utils_3.1-0
## [34] cli_3.6.3 rmarkdown_2.28 crayon_1.5.3
## [37] ragg_1.3.2 generics_0.1.3 httr_1.4.7
## [40] rjson_0.2.21 cachem_1.1.0 zlibbioc_1.50.0
## [43] BiocManager_1.30.23 XVector_0.44.0 vctrs_0.6.5
## [46] Matrix_1.7-0 jsonlite_1.8.8 bookdown_0.40
## [49] tensor_1.5 systemfonts_1.1.0 magick_2.8.4
## [52] spatstat.univar_3.0-0 jquerylib_0.1.4 goftest_1.2-3
## [55] glue_1.7.0 spatstat.random_3.3-1 pkgdown_2.1.0
## [58] gtable_0.3.5 deldir_2.0-4 UCSC.utils_1.0.0
## [61] munsell_0.5.1 tibble_3.2.1 pillar_1.9.0
## [64] htmltools_0.5.8.1 GenomeInfoDbData_1.2.12 R6_2.5.1
## [67] textshaping_0.4.0 evaluate_0.24.0 lattice_0.22-6
## [70] highr_0.11 bslib_0.8.0 Rcpp_1.0.13
## [73] gridExtra_2.3 SparseArray_1.4.8 nlme_3.1-164
## [76] spatstat.sparse_3.1-0 xfun_0.47 fs_1.6.4
## [79] pkgconfig_2.0.3
AT, YF, TY, ML, JZ, VO, MD are authors of the package code. MD and YF wrote the vignette. AT, YF and TY designed the package.