pymaid.ClustResults

class pymaid.ClustResults(mat, labels=None, mat_type='distance')[source]

Class to handle, analyze and plot similarity/distance matrices.

Contains thin wrappers for scipy.cluster.

dist_mat
Type:

Distance matrix (0=similar, 1=dissimilar)

sim_mat
Type:

Similarity matrix (0=dissimilar, 1=similar)

linkage

to generate linkage. By default, WARD’s algorithm is used.

Type:

Hierarchical clustering. Run pymaid.ClustResults.cluster()

leafs
Type:

list of skids

Examples

>>> import matplotlib.pyplot as plt
>>> # Get a bunch of neurons
>>> nl = pymaid.get_neuron('annotation:glomerulus DA1')
>>> # Perform connectivity clustering
>>> res = pymaid.cluster_by_connectivity(nl)
>>> # `res` is a ClustResults object with handy methods:
>>> res.plot_matrix()
>>> plt.show()
>>> # Extract 5 clusters
>>> res.get_clusters(5, criterion = 'maxclust')

Initialize class instance.

Parameters:
  • mat (numpy.array | pandas.DataFrame) – Distance or similarity matrix.

  • labels (list, optional) – Labels for matrix.

  • mat_type ('distance' | 'similarity', default = 'distance') –

    Sets the type of input matrix:
    • ’similarity’ = high values are more similar

    • ’distance’ = low values are more similar

    The “missing” matrix type will be computed. For clustering, plotting, etc. distance matrices are used.

__init__(mat, labels=None, mat_type='distance')[source]

Initialize class instance.

Parameters:
  • mat (numpy.array | pandas.DataFrame) – Distance or similarity matrix.

  • labels (list, optional) – Labels for matrix.

  • mat_type ('distance' | 'similarity', default = 'distance') –

    Sets the type of input matrix:
    • ’similarity’ = high values are more similar

    • ’distance’ = low values are more similar

    The “missing” matrix type will be computed. For clustering, plotting, etc. distance matrices are used.

Methods

__init__(mat[, labels, mat_type])

Initialize class instance.

calc_agg_coeff()

Return the agglomerative coefficient.

calc_cophenet()

Return Cophenetic Correlation coefficient of your clustering.

cluster([method])

Cluster distance matrix.

get_clusters(k[, criterion, return_type])

Get get clusters.

get_colormap([k, criterion])

Generate colormap based on clustering.

get_leafs([use_labels])

Retrieve leaf labels.

plot3d([k, criterion])

Plot neuron using pymaid.plot.plot3d().

plot_dendrogram([color_threshold, ...])

Plot dendrogram using matplotlib.

plot_matrix()

Plot distance matrix and dendrogram using matplotlib.

plot_matrix2(**kwargs)

Plot distance matrix and dendrogram using seaborn.

to_selection([fname, k, criterion])

Convert clustered neurons into json file.

to_tree()

Turn linkage to ete3 tree.