MPX Quality Control
This tutorial details the first steps of data analysis to quality control and clean up the MPX data output from Pixelator.
After completing this tutorial, you should be able to:
- Use the edge rank plot to manually set cell calling thresholds and filter low-quality cells.
- Aggregate data across samples and visualize sample-level QC metrics like number of cells.
- Check distributions of quality metrics like molecule counts and graph connectivity.
- Identify and remove cell outliers using the antibody count distribution metric Tau.
Setup
First, we will load packages necessary for downstream processing.
from pathlib import Path
from pixelator import read
from pixelator.plot import edge_rank_plot, cell_count_plot, scatter_umi_per_upia_vs_tau
import seaborn as sns
sns.set_style("whitegrid")
from pixelator import read
DATA_DIR = Path("<path to the directory to save datasets to>")
Load data
In this tutorial we will continue where we left off after the previous tutorial Data handling, where we combined MPX data from two samples, and read the combined object directly.
baseurl = "https://pixelgen-technologies-datasets.s3.eu-north-1.amazonaws.com/mpx-datasets/pixelator/0.18.x/1k-human-pbmcs-v1.0-immunology-I"
!curl -L -O -C - --create-dirs --output-dir {DATA_DIR} "{baseurl}/Sample01_human_pbmcs_unstimulated.layout.dataset.pxl"
!curl -L -O -C - --create-dirs --output-dir {DATA_DIR} "{baseurl}/Sample02_human_pbmcs_unstimulated.layout.dataset.pxl"
from pixelator import simple_aggregate
paths = [
DATA_DIR / "Sample01_human_pbmcs_unstimulated.layout.dataset.pxl",
DATA_DIR / "Sample02_human_pbmcs_unstimulated.layout.dataset.pxl",
]
pg_data_combined_pxl_object = simple_aggregate(
["sample1", "sample2"], [read(path) for path in paths]
)
# 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
Cell calling: Edge rank plot
Here, we use the edge rank plot to perform an additional quality control of the called cells, to make a manual adjustment to the number of cells that were called by Pixelator. This removes cells that deviate from the component size distribution, and might not represent whole cells.
edge_rank_df = pg_data_combined.obs[["sample", "molecules"]].copy()
edge_rank_df["rank"] = edge_rank_df.groupby(["sample"])["molecules"].rank(
ascending=False, method="first"
)
edge_rank_df["edges"] = edge_rank_df["molecules"]
fig, ax = edge_rank_plot(edge_rank_df, group_by="sample")
It looks like components are declining rapidly in size at around 5000 molecules, and we will thus set a manual cutoff at that point, represented by a dashed line.
fig, ax = edge_rank_plot(edge_rank_df, group_by="sample")
ax.axhline(5000, linestyle="--")
# Filter cells to have at least 5000 edges
pg_data_combined = pg_data_combined[pg_data_combined.obs["molecules"] >= 5000]
Here, we plot the number of called cells per condition and replicate.
cells_per_sample_df = (
pg_data_combined.obs.groupby("sample").size().to_frame(name="size").reset_index()
)
fig, ax = cell_count_plot(pg_data_combined.obs, color_by="sample")
Here, we visualize the distribution of some metrics among components.
metrics_per_sample_df = pg_data_combined.obs[
["sample", "molecules", "mean_molecules_per_a_pixel", "mean_reads_per_molecule"]
].melt(id_vars=["sample"])
metrics_plot = sns.catplot(
data=metrics_per_sample_df,
x="sample",
col="variable",
y="value",
kind="violin",
sharex=True,
sharey=False,
margin_titles=True,
hue="sample",
).set_titles(col_template="{col_name}")
metrics_plot
Antibody count distribution outlier removal
Here, we have plotted the mean_molecules_per_a_pixel
stat against
Tau,
and colored each component by Pixelator’s classification of Tau
(low, normal, or high). It looks like Pixelator has accurately
picked out a single outlier that might be an outlier antibody complex or
a component that has low specificity, i.e. bound by many more different
types of antibodies than we would expect from a normal cell. As this
outlier is likely a technical artefact, will remove it from the
analysis.
tau_metrics_df = pg_data_combined.obs[["sample", "tau", "mean_molecules_per_a_pixel", "tau_type"]]
tau_metrics_df["umi_per_upia"] = tau_metrics_df["mean_molecules_per_a_pixel"]
fig, ax = scatter_umi_per_upia_vs_tau(tau_metrics_df, group_by="sample")
Going through the above steps we have performed critical quality control by filtering low-quality cells and identifying outliers. With a clean, high-quality MPX dataset in hand, we are ready to proceed to the next step, in which we will be leveraging protein abundance for the annotation of different cell populations.