[Jtreeview-cvs] jtreeview commit notification
Brought to you by:
alokito
|
From: Alex S. <av...@us...> - 2004-07-01 20:37:01
|
Update of /cvsroot/jtreeview/LinkedView/src/edu/stanford/genetics/treeview/dendroview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12946/src/edu/stanford/genetics/treeview/dendroview Modified Files: Tag: SpellmanBeta ColorBarExportPanel.java GifColorBarExportPanel.java FontSelectable.java GlobalView.java FontSelector.java ColorSet.java BitmapExportPanel.java FillMap.java CharDendroView.java PostscriptExportPanel.java TextView.java LeftTreeDrawer.java GifExportPanel.java TreeDrawer.java ColorPresets.java CharColorExtractor.java CharColorSet.java SummaryPanel.java KnnDendroView.java GTRView.java ZoomView.java ATRView.java PostScriptMaker.java ColorExtractor.java NullMap.java BitmapColorBarExportPanel.java DendroView.java IntegerMap.java FontSettingsPanel.java FUOptionsPanel.java SummaryViewWizard.java ExportPanel.java MapContainer.java KnnArrayDrawer.java CharArrayDrawer.java ArrayNameView.java PostscriptColorBarExportPanel.java ATRZoomView.java TreeColorer.java FixedMap.java ColorPresetEditor.java ColorSetEditor.java PixelSettingsSelector.java MapSelector.java ArrayDrawer.java DendroException.java InvertedTreeDrawer.java DoubleArrayDrawer.java Added Files: Tag: SpellmanBeta AtrAligner.java TreeAnalysisNode.java AtrAnalysisNode.java Log Message: Index: DendroView.java =================================================================== RCS file: /cvsroot/jtreeview/LinkedView/src/edu/stanford/genetics/treeview/dendroview/DendroView.java,v retrieving revision 1.34 retrieving revision 1.34.2.1 diff -C2 -d -r1.34 -r1.34.2.1 *** DendroView.java 18 May 2004 18:17:15 -0000 1.34 --- DendroView.java 1 Jul 2004 20:36:17 -0000 1.34.2.1 *************** *** 24,28 **** --- 24,34 ---- import edu.stanford.genetics.treeview.*; + import com.gurge.amd.*; + + import edu.stanford.genetics.treeview.dendroview.AtrAligner; + import edu.stanford.genetics.treeview.dendroview.DendroException; + import edu.stanford.genetics.treeview.dendroview.TreeColorer; + import edu.stanford.genetics.treeview.model.AtrTVModel; import edu.stanford.genetics.treeview.model.TVModel; *************** *** 32,35 **** --- 38,42 ---- import java.lang.String; import java.io.*; + import javax.swing.*; *************** *** 166,169 **** --- 173,383 ---- windowActive = flag; } + /** + * Finds the currently selected arrays, mirror image flips them, and then rebuilds all necessary trees and saved data to the .jtv file. + * + */ + private void flipSelectedATRNode() + { + int leftIndex, rightIndex; + String selectedID; + TreeDrawerNode arrayNode = getArraySelection().getSelectedNode(); + + if(arrayNode == null || arrayNode.isLeaf()) + { + return; + } + + selectedID = arrayNode.getId(); + + //find the starting index of the left array tree, the ending index of the right array tree + leftIndex = dataModel.getArrayHeaderInfo().getHeaderIndex(arrayNode.getLeft().getLeftLeaf().getId()); + rightIndex = dataModel.getArrayHeaderInfo().getHeaderIndex(arrayNode.getRight().getRightLeaf().getId()); + + int num = dataModel.getDataMatrix().getNumCol(); + + int [] newOrder = new int[num]; + + for(int i = 0; i < num; i++) + { + newOrder[i] = i; + } + + for(int i = 0; i <= (rightIndex - leftIndex); i++) + { + newOrder[leftIndex + i] = rightIndex - i; + } + + /*System.out.print("Fliping to: "); + for(int i = 0; i < newOrder.length; i++) + { + System.out.print(newOrder[i] + " "); + } + System.out.println("");*/ + + ((TVModel)dataModel).reorderArrays(newOrder); + ((TVModel)dataModel).saveOrder(newOrder); + ((Observable)dataModel).notifyObservers(); + + updateATRDrawer(selectedID); + } + + /** + * Aligns the current ATR to the passed model as best as possible, saves the new ordering to the .jtv file. + * @param model - AtrTVModel with which to align. + */ + public void alignAtrToModel(AtrTVModel model) + { + HeaderInfo headers = model.getArrayHeaderInfo(); + + try{ + String selectedID = null; + + try { + selectedID = getArraySelection().getSelectedNode().getId(); + } + catch(NullPointerException npe) + { + } + + + int [] ordering; + ordering = AtrAligner.align(dataModel.getAtrHeaderInfo(), dataModel.getArrayHeaderInfo(), + model.getAtrHeaderInfo(), model.getArrayHeaderInfo()); + + /*System.out.print("New ordering: "); + for(int i = 0; i < ordering.length; i++) + { + System.out.print(ordering[i] + " "); + } + System.out.println();*/ + + + ((TVModel)dataModel).reorderArrays(ordering); + ((TVModel)dataModel).saveOrder(ordering); + ((Observable)dataModel).notifyObservers(); + + if(selectedID != null) + { + updateATRDrawer(selectedID); + } + } + catch(Exception e) + { + System.out.println(e.toString()); + } + } + + + /** + * Updates the ATRDrawer to reflect changes in the DataMode array order; rebuilds the TreeDrawerNode tree. + * @param selectedID ID of the node selected before a change in tree structure was made. This node is then found and reselected after the ATR tree is rebuilt. + */ + private void updateATRDrawer(String selectedID) + { + try { + TVModel tvmodel = (TVModel)dataModel; + invertedTreeDrawer.setData(tvmodel.getAtrHeaderInfo(), tvmodel.getArrayHeaderInfo()); + HeaderInfo trHeaderInfo = tvmodel.getAtrHeaderInfo(); + if (trHeaderInfo.getIndex("NODECOLOR") >= 0) { + TreeColorer.colorUsingHeader (invertedTreeDrawer.getRootNode(), + trHeaderInfo, + trHeaderInfo.getIndex("NODECOLOR")); + + } + } + catch (DendroException e) { + // LogPanel.println("Had problem setting up the array tree : " + e.getMessage()); + // e.printStackTrace(); + Box mismatch = new Box(BoxLayout.Y_AXIS); mismatch.add(new JLabel(e.getMessage())); + mismatch.add(new JLabel("Perhaps there is a mismatch between your ATR and CDT files?")); + mismatch.add(new JLabel("Ditching Array Tree, since it's lame.")); + JOptionPane.showMessageDialog(viewFrame, mismatch, "Tree Construction Error", JOptionPane.ERROR_MESSAGE); + atrview.setEnabled(false); + atrzview.setEnabled(false); + try{invertedTreeDrawer.setData(null, null);} catch (DendroException ex) {} + } + + TreeDrawerNode arrayNode = invertedTreeDrawer.getRootNode().findNode(selectedID); + arraySelection.setSelectedNode(arrayNode); + atrzview.setSelectedNode(arrayNode); + atrview.setSelectedNode(arrayNode); + arraySelection.notifyObservers(); + + + invertedTreeDrawer.notifyObservers(); + } + /** + * Creates an AtrTVModel for use in tree alignment. + * @param fileSet + * @return a new AtrTVModel with the file set loaded into it. + * @throws LoadException + */ + protected AtrTVModel makeAtrModel(FileSet fileSet) throws LoadException { + AtrTVModel atrTVModel = new AtrTVModel(); + + try { + atrTVModel.loadNew(fileSet); + } catch (LoadException e) { + JOptionPane.showMessageDialog(this, e); + throw e; + } + + return atrTVModel; + } + + + /** + * Open a dialog which allows the user to select a new CDT data file for tree alignment. + * + * @return The fileset corresponding to the dataset. + */ + /* + * Unknow what actually happens if the file CDT does not have an associated ATR. + */ + protected FileSet offerATRFileSelection() throws LoadException + { + FileSet fileSet1; // will be chosen... + + JFileChooser fileDialog = new JFileChooser(); + setupATRFileDialog(fileDialog); + int retVal = fileDialog.showOpenDialog(this); + if(retVal == JFileChooser.APPROVE_OPTION) + { + File chosen = fileDialog.getSelectedFile(); + + fileSet1 = new FileSet(chosen.getName(), chosen.getParent() + File.separator); + } + else + { + throw new LoadException("File Dialog closed without selection...", LoadException.NOFILE); + } + + return fileSet1; + } + + /** + * Sets up a dialog for loading ATR files for tree alignment. + * @param fileDialog the dialog to setup + */ + protected void setupATRFileDialog(JFileChooser fileDialog) { + CdtFilter ff = new CdtFilter(); + try { + fileDialog.addChoosableFileFilter(ff); + // will fail on pre-1.3 swings + fileDialog.setAcceptAllFileFilterUsed(true); + } catch (Exception e) { + // hmm... I'll just assume that there's no accept all. + fileDialog.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { + public boolean accept (File f) { + return true; + } + public String getDescription () { + return "All Files"; + } + }); + } + fileDialog.setFileFilter(ff); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + } *************** *** 862,866 **** */ public void populateAnalysisMenu(Menu menu) { ! MenuItem summaryItem = new MenuItem("Summary Window..."); summaryItem.addActionListener(new ActionListener() { --- 1076,1119 ---- */ public void populateAnalysisMenu(Menu menu) { ! MenuItem flipNodeItem = new MenuItem("Flip Tree Node", new MenuShortcut(KeyEvent.VK_L)); ! flipNodeItem.addActionListener( ! new ActionListener() ! { ! public void actionPerformed(ActionEvent ae) ! { ! flipSelectedATRNode(); ! } ! } ! ); ! menu.add(flipNodeItem); ! ! ! MenuItem alignToTreeItem = new MenuItem("Align to Tree...", new MenuShortcut(KeyEvent.VK_A)); ! alignToTreeItem.addActionListener( ! new ActionListener() ! { ! public void actionPerformed(ActionEvent ae) ! { ! try ! { ! FileSet fileSet = offerATRFileSelection(); ! AtrTVModel atrModel = makeAtrModel(fileSet); ! ! alignAtrToModel(atrModel); ! ! } ! catch (LoadException e) ! { ! if ((e.getType() != LoadException.INTPARSE) && ! (e.getType() != LoadException.NOFILE)) { ! LogPanel.println("Could not open file: " + e.getMessage()); ! e.printStackTrace(); ! } ! } ! } ! } ! ); ! menu.add(alignToTreeItem); ! MenuItem summaryItem = new MenuItem("Summary Window..."); summaryItem.addActionListener(new ActionListener() { --- NEW FILE: TreeAnalysisNode.java --- /* BEGIN_HEADER Java TreeView * * $Author: avsegal * $RCSfile: TreeAnalysisNode.java * $Revision: * $Date: Jun 25, 2004 * $Name: * * This file is part of Java TreeView * Copyright (C) 2001-2003 Alok Saldanha, All Rights Reserved. * * This software is provided under the GNU GPL Version 2. In particular, * * 1) If you modify a source file, make a comment in it containing your name and the date. * 2) If you distribute a modified version, you must do it under the GPL 2. * 3) Developers are encouraged but not required to notify the Java TreeView maintainers at al...@ge... when they make a useful addition. It would be nice if significant contributions could be merged into the main distribution. * * A full copy of the license can be found in gpl.txt or online at * http://www.gnu.org/licenses/gpl.txt * * END_HEADER */ package edu.stanford.genetics.treeview.dendroview; /** * @author avsegal * * Generic class for analysis of ATR and GTR trees. */ import java.util.Vector; public abstract class TreeAnalysisNode { /** * Create a new node with given id. * @param pID the id of the node */ TreeAnalysisNode(String pID) { id = pID; left = null; right = null; parent = null; } /** * Create a new node with a given id and parent. * @param pID the id of the node * @param pParent the parent of the node */ TreeAnalysisNode(String pID, TreeAnalysisNode pParent) { id = pID; left = null; right = null; parent = pParent; } /** * Gets the node's id. * @return the id */ public String getID() { return id; } /** * Gets the index of this node. * @return the index */ public int getIndex() { return index; } /** * Sets the index of this node. * @param ind index to set */ public void setIndex(int ind) { index = ind; } /** * Is this a root node? * @return true if this node is a root, false otherwise */ public boolean isRoot() { return (parent == null); } /** * Is this a leaf node? * @return true if this node is a leaf, false otherwise */ public boolean isLeaf() { return (left == null && right == null); } /** * Gets the leftmost leaf of the subtree rooted at this node. * @return the leftmost leaf of subtree. */ public TreeAnalysisNode getLeftLeaf() { if(isLeaf()) { return this; } if(left != null) { return left.getLeftLeaf(); } return right.getLeftLeaf(); // right cannot be null, otherwise this is a leaf } /** * Gets the rightmost leaf of the subtree rooted at this node. * @return the rightmost leaf of subtree. */ public TreeAnalysisNode getRightLeaf() { if(isLeaf()) { return this; } if(right != null) { return right.getRightLeaf(); } return left.getRightLeaf(); // left cannot be null, otherwise this is a leaf } /** * Switched the left and right child. * */ public void flip() { TreeAnalysisNode temp; temp = left; left = right; right = temp; } /** * Gives a listing, in order, of all nodes in this tree. * @param v vector to be filled with the listing */ public void enumerate(Vector v) { if(left != null) { left.enumerate(v); } v.add(this); if(right != null) { right.enumerate(v); } } /** * Computes the root of this node's tree. * @return the root node */ public TreeAnalysisNode findRoot() { if(isRoot()) { return this; } return parent.findRoot(); } /** * Find a node with given id in this subtree. * @param id id to look for * @return node found, or null if no such node exists */ public TreeAnalysisNode find(String id) { TreeAnalysisNode temp; if(getID().equals(id)) { return this; } if(left != null) { temp = left.find(id); if(temp != null) { return temp; } } if(right != null) { temp = right.find(id); if(temp != null) { return temp; } } return null; } /** * Set the left child. * @param node left child */ public void setLeft(TreeAnalysisNode node) { left = node; } /** * Gets the left child. * @return left child */ public TreeAnalysisNode getLeft() { return left; } /** * Set the right child. * @param node right child */ public void setRight(TreeAnalysisNode node) { right = node; } /** * Gets the right child. * @return right child */ public TreeAnalysisNode getRight() { return right; } /** * Sets the parent. * @param node parent */ public void setParent(TreeAnalysisNode node) { parent = node; } /** * Gets the parent. * @return parent */ public TreeAnalysisNode getParent() { return parent; } TreeAnalysisNode left; TreeAnalysisNode right; TreeAnalysisNode parent; String id; int index; } --- NEW FILE: AtrAligner.java --- /* BEGIN_HEADER Java TreeView * * $Author: avsegal * $RCSfile: AtrAligner.java * $Revision: * $Date: Jun 25, 2004 * $Name: * * This file is part of Java TreeView * Copyright (C) 2001-2003 Alok Saldanha, All Rights Reserved. * * This software is provided under the GNU GPL Version 2. In particular, * * 1) If you modify a source file, make a comment in it containing your name and the date. * 2) If you distribute a modified version, you must do it under the GPL 2. * 3) Developers are encouraged but not required to notify the Java TreeView maintainers at al...@ge... when they make a useful addition. It would be nice if significant contributions could be merged into the main distribution. * * A full copy of the license can be found in gpl.txt or online at * http://www.gnu.org/licenses/gpl.txt * * END_HEADER */ package edu.stanford.genetics.treeview.dendroview; /** * @author avsegal * * Aligns the array ordering to match a different array tree. Used statically two * align one fileset to another. */ import edu.stanford.genetics.treeview.*; import java.util.*; public class AtrAligner { /** * * @param atrHeader1 the atr header to be aligned * @param arrayHeader1 the array header to be aligned * @param atrHeader2 the atr header to align to * @param arrayHeader2 the array header to align to * @return a new ordering of arrayHeader1 * @throws DendroException */ public static int [] align(HeaderInfo atrHeader1, HeaderInfo arrayHeader1, HeaderInfo atrHeader2, HeaderInfo arrayHeader2) throws DendroException { int numArrays = arrayHeader1.getNumHeaders(); int [] newOrder = new int[numArrays]; AtrAnalysisNode root1; for(int i = 0; i < numArrays; i++) { newOrder[i] = i; } root1 = createAnalysisTree(atrHeader1, arrayHeader1); alignTree(root1, arrayHeader1, arrayHeader2, newOrder); return newOrder; } /** * Creates an AtrAnalysis tree based on the atr and array headers. * @param atrHeader ATR header * @param arrayHeader array header * @return the root node of the tree * @throws DendroException */ private static AtrAnalysisNode createAnalysisTree(HeaderInfo atrHeader, HeaderInfo arrayHeader) throws DendroException { int numArrays = arrayHeader.getNumHeaders(); AtrAnalysisNode [] leafNodes = new AtrAnalysisNode[numArrays]; Hashtable id2node = new Hashtable(((atrHeader.getNumHeaders() * 4) /3)/2, .75f); String newId, leftId, rightId; AtrAnalysisNode newN, leftN, rightN; for(int i = 0; i < atrHeader.getNumHeaders(); i++) { newId = atrHeader.getHeader(i, "NODEID"); leftId = atrHeader.getHeader(i, "LEFT"); rightId = atrHeader.getHeader(i, "RIGHT"); newN = (AtrAnalysisNode)id2node.get(newId); leftN = (AtrAnalysisNode)id2node.get(leftId); rightN = (AtrAnalysisNode)id2node.get(rightId); if (newN != null) { System.out.println("Symbol '" + newId + "' appeared twice, building weird tree"); } else { newN = new AtrAnalysisNode(newId, null); id2node.put(newId, newN); } if (leftN == null) { // this means that the identifier for leftn is a new leaf int val; // stores index (y location) try { val = arrayHeader.getHeaderIndex(leftId); } catch (java.lang.NullPointerException ex) { throw new DendroException("Identifier " + leftId + " from tree file not found in CDT! Exception was " + ex); } leftN = new AtrAnalysisNode(leftId, newN); leftN.setIndex(val); leftN.setName(arrayHeader.getHeader(val, "GID")); leafNodes[val] = leftN; id2node.put(leftId, leftN); } if (rightN == null) { // this means that the identifier for rightn is a new leaf // System.out.println("Looking up " + rightId); int val; // stores index (y location) try { val = arrayHeader.getHeaderIndex(rightId); } catch (java.lang.NullPointerException ex) { throw new DendroException("Identifier " + rightId + " from tree file not found in CDT! Exception was " + ex); } rightN = new AtrAnalysisNode(rightId, newN); rightN.setIndex(val); rightN.setName(arrayHeader.getHeader(val, "GID")); leafNodes[val] = rightN; id2node.put(rightId, rightN); } if(leftN.getIndex() > rightN.getIndex()) { AtrAnalysisNode temp = leftN; leftN = rightN; rightN = temp; } rightN.setParent(newN); leftN.setParent(newN); newN.setLeft(leftN); newN.setRight(rightN); } return (AtrAnalysisNode)leafNodes[0].findRoot(); } /** * Aligns tree rooted at root1 to a different atr tree as best as possible. * @param root1 root of the tree to align * @param arrayHeader1 array header of the tree to align * @param arrayHeader2 array header of the tree to align to * @param ordering the ordering array which this method will fill */ private static void alignTree(AtrAnalysisNode root1, HeaderInfo arrayHeader1, HeaderInfo arrayHeader2, int [] ordering) { Vector v1 = new Vector(); Hashtable gid2index = new Hashtable(); int gidIndex = arrayHeader2.getIndex("GID"); for(int i = 0; i < arrayHeader2.getNumHeaders(); i++) { gid2index.put(arrayHeader2.getHeader(i)[gidIndex], new Integer(i)); } root1.indexTree(arrayHeader2, gid2index); root1.enumerate(v1); for(int i = 0; i < v1.size(); i++) { ordering[i] = arrayHeader1.getHeaderIndex(((AtrAnalysisNode)v1.get(i)).getID()); } } } Index: ColorBarExportPanel.java =================================================================== RCS file: /cvsroot/jtreeview/LinkedView/src/edu/stanford/genetics/treeview/dendroview/ColorBarExportPanel.java,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -C2 -d -r1.10 -r1.10.2.1 *** ColorBarExportPanel.java 18 May 2004 05:05:51 -0000 1.10 --- ColorBarExportPanel.java 1 Jul 2004 20:36:17 -0000 1.10.2.1 *************** *** 1045,1047 **** --- 1045,1052 ---- return dataMatrix[x + y * nCol]; } + public void setValue(double value, int x, int y) + { + dataMatrix[x + y*nCol] = value; + } + } --- NEW FILE: AtrAnalysisNode.java --- /* BEGIN_HEADER Java TreeView * * $Author: avsegal * $RCSfile: AtrAnalysisNode.java * $Revision: * $Date: Jun 25, 2004 * $Name: * * This file is part of Java TreeView * Copyright (C) 2001-2003 Alok Saldanha, All Rights Reserved. * * This software is provided under the GNU GPL Version 2. In particular, * * 1) If you modify a source file, make a comment in it containing your name and the date. * 2) If you distribute a modified version, you must do it under the GPL 2. * 3) Developers are encouraged but not required to notify the Java TreeView maintainers at al...@ge... when they make a useful addition. It would be nice if significant contributions could be merged into the main distribution. * * A full copy of the license can be found in gpl.txt or online at * http://www.gnu.org/licenses/gpl.txt * * END_HEADER */ package edu.stanford.genetics.treeview.dendroview; /** * @author avsegal * * Binary tree node for analysis of array trees. The tree is parent-linked. */ import edu.stanford.genetics.treeview.*; import java.util.*; public class AtrAnalysisNode extends TreeAnalysisNode { /** * Creates a new node. * @param pID ID of the node in the ATR file */ public AtrAnalysisNode(String pID) { super(pID); leafCount = -1; averageIndex = -1; name = ""; } /** * Creates a new node with a given parent. * @param pID ID of the node in the ATR file * @param pParent parent of this node */ public AtrAnalysisNode(String pID, TreeAnalysisNode pParent) { super(pID, pParent); leafCount = -1; averageIndex = -1; name = ""; } /** * Sets the name of this node. * @param name the name to set */ public void setName(String name) { this.name = name; } /** * Returns the node's name. * @return the node's name */ public String getName() { return name; } /** * Returns the average of all leaf weights in this subtree. This is used in the alignment algorithm. * @return the average index of leaves */ public double getAverageSubtreeIndex() { double sum = 0; double num = 0; Vector v = new Vector(); enumerate(v); for(int i = 0; i < v.size(); i++) { if(((TreeAnalysisNode)v.elementAt(i)).isLeaf()) { sum += ((TreeAnalysisNode)v.elementAt(i)).getIndex(); num++; } } return sum/num; } /** * Returns a vector of all leaves in this subtree, in order. * @param v the vector to fill with leaves */ public void enumerate(Vector v) { if(left != null) { left.enumerate(v); } if(isLeaf()) { v.add(this); } if(right != null) { right.enumerate(v); } } /** * Gets the number of leaves. * @return the number of leaves in this subtree */ public int getLeafCount() { if(leafCount == -1) { if(isLeaf()) { leafCount = 1; } else { leafCount = 0; if(left != null) { leafCount += ((AtrAnalysisNode)left).getLeafCount(); } else if(right != null) { leafCount += ((AtrAnalysisNode)right).getLeafCount(); } } } return leafCount; } /** * Calculates the average index of all nodes. * @param arrayHeader the arrayHeader to use for index look up * @param gid2index hashtable for reverse index look up (by array name) * @return the average index for this subtree */ private double computeAverageIndexTree(HeaderInfo arrayHeader, Hashtable gid2index) { double leftSum = 0, rightSum = 0; if(isLeaf()) { int val = 0; try { val = ((Integer)gid2index.get(getName())).intValue(); } catch (java.lang.NullPointerException ex) { leafCount = 0; //do nothing, since we want to ignore non-matched aspects of mostly equivelent trees. } setIndex(val); averageIndex = val; } else { leftSum = ((AtrAnalysisNode)left).computeAverageIndexTree(arrayHeader, gid2index); rightSum = ((AtrAnalysisNode)right).computeAverageIndexTree(arrayHeader, gid2index); leftSum *= ((AtrAnalysisNode)left).getLeafCount(); rightSum *= ((AtrAnalysisNode)right).getLeafCount(); averageIndex = (leftSum + rightSum)/(((AtrAnalysisNode)left).getLeafCount() + ((AtrAnalysisNode)right).getLeafCount()); } return averageIndex; } /** * Rearranged the tree by average index. * */ private void arrangeByAverageIndex() { if(left == null || right == null) { return; } AtrAnalysisNode temp; if(((AtrAnalysisNode)left).getAverageIndex() > ((AtrAnalysisNode)right).getAverageIndex()) { temp = (AtrAnalysisNode)left; left = right; right = temp; } ((AtrAnalysisNode)left).arrangeByAverageIndex(); ((AtrAnalysisNode)right).arrangeByAverageIndex(); } /** * Calculates all the indecies. * @param arrayHeader the arrayHeader to use for index look up * @param gid2index hashtable for reverse index look up (by array name) */ public void indexTree(HeaderInfo arrayHeader, Hashtable gid2index) { computeAverageIndexTree(arrayHeader, gid2index); arrangeByAverageIndex(); } /** * Gets the average index of this subtree. * @return the average index of this subtree. */ public double getAverageIndex() { return averageIndex; } int leafCount; double averageIndex; String name; } |