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.
- metaspace_converter.to_anndata.create_annotation_id(formula, adduct, chem_mod='', neutral_loss='')[source]
- Return type:
- metaspace_converter.to_anndata.get_dataset(dataset=None, dataset_id=None, sm=None)[source]
Fetch a dataset instance, if not provided
- Return type:
- 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:
- Return type:
- 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 SquidPysm (
Optional
[SMInstance
]) – Optionally a cached SMInstanceannotation_filter – Additional keyword arguments passed to the METASPACE API.
- Return type:
- 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 notmetadata_as_obs
SquidPy metadata:
.uns["spatial"]
ifadd_optical_image
- An
- Raises:
ValueError – If something is wrong with the input data or parameters
metaspace.sm_annotation_utils.DatasetNotFound – If the dataset ID is not found
ConnectionError – For any other network connectivity problems