mesa.multiomics.multiomics_spatial.get_neighborhood_composition

mesa.multiomics.multiomics_spatial.get_neighborhood_composition(knn_indices, labels, all_labels, percentage=True)

Compute the global composition of neighbors for each sample, either in percentage or count form, based on k-nearest neighbors (k-NN) indices and specific cluster labels.

Parameters:
  • knn_indices (numpy.ndarray of shape (n_samples, n_neighbors)) – An array where each row represents the k-nearest neighbors’ indices for that sample, indicating the nearest neighbors.

  • labels (numpy.ndarray of shape (n_samples,)) – Cluster labels for each sample that appear in this particular region, used to determine neighborhood composition.

  • all_labels (numpy.ndarray) – All unique cluster labels across the entire dataset, used for reference in composition calculations.

  • percentage (bool, optional) – Specifies whether to return the composition as a percentage of the total or as a raw count. Default is True.

Returns:

An array where each row represents the composition of neighbors for each sample, either as a percentage or a count, based on the cluster labels.

Return type:

numpy.ndarray of shape (n_samples, len(all_labels))