Differential Abundance
So far, we have seen how to merge, normalize, integrate and annotate the cell types in our dataset. We can now proceed to the biological interpretation of our experiment. Proximity Network Assay (PNA) data contains a wealth of spatial data that we will discuss in the following tutorials. Here, we will focus on the differential abundance of markers across conditions.
After completing this tutorial, you should be able to:
- Identify abundance changes across conditions within a cell type
- Visualize these changes in a clear way
Setup
from matplotlib.pyplot import rc_context
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
import pandas as pd
from pixelator import read_pna as read
from pixelator.common.statistics import clr_transformation
from pixelator.pna.analysis import differential_abundance
import seaborn as sns
sns.set_style("whitegrid")
DATA_DIR = Path("./pna-analysis")
from pixelator.pna.pixeldataset.download import DownloadableDatasets
DATA_DIR.mkdir(parents=True, exist_ok=True)
DownloadableDatasets.download_dataset(
"pna062-unstim-pbmcs",
output_path=DATA_DIR / "PNA062_unstim_PBMCs_1000cells_S02_S2.layout.pxl",
)
DownloadableDatasets.download_dataset(
"pna062-pha-pbmcs",
output_path=DATA_DIR / "PNA062_PHA_PBMCs_1000cells_S04_S4.layout.pxl",
)
Load data
To illustrate the annotation workflow we continue with the cell type annotations from the previous tutorial. We will also recreate the merged and harmonized object. As described before, this merged and harmonized object contains two samples: a resting and PHA stimulated PBMC sample.
pg_data_combined_pxl_object = read([
DATA_DIR/ "PNA062_unstim_PBMCs_1000cells_S02_S2.layout.pxl",
DATA_DIR/ "PNA062_PHA_PBMCs_1000cells_S04_S4.layout.pxl",
])
filtered_cells = list(pd.read_csv(DATA_DIR / "qc_filtered_cells.csv")["component"])
pg_data_combined_pxl_object = pg_data_combined_pxl_object.filter(components=filtered_cells)
# In this tutorial we will mostly work with the AnnData object
# so we will start by selecting that from the pixel data object
pg_data_combined = pg_data_combined_pxl_object.adata()
# Adding cell-type annotations saved in the last tutorial
pg_data_combined.obs = pg_data_combined.obs.join(pd.read_csv(DATA_DIR / "cell_type_annotations.csv").set_index("component"))
# Perform CLR normalization
pg_data_combined.layers["clr"] = clr_transformation(
pg_data_combined.to_df(),
axis=1, non_negative=True
)
Differential Abundance in CD8 T cells
As PHA is a T cell mitogen, one might be interested in how PHA treatment affects protein abundance in T cells. Therefore, in this tutorial, we will subset the data to only include the CD8 T cells and then perform a differential abundance analysis of the PHA treated cells versus the resting cells.
differential_abundance compares a target condition with a reference on
the matrix it is given. contrast_column names the observation column
that holds the conditions, targets is the condition of interest, and
reference is the baseline. The cells are already subset to CD8 T
cells, so this comparison is PHA stimulated versus Resting within that
cell type. CLR normalization is done above and stored in the clr
layer; pass that layer so the test uses those values. difference is
the mean CLR in the target minus the mean CLR in the reference.
pvals_adj is the multiple-testing adjustment across the markers in
this call.
# Subset data to only include CD8 T cells
cd8_t_cells = pg_data_combined[pg_data_combined.obs['cell_type'] == 'CD8 T',:]
# naming the conditions
cd8_t_cells.obs["condition"] = "Resting"
cd8_t_cells.obs.loc[
cd8_t_cells.obs["sample"].astype(str).str.contains("PHA", na=False),
"condition",
] = "PHA stimulated"
cd8_t_cells.obs["condition"] = pd.Categorical(
cd8_t_cells.obs["condition"],
categories=["Resting", "PHA stimulated"],
ordered=True,
)
# Mean CLR difference between PHA-stimulated and resting CD8 T cells
diff_exp_df = differential_abundance(
cd8_t_cells,
contrast_column="condition",
reference="Resting",
targets="PHA stimulated",
layer="clr",
)
diff_exp_df
| marker | pvals | pvals_adj | difference | pct_nz_group | pct_nz_reference | target | reference | |
|---|---|---|---|---|---|---|---|---|
| 0 | CD37 | 9.988615e-59 | 1.578201e-56 | 0.837815 | 0.996825 | 1.000000 | PHA stimulated | Resting |
| 1 | CD20 | 3.697717e-53 | 5.842393e-51 | 0.584936 | 1.000000 | 0.880795 | PHA stimulated | Resting |
| 2 | CD278 | 2.790213e-48 | 4.408536e-46 | 0.739480 | 1.000000 | 0.847682 | PHA stimulated | Resting |
| 3 | CD38 | 5.677483e-48 | 8.970422e-46 | 2.058893 | 1.000000 | 0.973510 | PHA stimulated | Resting |
| 4 | CD274 | 6.224112e-46 | 9.834097e-44 | 0.379040 | 1.000000 | 0.960265 | PHA stimulated | Resting |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 153 | CD41 | 3.368665e-35 | 5.322490e-33 | -0.406499 | 0.990476 | 0.993377 | PHA stimulated | Resting |
| 154 | CD48 | 3.726829e-42 | 5.888391e-40 | -0.848904 | 1.000000 | 1.000000 | PHA stimulated | Resting |
| 155 | CD277 | 1.332853e-42 | 2.105907e-40 | -0.807645 | 0.996825 | 1.000000 | PHA stimulated | Resting |
| 156 | CD305 | 2.120235e-43 | 3.349971e-41 | -0.965747 | 0.993651 | 1.000000 | PHA stimulated | Resting |
| 157 | CD36 | 6.047983e-60 | 9.555814e-58 | -0.681883 | 0.984127 | 1.000000 | PHA stimulated | Resting |
158 rows × 8 columns
Let’s visualize these results as a volcano plot and annotate the 10
markers with the highest mean difference and the 10 with the lowest. The
x-axis is difference (mean CLR in PHA-stimulated cells minus mean CLR
in resting cells).
diff_exp_df["-log10(adjusted p-value)"] = -np.log10(diff_exp_df["pvals_adj"])
diff_exp_df["Significant"] = diff_exp_df["pvals_adj"] < 0.01
markers_to_label = (
diff_exp_df.nlargest(10, "difference")["marker"].tolist()
+ diff_exp_df.nsmallest(10, "difference")["marker"].tolist()
)
# Create scatter plot
plt.figure(figsize=(10, 6))
sns.scatterplot(data=diff_exp_df, x='difference', y='-log10(adjusted p-value)', hue='Significant')
for _, row in diff_exp_df[diff_exp_df["marker"].isin(markers_to_label)].iterrows():
plt.annotate(
row["marker"],
(row["difference"], row["-log10(adjusted p-value)"]),
xytext=(5, 5),
textcoords="offset points",
)

Alternatively, in a heatmap we can visualize the average normalized values in the CD8 T cells of each sample for the 7 markers with the highest mean difference and the 7 with the lowest.
markers_to_plot = (
diff_exp_df.nlargest(7, "difference")["marker"].tolist()
+ diff_exp_df.nsmallest(7, "difference")["marker"].tolist()
)
sample_order = (
cd8_t_cells.obs[["sample", "condition"]]
.drop_duplicates()
.sort_values("condition")["sample"]
)
mean_values = pd.DataFrame()
for sample in sample_order:
sample_cells = cd8_t_cells[cd8_t_cells.obs["sample"] == sample]
mean_values[sample] = sample_cells[:, markers_to_plot].to_df("clr").mean()
plt.figure(figsize=(10, 8))
sns.heatmap(
mean_values.loc[markers_to_plot],
cmap="viridis",
yticklabels=True,
xticklabels=True,
linewidths=1,
linecolor="black",
)
plt.title("Average CLR values in CD8 T cells per sample")
plt.xticks(rotation=0)
plt.yticks(rotation=0)
plt.tight_layout()

In this example, it seems that many of the T cell relevant markers (such as CD71, CD38 and CD25) show a significant increase in abundance upon PHA stimulation. KLRG1 decreases, and so do CD162, CD48, and CD102, which stay high in both samples.
However, abundance is only one facet of the rich multidimensional data generated by Proximity Network experiments. We are now ready to transition into the spatial realm, exploring the arrangement and interactions of proteins on the cell surface. In the upcoming tutorials, we will leverage the graph nature and spatial metrics within Proximity Network Assay data to unravel the spatial biology of cells, surveying protein clustering and colocalization patterns and how these contribute to cell identity, signaling, and function. Abundance has illuminated cell types; spatiality will illuminate the molecular geography that defines them.