Back to index

python-biopython  1.60
Classes | Functions
Bio.Cluster Namespace Reference

Classes

class  Record

Functions

def _treesort
def _savetree
def read

Function Documentation

def Bio.Cluster._savetree (   jobname,
  tree,
  order,
  transpose 
) [private]

Definition at line 58 of file __init__.py.

00058 
00059 def _savetree(jobname, tree, order, transpose):
00060     # Save the hierarchical clustering solution given by the tree, following
00061     # the specified order, in a file whose name is based on jobname.
00062     if transpose == 0:
00063         extension = ".gtr"
00064         keyword = "GENE"
00065     else:
00066         extension = ".atr"
00067         keyword = "ARRY"
00068     nnodes = len(tree)
00069     outputfile = open(jobname+extension, "w")
00070     nodeindex = 0
00071     nodeID = [''] * nnodes
00072     nodecounts = numpy.zeros(nnodes, int)
00073     nodeorder = numpy.zeros(nnodes)
00074     nodedist = numpy.array([node.distance for node in tree])
00075     for nodeindex in range(nnodes):
00076         min1 = tree[nodeindex].left
00077         min2 = tree[nodeindex].right
00078         nodeID[nodeindex] = "NODE%dX" % (nodeindex+1)
00079         outputfile.write(nodeID[nodeindex])
00080         outputfile.write("\t")
00081         if min1 < 0:
00082             index1 = -min1-1
00083             order1 = nodeorder[index1]
00084             counts1 = nodecounts[index1]
00085             outputfile.write(nodeID[index1]+"\t")
00086             nodedist[nodeindex] = max(nodedist[nodeindex],nodedist[index1])
00087         else:
00088             order1 = order[min1]
00089             counts1 = 1
00090             outputfile.write("%s%dX\t" % (keyword, min1))
00091         if min2 < 0:
00092             index2 = -min2-1
00093             order2 = nodeorder[index2]
00094             counts2 = nodecounts[index2]
00095             outputfile.write(nodeID[index2]+"\t")
00096             nodedist[nodeindex] = max(nodedist[nodeindex],nodedist[index2])
00097         else:
00098             order2 = order[min2]
00099             counts2 = 1
00100             outputfile.write("%s%dX\t" % (keyword, min2))
00101         outputfile.write(str(1.0-nodedist[nodeindex]))
00102         outputfile.write("\n")
00103         counts = counts1 + counts2
00104         nodecounts[nodeindex] = counts
00105         nodeorder[nodeindex] = (counts1*order1+counts2*order2) / counts
00106     outputfile.close()
00107     # Now set up order based on the tree structure
00108     index = _treesort(order, nodeorder, nodecounts, tree)
00109     return index
00110 

Here is the call graph for this function:

def Bio.Cluster._treesort (   order,
  nodeorder,
  nodecounts,
  tree 
) [private]

Definition at line 5 of file __init__.py.

00005 
00006 def _treesort(order, nodeorder, nodecounts, tree):
00007     # Find the order of the nodes consistent with the hierarchical clustering
00008     # tree, taking into account the preferred order of nodes.
00009     nNodes = len(tree)
00010     nElements = nNodes + 1
00011     neworder = numpy.zeros(nElements)
00012     clusterids = numpy.arange(nElements)
00013     for i in range(nNodes):
00014         i1 = tree[i].left
00015         i2 = tree[i].right
00016         if i1 < 0:
00017             order1 = nodeorder[-i1-1]
00018             count1 = nodecounts[-i1-1]
00019         else:
00020             order1 = order[i1]
00021             count1 = 1
00022         if i2 < 0:
00023             order2 = nodeorder[-i2-1]
00024             count2 = nodecounts[-i2-1]
00025         else:
00026             order2 = order[i2]
00027             count2 = 1
00028         # If order1 and order2 are equal, their order is determined
00029         # by the order in which they were clustered
00030         if i1 < i2:
00031             if order1 < order2:
00032                 increase = count1
00033             else:
00034                 increase = count2
00035             for j in range(nElements):
00036                 clusterid = clusterids[j]
00037                 if clusterid == i1 and order1 >= order2:
00038                     neworder[j] += increase
00039                 if clusterid == i2 and order1 < order2:
00040                     neworder[j] += increase
00041                 if clusterid == i1 or clusterid == i2:
00042                     clusterids[j] = -i-1
00043         else:
00044             if order1 <= order2:
00045                 increase = count1
00046             else:
00047                 increase = count2
00048             for j in range(nElements):
00049                 clusterid = clusterids[j]
00050                 if clusterid == i1 and order1 > order2:
00051                     neworder[j] += increase
00052                 if clusterid == i2 and order1 <= order2:
00053                     neworder[j] += increase
00054                 if clusterid == i1 or clusterid == i2:
00055                     clusterids[j] = -i-1
00056     return numpy.argsort(neworder)
00057 

Here is the caller graph for this function:

def Bio.Cluster.read (   handle)
Read gene expression data from the file handle and return a Record.

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

Definition at line 629 of file __init__.py.

00629 
00630 def read(handle):
00631     """Read gene expression data from the file handle and return a Record.
00632 
00633 The file should be in the file format defined for Michael Eisen's
00634 Cluster/TreeView program.
00635 
00636 """
00637     return Record(handle)