athena.metrics.heterogeneity.metrics module

Summary

Functions:

abundance

Computes the abundance of species on the observation or the sample level.

hill_number

Computes the Hill Numbers on the observation or the sample level

quadratic_entropy

Computes the quadratic entropy, taking relative abundance and similarity between observations into account.

renyi_entropy

Computes the Renyi-Entropy.

richness

Computes the richness on the observation or the sample level

shannon

Computes the Shannon Index on the observation or the sample level

simpson

Computes the Simpson Index on the observation or the sample level

Reference

richness(so, spl, attr, *, local=True, key_added=None, graph_key='knn', inplace=True)[source]

Computes the richness on the observation or the sample level

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • local – Whether to compute the metric on the observation or the sample level

  • key_added – Key added to either obs or spl depending on the choice of local

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

  • inplace – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.richness(so, spl, 'meta_id', local=False)
sh.metrics.richness(so, spl, 'meta_id', local=True)
Return type

None

shannon(so, spl, attr, *, local=True, key_added=None, graph_key='knn', base=2, inplace=True)[source]

Computes the Shannon Index on the observation or the sample level

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • local – Whether to compute the metric on the observation or the sample level

  • key_added – Key added to either obs or spl depending on the choice of local

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

  • inplace – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.shannon(so, spl, 'meta_id', local=False)
sh.metrics.shannon(so, spl, 'meta_id', local=True)
Return type

None

simpson(so, spl, attr, *, local=True, key_added=None, graph_key='knn', inplace=True)[source]

Computes the Simpson Index on the observation or the sample level

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • local – Whether to compute the metric on the observation or the sample level

  • key_added – Key added to either obs or spl depending on the choice of local

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

  • inplace – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.simpson(so, spl, 'meta_id', local=False)
sh.metrics.simpson(so, spl, 'meta_id', local=True)
Return type

None

hill_number(so, spl, attr, q, *, local=True, key_added=None, graph_key='knn', inplace=True)[source]

Computes the Hill Numbers on the observation or the sample level

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • q (float) – The hill coefficient as defined here.

  • local – Whether to compute the metric on the observation or the sample level

  • key_added – Key added to either obs or spl depending on the choice of local

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

  • inplace – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.hill_number(so, spl, 'meta_id', q=2, local=False)
sh.metrics.hill_number(so, spl, 'meta_id', q=2, local=True)
renyi_entropy(so, spl, attr, q, *, local=True, key_added=None, graph_key='knn', base=2, inplace=True)[source]

Computes the Renyi-Entropy.

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • q (float) – The renyi coefficient as defined here

  • local – Whether to compute the metric on the observation or the sample level

  • key_added – Key added to either obs or spl depending on the choice of local

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

  • inplace – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.renyi_entropy(so, spl, 'meta_id', q=2, local=False)
sh.metrics.renyi_entropy(so, spl, 'meta_id', q=2, local=True)
quadratic_entropy(so, spl, attr, *, metric='minkowski', metric_kwargs={}, scale=True, local=True, key_added=None, graph_key='knn', inplace=True)[source]

Computes the quadratic entropy, taking relative abundance and similarity between observations into account.

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • metric – metric used to compute distance of observations in the features space so.X[spl]

  • metric_kwargs – key word arguments for metric

  • scale (bool) – whether to scale features of observations to unit variance and 0 mean

  • local – whether to compute the metric on the observation or the sample level

  • key_added – Key added to either obs or spl depending on the choice of local

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

  • inplace – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Notes

The implementation computes an average feature vector for each group in attr based on all observations in the sample. Thus, if staining biases across samples exists this will directly distort this metric.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.quadratic_entropy(so, spl, 'meta_id', local=False)
sh.metrics.quadratic_entropy(so, spl, 'meta_id', local=True)
abundance(so, spl, attr, *, mode='proportion', key_added=None, graph_key='knn', local=False, inplace=True)[source]

Computes the abundance of species on the observation or the sample level.

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

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

  • local – Whether to compute the metric on the observation or the sample level

  • key_added (Optional[str]) – Key added to either uns[spl] or obs depending on the choice of local

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

  • inplace (bool) – Whether to add the metric to the current SpatialOmics instance or to return a new one.

Examples

so = sh.dataset.imc()
spl = so.spl.index[0]

sh.metrics.abundance(so, spl, 'meta_id', local=False)
sh.metrics.abundance(so, spl, 'meta_id', local=True)