Package Bio :: Package Cluster :: Module cluster
[hide private]
[frames] | no frames]

Module cluster

C Clustering Library

Functions [hide private]
cdata, cmask

clustercentroids(data, mask=None, transport=0, clusterid, method='a')
The clustercentroids routine calculates the cluster centroids, given to which cluster each element belongs.
the distance between the

clusterdistance(data, mask=None, weight=None, index1, index2, dist='e', method='a', transpose=0)
two clusters
distance matrix as a list of arrays

distancematrix(data, mask=None, weight=None, transpose=0, dist='e')
This function returns the distance matrix between gene expression data.
clusterid, error, nfound

kcluster(data, nclusters=2, mask=None, weight=None, transpose=0, npass=1, method='a', dist='e', initialid=None)
This function implements k-means clustering.
clusterid, error, nfound

kmedoids(distance, nclusters=2, npass=1, initialid=None)
This function implements k-medoids clustering.
arithmetic mean of the 1D array data.

mean(data)
median value of the 1D array data

median(data)
Note: data will be partially ordered upon return.
(columnmean, coordinates, pc, eigenvalues)

pca(data)
This function returns the principal component decomposition of the gene expression data.
clusterid, celldata

somcluster(data, mask=None, weight=None, transpose=0, nxgrid=2, nygrid=1, inittau=0.02, niter=1, dist='e')
This function implements a self-organizing map on a rectangular grid.
Tree object

treecluster(data=None, mask=None, weight=None, transpose=0, dist='e', method='m', distancematrix=None)
This function implements the pairwise single, complete, centroid, and average linkage hierarchical clustering methods.
 
version()
This function returns the version number of the C Clustering Library as a string.
Variables [hide private]
  __package__ = None
hash(x)
Function Details [hide private]

clustercentroids(data, mask=None, transport=0, clusterid, method='a')

 
The clustercentroids routine calculates the cluster centroids, given to
which cluster each element belongs. The centroid is defined as either
the mean or the median over all elements for each dimension.
data     : nrows x ncolumns array containing the expression data
mask     : nrows x ncolumns array of integers, showing which data are
           missing. If mask[i][j]==0, then data[i][j] is missing.
transpose: if equal to 0, gene (row) clusters are considered;
           if equal to 1, microarray (column) clusters are considered.
clusterid: array containing the cluster number for each gene or
           microarray. The cluster number should be non-negative.
method   : specifies whether the centroid is calculated from the
           arithmetic mean (method=='a', default) or the median
           (method=='m') over each dimension.

Return values:
cdata    : 2D array containing the cluster centroids. If transpose==0,
           then the dimensions of cdata are nclusters x ncolumns. If
           transpose==1, then the dimensions of cdata are
           nrows x nclusters.
cmask    : 2D array of integers describing which elements in cdata,
           if any, are missing.

Returns:
cdata, cmask

clusterdistance(data, mask=None, weight=None, index1, index2, dist='e', method='a', transpose=0)

 
                                            two clusters

data     : nrows x ncolumns array containing the expression data
mask     : nrows x ncolumns array of integers, showing which data are
           missing. If mask[i][j]==0, then data[i][j] is missing.
weight   : the weights to be used when calculating distances
index1   : 1D array identifying which genes/microarrays belong to the
           first cluster. If the cluster contains only one gene, then
           index1 can also be written as a single integer.
index2   : 1D array identifying which genes/microarrays belong to the
           second cluster. If the cluster contains only one gene, then
           index2 can also be written as a single integer.
transpose: if equal to 0, genes (rows) are clustered;
           if equal to 1, microarrays (columns) are clustered.
dist     : specifies the distance function to be used:
           dist=='e': Euclidean distance
           dist=='b': City Block distance
           dist=='c': Pearson correlation
           dist=='a': absolute value of the correlation
           dist=='u': uncentered correlation
           dist=='x': absolute uncentered correlation
           dist=='s': Spearman's rank correlation
           dist=='k': Kendall's tau
method   : specifies how the distance between two clusters is defined:
           method=='a': the distance between the arithmetic means of the
                        two clusters
           method=='m': the distance between the medians of the two
                        clusters
           method=='s': the smallest pairwise distance between members
                        of the two clusters
           method=='x': the largest pairwise distance between members of
                        the two clusters
           method=='v': average of the pairwise distances between
                        members of the clusters
transpose: if equal to 0: clusters of genes (rows) are considered;
           if equal to 1: clusters of microarrays (columns) are
                          considered.

Returns:
the distance between the

distancematrix(data, mask=None, weight=None, transpose=0, dist='e')

 
This function returns the distance matrix between gene expression data.
data     : nrows x ncolumns array containing the expression data
mask     : nrows x ncolumns array of integers, showing which data are
           missing. If mask[i][j]==0, then data[i][j] is missing.
weight   : the weights to be used when calculating distances.
transpose: if equal to 0: the distances between genes (rows) are
                          calculated;
           if equal to 1, the distances beteeen microarrays (columns)
                          are calculated.
dist     : specifies the distance function to be used:
           dist=='e': Euclidean distance
           dist=='b': City Block distance
           dist=='c': Pearson correlation
           dist=='a': absolute value of the correlation
           dist=='u': uncentered correlation
           dist=='x': absolute uncentered correlation
           dist=='s': Spearman's rank correlation
           dist=='k': Kendall's tau

Return value:
The distance matrix is returned as a list of 1D arrays containing the
distance matrix between the gene expression data. The number of columns
in each row is equal to the row number. Hence, the first row has zero
elements. An example of the return value is
matrix = [[],
          array([1.]),
          array([7., 3.]),
          array([4., 2., 6.])]
This corresponds to the distance matrix
 [0., 1., 7., 4.]
 [1., 0., 3., 2.]
 [7., 3., 0., 6.]
 [4., 2., 6., 0.]

Returns:
distance matrix as a list of arrays

kcluster(data, nclusters=2, mask=None, weight=None, transpose=0, npass=1, method='a', dist='e', initialid=None)

 
This function implements k-means clustering.
data     : nrows x ncolumns array containing the expression data
nclusters: number of clusters (the 'k' in k-means)
mask     : nrows x ncolumns array of integers, showing which data are
           missing. If mask[i][j]==0, then data[i][j] is missing.
weight   : the weights to be used when calculating distances
transpose: if equal to 0, genes (rows) are clustered;
           if equal to 1, microarrays (columns) are clustered.
npass    : number of times the k-means clustering algorithm is
           performed, each time with a different (random) initial
           condition.
method   : specifies how the center of a cluster is found:
           method=='a': arithmetic mean
           method=='m': median
dist     : specifies the distance function to be used:
           dist=='e': Euclidean distance
           dist=='b': City Block distance
           dist=='c': Pearson correlation
           dist=='a': absolute value of the correlation
           dist=='u': uncentered correlation
           dist=='x': absolute uncentered correlation
           dist=='s': Spearman's rank correlation
           dist=='k': Kendall's tau
initialid: the initial clustering from which the algorithm should start.
           If initialid is None, the routine carries out npass
           repetitions of the EM algorithm, each time starting from a
           different random initial clustering. If initialid is given,
           the routine carries out the EM algorithm only once, starting
           from the given initial clustering and without randomizing the
           order in which items are assigned to clusters (i.e., using
           the same order as in the data matrix). In that case, the
           k-means algorithm is fully deterministic.

Return values:
clusterid: array containing the number of the cluster to which each
           gene/microarray was assigned in the best k-means clustering
           solution that was found in the npass runs;
error:     the within-cluster sum of distances for the returned k-means
           clustering solution;
nfound:    the number of times this solution was found.

Returns:
clusterid, error, nfound

kmedoids(distance, nclusters=2, npass=1, initialid=None)

 
This function implements k-medoids clustering.
distance:  The distance matrix between the elements. There are three
           ways in which you can pass a distance matrix:
           #1: a 2D Numerical Python array (in which only the left-lower
               part of the array will be accessed);
           #2: a 1D Numerical Python array containing the distances
               consecutively;
           #3: a list of rows containing the lower-triangular part of
               the distance matrix.
           Examples are:
           >>> distance = array([[0.0, 1.1, 2.3],
                                 [1.1, 0.0, 4.5],
                                 [2.3, 4.5, 0.0]])
           (option #1)
           >>> distance = array([1.1, 2.3, 4.5])
           (option #2)
           >>> distance = [array([]),
                           array([1.1]),
                           array([2.3, 4.5])
                          ]
           (option #3)
           These three correspond to the same distance matrix.
nclusters: number of clusters (the 'k' in k-medoids)
npass    : the number of times the k-medoids clustering algorithm is
           performed, each time with a different (random) initial
           condition.
initialid: the initial clustering from which the algorithm should start.
           If initialid is not given, the routine carries out npass
           repetitions of the EM algorithm, each time starting from a
           different random initial clustering. If initialid is given,
           the routine carries out the EM algorithm only once, starting
           from the initial clustering specified by initialid and
           without randomizing the order in which items are assigned to
           clusters (i.e., using the same order as in the data matrix).
           In that case, the k-means algorithm is fully deterministic.

Return values:
clusterid: array containing the number of the cluster to which each
           gene/microarray was assigned in the best k-means clustering
           solution that was found in the npass runs;
error:     the within-cluster sum of distances for the returned k-means
           clustering solution;
nfound:    the number of times this solution was found.

Returns:
clusterid, error, nfound

pca(data)

 
This function returns the principal component decomposition of the gene
expression data.
data     : nrows x ncolumns array containing the expression data

Return value:
This function returns an array containing the mean of each column, the
principal components as an nmin x ncolumns array, as well as the
coordinates (an nrows x nmin array) of the data along the principal
components, and the associated eigenvalues. The principal components, the
coordinates, and the eigenvalues are sorted by the magnitude of the
eigenvalue, with the largest eigenvalues appearing first. Here, nmin is
the smaller of nrows and ncolumns.
Adding the column means to the dot product of the coordinates and the
principal components,
>>> columnmean + dot(coordinates, pc)
recreates the data matrix.

Returns:
(columnmean, coordinates, pc, eigenvalues)

somcluster(data, mask=None, weight=None, transpose=0, nxgrid=2, nygrid=1, inittau=0.02, niter=1, dist='e')

 
This function implements a self-organizing map on a rectangular grid.
data     : nrows x ncolumns array containing the gene expression data
mask     : nrows x ncolumns array of integers, showing which data are
           missing. If mask[i][j]==0, then data[i][j] is missing.
weight   : the weights to be used when calculating distances
transpose: if equal to 0, genes (rows) are clustered;
           if equal to 1, microarrays (columns) are clustered.
nxgrid   : the horizontal dimension of the rectangular SOM map
nygrid   : the vertical dimension of the rectangular SOM map
inittau  : the initial value of tau (the neighborbood function)
niter    : the number of iterations
dist     : specifies the distance function to be used:
           dist=='e': Euclidean distance
           dist=='b': City Block distance
           dist=='c': Pearson correlation
           dist=='a': absolute value of the correlation
           dist=='u': uncentered correlation
           dist=='x': absolute uncentered correlation
           dist=='s': Spearman's rank correlation
           dist=='k': Kendall's tau

Return values:
clusterid: array with two columns, while the number of rows is equal to
           the number of genes or the number of microarrays depending on
           whether genes or microarrays are being clustered. Each row in
           the array contains the x and y coordinates of the cell in the
           rectangular SOM grid to which the gene or microarray was
           assigned.
celldata:  an array with dimensions (nxgrid, nygrid, number of
           microarrays) if genes are being clustered, or (nxgrid,
           nygrid, number of genes) if microarrays are being clustered.
           Each element [ix][iy] of this array is a 1D vector containing
           the gene expression data for the centroid of the cluster in
           the SOM grid cell with coordinates (ix, iy).

Returns:
clusterid, celldata

treecluster(data=None, mask=None, weight=None, transpose=0, dist='e', method='m', distancematrix=None)

 
This function implements the pairwise single, complete, centroid, and
average linkage hierarchical clustering methods.
data     : nrows x ncolumns array containing the gene expression data.
mask     : nrows x ncolumns array of integers, showing which data are
           missing. If mask[i][j]==0, then data[i][j] is missing.
weight   : the weights to be used when calculating distances.
transpose: if equal to 0, genes (rows) are clustered;
           if equal to 1, microarrays (columns) are clustered.
dist     : specifies the distance function to be used:
           dist=='e': Euclidean distance
           dist=='b': City Block distance
           dist=='c': Pearson correlation
           dist=='a': absolute value of the correlation
           dist=='u': uncentered correlation
           dist=='x': absolute uncentered correlation
           dist=='s': Spearman's rank correlation
           dist=='k': Kendall's tau
method   : specifies which linkage method is used:
           method=='s': Single pairwise linkage
           method=='m': Complete (maximum) pairwise linkage (default)
           method=='c': Centroid linkage
           method=='a': Average pairwise linkage
distancematrix:  The distance matrix between the elements. There are
           three ways in which you can pass a distance matrix:
           #1: a 2D Numerical Python array (in which only the left-lower
               part of the array will be accessed);
           #2: a 1D Numerical Python array containing the distances
               consecutively;
           #3: a list of rows containing the lower-triangular part of
               the distance matrix.
           Examples are:
           >>> distance = array([[0.0, 1.1, 2.3],
                                 [1.1, 0.0, 4.5],
                                 [2.3, 4.5, 0.0]])
           (option #1)
           >>> distance = array([1.1, 2.3, 4.5])
           (option #2)
           >>> distance = [array([]),
                           array([1.1]),
                           array([2.3, 4.5])
                          ]
           (option #3)
           These three correspond to the same distance matrix.
           PLEASE NOTE:
           As the treecluster routine may shuffle the values in the
           distance matrix as part of the clustering algorithm, be sure
           to save this array in a different variable before calling
           treecluster if you need it later.

Either data or distancematrix should be None. If distancematrix==None,
the hierarchical clustering solution is calculated from the gene
expression data stored in the argument data. If data==None, the
hierarchical clustering solution is calculated from the distance matrix
instead. Pairwise centroid-linkage clustering can be calculated only
from the gene expression data and not from the distance matrix. Pairwise
single-, maximum-, and average-linkage clustering can be calculated from
either the gene expression data or from the distance matrix.

Return value:
treecluster returns a Tree object describing the hierarchical clustering
result. See the description of the Tree class for more information.

Returns:
Tree object