mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/som/SOMGUI.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2005, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4  */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: SOMGUI.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.9 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 20:59:54 $
2 26 Feb 07 jari 9  * $Author: caliente $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.gui.impl.som;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 15 import java.awt.event.WindowEvent;
2 26 Feb 07 jari 16 import java.util.Arrays;
2 26 Feb 07 jari 17
2 26 Feb 07 jari 18 import javax.swing.JOptionPane;
2 26 Feb 07 jari 19 import javax.swing.tree.DefaultMutableTreeNode;
2 26 Feb 07 jari 20
2 26 Feb 07 jari 21 import org.tigr.microarray.mev.cluster.Cluster;
2 26 Feb 07 jari 22 import org.tigr.microarray.mev.cluster.Node;
2 26 Feb 07 jari 23 import org.tigr.microarray.mev.cluster.NodeList;
2 26 Feb 07 jari 24 import org.tigr.microarray.mev.cluster.NodeValueList;
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.cluster.algorithm.Algorithm;
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData;
2 26 Feb 07 jari 27 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent;
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmListener;
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.cluster.gui.IClusterGUI;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 34 import org.tigr.microarray.mev.cluster.gui.IDistanceMenu;
2 26 Feb 07 jari 35 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 36 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 37 import org.tigr.microarray.mev.cluster.gui.LeafInfo;
2 26 Feb 07 jari 38 import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject;
2 26 Feb 07 jari 39 import org.tigr.microarray.mev.cluster.gui.helpers.ClusterTableViewer;
2 26 Feb 07 jari 40 import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterTableViewer;
2 26 Feb 07 jari 41 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener;
2 26 Feb 07 jari 42 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.Progress;
2 26 Feb 07 jari 43 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLGUI;
2 26 Feb 07 jari 44 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLInitDialog;
2 26 Feb 07 jari 45 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData;
2 26 Feb 07 jari 46 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLViewer;
2 26 Feb 07 jari 47 import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI;
2 26 Feb 07 jari 48 import org.tigr.util.FloatMatrix;
2 26 Feb 07 jari 49
2 26 Feb 07 jari 50
2 26 Feb 07 jari 51 public class SOMGUI implements IClusterGUI, IScriptGUI {
2 26 Feb 07 jari 52     
2 26 Feb 07 jari 53     private Experiment experiment;
2 26 Feb 07 jari 54     private IData data;
2 26 Feb 07 jari 55     private Algorithm algorithm;
2 26 Feb 07 jari 56     private Progress progress;
2 26 Feb 07 jari 57     
2 26 Feb 07 jari 58     private int[][] clusters;
2 26 Feb 07 jari 59     private FloatMatrix codes;
2 26 Feb 07 jari 60     private FloatMatrix u_matrix;
2 26 Feb 07 jari 61     private FloatMatrix means;
2 26 Feb 07 jari 62     private FloatMatrix variances;
2 26 Feb 07 jari 63     private boolean clusterGenes;
2 26 Feb 07 jari 64     
2 26 Feb 07 jari 65     /**
2 26 Feb 07 jari 66      * Initialize the algorithm's parameters and execute it.
2 26 Feb 07 jari 67      */
2 26 Feb 07 jari 68     public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException {
2 26 Feb 07 jari 69
2 26 Feb 07 jari 70         IDistanceMenu menu = framework.getDistanceMenu();
2 26 Feb 07 jari 71         int function = menu.getDistanceFunction();
2 26 Feb 07 jari 72         if (function == Algorithm.DEFAULT) {
2 26 Feb 07 jari 73             function = Algorithm.EUCLIDEAN;
2 26 Feb 07 jari 74         } 
2 26 Feb 07 jari 75             
2 26 Feb 07 jari 76         this.data = framework.getData();
2 26 Feb 07 jari 77         SOMInitDialog som_dialog = new SOMInitDialog(framework.getFrame(), 3, 3, 2000, 0.05f, 3f, 1, 1, 0, menu.getFunctionName(function), menu.isAbsoluteDistance());
2 26 Feb 07 jari 78         if (som_dialog.showModal() != JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 79             return null;
2 26 Feb 07 jari 80         }
2 26 Feb 07 jari 81         clusterGenes = som_dialog.isClusterGenes();
2 26 Feb 07 jari 82         boolean isHierarchicalTree = som_dialog.isHierarchicalTree();
2 26 Feb 07 jari 83         // hcl init
2 26 Feb 07 jari 84         int hcl_method = 0;
2 26 Feb 07 jari 85         boolean hcl_samples = false;
2 26 Feb 07 jari 86         boolean hcl_genes = false;
2 26 Feb 07 jari 87         int hcl_metric = 4;
2 26 Feb 07 jari 88         boolean hcl_absolute = false;
2 26 Feb 07 jari 89         if (isHierarchicalTree) {
2 26 Feb 07 jari 90                         
2 26 Feb 07 jari 91             HCLInitDialog hcl_dialog = new HCLInitDialog(framework.getFrame(), menu.getFunctionName(som_dialog.getDistanceMetric()), som_dialog.isAbsoluteDistance(), true);
2 26 Feb 07 jari 92             if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 93                 return null;
2 26 Feb 07 jari 94             }
2 26 Feb 07 jari 95             hcl_method = hcl_dialog.getMethod();
2 26 Feb 07 jari 96             hcl_samples = hcl_dialog.isClusterExperiments();
2 26 Feb 07 jari 97             hcl_genes = hcl_dialog.isClusterGenes();
2 26 Feb 07 jari 98             hcl_metric = hcl_dialog.getDistanceMetric();
2 26 Feb 07 jari 99             hcl_absolute = hcl_dialog.getAbsoluteSelection();
2 26 Feb 07 jari 100         }
2 26 Feb 07 jari 101         
2 26 Feb 07 jari 102         this.experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 103         GeneralInfo info = new GeneralInfo();
2 26 Feb 07 jari 104         info.alpha = som_dialog.getAlpha();
2 26 Feb 07 jari 105         info.radius = som_dialog.getRadius();
2 26 Feb 07 jari 106         if(clusterGenes)
2 26 Feb 07 jari 107             info.dimension   = this.experiment.getNumberOfSamples();
2 26 Feb 07 jari 108         else
2 26 Feb 07 jari 109             info.dimension = this.experiment.getNumberOfGenes();
2 26 Feb 07 jari 110         info.dimension_x = som_dialog.getDimensionX();
2 26 Feb 07 jari 111         info.dimension_y = som_dialog.getDimensionY();
2 26 Feb 07 jari 112         info.clusters    = info.dimension_x * info.dimension_y;
2 26 Feb 07 jari 113         info.iterations  = som_dialog.getIterations();
2 26 Feb 07 jari 114         info.neiborhood  = som_dialog.getNeighborhood() == 0 ? "bubble" : "gaussian";
2 26 Feb 07 jari 115         info.topology    = som_dialog.getTopology() == 0 ? "hexagonal" : "rectangular";
2 26 Feb 07 jari 116         info.init_type   = som_dialog.getInitType() == 0 ? "vector" : "genes";
2 26 Feb 07 jari 117         info.hcl = isHierarchicalTree;
2 26 Feb 07 jari 118         info.hcl_genes = hcl_genes;
2 26 Feb 07 jari 119         info.hcl_samples = hcl_samples;
2 26 Feb 07 jari 120         info.hcl_method = hcl_method;
2 26 Feb 07 jari 121         
2 26 Feb 07 jari 122         Listener listener = new Listener();
2 26 Feb 07 jari 123         try {
2 26 Feb 07 jari 124             algorithm = framework.getAlgorithmFactory().getAlgorithm("SOM");
2 26 Feb 07 jari 125             algorithm.addAlgorithmListener(listener);
2 26 Feb 07 jari 126             
2 26 Feb 07 jari 127             this.progress = new Progress(framework.getFrame(), "SOM Training", listener);
2 26 Feb 07 jari 128             this.progress.show();
2 26 Feb 07 jari 129             
2 26 Feb 07 jari 130             AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 131             FloatMatrix matrix = framework.getData().getExperiment().getMatrix();
2 26 Feb 07 jari 132             if(!clusterGenes)
2 26 Feb 07 jari 133                 matrix = matrix.transpose();
2 26 Feb 07 jari 134             data.addMatrix("experiment", matrix);
2 26 Feb 07 jari 135             data.addParam("distance-factor", String.valueOf(1f));
2 26 Feb 07 jari 136             data.addParam("distance-absolute", String.valueOf(som_dialog.isAbsoluteDistance()));
2 26 Feb 07 jari 137             
2 26 Feb 07 jari 138             function = som_dialog.getDistanceMetric();
2 26 Feb 07 jari 139             info.function = menu.getFunctionName(function);
2 26 Feb 07 jari 140             data.addParam("distance-function", String.valueOf(function));
2 26 Feb 07 jari 141             data.addParam("dimension-x", String.valueOf(info.dimension_x));
2 26 Feb 07 jari 142             data.addParam("dimension-y", String.valueOf(info.dimension_y));
2 26 Feb 07 jari 143             data.addParam("iterations", String.valueOf(info.iterations));
2 26 Feb 07 jari 144             data.addParam("topology", info.topology);
2 26 Feb 07 jari 145             data.addParam("is_neighborhood_bubble", String.valueOf(info.neiborhood.equals("bubble")));
2 26 Feb 07 jari 146             data.addParam("is_random_vector", String.valueOf(info.init_type.equals("vector")));
2 26 Feb 07 jari 147             data.addParam("radius", String.valueOf(info.radius));
2 26 Feb 07 jari 148             data.addParam("alpha", String.valueOf(info.alpha));
2 26 Feb 07 jari 149             data.addParam("som-cluster-genes", String.valueOf(clusterGenes));
2 26 Feb 07 jari 150             // hcl parameters
2 26 Feb 07 jari 151             if (isHierarchicalTree) {
2 26 Feb 07 jari 152                 data.addParam("hierarchical-tree", String.valueOf(true));
2 26 Feb 07 jari 153                 data.addParam("method-linkage", String.valueOf(hcl_method));
2 26 Feb 07 jari 154                 data.addParam("calculate-genes", String.valueOf(hcl_genes));
2 26 Feb 07 jari 155                 data.addParam("calculate-experiments", String.valueOf(hcl_samples));     
2 26 Feb 07 jari 156                 data.addParam("hcl-distance-function", String.valueOf(hcl_metric));
2 26 Feb 07 jari 157                 data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute));
2 26 Feb 07 jari 158             }
2 26 Feb 07 jari 159             
2 26 Feb 07 jari 160             long startTime = System.currentTimeMillis();
2 26 Feb 07 jari 161             AlgorithmData result = algorithm.execute(data);
2 26 Feb 07 jari 162             info.time = System.currentTimeMillis()-startTime;
2 26 Feb 07 jari 163             // obtain the clusters
2 26 Feb 07 jari 164             Cluster result_cluster = result.getCluster("cluster");
2 26 Feb 07 jari 165             NodeList nodeList = result_cluster.getNodeList();
2 26 Feb 07 jari 166             this.clusters = new int[nodeList.getSize()][];
2 26 Feb 07 jari 167             for (int i=0; i<this.clusters.length; i++) {
2 26 Feb 07 jari 168                 this.clusters[i] = nodeList.getNode(i).getFeaturesIndexes();
2 26 Feb 07 jari 169             }
2 26 Feb 07 jari 170             // obtain the codes
2 26 Feb 07 jari 171             this.codes = result.getMatrix("codes");
2 26 Feb 07 jari 172             // obtain the u-matrix
2 26 Feb 07 jari 173             this.u_matrix = result.getMatrix("u_matrix");
2 26 Feb 07 jari 174             // means, variances
2 26 Feb 07 jari 175             this.means = result.getMatrix("clusters_means");
2 26 Feb 07 jari 176             this.variances = result.getMatrix("clusters_variances");
2 26 Feb 07 jari 177             return createResultTree(result_cluster, info);
2 26 Feb 07 jari 178         } finally {
2 26 Feb 07 jari 179             if (algorithm != null) {
2 26 Feb 07 jari 180                 algorithm.removeAlgorithmListener(listener);
2 26 Feb 07 jari 181             }
2 26 Feb 07 jari 182             if (progress != null) {
2 26 Feb 07 jari 183                 progress.dispose();
2 26 Feb 07 jari 184             }
2 26 Feb 07 jari 185         }
2 26 Feb 07 jari 186     }
2 26 Feb 07 jari 187     
2 26 Feb 07 jari 188     
2 26 Feb 07 jari 189     /**
2 26 Feb 07 jari 190      *  Script Support
2 26 Feb 07 jari 191      */
2 26 Feb 07 jari 192     
2 26 Feb 07 jari 193     public AlgorithmData getScriptParameters(IFramework framework) {
2 26 Feb 07 jari 194         
2 26 Feb 07 jari 195         IDistanceMenu menu = framework.getDistanceMenu();
2 26 Feb 07 jari 196         int function = menu.getDistanceFunction();
2 26 Feb 07 jari 197         if (function == Algorithm.DEFAULT) {
2 26 Feb 07 jari 198             function = Algorithm.EUCLIDEAN;
2 26 Feb 07 jari 199         } 
2 26 Feb 07 jari 200             
2 26 Feb 07 jari 201         this.data = framework.getData();
2 26 Feb 07 jari 202         SOMInitDialog som_dialog = new SOMInitDialog(framework.getFrame(), 3, 3, 2000, 0.05f, 3f, 1, 1, 0, menu.getFunctionName(function), menu.isAbsoluteDistance());
2 26 Feb 07 jari 203         if (som_dialog.showModal() != JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 204             return null;
2 26 Feb 07 jari 205         }
2 26 Feb 07 jari 206         clusterGenes = som_dialog.isClusterGenes();
2 26 Feb 07 jari 207         boolean isHierarchicalTree = som_dialog.isHierarchicalTree();
2 26 Feb 07 jari 208         // hcl init
2 26 Feb 07 jari 209         int hcl_method = 0;
2 26 Feb 07 jari 210         boolean hcl_samples = false;
2 26 Feb 07 jari 211         boolean hcl_genes = false;
2 26 Feb 07 jari 212         int hcl_metric = 4;
2 26 Feb 07 jari 213         boolean hcl_absolute = false;        
2 26 Feb 07 jari 214         if (isHierarchicalTree) {
2 26 Feb 07 jari 215             HCLInitDialog hcl_dialog = new HCLInitDialog(framework.getFrame(), menu.getFunctionName(som_dialog.getDistanceMetric()), som_dialog.isAbsoluteDistance(), true);
2 26 Feb 07 jari 216             if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 217                 return null;
2 26 Feb 07 jari 218             }
2 26 Feb 07 jari 219             hcl_method = hcl_dialog.getMethod();
2 26 Feb 07 jari 220             hcl_samples = hcl_dialog.isClusterExperiments();
2 26 Feb 07 jari 221             hcl_genes = hcl_dialog.isClusterGenes();
2 26 Feb 07 jari 222             hcl_metric = hcl_dialog.getDistanceMetric();
2 26 Feb 07 jari 223             hcl_absolute = hcl_dialog.getAbsoluteSelection();
2 26 Feb 07 jari 224         }
2 26 Feb 07 jari 225         
2 26 Feb 07 jari 226         this.experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 227         GeneralInfo info = new GeneralInfo();
2 26 Feb 07 jari 228         info.alpha = som_dialog.getAlpha();
2 26 Feb 07 jari 229         info.radius = som_dialog.getRadius();
2 26 Feb 07 jari 230         if(clusterGenes)
2 26 Feb 07 jari 231             info.dimension   = this.experiment.getNumberOfSamples();
2 26 Feb 07 jari 232         else
2 26 Feb 07 jari 233             info.dimension = this.experiment.getNumberOfGenes();
2 26 Feb 07 jari 234         info.dimension_x = som_dialog.getDimensionX();
2 26 Feb 07 jari 235         info.dimension_y = som_dialog.getDimensionY();
2 26 Feb 07 jari 236         info.clusters    = info.dimension_x * info.dimension_y;
2 26 Feb 07 jari 237         info.iterations  = som_dialog.getIterations();
2 26 Feb 07 jari 238         info.neiborhood  = som_dialog.getNeighborhood() == 0 ? "bubble" : "gaussian";
2 26 Feb 07 jari 239         info.topology    = som_dialog.getTopology() == 0 ? "hexagonal" : "rectangular";
2 26 Feb 07 jari 240         info.init_type   = som_dialog.getInitType() == 0 ? "vector" : "genes";
2 26 Feb 07 jari 241         info.hcl = isHierarchicalTree;
2 26 Feb 07 jari 242         info.hcl_genes = hcl_genes;
2 26 Feb 07 jari 243         info.hcl_samples = hcl_samples;
2 26 Feb 07 jari 244         info.hcl_method = hcl_method;
2 26 Feb 07 jari 245         
2 26 Feb 07 jari 246         Listener listener = new Listener();
2 26 Feb 07 jari 247         
2 26 Feb 07 jari 248         AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 249         FloatMatrix matrix = framework.getData().getExperiment().getMatrix();
2 26 Feb 07 jari 250         
2 26 Feb 07 jari 251         data.addParam("distance-factor", String.valueOf(1f));
2 26 Feb 07 jari 252
2 26 Feb 07 jari 253         data.addParam("distance-absolute", String.valueOf(som_dialog.isAbsoluteDistance()));
2 26 Feb 07 jari 254
2 26 Feb 07 jari 255         function = som_dialog.getDistanceMetric();
2 26 Feb 07 jari 256         info.function = menu.getFunctionName(function);
2 26 Feb 07 jari 257         data.addParam("distance-function", String.valueOf(function));        
2 26 Feb 07 jari 258
2 26 Feb 07 jari 259         data.addParam("dimension-x", String.valueOf(info.dimension_x));
2 26 Feb 07 jari 260         data.addParam("dimension-y", String.valueOf(info.dimension_y));
2 26 Feb 07 jari 261         data.addParam("iterations", String.valueOf(info.iterations));
2 26 Feb 07 jari 262         data.addParam("topology", info.topology);
2 26 Feb 07 jari 263         data.addParam("is_neighborhood_bubble", String.valueOf(info.neiborhood.equals("bubble")));
2 26 Feb 07 jari 264         data.addParam("is_random_vector", String.valueOf(info.init_type.equals("vector")));
2 26 Feb 07 jari 265         data.addParam("radius", String.valueOf(info.radius));
2 26 Feb 07 jari 266         data.addParam("alpha", String.valueOf(info.alpha));
2 26 Feb 07 jari 267         data.addParam("som-cluster-genes", String.valueOf(clusterGenes));
2 26 Feb 07 jari 268         // hcl parameters
2 26 Feb 07 jari 269         if (isHierarchicalTree) {
2 26 Feb 07 jari 270             data.addParam("hierarchical-tree", String.valueOf(true));
2 26 Feb 07 jari 271             data.addParam("method-linkage", String.valueOf(hcl_method));
2 26 Feb 07 jari 272             data.addParam("calculate-genes", String.valueOf(hcl_genes));
2 26 Feb 07 jari 273             data.addParam("calculate-experiments", String.valueOf(hcl_samples));
2 26 Feb 07 jari 274             data.addParam("hcl-distance-function", String.valueOf(hcl_metric));
2 26 Feb 07 jari 275             data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute));
2 26 Feb 07 jari 276         }
2 26 Feb 07 jari 277         
2 26 Feb 07 jari 278         //script control parameters
2 26 Feb 07 jari 279         
2 26 Feb 07 jari 280         // alg name
2 26 Feb 07 jari 281         data.addParam("name", "SOM");
2 26 Feb 07 jari 282         
2 26 Feb 07 jari 283         // alg type
2 26 Feb 07 jari 284         if(clusterGenes)
2 26 Feb 07 jari 285             data.addParam("alg-type", "cluster-genes");
2 26 Feb 07 jari 286         else
2 26 Feb 07 jari 287             data.addParam("alg-type", "cluster-experiments");
2 26 Feb 07 jari 288         
2 26 Feb 07 jari 289         // output class
2 26 Feb 07 jari 290         if(clusterGenes)
2 26 Feb 07 jari 291             data.addParam("output-class", "multi-gene-cluster-output");
2 26 Feb 07 jari 292         else
2 26 Feb 07 jari 293             data.addParam("output-class", "multi-experiment-cluster-output");
2 26 Feb 07 jari 294         
2 26 Feb 07 jari 295         //output nodes
2 26 Feb 07 jari 296         String [] outputNodes = new String[1];
2 26 Feb 07 jari 297         outputNodes[0] = "Multi-cluster";
2 26 Feb 07 jari 298         data.addStringArray("output-nodes", outputNodes);
2 26 Feb 07 jari 299         
2 26 Feb 07 jari 300         return data;
2 26 Feb 07 jari 301     }
2 26 Feb 07 jari 302     
2 26 Feb 07 jari 303     public DefaultMutableTreeNode executeScript(IFramework framework, AlgorithmData algData, Experiment experiment) throws AlgorithmException {
2 26 Feb 07 jari 304         this.data = framework.getData();
2 26 Feb 07 jari 305         this.experiment = experiment;
2 26 Feb 07 jari 306         Listener listener = new Listener();
2 26 Feb 07 jari 307         this.clusterGenes = algData.getParams().getBoolean("som-cluster-genes");
2 26 Feb 07 jari 308         try {
2 26 Feb 07 jari 309             algorithm = framework.getAlgorithmFactory().getAlgorithm("SOM");
2 26 Feb 07 jari 310             algorithm.addAlgorithmListener(listener);
2 26 Feb 07 jari 311             
2 26 Feb 07 jari 312             this.progress = new Progress(framework.getFrame(), "SOM Training", listener);
2 26 Feb 07 jari 313             this.progress.show();
2 26 Feb 07 jari 314             
2 26 Feb 07 jari 315             FloatMatrix matrix = framework.getData().getExperiment().getMatrix();
2 26 Feb 07 jari 316             if(!clusterGenes)
2 26 Feb 07 jari 317                 matrix = matrix.transpose();
2 26 Feb 07 jari 318             algData.addMatrix("experiment", matrix);
2 26 Feb 07 jari 319             
2 26 Feb 07 jari 320             long startTime = System.currentTimeMillis();
2 26 Feb 07 jari 321             AlgorithmData result = algorithm.execute(algData);
2 26 Feb 07 jari 322             GeneralInfo info = new GeneralInfo();
2 26 Feb 07 jari 323             info.time = System.currentTimeMillis()-startTime;
2 26 Feb 07 jari 324             // obtain the clusters
2 26 Feb 07 jari 325             Cluster result_cluster = result.getCluster("cluster");
2 26 Feb 07 jari 326             NodeList nodeList = result_cluster.getNodeList();
2 26 Feb 07 jari 327             this.clusters = new int[nodeList.getSize()][];
2 26 Feb 07 jari 328             for (int i=0; i<this.clusters.length; i++) {
2 26 Feb 07 jari 329                 this.clusters[i] = nodeList.getNode(i).getFeaturesIndexes();
2 26 Feb 07 jari 330             }
2 26 Feb 07 jari 331             // obtain the codes
2 26 Feb 07 jari 332             this.codes = result.getMatrix("codes");
2 26 Feb 07 jari 333             // obtain the u-matrix
2 26 Feb 07 jari 334             this.u_matrix = result.getMatrix("u_matrix");
2 26 Feb 07 jari 335             // means, variances
2 26 Feb 07 jari 336             this.means = result.getMatrix("clusters_means");
2 26 Feb 07 jari 337             this.variances = result.getMatrix("clusters_variances");
2 26 Feb 07 jari 338             
2 26 Feb 07 jari 339             
2 26 Feb 07 jari 340             IDistanceMenu menu = framework.getDistanceMenu();
2 26 Feb 07 jari 341             
2 26 Feb 07 jari 342             AlgorithmParameters params = algData.getParams();
2 26 Feb 07 jari 343             
2 26 Feb 07 jari 344             info.alpha = params.getFloat("alpha");
2 26 Feb 07 jari 345             info.radius = params.getFloat("radius");
2 26 Feb 07 jari 346             if(clusterGenes)
2 26 Feb 07 jari 347                 info.dimension   = this.experiment.getNumberOfSamples();
2 26 Feb 07 jari 348             else
2 26 Feb 07 jari 349                 info.dimension = this.experiment.getNumberOfGenes();
2 26 Feb 07 jari 350             info.dimension_x = params.getInt("dimension-x");
2 26 Feb 07 jari 351             info.dimension_y = params.getInt("dimension-y");
2 26 Feb 07 jari 352             info.clusters    = info.dimension_x * info.dimension_y;
2 26 Feb 07 jari 353             info.iterations  = params.getInt("iterations");
2 26 Feb 07 jari 354             info.neiborhood  = params.getBoolean("is-neighborhood-bubble") ? "bubble" : "gaussian";
2 26 Feb 07 jari 355             info.topology    = params.getString("topology");
2 26 Feb 07 jari 356             info.init_type   = params.getBoolean("is-random-vector") ? "vector" : "genes";
2 26 Feb 07 jari 357             info.hcl = params.getBoolean("hierarchical-tree");
2 26 Feb 07 jari 358             info.hcl_genes = params.getBoolean("calculate-genes");
2 26 Feb 07 jari 359             info.hcl_samples = params.getBoolean("calculate-experiments");
2 26 Feb 07 jari 360             if(info.hcl_genes)
2 26 Feb 07 jari 361                 info.hcl_method = params.getInt("method-linkage");
2 26 Feb 07 jari 362             
2 26 Feb 07 jari 363             return createResultTree(result_cluster, info);
2 26 Feb 07 jari 364         } finally {
2 26 Feb 07 jari 365             if (algorithm != null) {
2 26 Feb 07 jari 366                 algorithm.removeAlgorithmListener(listener);
2 26 Feb 07 jari 367             }
2 26 Feb 07 jari 368             if (progress != null) {
2 26 Feb 07 jari 369                 progress.dispose();
2 26 Feb 07 jari 370             }
2 26 Feb 07 jari 371         }
2 26 Feb 07 jari 372     }
2 26 Feb 07 jari 373     
2 26 Feb 07 jari 374     
2 26 Feb 07 jari 375     /**
2 26 Feb 07 jari 376      * Creates the result tree.
2 26 Feb 07 jari 377      */
2 26 Feb 07 jari 378     private DefaultMutableTreeNode createResultTree(Cluster result_cluster, GeneralInfo info) {
2 26 Feb 07 jari 379         DefaultMutableTreeNode root;
2 26 Feb 07 jari 380         if(this.clusterGenes)
2 26 Feb 07 jari 381             root = new DefaultMutableTreeNode("SOM - genes");
2 26 Feb 07 jari 382         else
2 26 Feb 07 jari 383             root = new DefaultMutableTreeNode("SOM - samples");
2 26 Feb 07 jari 384         addResultNodes(root, result_cluster, info);
2 26 Feb 07 jari 385         return root;
2 26 Feb 07 jari 386     }
2 26 Feb 07 jari 387     
2 26 Feb 07 jari 388     /**
2 26 Feb 07 jari 389      * Adds nodes into the result tree root node.
2 26 Feb 07 jari 390      */
2 26 Feb 07 jari 391     private void addResultNodes(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) {
2 26 Feb 07 jari 392         addExpressionImages(root, info);
2 26 Feb 07 jari 393         addHierarchicalTrees(root, result_cluster, info);
2 26 Feb 07 jari 394         addCentroidViews(root, info);
2 26 Feb 07 jari 395         addSOMViews(root, info);
2 26 Feb 07 jari 396         addTableViews(root, info);
2 26 Feb 07 jari 397         addClusterInfo(root);
2 26 Feb 07 jari 398         addGeneralInfo(root, info);
2 26 Feb 07 jari 399     }
2 26 Feb 07 jari 400     
2 26 Feb 07 jari 401     private void addTableViews(DefaultMutableTreeNode root, GeneralInfo info) {
2 26 Feb 07 jari 402         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Table views");
2 26 Feb 07 jari 403         //SOMExperimentViewer expViewer;
2 26 Feb 07 jari 404         IViewer tabViewer;
2 26 Feb 07 jari 405         if(clusterGenes)
2 26 Feb 07 jari 406             tabViewer = new ClusterTableViewer(this.experiment, this.clusters, this.data);
2 26 Feb 07 jari 407         else
2 26 Feb 07 jari 408             tabViewer = new ExperimentClusterTableViewer(this.experiment, this.clusters, this.data);
2 26 Feb 07 jari 409         //return; //placeholder for ExptClusterTableViewer
2 26 Feb 07 jari 410         //expViewer = new SOMExperimentClusterViewer(this.experiment, this.clusters, "SOM Vector", this.codes);
2 26 Feb 07 jari 411         int cluster;
2 26 Feb 07 jari 412         for (int x=0; x<info.dimension_x; x++) {
2 26 Feb 07 jari 413             for (int y=0; y<info.dimension_y; y++) {
2 26 Feb 07 jari 414                 cluster = x*info.dimension_y+y;
2 26 Feb 07 jari 415                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(cluster+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", tabViewer, new Integer(cluster))));
2 26 Feb 07 jari 416             }
2 26 Feb 07 jari 417         }
2 26 Feb 07 jari 418         root.add(node);
2 26 Feb 07 jari 419     }
2 26 Feb 07 jari 420     
2 26 Feb 07 jari 421     /**
2 26 Feb 07 jari 422      * Adds experiment viewer nodes.
2 26 Feb 07 jari 423      */
2 26 Feb 07 jari 424     private void addExpressionImages(DefaultMutableTreeNode root, GeneralInfo info) {
2 26 Feb 07 jari 425         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images");
2 26 Feb 07 jari 426         //SOMExperimentViewer expViewer;
2 26 Feb 07 jari 427         IViewer expViewer;
2 26 Feb 07 jari 428         if(clusterGenes)
2 26 Feb 07 jari 429             expViewer = new SOMExperimentViewer(this.experiment, this.clusters, this.codes);
2 26 Feb 07 jari 430         else
2 26 Feb 07 jari 431             expViewer = new SOMExperimentClusterViewer(this.experiment, this.clusters, "SOM Vector", this.codes);
2 26 Feb 07 jari 432         int cluster;
2 26 Feb 07 jari 433         for (int x=0; x<info.dimension_x; x++) {
2 26 Feb 07 jari 434             for (int y=0; y<info.dimension_y; y++) {
2 26 Feb 07 jari 435                 cluster = x*info.dimension_y+y;
2 26 Feb 07 jari 436                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(cluster+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", expViewer, new Integer(cluster))));
2 26 Feb 07 jari 437             }
2 26 Feb 07 jari 438         }
2 26 Feb 07 jari 439         root.add(node);
2 26 Feb 07 jari 440     }
2 26 Feb 07 jari 441     
2 26 Feb 07 jari 442     /**
2 26 Feb 07 jari 443      * Adds nodes to display hierarchical trees.
2 26 Feb 07 jari 444      */
2 26 Feb 07 jari 445     private void addHierarchicalTrees(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) {
2 26 Feb 07 jari 446         if (!info.hcl) {
2 26 Feb 07 jari 447             return;
2 26 Feb 07 jari 448         }
2 26 Feb 07 jari 449         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Hierarchical Trees");
2 26 Feb 07 jari 450         NodeList nodeList = result_cluster.getNodeList();
2 26 Feb 07 jari 451         int [][] hclClusters = this.clusters;
2 26 Feb 07 jari 452         int x, y;
2 26 Feb 07 jari 453         int k = nodeList.getSize();
2 26 Feb 07 jari 454         
2 26 Feb 07 jari 455         if(!this.clusterGenes){
2 26 Feb 07 jari 456             hclClusters = new int[k][];
2 26 Feb 07 jari 457             for (int i=0; i<k; i++) {
2 26 Feb 07 jari 458                 hclClusters[i] = nodeList.getNode(i).getFeaturesIndexes();
2 26 Feb 07 jari 459             }
2 26 Feb 07 jari 460             if(info.hcl_samples)
2 26 Feb 07 jari 461                 hclClusters = getOrderedIndices(nodeList, hclClusters, info.hcl_genes);
2 26 Feb 07 jari 462         }
2 26 Feb 07 jari 463         for (int i=0; i<nodeList.getSize(); i++) {
2 26 Feb 07 jari 464             x = i/info.dimension_y;
2 26 Feb 07 jari 465             y = i%info.dimension_y;
2 26 Feb 07 jari 466             if(clusterGenes)
2 26 Feb 07 jari 467                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", createHCLViewer(nodeList.getNode(i), info, hclClusters))));
2 26 Feb 07 jari 468             else
2 26 Feb 07 jari 469                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", createHCLViewer(nodeList.getNode(i), info, hclClusters), new Integer(i))));
2 26 Feb 07 jari 470         }
2 26 Feb 07 jari 471         root.add(node);
2 26 Feb 07 jari 472     }
2 26 Feb 07 jari 473     
2 26 Feb 07 jari 474     /**
2 26 Feb 07 jari 475      * Creates an <code>HCLViewer</code>.
2 26 Feb 07 jari 476      */
2 26 Feb 07 jari 477     private IViewer createHCLViewer(Node clusterNode, GeneralInfo info, int [][] sampleClusters) {
2 26 Feb 07 jari 478         HCLTreeData genes_result = info.hcl_genes ? getResult(clusterNode, 0) : null;
2 26 Feb 07 jari 479         HCLTreeData samples_result = info.hcl_samples ? getResult(clusterNode, info.hcl_genes ? 4 : 0) : null;
2 26 Feb 07 jari 480         if(this.clusterGenes)
2 26 Feb 07 jari 481             return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result);
2 26 Feb 07 jari 482         else
2 26 Feb 07 jari 483             return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result, sampleClusters, true);
2 26 Feb 07 jari 484     }
2 26 Feb 07 jari 485     
2 26 Feb 07 jari 486     /**
2 26 Feb 07 jari 487      * Returns a hcl tree data from the specified cluster node.
2 26 Feb 07 jari 488      */
2 26 Feb 07 jari 489     private HCLTreeData getResult(Node clusterNode, int pos) {
2 26 Feb 07 jari 490         HCLTreeData data = new HCLTreeData();
2 26 Feb 07 jari 491         NodeValueList valueList = clusterNode.getValues();
2 26 Feb 07 jari 492         data.child_1_array = (int[])valueList.getNodeValue(pos).value;
2 26 Feb 07 jari 493         data.child_2_array = (int[])valueList.getNodeValue(pos+1).value;
2 26 Feb 07 jari 494         data.node_order = (int[])valueList.getNodeValue(pos+2).value;
2 26 Feb 07 jari 495         data.height = (float[])valueList.getNodeValue(pos+3).value;
2 26 Feb 07 jari 496         return data;
2 26 Feb 07 jari 497     }
2 26 Feb 07 jari 498     
2 26 Feb 07 jari 499     /**
2 26 Feb 07 jari 500      * Adds node with cluster information.
2 26 Feb 07 jari 501      */
2 26 Feb 07 jari 502     private void addClusterInfo(DefaultMutableTreeNode root) {
2 26 Feb 07 jari 503         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information");
2 26 Feb 07 jari 504         if(this.clusterGenes)
2 26 Feb 07 jari 505             node.add(new DefaultMutableTreeNode(new LeafInfo("Genes in Clusters (#,%)", new SOMInfoViewer(this.clusters, this.experiment.getNumberOfGenes()))));
2 26 Feb 07 jari 506         else
2 26 Feb 07 jari 507             node.add(new DefaultMutableTreeNode(new LeafInfo("Samples in Clusters (#,%)", new SOMInfoViewer(this.clusters, this.experiment.getNumberOfSamples(), false))));
2 26 Feb 07 jari 508         root.add(node);
2 26 Feb 07 jari 509     }
2 26 Feb 07 jari 510     
2 26 Feb 07 jari 511     /**
2 26 Feb 07 jari 512      * Adds centroid and expression viewers nodes.
2 26 Feb 07 jari 513      */
2 26 Feb 07 jari 514     private void addCentroidViews(DefaultMutableTreeNode root, GeneralInfo info) {
2 26 Feb 07 jari 515         DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs");
2 26 Feb 07 jari 516         DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs");
2 26 Feb 07 jari 517         SOMCentroidViewer centroidViewer;
2 26 Feb 07 jari 518         SOMExperimentCentroidViewer expCentroidViewer;
2 26 Feb 07 jari 519         
2 26 Feb 07 jari 520         if(clusterGenes){
2 26 Feb 07 jari 521             centroidViewer = new SOMCentroidViewer(this.experiment, this.clusters);
2 26 Feb 07 jari 522             centroidViewer.setMeans(this.means.A);
2 26 Feb 07 jari 523             centroidViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 524             centroidViewer.setCodes(this.codes.A);
2 26 Feb 07 jari 525             int cluster;
2 26 Feb 07 jari 526             for (int x=0; x<info.dimension_x; x++) {
2 26 Feb 07 jari 527                 for (int y=0; y<info.dimension_y; y++) {
2 26 Feb 07 jari 528                     cluster = x*info.dimension_y+y;
2 26 Feb 07 jari 529                     centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(cluster+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", centroidViewer, new CentroidUserObject(cluster, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 530                     expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(cluster+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", centroidViewer, new CentroidUserObject(cluster, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 531                 }
2 26 Feb 07 jari 532             }
2 26 Feb 07 jari 533             SOMCentroidsViewer centroidsViewer = new SOMCentroidsViewer(this.experiment, clusters);
2 26 Feb 07 jari 534             centroidsViewer.setMeans(this.means.A);
2 26 Feb 07 jari 535             centroidsViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 536             centroidsViewer.setCodes(this.codes.A);
2 26 Feb 07 jari 537             
2 26 Feb 07 jari 538             centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 539             expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 540         }
2 26 Feb 07 jari 541         else{
2 26 Feb 07 jari 542             expCentroidViewer = new SOMExperimentCentroidViewer(this.experiment, this.clusters);
2 26 Feb 07 jari 543             expCentroidViewer.setMeans(this.means.A);
2 26 Feb 07 jari 544             expCentroidViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 545             expCentroidViewer.setCodes(this.codes.A);
2 26 Feb 07 jari 546             int cluster;
2 26 Feb 07 jari 547             for (int x=0; x<info.dimension_x; x++) {
2 26 Feb 07 jari 548                 for (int y=0; y<info.dimension_y; y++) {
2 26 Feb 07 jari 549                     cluster = x*info.dimension_y+y;
2 26 Feb 07 jari 550                     centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(cluster+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", expCentroidViewer, new CentroidUserObject(cluster, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 551                     expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(cluster+1)+" ("+String.valueOf(x+1)+","+String.valueOf(y+1)+")", expCentroidViewer, new CentroidUserObject(cluster, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 552                 }
2 26 Feb 07 jari 553             }
2 26 Feb 07 jari 554             SOMExperimentCentroidsViewer centroidsViewer = new SOMExperimentCentroidsViewer(this.experiment, clusters);
2 26 Feb 07 jari 555             centroidsViewer.setMeans(this.means.A);
2 26 Feb 07 jari 556             centroidsViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 557             centroidsViewer.setCodes(this.codes.A);
2 26 Feb 07 jari 558             
2 26 Feb 07 jari 559             centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 560             expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 561         }
2 26 Feb 07 jari 562         root.add(centroidNode);
2 26 Feb 07 jari 563         root.add(expressionNode);
2 26 Feb 07 jari 564     }
2 26 Feb 07 jari 565     
2 26 Feb 07 jari 566     
2 26 Feb 07 jari 567     
2 26 Feb 07 jari 568     /**
2 26 Feb 07 jari 569      * Adds som visualization nodes.
2 26 Feb 07 jari 570      */
2 26 Feb 07 jari 571     private void addSOMViews(DefaultMutableTreeNode root, GeneralInfo info) {
2 26 Feb 07 jari 572         DefaultMutableTreeNode somNode = new DefaultMutableTreeNode("SOM Visualization");
2 26 Feb 07 jari 573         somNode.add(new DefaultMutableTreeNode(new LeafInfo("U-Matrix Color", new UMatrixColorViewer(this.clusters, this.u_matrix, info.dimension_x, info.dimension_y, info.topology))));
2 26 Feb 07 jari 574         somNode.add(new DefaultMutableTreeNode(new LeafInfo("U-Matrix Distance", new UMatrixDistanceViewer(this.clusters, this.u_matrix, info.dimension_x, info.dimension_y, info.topology))));
2 26 Feb 07 jari 575         root.add(somNode);
2 26 Feb 07 jari 576     }
2 26 Feb 07 jari 577     
2 26 Feb 07 jari 578     /**
2 26 Feb 07 jari 579      * Adds the general info node.
2 26 Feb 07 jari 580      */
2 26 Feb 07 jari 581     private void addGeneralInfo(DefaultMutableTreeNode root, GeneralInfo info) {
2 26 Feb 07 jari 582         DefaultMutableTreeNode node = new DefaultMutableTreeNode("General Information");
2 26 Feb 07 jari 583         node.add(new DefaultMutableTreeNode("clusters: "+String.valueOf(info.clusters)));
2 26 Feb 07 jari 584         node.add(new DefaultMutableTreeNode("iterations: "+String.valueOf(info.iterations)));
2 26 Feb 07 jari 585         node.add(new DefaultMutableTreeNode("dimension: "+String.valueOf(info.dimension)));
2 26 Feb 07 jari 586         node.add(new DefaultMutableTreeNode("dimension x: "+String.valueOf(info.dimension_x)));
2 26 Feb 07 jari 587         node.add(new DefaultMutableTreeNode("dimension y: "+String.valueOf(info.dimension_y)));
2 26 Feb 07 jari 588         node.add(new DefaultMutableTreeNode("topology: "+info.topology));
2 26 Feb 07 jari 589         node.add(new DefaultMutableTreeNode("neiborhood: "+info.neiborhood));
2 26 Feb 07 jari 590         node.add(new DefaultMutableTreeNode("init type: "+info.init_type));
2 26 Feb 07 jari 591         node.add(new DefaultMutableTreeNode("alpha: "+String.valueOf(info.alpha)));
2 26 Feb 07 jari 592         node.add(new DefaultMutableTreeNode("radius: "+String.valueOf(info.radius)));
2 26 Feb 07 jari 593         node.add(new DefaultMutableTreeNode("HCL: "+info.getMethodName()));
2 26 Feb 07 jari 594         node.add(new DefaultMutableTreeNode("time: "+String.valueOf(info.time)+" ms"));
2 26 Feb 07 jari 595         node.add(new DefaultMutableTreeNode(info.function));
2 26 Feb 07 jari 596         root.add(node);
2 26 Feb 07 jari 597     }
2 26 Feb 07 jari 598     
2 26 Feb 07 jari 599     
2 26 Feb 07 jari 600     /***************************************************************************************
2 26 Feb 07 jari 601      * Code to order sample clustering results based on HCL runs.  sampleClusters contain an array
2 26 Feb 07 jari 602      * of sample indices for each experiment cluster.  Note that these indicies are ordered in
2 26 Feb 07 jari 603      * an order which matches HCL input matrix sample order so that HCL results (node-order) can
2 26 Feb 07 jari 604      * be used to order leaf indices to match HCL samples results
2 26 Feb 07 jari 605      */
2 26 Feb 07 jari 606     private int [][] getOrderedIndices(NodeList nodeList, int [][] sampleClusters, boolean calcGeneHCL){
2 26 Feb 07 jari 607         HCLTreeData result;
2 26 Feb 07 jari 608         for(int i = 0; i < sampleClusters.length ; i++){
2 26 Feb 07 jari 609             if(sampleClusters[i].length > 0){
2 26 Feb 07 jari 610                 result = getResult(nodeList.getNode(i), calcGeneHCL ? 4 : 0);  //get sample Result
2 26 Feb 07 jari 611                 sampleClusters[i] = getSampleOrder(result, sampleClusters[i]);
2 26 Feb 07 jari 612             }
2 26 Feb 07 jari 613         }
2 26 Feb 07 jari 614         return sampleClusters;
2 26 Feb 07 jari 615     }
2 26 Feb 07 jari 616     
2 26 Feb 07 jari 617     private int[] getSampleOrder(HCLTreeData result, int[] indices) {
2 26 Feb 07 jari 618         return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices);
2 26 Feb 07 jari 619     }
2 26 Feb 07 jari 620     
2 26 Feb 07 jari 621     private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) {
2 26 Feb 07 jari 622         int[] leafOrder = new int[nodeOrder.length];
2 26 Feb 07 jari 623         Arrays.fill(leafOrder, -1);
2 26 Feb 07 jari 624         fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices);
2 26 Feb 07 jari 625         return leafOrder;
2 26 Feb 07 jari 626     }
2 26 Feb 07 jari 627     
2 26 Feb 07 jari 628     private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) {
2 26 Feb 07 jari 629         if (child1[index] != -1) {
2 26 Feb 07 jari 630             pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices);
2 26 Feb 07 jari 631         }
2 26 Feb 07 jari 632         if (child2[index] != -1) {
2 26 Feb 07 jari 633             pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices);
2 26 Feb 07 jari 634         } else {
2 26 Feb 07 jari 635             leafOrder[pos] = indices == null ? index : indices[index];
2 26 Feb 07 jari 636             pos++;
2 26 Feb 07 jari 637         }
2 26 Feb 07 jari 638         return pos;
2 26 Feb 07 jari 639     }
2 26 Feb 07 jari 640     
2 26 Feb 07 jari 641     
2 26 Feb 07 jari 642     
2 26 Feb 07 jari 643     /****************************************************************************************
2 26 Feb 07 jari 644      * End of Sample Cluster index ordering code
2 26 Feb 07 jari 645      */
2 26 Feb 07 jari 646     
2 26 Feb 07 jari 647     
2 26 Feb 07 jari 648     /**
2 26 Feb 07 jari 649      * The class to listen to a dialog and algorithm events.
2 26 Feb 07 jari 650      */
2 26 Feb 07 jari 651     private class Listener extends DialogListener implements AlgorithmListener {
2 26 Feb 07 jari 652         
2 26 Feb 07 jari 653         public void valueChanged(AlgorithmEvent event) {
2 26 Feb 07 jari 654             switch (event.getId()) {
2 26 Feb 07 jari 655                 case AlgorithmEvent.SET_UNITS:
2 26 Feb 07 jari 656                     progress.setUnits(event.getIntValue());
2 26 Feb 07 jari 657                     progress.setDescription(event.getDescription());
2 26 Feb 07 jari 658                     break;
2 26 Feb 07 jari 659                 case AlgorithmEvent.PROGRESS_VALUE:
2 26 Feb 07 jari 660                     progress.setValue(event.getIntValue());
2 26 Feb 07 jari 661                     progress.setDescription(event.getDescription());
2 26 Feb 07 jari 662                     break;
2 26 Feb 07 jari 663             }
2 26 Feb 07 jari 664         }
2 26 Feb 07 jari 665         
2 26 Feb 07 jari 666         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 667             String command = e.getActionCommand();
2 26 Feb 07 jari 668             if (command.equals("cancel-command")) {
2 26 Feb 07 jari 669                 algorithm.abort();
2 26 Feb 07 jari 670                 progress.dispose();
2 26 Feb 07 jari 671             }
2 26 Feb 07 jari 672         }
2 26 Feb 07 jari 673         
2 26 Feb 07 jari 674         public void windowClosing(WindowEvent e) {
2 26 Feb 07 jari 675             algorithm.abort();
2 26 Feb 07 jari 676             progress.dispose();
2 26 Feb 07 jari 677         }
2 26 Feb 07 jari 678     }
2 26 Feb 07 jari 679     
2 26 Feb 07 jari 680     /**
2 26 Feb 07 jari 681      * The general info structure.
2 26 Feb 07 jari 682      */
2 26 Feb 07 jari 683     private class GeneralInfo {
2 26 Feb 07 jari 684         public int clusters;
2 26 Feb 07 jari 685         public long iterations;
2 26 Feb 07 jari 686         public int dimension;
2 26 Feb 07 jari 687         public int dimension_x;
2 26 Feb 07 jari 688         public int dimension_y;
2 26 Feb 07 jari 689         public String topology;
2 26 Feb 07 jari 690         public String neiborhood;
2 26 Feb 07 jari 691         public String init_type;
2 26 Feb 07 jari 692         public float alpha;
2 26 Feb 07 jari 693         public float radius;
2 26 Feb 07 jari 694         public long time;
2 26 Feb 07 jari 695         public String function;
2 26 Feb 07 jari 696         
2 26 Feb 07 jari 697         private boolean hcl;
2 26 Feb 07 jari 698         private int hcl_method;
2 26 Feb 07 jari 699         private boolean hcl_genes;
2 26 Feb 07 jari 700         private boolean hcl_samples;
2 26 Feb 07 jari 701         
2 26 Feb 07 jari 702         public String getMethodName() {
2 26 Feb 07 jari 703             return hcl ? HCLGUI.GeneralInfo.getMethodName(hcl_method) : "no linkage";
2 26 Feb 07 jari 704         }
2 26 Feb 07 jari 705     }
2 26 Feb 07 jari 706 }