Spatial Analyses
In this tutorial we will show you how you can analyze the spatial configuration of proteins on the cell surface of single cells, using PNA data.
Pixelator will generate a number of metrics from the graph structure inherent to the PNA data. In this tutorial we will show you how you can approach spatial analysis using the PNA proximity scores to get a deeper understanding of how proteins are organized on the cell surface.
After completing this tutorial, you will be able to:
-
Interact with PNA proximity scores to analyze protein clustering and colocalization on the cell surfaces.
-
Quantify changes in protein clustering: Utilize PNA proximity scores and differential tests to measure and compare protein clustering between conditions, revealing spatial rearrangements upon cellular stimulation.
-
Identify changes in protein colocalization: Conduct differential proximity analysis to pinpoint protein pairs with significant changes in co-occurance across different samples, uncovering potential protein interactions under specific conditions.
-
Visualize and interpret data: Effectively communicate your findings through volcano plots and heatmaps for differential analyses.
Setup
library(pixelatorR)
library(dplyr)
library(tibble)
library(stringr)
library(ggrepel)
library(Seurat)
library(here)
library(pheatmap)
library(ggplot2)
library(tidygraph)
library(ggraph)
library(tidyr)
Load data
We begin by loading our resting PBMC and PHA-stimulated PBMC dataset from previous tutorials.
DATA_DIR <- "path/to/local/folder"
Sys.setenv("DATA_DIR" = DATA_DIR)
# Load the object that you saved in the previous tutorial. This is not needed if it is still in your workspace.
pg_data_combined <- readRDS(file.path(DATA_DIR, "combined_data_annotated.rds"))
pg_data_combined
An object of class Seurat
474 features across 2066 samples within 3 assays
Active assay: PNA (158 features, 158 variable features)
3 layers present: counts, data, scale.data
2 other assays present: clr_assay, log_assay
4 dimensional reductions calculated: pca, umap, harmony, harmony_umap
Obtaining proximity scores for target cells
Since T cells are the primary target of PHA, let us limit our analysis of spatial metrics to CD8 T cells. We use the cell types from the cell annotation tutorial.
pg_data_cd8 <- pg_data_combined %>%
subset(cell_type == "CD8 T cells")
ProximityScores(pg_data_cd8) %>%
head() %>%
knitr::kable()
marker_1 | marker_2 | join_count | join_count_expected_mean | join_count_expected_sd | join_count_z | join_count_p | log2_ratio | component |
---|---|---|---|---|---|---|---|---|
HLA-DR-DP-DQ | HLA-DR-DP-DQ | 13 | 0.75 | 0.8453677 | 12.25 | 0.0000000 | 3.70044 | resting_57cde5dd18da0c53 |
HLA-DR-DP-DQ | IgE | 0 | 0.03 | 0.1714466 | -0.03 | 0.4880335 | 0.00000 | resting_57cde5dd18da0c53 |
HLA-DR-DP-DQ | IgM | 1 | 0.08 | 0.2726599 | 0.92 | 0.1787864 | 0.00000 | resting_57cde5dd18da0c53 |
HLA-DR-DP-DQ | NKp80 | 0 | 0.05 | 0.2190429 | -0.05 | 0.4800612 | 0.00000 | resting_57cde5dd18da0c53 |
HLA-DR-DP-DQ | IgD | 0 | 0.03 | 0.1714466 | -0.03 | 0.4880335 | 0.00000 | resting_57cde5dd18da0c53 |
HLA-DR-DP-DQ | VISTA | 0 | 0.01 | 0.1000000 | -0.01 | 0.4960106 | 0.00000 | resting_57cde5dd18da0c53 |
The measures in each row of the proximity scores’ table correspond to a protein pair (marker_1 and marker_2) in a given component. When marker_1 and marker_2 are the same, the measure indicates the clustering degree of that protein in the component; when they are different, the measure indicates the colocalization degree of those two proteins.
Proximity measures
When analyzing spatial proximity, we primarily examine two key values. First, “join_count_z” is a z-score indicating the statistical significance of the observed number of links between marker_1 and marker_2 antibodies compared to random expectation. A higher absolute z-score suggests a more significant deviation from chance, but it reflects significance, not the degree of proximity itself. Higher total counts can lead to higher z-scores even for similar proximity degrees. Second, “log2_ratio” represents the log2 of the ratio between observed and expected (by chance) edges between marker_1 and marker_2. This metric provides a more direct measure of the degree of proximity. Therefore, to answer questions like “Are these two proteins colocalized?” or “Is this protein significantly clustered?”, focus on the “join_count_z” value. For questions such as “Has this marker’s clustering increased after stimulation?”, the log2_ratio metric is more informative.
Filtering the low-abundance markers
Not all proteins will be expressed by every cell, i.e. some proteins might have very low abundance in some cells. For such proteins, the proximity scores should be excluded in the corresponding cells. Typically, filtration should be performed before spatial proximity analysis to reduce the potential noise from low abundance markers.
There are two values that we typically use for filtering out the proximity scores of low-abundance proteins The first value, “min_count”, is the lower of marker_1 and marker_2 antibody counts in the component; let us filter out any proteins with fewer than 50 counts. The second value, “join_count_expected_mean”, is the number of expected links between the marker_1 and marker_2 antibodies if they had been randomly distributed in the component; let us filter any protein pairs that have fewer than 10 expected edges between them.
filtered_cd8_proximity_scores <- ProximityScores(
pg_data_cd8,
meta_data_columns = "condition",
add_marker_counts = TRUE
) %>%
mutate(min_count = pmin(count_1, count_2)) %>%
filter(min_count >= 50 & join_count_expected_mean >= 10)
Clustering analysis
Let’s look at the significantly clustered proteins in each sample. Here, we consider a protein to be significantly clustered if it’s median proximity z-score is above 2 and is detected in at least 50 cells.
clustering_scores = filtered_cd8_proximity_scores %>%
filter(marker_1 == marker_2)
sample_clustering <- clustering_scores %>%
group_by(condition, marker_1) %>%
summarise(
n = n(),
med_z_score = median(join_count_z),
.groups = "drop"
) %>%
arrange(desc(med_z_score))
sample_clustering %>%
filter(med_z_score > 2 & n > 50) %>%
pivot_wider(
names_from = condition,
values_from = c(n, med_z_score)
) %>%
head(n = 10) %>%
knitr::kable()
marker_1 | n_stimulated | n_resting | med_z_score_stimulated | med_z_score_resting |
---|---|---|---|---|
CD82 | 179 | NA | 16.392566 | NA |
CD8 | 257 | 117 | 6.728384 | 10.058386 |
CD52 | 252 | 107 | 6.881706 | 2.996102 |
CD45RA | 130 | 80 | 2.368941 | 5.367366 |
CD45RB | 236 | 118 | 3.723749 | 4.666049 |
CD3e | 271 | 131 | 4.061809 | 2.701777 |
HLA-ABC | 272 | NA | 3.627938 | NA |
CD43 | 272 | 132 | 3.495544 | 3.254246 |
CD102 | NA | 120 | NA | 3.259207 |
CD2 | 269 | 128 | 3.007855 | 2.078028 |
Here we can for example see that many cells display CD82 clustering after PHA stimulation whereas many cells display CD52 clustering in btoh conditions.
Differential clustering analysis
Another question is whether we can observe an increase in clustering of any proteins upon stimulation. We already expect CD82 to be one of those but we recall that join_count_z is an indication of significance, so this time, we compare degrees of clustering using the log2_ratio.
test_results <- DifferentialProximityAnalysis(
clustering_scores,
target = "stimulated",
reference = "resting",
contrast_column = "condition",
proximity_metric = "log2_ratio",
min_n_obs = 25
)
# Visualize this in a volcano plot
test_results %>%
left_join(
clustering_scores %>%
group_by(marker_1, marker_2, condition) %>%
summarize(med_log2_ratio = median(log2_ratio), .groups = "drop"),
by = c("marker_1", "marker_2", "target" = "condition")
) %>%
ggplot(aes(diff_median, -log10(p_adj), label = marker_1, color = med_log2_ratio)) +
geom_point() +
geom_text_repel(max.overlaps = 5) +
theme_minimal() +
guides(color = guide_colorbar(title.position = "top")) +
labs(x = "Difference in medians",
y = expression(-log[10] ~ (adj. ~ p - value)),
color = "Median clustering\nafter stimulation") +
geom_vline(xintercept = 0, linetype = "dashed")
We see that CD82 and CD52 have indeed increased in clustering after PHA-stimulation as well as other markers including CD3e, CD44, CD45, HLA-ABC, and B2M. We also see that CD5 and CD27 have decreased in clustering. Let us now look at the clustering distributions for these markers.
clustering_scores %>%
filter(marker_1 %in% c("CD3e", "CD5", "CD27", "CD52", "CD82", "CD102", "HLA-ABC", "B2M")) %>%
ggplot(aes(marker_1, log2_ratio, fill = condition)) +
geom_violin(draw_quantiles = 0.5) +
facet_wrap(~marker_1, scales = "free", ncol = 4) +
theme_bw() +
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) +
labs(title = "Clustering distributions")
Colocalization analysis
Another aspect of spatial organization is whether pairs of proteins colocalize. So now, we focus on protein-pairs and their proximity scores. Here, we consider a protein pair to be significantly colocalized it’s median proximity z-score is above 2 and is detected in at least 50 cells.
colocalization_scores = filtered_cd8_proximity_scores %>%
filter(marker_1 != marker_2)
sample_colocalization <- colocalization_scores %>%
group_by(condition, marker_1, marker_2) %>%
summarise(
n = n(),
med_z_score = median(join_count_z),
.groups = "drop"
) %>%
arrange(desc(med_z_score))
sample_colocalization %>%
filter(med_z_score > 2 & n > 50) %>%
pivot_wider(
names_from = condition,
values_from = c(n, med_z_score)
) %>%
head(n = 10) %>%
knitr::kable()
marker_1 | marker_2 | n_stimulated | n_resting | med_z_score_stimulated | med_z_score_resting |
---|---|---|---|---|---|
CD81 | CD82 | 119 | NA | 8.396867 | NA |
CD53 | CD82 | 63 | NA | 4.678509 | NA |
CD45 | CD45RB | 272 | 132 | 4.629643 | 4.093078 |
CD45RB | CD8 | 265 | 124 | 3.836356 | 4.248177 |
CD45RA | CD45RB | NA | 113 | NA | 4.238013 |
CD45 | CD8 | 271 | NA | 4.134421 | NA |
CD52 | CD59 | 271 | 130 | 3.710393 | 3.551544 |
CD43 | CD45RB | 271 | 132 | 3.158135 | 3.562143 |
CD43 | CD8 | 271 | NA | 3.545314 | NA |
B2M | CD8 | 271 | NA | 3.206260 | NA |
Here we can for example see that CD52/CD59 is significantly colocalized in both unstimulated and PHA-stimulated CD8 T cells whereas CD81/D82 is only significantly colocalized in PHA-stimulated CD8 T cells.
Given that there can be several colocalizing protein-pairs, a protein-pair graph illustration is one alternative for getting an overview of colocalization patterns in a sample. Below we use the same filtering procedure as above to filter for significant colocalization pairs.
markers_to_plot <- c("CD52", "CD59", "CD81", "CD82", "CD43", "CD44", "CD45", "CD45RA", "CD45RB", "CD8")
df_net <- filtered_cd8_proximity_scores %>%
filter(marker_1 %in% markers_to_plot & marker_2 %in% markers_to_plot) %>%
select(marker_1, marker_2, join_count_z, component) %>%
mutate(treatment = gsub("_.*", "", component)) %>%
group_by(treatment, marker_1, marker_2) %>%
summarize(med_coloc = median(join_count_z), n = n(), .groups = "drop") %>%
filter(med_coloc > 2 & n > 50) %>%
mutate(from = marker_1, to = marker_2)
tidygraph::as_tbl_graph(df_net) %>%
ggraph(layout = "kk") +
geom_edge_link(aes(color = med_coloc, width = abs(med_coloc))) +
geom_node_label(aes(label = name), size = 3) +
scale_edge_color_gradientn(
colours = c("#1F395F", "#647DA3", "#BBC8DA",
"#FFFFFF", "#F0BCCD", "#BE5F7D",
"#781534"),
limits = c(-abs(max(df_net$med_coloc)), abs(max(df_net$med_coloc)))
) +
scale_x_continuous(expand = c(0.2, 0.2)) +
scale_y_continuous(expand = c(0.2, 0.2)) +
facet_edges(~treatment, nrow = 1) +
theme(aspect.ratio = 1,
panel.background = element_rect(fill = "white", color = "black"),
panel.spacing = unit(1, "lines")) +
labs(edge_color = "Median\nZ score") +
guides(edge_width = "none")
Keep in mind that the decision to remove protein pairs present in fewer cells should be guided by your experimental goals. If you aim to identify colocalization changes in rare cell subpopulations, retaining these pairs for downstream analysis might be crucial.
Colocalization analysis
Let’s run a differential colocalization test to find protein-pairs that differ significantly in proximity scores between conditions.
coloc_test_results <- DifferentialProximityAnalysis(
colocalization_scores,
target = "stimulated",
reference = "resting",
contrast_column = "condition",
proximity_metric = "log2_ratio",
min_n_obs = 50
)
# Visualize this in a volcano plot
coloc_test_results %>%
mutate(pair = paste0(marker_1, "/", marker_2)) %>%
arrange(-diff_median) %>%
mutate(label = case_when(
row_number() %in% 1:5 ~ pair,
row_number() %in% (n() - 4):n() ~ pair,
TRUE ~ NA_character_
)) %>%
ggplot(aes(diff_median, -log10(p_adj), label = label)) +
geom_point() +
geom_text_repel(max.overlaps = 5) +
theme_minimal() +
guides(color = guide_colorbar(title.position = "top")) +
labs(
x = "Difference in medians",
y = expression(-log[10] ~ (adj. ~ p - value))
)
We observe several differentially colocalized protein pairs. Let us look at a clustered heatmap to get a better grasp of these protein pair colocalization patterns.
ColocalizationHeatmap(
coloc_test_results %>%
mutate(diff_median = case_when(
p_adj < 0.001 ~ diff_median,
TRUE ~ 0
)),
#filter(p_adj < 0.001),
marker1_col = "marker_1",
marker2_col = "marker_2",
value_col = "diff_median",
type = "dots",
size_col_transform = \(x) {-log10(x)}
) &
labs(size = "-log10p(p_adj)")
Now let’s take a holistic view of colocalization scores and make a UMAP. We will only include protein pairs that display a large difference in colocalization score between our two conditions.
# Make sure that we are using the correct assay
DefaultAssay(pg_data_cd8) <- "PNA"
# Convert colocalization table to a new assay
pg_data_cd8 <- ProximityScoresToAssay(pg_data_cd8, values_from = "log2_ratio", missing_obs = 0)
DefaultAssay(pg_data_cd8) <- "proximity"
# Filter test results to define pairs of interest
proteins_of_interest <- coloc_test_results %>%
filter(p_adj < 0.01) %>%
arrange(-diff_median) %>%
select(marker_1, marker_2) %>%
unlist() %>%
unique()
# Find pairs of interest
pairs_of_interest <- coloc_test_results %>%
select(marker_1, marker_2) %>%
filter(
marker_1 %in% proteins_of_interest &
marker_2 %in% proteins_of_interest
) %>%
tidyr::unite(marker_1, marker_2, col = "pairs", sep = "/") %>%
pull(pairs)
# Set variable features
VariableFeatures(pg_data_cd8) <- pairs_of_interest
# Create UMAP
pg_data_cd8 <- pg_data_cd8 %>%
ScaleData() %>%
RunPCA(reduction.name = "pca_coloc") %>%
RunUMAP(dims = 1:10, reduction = "pca_coloc", reduction.name = "umap_coloc")
# Plot
DimPlot(pg_data_cd8, group.by = "condition", reduction = "umap_coloc") +
theme_classic() +
labs(title = "UMAP of CD8 T cells based on colocalization scores")
Building upon the insights gained from Proximity Network Assay data analysis, we now turn our attention to the spatial organization of proteins on the cell surface and how their clustering and interactions vary across conditions. The next tutorial in this series introduces cell graph visualizations, an exciting method that allows us to visualize and intuitively understand the dynamic clustering of proteins, providing deeper insights into their roles in cellular function.