Package: metaspace-converter
METASPACE converterPython package to download and convert datasets from theMETASPACEknowledge base to common formats for single-cell and spatial omics analysis.
Datasets can be directly downloaded toAnnDataandSpatialDataobjects.AnnDatais the underlying data format
of many packages of thescversesuch asscanpyfor single-cell data analysis andsquidpyfor spatial omics analysis.Another supported format that is part of thescverseisSpatialDatafor 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 theGitHub repository.InstallationOur package requirespython >= 3.9.You can install the package directly fromPyPI:pipinstallmetaspace-converterShort tutorialThe full documentation for the package can be found here:https://metaspace2020.github.io/metaspace-converter/The METASPACE-converter package uses thepython clientto download datasets from METASPACE.
It serves as a wrapper that downloads and converts datasets directly toAnnDataandSpatialDataobjects.If you also need to upload or modify datasets on METASPACE, please check theMETASPACE python client documentation.AnnDataDatasets can be downloaded to AnnData objects using themetaspace_to_anndatafunction.
This allows downstream analysis e.g. withscanpyorsquidpy.Scanpyfrommetaspace_converterimportmetaspace_to_anndataimportscanpyassc# Download data and convert to an AnnData objectadata=metaspace_to_anndata(dataset_id="2022-08-05_17h28m56s",fdr=0.1,database=("BraChemDB","2018-01"),)# Visualization with ScanPysc.pl.spatial(adata,# Choose the first ion for visualizationcolor=adata.var.index[0],img_key=None,spot_size=1,)SquidpyOptical 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.frommetaspace_converterimportmetaspace_to_anndataimportsquidpyassq# Download dataset with optical background imageadata=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 arraysIf you want to work with the ion images as numpy arrays, the functionanndata_to_image_arraycan
convert previously downloaded AnnData objects to numpy arrays.frommetaspace_converterimportmetaspace_to_anndata,anndata_to_image_array# Download dataadata2=metaspace_to_anndata(dataset_id="2023-11-14_21h58m39s",fdr=0.1)ion_images=anndata_to_image_array(adata2)# 20 ion images of shape 130x143print(ion_images.shape)# > (20, 130, 143)SpatialDataDownload to theSpatialDataformat equally easy and
can be done with themetaspace_to_spatialdatafunction.Here using a reversed colormap which better represents intense values on a bright background.frommetaspace_converterimportmetaspace_to_spatialdataimportspatialdata_plot# noqa: Not directly used but extends spatialdata# Download dataset with optical background imagesdata=metaspace_to_spatialdata(dataset_id="2022-08-05_17h28m56s",fdr=0.1,database=("BraChemDB","2018-01"),)# Workaround: spatialdata-plot currently does not use points transformationsdata.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.table.var.index[0],alpha=1,size=2,cmap="viridis_r",).pl.show(title=sdata.table.var.index[0],coordinate_systems="global"))LicenseUnless specified otherwise in file headers or LICENSE files present in subdirectories, all files are licensed under theApache 2.0 license.