metaspace_converter.to_anndata module

metaspace_converter.to_anndata.all_image_pixel_coordinates(shape)[source]

Returns a list of Y, X coordinates (Numpy order) for every pixel of an image.

Parameters:

shape (tuple[int, int]) – The shape of a 2D image

Return type:

ndarray

Returns:

Array of shape (number of pixels, 2)

metaspace_converter.to_anndata.create_annotation_id(formula, adduct, chem_mod='', neutral_loss='')[source]
Return type:

str

metaspace_converter.to_anndata.get_dataset(dataset=None, dataset_id=None, sm=None)[source]

Fetch a dataset instance, if not provided

Return type:

SMDataset

metaspace_converter.to_anndata.get_ion_image_shape(dataset=None, dataset_id=None, sm=None)[source]

Get the shape of a METASPACE dataset (in Numpy order).

Parameters:
  • dataset (Optional[SMDataset]) – A METASPACE dataset instance. If not provided, a dataset ID must be provided.

  • dataset_id (Optional[str]) – An optional METASPACE dataset ID, if no dataset instance is provided.

  • sm (Optional[SMInstance]) – An optional SMInstance, otherwise one will be created.

Return type:

tuple[int, int]

metaspace_converter.to_anndata.metaspace_to_anndata(dataset=None, dataset_id=None, database=None, fdr=0.1, use_tic=False, metadata_as_obs=False, add_optical_image=False, sm=None, **annotation_filter)[source]

Downloads a METASPACE dataset to an AnnData object.

See: https://metaspace2020.eu/about

Parameters:
  • dataset (Optional[SMDataset]) – A METASPACE dataset instance. If not provided, the dataset_id must be given.

  • dataset_id (Optional[str]) – The unique ID of a dataset on METASPACE, e.g. “2021-09-03_11h43m13s”

  • database (Optional[tuple[str, str]]) – A single METASPACE database given as a tuple of name and version. Usually it is displayed on METASPACE as “HMDB – v4” which corresponds to (“HMDB”, “v4”).

  • fdr (Optional[float]) – Returns only annotations for which the false discovery rate is less or equal to this limit.

  • use_tic (bool) – When True, the output values will be scaled by the total ion count per pixel and will be in 0.0 to 1.0 range.

  • metadata_as_obs (bool) – Whether to store metadata in the obs dataframe instead of uns. For a single METASPACE dataset, metadata is the same for all pixels, so it would be duplicated for all obs. When combining multiple datasets, it would be preserved in obs but not in uns.

  • add_optical_image (bool) – Whether to embed the optical image for SquidPy

  • sm (Optional[SMInstance]) – Optionally a cached SMInstance

  • annotation_filter – Additional keyword arguments passed to the METASPACE API.

Return type:

AnnData

Returns:

An AnnData object with
  • ion intensities: .X

  • ion image pixel coordinates: .obs[["ion_image_pixel_x", "ion_image_pixel_y"]]

  • spatial coordinates: .obsm["spatial"]

  • ion properties: .var, for example “formula”, “adduct”, “mz”, “fdr”, “moleculeNames”, “moleculeIds”, “intensity”…

  • METASPACE metadata: .uns["metaspace"] if not metadata_as_obs

  • SquidPy metadata: .uns["spatial"] if add_optical_image

Raises: