Skip to content

Toy data

A bundled 120-spectrum / 601-m/z-bin slice of the public mouse pancreas MALDI dataset, useful for quick try-outs and for the test suite.

Source

Sliced from the Zenodo deposit 10.5281/zenodo.3607915 (MALDI FTICR MS imaging data of pancreatic mouse tissue; Prade et al., 2020; CC BY 4.0), after gridding to 0.25 m/z in CodeInPaper/MousePancreate.ipynb. The bundled slice covers:

  • Spatial window: 120 spectra drawn without replacement (seed 0) from the 21×21 pixels around (x=1636, y=863).
  • m/z range: [100, 250], 601 bins at 0.25 m/z spacing.
  • The "unknown" companion reads every spectrum two bins lower in m/z, so each peak sits two bins (0.5 m/z) higher than in the reference, and multiplies it by lognormal noise (σ = 0.05, about ±5%). PGAlign should recover a per-group shift of +2.

The slice is stored as a compressed .npz (~230 KB) inside the package. scripts/make_toy_data.py rebuilds it from the gridded source file.

Usage

import pgalign as pg

unk, ref = pg.datasets.load_mouse_pancreas_toy()

print(unk.shape, ref.shape)        # (120, 601) (120, 601)
print(ref.var["m/z"].head())       # 100.0, 100.25, ..., 250.0

End-to-end on the toy data

import pgalign as pg

unk, ref = pg.datasets.load_mouse_pancreas_toy()
res = pg.align(unk, ref)

print(res.summary())                  # 7 groups paired, 7 shifted, 0 flagged at tau = 0.1
print(res.shifts["offset"].unique())  # [2]: every paired group recovers the planted shift

aligned = res.aligned                 # unknown spectra on the reference m/z grid
print(aligned.shape)                  # (120, 599): two bins lost at the top

With smooth=False (the peak caller of the simulation study and the canine sarcoma analysis) 15 groups are paired, and each again recovers the shift of +2.

API

pgalign.datasets.load_mouse_pancreas_toy

load_mouse_pancreas_toy()

Return two AnnData objects (unknown, reference) from a downsampled mouse-pancreas MALDI slice.

The data is a 120-spectrum, 601-bin slice of the public mouse pancreas dataset (Zenodo 10.5281/zenodo.3607915, Prade et al., 2020, CC BY 4.0), drawn from the 21 x 21 pixel window centred at (1636, 863) and the m/z range [100, 250] on a 0.25 m/z grid. The "unknown" companion is the same spectra shifted two bins higher in m/z, with multiplicative lognormal noise (sigma 0.05), so PGAlign should recover a shift of +2 bins. scripts/make_toy_data.py in the repository rebuilds it.

Returns

unk : anndata.AnnData The shifted "unknown" spectrum. ref : anndata.AnnData The unshifted reference spectrum.

Source code in pgalign/datasets.py
def load_mouse_pancreas_toy():
    """Return two AnnData objects (unknown, reference) from a downsampled mouse-pancreas MALDI slice.

    The data is a 120-spectrum, 601-bin slice of the public mouse pancreas dataset
    (Zenodo `10.5281/zenodo.3607915`, Prade et al., 2020, CC BY 4.0), drawn from the
    21 x 21 pixel window centred at (1636, 863) and the m/z range [100, 250] on a
    0.25 m/z grid. The "unknown" companion is the same spectra shifted two bins higher
    in m/z, with multiplicative lognormal noise (sigma 0.05), so PGAlign should recover
    a shift of +2 bins. ``scripts/make_toy_data.py`` in the repository rebuilds it.

    Returns
    -------
    unk : anndata.AnnData
        The shifted "unknown" spectrum.
    ref : anndata.AnnData
        The unshifted reference spectrum.
    """
    with resources.files(__package__).joinpath("data/mouse_pancreas_toy.npz").open("rb") as f:
        npz = np.load(f)
        X_ref = npz["X_ref"]
        X_unk = npz["X_unk"]
        mz = npz["mz"]
        x = npz["x"]
        y = npz["y"]

    var = pd.DataFrame({"m/z": mz.astype(float)}, index=[str(v) for v in mz])
    obs = pd.DataFrame({"x": x, "y": y}, index=[f"s{i}" for i in range(len(x))])
    ref = sc.AnnData(X=X_ref, var=var, obs=obs)
    unk = sc.AnnData(X=X_unk, var=var.copy(), obs=obs.copy())
    return unk, ref