コード例 #1
0
ファイル: cluster.py プロジェクト: agiorgetti1971/ProDy-1
def calcGNMDomains(modes, method=Hierarchy, **kwargs):
    """Uses spectral clustering to separate structural domains in the chromosome.
    
    :arg modes: GNM modes used for segmentation
    :type modes: :class:`ModeSet`

    :arg method: Label assignment algorithm used after Laplacian embedding of loci.
    :type method: func
    """

    V, mask = _getEigvecs(modes, row_norm=True, remove_zero_rows=True)

    labels_ = method(V, **kwargs)

    labels = np.empty(len(mask))
    labels.fill(np.nan)
    labels[mask] = labels_

    currlbl = labels_[np.argmax(~np.isnan(labels_))]

    for i in range(len(labels)):
        l = labels[i]
        if np.isnan(l):
            labels[i] = currlbl
        elif currlbl != l:
            currlbl = l

    return labels
コード例 #2
0
ファイル: cluster.py プロジェクト: agiorgetti1971/ProDy-1
def showLinkage(V, **kwargs):
    """Shows the dendrogram of hierarchical clustering on *V*. See :func:`scipy.cluster.hierarchy.dendrogram` for details.

    :arg V: row-normalized eigenvectors for the purpose of clustering.
    :type V: :class:`numpy.ndarray`

    """

    V, _ = _getEigvecs(V, row_norm=True, remove_zero_rows=True)
    try:
        from scipy.cluster.hierarchy import linkage, dendrogram
    except ImportError:
        raise ImportError('Use of this function (showLinkage) requires the '
                          'installation of scipy.')
    
    method = kwargs.pop('method', 'single')
    metric = kwargs.pop('metric', 'euclidean')
    Z = linkage(V, method=method, metric=metric)

    no_labels = kwargs.pop('no_labels', True)
    dendrogram(Z, no_labels=no_labels, **kwargs)
    if SETTINGS['auto_show']:
        showFigure()
    return Z