spac.utils.annotation_category_relations(adata, source_annotation, target_annotation, prefix=False)[source]

Calculates the count of unique relationships between two annotations in an AnnData object. Relationship is defined as a unique pair of values, one from the ‘source_annotation’ and one from the ‘target_annotation’.

Returns a DataFrame with columns ‘source_annotation’, ‘target_annotation’, ‘count’, ‘percentage_source’, and ‘percentage_target’. Where ‘count’ represents the number of occurrences of each relationship, percentage_source represents the percentage of the count of link over the total count of the source label, and percentage_target represents the percentage of the count of link over the total count of the target.

If the prefix is set to True, it appends “source_” and “target_” prefixes to labels in the “source” and “target” columns, respectively.

Parameters:
  • adata (AnnData) – The annotated data matrix of shape n_obs * n_vars. Rows correspond to cells and columns to genes.

  • source_annotation (str) – The name of the source annotation column in the adata object.

  • target_annotation (str) – The name of the target annotation column in the adata object.

  • prefix (bool, optional) – If True, appends “source_” and “target_” prefixes to the “source” and “target” columns, respectively.

Returns:

relationships – A DataFrame with the source and target categories, their counts and their percentages.

Return type:

pandas.DataFrame