Package Bio :: Package Cluster :: Class Record
[hide private]
[frames] | no frames]

Class Record

source code

object --+
         |
        Record

Store gene expression data.

A Record stores the gene expression data and related information contained
in a data file following the file format defined for Michael Eisen's
Cluster/TreeView program. A Record has the following members:

data:     a matrix containing the gene expression data
mask:     a matrix containing only 1's and 0's, denoting which values
          are present (1) or missing (0). If all elements of mask are
          one (no missing data), then mask is set to None.
geneid:   a list containing a unique identifier for each gene
          (e.g., ORF name)
genename: a list containing an additional description for each gene
          (e.g., gene name)
gweight:  the weight to be used for each gene when calculating the
          distance
gorder:   an array of real numbers indicating the preferred order of the
          genes in the output file
expid:    a list containing a unique identifier for each experimental
          condition
eweight:  the weight to be used for each experimental condition when
          calculating the distance
eorder:   an array of real numbers indication the preferred order in the
          output file of the experimental conditions
uniqid:   the string that was used instead of UNIQID in the input file.

Instance Methods [hide private]
 
__init__(self, handle=None)
Read gene expression data from the file handle and return a Record.
source code
 
treecluster(self, transpose=0, method='m', dist='e')
Apply hierarchical clustering and return a Tree object.
source code
 
kcluster(self, nclusters=2, transpose=0, npass=1, method='a', dist='e', initialid=None)
Apply k-means or k-median clustering.
source code
 
somcluster(self, transpose=0, nxgrid=2, nygrid=1, inittau=0.02, niter=1, dist='e')
Calculate a self-organizing map on a rectangular grid.
source code
 
clustercentroids(self, clusterid=None, method='a', transpose=0)
Calculate the cluster centroids and return a tuple (cdata, cmask).
source code
 
clusterdistance(self, index1=[0], index2=[0], method='a', dist='e', transpose=0)
Calculate the distance between two clusters.
source code
 
distancematrix(self, transpose=0, dist='e')
Calculate the distance matrix and return it as a list of arrays
source code
 
save(self, jobname, geneclusters=None, expclusters=None)
Save the clustering results.
source code
 
_savekmeans(self, filename, clusterids, order, transpose) source code
 
_savedata(self, jobname, gid, aid, geneindex, expindex) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, handle=None)
(Constructor)

source code 
Read gene expression data from the file handle and return a Record.

The file should be in the format defined for Michael Eisen's
Cluster/TreeView program.

Overrides: object.__init__

treecluster(self, transpose=0, method='m', dist='e')

source code 
Apply hierarchical clustering and return a Tree object.

The pairwise single, complete, centroid, and average linkage hierarchical
clustering methods are available.

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

See the description of the Tree class for more information about the Tree
object returned by this method.

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

source code 
Apply k-means or k-median clustering.

This method returns a tuple (clusterid, error, nfound).

nclusters: number of clusters (the 'k' in k-means)
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.

somcluster(self, transpose=0, nxgrid=2, nygrid=1, inittau=0.02, niter=1, dist='e')

source code 
Calculate a self-organizing map on a rectangular grid.

The somcluster method returns a tuple (clusterid, celldata).

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).

clustercentroids(self, clusterid=None, method='a', transpose=0)

source code 
Calculate the cluster centroids and return a tuple (cdata, cmask).

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 how the centroid is calculated:
           method=='a': arithmetic mean over each dimension. (default)
           method=='m': median 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.

clusterdistance(self, index1=[0], index2=[0], method='a', dist='e', transpose=0)

source code 
Calculate the distance between two clusters.

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.

distancematrix(self, transpose=0, dist='e')

source code 
Calculate the distance matrix and return it as a list of arrays

transpose: if equal to 0: calculate the distances between genes (rows);
           if equal to 1: calculate the distances beteeen microarrays
                          (columns).
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.]

save(self, jobname, geneclusters=None, expclusters=None)

source code 
Save the clustering results.

The saved files follow the convention for the Java TreeView program,
which can therefore be used to view the clustering result.

Arguments:
jobname:   The base name of the files to be saved. The filenames are
           jobname.cdt, jobname.gtr, and jobname.atr for
           hierarchical clustering, and jobname-K*.cdt,
           jobname-K*.kgg, jobname-K*.kag for k-means clustering
           results.
geneclusters=None:  For hierarchical clustering results, geneclusters
           is a Tree object as returned by the treecluster method.
           For k-means clustering results, geneclusters is a vector
           containing ngenes integers, describing to which cluster a
           given gene belongs. This vector can be calculated by
           kcluster.
expclusters=None:  For hierarchical clustering results, expclusters
           is a Tree object as returned by the treecluster method.
           For k-means clustering results, expclusters is a vector
           containing nexps integers, describing to which cluster a
           given experimental condition belongs. This vector can be
           calculated by kcluster.