tacco.tools.co_occurrence_matrix¶
- co_occurrence_matrix(adata, annotation_key, center_key=None, sample_key=None, position_key=('x', 'y'), result_key=None, max_distance=None, **kw_args)[source]¶
Calculates a spatial co-occurence score given by the conditional probability to find an annotation a at some distance d from an observation with annotation b, normalized by the probability to find an annotation a at distance d from an observation disregarding the value of its annotation: p(a|bd)/p(a|d). This is a convenience wrapper around
co_occurrence()
which just calculates the co-occurence score for the first distance bin.- Parameters:
adata – A
AnnData
annotation_key – The .obs or .obsm key for the annotation a in p(a|bd)/p(a|d).
center_key – The .obs or .obsm key for the annotation b in p(a|bd)/p(a|d). If None, takes the annotation_key.
sample_key – A categorical sample annotation. The result from different samples is averaged for the final result and their standard deviation gives an estimation of the error. If None, all observations are assumed to be on the same sample.
position_key – The .obsm key or array-like of .obs keys with the position space coordinates
result_key – The .uns key to contain the result. If None, the result is returned as a dictionary { “occ”: scores, “interval”: intervals, “annotation”: annotations, “center”: center }, with scores containing the p(a|bd)/p(a|d) values as a
ndarray
with dimensions according to a, b, and d, intervals containing the boundaries of the distance bins, annotations containing the order of the a annotations in scores, and center the order of the b annotations.max_distance – The maximum distance to use. If None or np.inf, uses the maximum distance in the data (if there are multiple samples, then only the first sample is used). If the distance matrix is not precomputed (see distance_key), None and np.inf result in dense distance computation (which can be infeasible for larger datasets).
**kw_args – Additional keyword arguments are forwarded to
co_occurrence()
.
- Returns:
Depending on result_key returns either the updated input adata or the result directly in the format described under result_key.