METASPACE converter
Python package to download and convert datasets from the METASPACE knowledge base to common formats for single-cell and spatial omics analysis. Datasets can be directly downloaded to AnnData and SpatialData objects.
AnnData is the underlying data format of many packages of the scverse such as scanpy for single-cell data analysis and squidpy for spatial omics analysis.
Another supported format that is part of the scverse is SpatialData for storing, aligning, and processing spatial omics data. This enables users to easily align and integrate METASPACE datasets to other spatial omics modalities.
Additionally, the commonly used colocalization analysis for spatial metabolomics can be performed with the package.
If you encounter any bugs or have suggestions for new features, please open an issue in the GitHub repository.
Installation
Our package requires python >= 3.9.
You can install the package directly from PyPI:
pip install metaspace-converter
Short tutorial
The full documentation for the package can be found here: https://metaspace2020.github.io/metaspace-converter/
The METASPACE-converter package uses the python client to download datasets from METASPACE. It serves as a wrapper that downloads and converts datasets directly to AnnData and SpatialData objects.
If you also need to upload or modify datasets on METASPACE, please check the METASPACE python client documentation.
AnnData
Datasets can be downloaded to AnnData objects using the metaspace_to_anndata function.
This allows downstream analysis e.g. with scanpy
or squidpy.
Scanpy
from metaspace_converter import metaspace_to_anndata
import scanpy as sc
# Download data and convert to an AnnData object
adata = metaspace_to_anndata(
dataset_id="2022-08-05_17h28m56s",
fdr=0.1,
database=("BraChemDB", "2018-01"),
)
# Visualization with ScanPy
sc.pl.spatial(
adata,
# Choose the first ion for visualization
color=adata.var.index[0],
img_key=None,
spot_size=1,
)
Squidpy
Optical images can also be downloaded, if available, and saved in the AnnData object. Squidpy allows for an easy overlay of ion images and the optical image.
from metaspace_converter import metaspace_to_anndata
import squidpy as sq
# Download dataset with optical background image
adata = metaspace_to_anndata(
dataset_id="2022-08-05_17h28m56s",
fdr=0.1,
database=("BraChemDB", "2018-01"),
add_optical_image=True,
)
sq.pl.spatial_scatter(
adata, color=adata.var.index[0], shape="square", img=True, size=15, alpha=0.5
)
Convert AnnData objects to ion image arrays
If you want to work with the ion images as numpy arrays, the function anndata_to_image_array can
convert previously downloaded AnnData objects to numpy arrays.
from metaspace_converter import metaspace_to_anndata, anndata_to_image_array
# Download data
adata2 = metaspace_to_anndata(dataset_id="2023-11-14_21h58m39s", fdr=0.1)
ion_images = anndata_to_image_array(adata2)
# 20 ion images of shape 130x143
print(ion_images.shape)
# > (20, 130, 143)
SpatialData
Download to the SpatialData format equally easy and
can be done with the metaspace_to_spatialdata function.
Here using a reversed colormap which better represents intense values on a bright background.
from metaspace_converter import metaspace_to_spatialdata
import spatialdata_plot # noqa: Not directly used but extends spatialdata
# Download dataset with optical background image
sdata = metaspace_to_spatialdata(
dataset_id="2022-08-05_17h28m56s",
fdr=0.1,
database=("BraChemDB", "2018-01"),
)
# Workaround: spatialdata-plot currently does not use points transformation
sdata.points["maldi_points"] = sdata.transform_element_to_coordinate_system(
sdata.points["maldi_points"], "global"
)
(
sdata.pl.render_images("optical_image")
.pl.render_points(
"maldi_points",
color=sdata.tables["table"].var.index[0],
alpha=1,
size=2,
cmap="viridis_r",
)
.pl.show(title=sdata.tables["table"].var.index[0], coordinate_systems="global")
)
License
Unless specified otherwise in file headers or LICENSE files present in subdirectories, all files are licensed under the Apache 2.0 license.
Metadata
Release files for metaspace-converter 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| metaspace_converter-1.1.2.tar.gz | 27.1 kB | Without provenance | Details for metaspace_converter-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| metaspace_converter-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for metaspace_converter-1.1.2-py3-none-any.whl |
Total release size: 57.5 kB
Release files / metaspace_converter-1.1.2.tar.gz
| Download URL | metaspace_converter-1.1.2.tar.gz |
|---|---|
| Size | 27.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46fd28c8b432b25379ff03e840064911530391bae0ee551afb1d3cf6b9097bc2
|
|
BLAKE2b-256 checksum How to use checksums |
f7ab29adb997930b67e43cae6540fe56297760b321e919ad6ff28655c7a11bb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / metaspace_converter-1.1.2-py3-none-any.whl
| Download URL | metaspace_converter-1.1.2-py3-none-any.whl |
|---|---|
| Size | 30.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba7e8f5872dc1b98423eb48e5e193dac9e4dfa64fbead8fd0ccb6a4259ef05f4
|
|
BLAKE2b-256 checksum How to use checksums |
b4d8fc7ffb8c1bcd067fecf05b58695a43892f7ab500a901222d00821baacb41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for metaspace-converter 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.