MERSCOPE mouse liver

In this notebook, we will use ovrlpy to investigate the Vizgen MERSCOPE’s mouse liver dataset.

We want to create a signal embedding of the transcriptome, and a vertical signal incoherence map to identify locations with a high risk of containing spatial doublets.

Settings and Imports

First, let’s define settings and input files.

from pathlib import Path

import matplotlib.pyplot as plt

import ovrlpy
sample_nr = 1
slice_nr = 1

# TODO: adjust path
data_path = Path("path/to/downloaded_data") / f"Liver{sample_nr}Slice{slice_nr}"

Loading the data

Next, we want to load the data.

coordinate_df = ovrlpy.io.read_MERSCOPE(data_path / "detected_transcripts.csv")

print(f"Number of transcripts: {len(coordinate_df):,}")
Number of transcripts: 417,243,171
coordinate_df.head()
shape: (5, 4)
xyzgene
f64f64f64cat
2506.407-95.451480.0"Comt"
2531.8447-95.187020.0"Comt"
2483.7969-91.3601150.0"Comt"
2505.7693-84.081650.0"Comt"
2501.394-81.387090.0"Comt"

Tissue overview

# only show every 5,000th transcript
n = 5_000

fig, ax = plt.subplots()
ax.scatter(coordinate_df[::n, "x"], coordinate_df[::n, "y"], s=0.1)
_ = ax.set(aspect="equal")
../_images/d729933ff1ec98b802701114bee6ef373f3a33dbe8547314949a0aa68eb203d9.png

Running the ovrlpy pipeline

ovrlpy provides a convenience function run to run the entire pipeline. The function creates a signal integrity map, a signal strength map and a Visualizer obejcet to visualize the results.

# ensure reproducibility by setting random_state
# min_distance???
liver = ovrlpy.Ovrlp(coordinate_df, n_components=10, n_workers=8, random_state=42)
liver.analyse()
Running vertical adjustment
Creating gene expression embeddings for visualization
determining pseudocells
found 94105 pseudocells
sampling expression:
100%|██████████| 72/72 [03:33<00:00,  2.96s/it]
Modeling 10 pseudo-celltype clusters;
Creating signal integrity map
100%|██████████| 420/420 [14:50<00:00,  2.12s/it]
_ = ovrlpy.plot_pseudocells(liver)
../_images/eafcd1beb77edf3962efad8f02cc083bf3feaaefa52d2a496ac9baae3b724809.png

Signal integrity of the liver sample

fig = ovrlpy.plot_signal_integrity(liver, signal_threshold=3)
../_images/ea52c16ebcc7b8894ca32227a06cdefdbd16e19f00981269abe391a63af65e37.png

Doublet probability

doublets = liver.detect_doublets(min_signal=3, integrity_sigma=3)
fig, ax = plt.subplots()
_scatter = ax.scatter(
    doublets["x"], doublets["y"], c=doublets["integrity"], s=0.2, cmap="viridis"
)
_ = ax.set_aspect("equal")
_ = fig.colorbar(_scatter, ax=ax)
../_images/6d1c9e61c8004e45faa393844133b614e6dabf18e44cc78a603d951b90f25351.png

Visualize a specific doublet event like so.

doublet_case = 1

x, y = doublets["x", "y"].row(doublet_case)

_ = ovrlpy.plot_region_of_interest(liver, x, y, window_size=40)
../_images/d6c04c0668fa09cb6801d829cdc3cfc532bf65014eb6df4a0e633b066d1dc125.png