diffsvg.tl.cluster_curves#

diffsvg.tl.cluster_curves(adata, by='average', n_clusters=5, genes=None, scale=False, coefs_key='dsvg_coefs', profiles_key='dsvg_profiles', key_added=None, random_state=0, n_init=100, inplace=True)#

Group genes by the shape of their fitted curves, with k-means on the spline coefficients.

Parameters:
adata

Annotated data matrix that diffsvg.tl.fit_model (or diffsvg.tl.fit_profiles, for by="profile") wrote into.

by default: 'average'

Which curves to compare:

  • "average": beta + beta_1 / 2, the combined curve: the mean of the two condition curves, weighting the conditions equally. Not beta alone, which with the 0/1 condition coding is the curve of condition 0.

  • "interaction": the interaction term beta_1, i.e. the shape of the difference curve f1 - f0. Not the level difference, which is a separate coefficient (categorical_beta).

  • "profile": beta of diffsvg.tl.fit_profiles, the one curve of a fit that ignores the condition. Without slide effects.

n_clusters default: 5

Number of clusters (k).

genes default: None

Genes to cluster, by default every fitted one.

scale default: False

Scale each gene’s coefficients to unit length, so that genes group by shape alone, however strong the trend. By default (False) the amplitude counts, so genes without a trend share one flat cluster. Scaling blows the noise of such genes up to the size of real trends, so combine it with genes, e.g. the genes with a clear trend.

coefs_key default: 'dsvg_coefs'

Prefixes passed to diffsvg.tl.fit_model / diffsvg.tl.fit_profiles.

profiles_key default: 'dsvg_profiles'

Prefixes passed to diffsvg.tl.fit_model / diffsvg.tl.fit_profiles.

key_added default: None

Where to write the result. Defaults to f"dsvg_cluster_{by}".

random_state default: 0

Passed to sklearn.cluster.KMeans. Many restarts cost next to nothing with one row per gene, and they make the result depend far less on the seed: on an 88-gene panel 10 gave up to 25 different partitions across 30 seeds, 100 mostly one.

n_init default: 100

Passed to sklearn.cluster.KMeans. Many restarts cost next to nothing with one row per gene, and they make the result depend far less on the seed: on an 88-gene panel 10 gave up to 25 different partitions across 30 seeds, 100 mostly one.

inplace default: True

If True (default), write adata.var[key_added] (categorical, NaN for genes not clustered) and adata.uns[key_added] (by, scale, n_clusters, silhouette, inertia, centers) and return None. Otherwise return the labels as a pandas.Series.

Returns:

None or pandas.Series Labels are "0", "1", …, the largest cluster first.

Examples

>>> dvg.tl.cluster_curves(adata, by="average", n_clusters=6)
>>> dvg.pl.plot_cluster_curves(adata, "dsvg_cluster_average")