athena.neighborhood.base_estimators module

Summary

Classes:

Interactions

Estimator to quantify interaction strength between different species in the sample.

RipleysK

Reference

class Interactions(so, spl, attr='meta_id', mode='classic', n_permutations=500, random_seed=None, alpha=0.01, graph_key='knn')[source]

Bases: object

Estimator to quantify interaction strength between different species in the sample.

VALID_MODES = ['classic', 'histoCAT', 'proportion']
VALID_PREDICTION_TYPES = ['pvalue', 'observation', 'diff']
__init__(so, spl, attr='meta_id', mode='classic', n_permutations=500, random_seed=None, alpha=0.01, graph_key='knn')[source]

Estimator to quantify interaction strength between different species in the sample.

Parameters
  • so – SpatialOmics

  • spl (str) – Sample for which to compute the interaction strength

  • attr (str) – Categorical feature in SpatialOmics.obs to use for the grouping

  • mode (str) – One of {classic, histoCAT, proportion}, see notes

  • n_permutations (int) – Number of permutations to compute p-values and the interactions strength score (mode diff)

  • random_seed – Random seed for permutations

  • alpha (float) – Threshold for significance

  • graph_key (str) – Specifies the graph representation to use in so.G[spl] if local=True.

Notes

classic and histoCAT are python implementations of the corresponding methods pubished by the Bodenmiller lab at UZH. The proportion method is similar to the classic method but normalises the score by the number of edges and is thus bound [0,1].

fit(prediction_type='observation', try_load=True)[source]

Compute the interactions scores for the sample.

Parameters
  • prediction_type (str) – One of {observation, pvalue, diff}, see Notes

  • try_load (bool) – load pre-computed permutation results if available

Returns:

Notes

observation: computes the observed interaction strength in the sample

pvalue: computes the P-value of a two-sided t-test for the interactions strength based on the random permutations

diff: computes the difference between observed and average interaction strength (across permutations)

Return type

None

predict()[source]

Predict interactions strengths of observations.

Returns: A dataframe with the interaction results.

Return type

DataFrame

generate_h0(relative_freq, observed, save=True)[source]
class RipleysK(so, spl, id, attr)[source]

Bases: object

__init__(so, spl, id, attr)[source]

Compute Ripley’s K for a given sample and group.

Parameters
  • so – SpatialOmics

  • spl (str) – Sample for which to compute the interaction strength

  • id – The category in the categorical feature attr, for which Ripley’s K should be computed

  • attr (str) – Categorical feature in SpatialOmics.obs to use for the grouping

  • graph_key – Specifies the graph representation to use in so.G[spl] if local=True.

fit()[source]
predict(radii, correction='ripley', mode='K')[source]

Estimate Ripley’s K

Parameters
  • radii (list) – List of radiis for which Ripley’s K is computed

  • correction (str) – Correction method to use to correct for boarder effects, see [1].

  • mode (str) – {K, csr-deviation}. If K, Ripley’s K is estimated, with csr-deviation the deviation from a poission process is computed.

Returns

Ripley’s K estimates

Notes

1

https://docs.astropy.org/en/stable/stats/ripley.html

csr_deviation(radii, correction='ripley')[source]

Compute deviation from random poisson process.

Parameters
  • radii – List of radiis for which Ripley’s K is computed

  • correction – Correction method to use to correct for boarder effects, see [1].

Returns:

Return type

ndarray