metaspace_converter.colocalization module

metaspace_converter.colocalization.coloc_ml_preprocessing(adata, layer='coloc_ml_preprocessing', median_filter_size=(3, 3), quantile_threshold=0.5)[source]

Preprocessing for colocalization analysis according to the colocML publication (https://doi.org/10.1093/bioinformatics/btaa085).

In the publication, the authors evaluated colocalization metrics and preprocessing approaches. They found the best performance for

  1. median filtering of ion images with a (3, 3) kernel size and

  2. quantile thresholding at 50%, meaning all pixels with intensities below the 50% quantile set to 0.

This function performs the same preprocessing steps. Recommended for call before running the colocalization function.

Parameters:
  • adata (AnnData) – An AnnData object.

  • layer (Optional[str]) – Key for the adata.layers dict in which the processed data will be saved. Default value is colocml_preprocessing. If None, adata.X will be overwritten with the processed data.

  • median_filter_size (Tuple[int, int]) – 2-dimensional filter size for the median filtering that will be performed per ion image.

  • quantile_threshold (float) – Float between 0 and 1. The function computes the quantile value per ion image and all pixels below the quantile threshold will be set to 0.

Returns:

None. The processed data is saved in layer. If layer is set to None, adata.X will be overwritten

Raises:

ValueError – If no annotations are available in adata.X.

metaspace_converter.colocalization.colocalization(adata, layer='coloc_ml_preprocessing')[source]

Colocalization of ion images using the cosine similarity metric.

In combination with the colocML_preprocessing function, this metric performed best in the colocML publication (https://doi.org/10.1093/bioinformatics/btaa085).

It is recommended to call the coloc_ml_preprocessing function beforehand.

Parameters:
  • adata (AnnData) – An AnnData object.

  • layer (Optional[str]) – Key for adata.layer from which the ionimage_data for preprocessing taken. If None, adata.X is used. coloc_ml_preprocessing will save the preprocessed data per default in adata.layer['coloc_ml_preprocessing'].

Returns:

None. The processed data is saved in adata.varp['colocalization'].

Raises:

ValueError – If layer is not found in adata.layers.