mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/kmcs/KMCSuppGUI.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2004, 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: KMCSuppGUI.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.9 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 20:59:52 $
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
2 26 Feb 07 jari 13 package org.tigr.microarray.mev.cluster.gui.impl.kmcs;
2 26 Feb 07 jari 14
2 26 Feb 07 jari 15 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 16 import java.awt.event.WindowEvent;
2 26 Feb 07 jari 17 import java.util.Arrays;
2 26 Feb 07 jari 18
2 26 Feb 07 jari 19 import javax.swing.JFrame;
2 26 Feb 07 jari 20 import javax.swing.JOptionPane;
2 26 Feb 07 jari 21 import javax.swing.tree.DefaultMutableTreeNode;
2 26 Feb 07 jari 22
2 26 Feb 07 jari 23 import org.tigr.microarray.mev.cluster.Cluster;
2 26 Feb 07 jari 24 import org.tigr.microarray.mev.cluster.Node;
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.cluster.NodeList;
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.NodeValueList;
2 26 Feb 07 jari 27 import org.tigr.microarray.mev.cluster.algorithm.Algorithm;
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent;
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmListener;
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 34 import org.tigr.microarray.mev.cluster.gui.IClusterGUI;
2 26 Feb 07 jari 35 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 36 import org.tigr.microarray.mev.cluster.gui.IDistanceMenu;
2 26 Feb 07 jari 37 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 38 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 39 import org.tigr.microarray.mev.cluster.gui.LeafInfo;
2 26 Feb 07 jari 40 import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject;
2 26 Feb 07 jari 41 import org.tigr.microarray.mev.cluster.gui.helpers.ClusterTableViewer;
2 26 Feb 07 jari 42 import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterTableViewer;
2 26 Feb 07 jari 43 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener;
2 26 Feb 07 jari 44 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.Progress;
2 26 Feb 07 jari 45 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLGUI;
2 26 Feb 07 jari 46 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLInitDialog;
2 26 Feb 07 jari 47 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData;
2 26 Feb 07 jari 48 import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLViewer;
2 26 Feb 07 jari 49 import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI;
2 26 Feb 07 jari 50 import org.tigr.util.FloatMatrix;
2 26 Feb 07 jari 51
2 26 Feb 07 jari 52
2 26 Feb 07 jari 53 /**
2 26 Feb 07 jari 54  *
2 26 Feb 07 jari 55  * @author  nbhagaba
2 26 Feb 07 jari 56  * @version
2 26 Feb 07 jari 57  */
2 26 Feb 07 jari 58 public class KMCSuppGUI implements IClusterGUI, IScriptGUI {
2 26 Feb 07 jari 59     
2 26 Feb 07 jari 60     
2 26 Feb 07 jari 61     private Algorithm algorithm;
2 26 Feb 07 jari 62     private Progress progress;
2 26 Feb 07 jari 63     //private Monitor monitor;
2 26 Feb 07 jari 64     
2 26 Feb 07 jari 65     private Experiment experiment;
2 26 Feb 07 jari 66     private int[][] clusters;
2 26 Feb 07 jari 67     private int k;
2 26 Feb 07 jari 68     private FloatMatrix means;
2 26 Feb 07 jari 69     private FloatMatrix variances;
2 26 Feb 07 jari 70     
2 26 Feb 07 jari 71     private IData data;
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     private boolean unassignedExists;
2 26 Feb 07 jari 74     private boolean clusterGenes;
2 26 Feb 07 jari 75     
2 26 Feb 07 jari 76     
2 26 Feb 07 jari 77     /** Creates new KMCSuppGUI */
2 26 Feb 07 jari 78     public KMCSuppGUI() {
2 26 Feb 07 jari 79     }
2 26 Feb 07 jari 80     
2 26 Feb 07 jari 81     public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException {
2 26 Feb 07 jari 82         // the default values
2 26 Feb 07 jari 83         int numClusters = 10;
2 26 Feb 07 jari 84         int iterations = 50;
2 26 Feb 07 jari 85         data = framework.getData();
2 26 Feb 07 jari 86
2 26 Feb 07 jari 87         IDistanceMenu menu = framework.getDistanceMenu();
2 26 Feb 07 jari 88         int function = menu.getDistanceFunction();
2 26 Feb 07 jari 89         if (function == Algorithm.DEFAULT) {
2 26 Feb 07 jari 90             function = Algorithm.EUCLIDEAN;
2 26 Feb 07 jari 91         }
2 26 Feb 07 jari 92             
2 26 Feb 07 jari 93         KMCSupportDialog kmcsDialog = new KMCSupportDialog((JFrame) framework.getFrame(), true, menu.getFunctionName(function), menu.isAbsoluteDistance());
2 26 Feb 07 jari 94         kmcsDialog.setVisible(true);
2 26 Feb 07 jari 95         
2 26 Feb 07 jari 96         if (!kmcsDialog.isOkPressed()) return null;
2 26 Feb 07 jari 97         int numReps = 0;
2 26 Feb 07 jari 98         double thresholdPercent = 0.0;
2 26 Feb 07 jari 99         try {
2 26 Feb 07 jari 100             numClusters = kmcsDialog.getNumClusters();
2 26 Feb 07 jari 101             iterations = kmcsDialog.getIterations();
2 26 Feb 07 jari 102             numReps = kmcsDialog.getNumReps();
2 26 Feb 07 jari 103             thresholdPercent = kmcsDialog.getThresholdPercent();
2 26 Feb 07 jari 104             clusterGenes = kmcsDialog.isClusterGenes();
2 26 Feb 07 jari 105         } catch (NumberFormatException nfe) {
2 26 Feb 07 jari 106             JOptionPane.showMessageDialog(framework.getFrame(), "Invalid input parameters!", "Error", JOptionPane.ERROR_MESSAGE);
2 26 Feb 07 jari 107             return null;
2 26 Feb 07 jari 108         }
2 26 Feb 07 jari 109         
2 26 Feb 07 jari 110         boolean isHierarchicalTree = kmcsDialog.isDrawTrees();
2 26 Feb 07 jari 111         boolean calculateMeans = kmcsDialog.meansChosen();
2 26 Feb 07 jari 112         // hcl init
2 26 Feb 07 jari 113         int hcl_method = 0;
2 26 Feb 07 jari 114         boolean hcl_samples = false;
2 26 Feb 07 jari 115         boolean hcl_genes = false;
2 26 Feb 07 jari 116         int hcl_function = kmcsDialog.getDistanceMetric();
2 26 Feb 07 jari 117         boolean hcl_absolute = kmcsDialog.getAbsoluteSelection();
2 26 Feb 07 jari 118         if (isHierarchicalTree) {
2 26 Feb 07 jari 119             HCLInitDialog hcl_dialog = new HCLInitDialog(framework.getFrame(), menu.getFunctionName(kmcsDialog.getDistanceMetric()), kmcsDialog.getAbsoluteSelection(), true);
2 26 Feb 07 jari 120           
2 26 Feb 07 jari 121             if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 122                 return null;
2 26 Feb 07 jari 123             }
2 26 Feb 07 jari 124             hcl_method = hcl_dialog.getMethod();
2 26 Feb 07 jari 125             hcl_samples = hcl_dialog.isClusterExperiments();
2 26 Feb 07 jari 126             hcl_genes = hcl_dialog.isClusterGenes();
2 26 Feb 07 jari 127             hcl_function = hcl_dialog.getDistanceMetric();
2 26 Feb 07 jari 128             hcl_absolute = hcl_dialog.getAbsoluteSelection();
2 26 Feb 07 jari 129         }
2 26 Feb 07 jari 130         this.experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 131         Listener listener = new Listener();
2 26 Feb 07 jari 132         try {
2 26 Feb 07 jari 133             algorithm = framework.getAlgorithmFactory().getAlgorithm("KMCS");
2 26 Feb 07 jari 134             algorithm.addAlgorithmListener(listener);
2 26 Feb 07 jari 135             
2 26 Feb 07 jari 136             int genes = experiment.getNumberOfGenes();
2 26 Feb 07 jari 137             //this.monitor = new Monitor(framework.getFrame(), "Reallocations", 25, 100, 210.0/genes);
2 26 Feb 07 jari 138             //this.monitor.setStepXFactor((int)Math.floor(245/iterations));
2 26 Feb 07 jari 139             //this.monitor.update(genes);
2 26 Feb 07 jari 140             //this.monitor.show();
2 26 Feb 07 jari 141             
2 26 Feb 07 jari 142             this.progress = new Progress(framework.getFrame(), "Calculating clusters", listener);
2 26 Feb 07 jari 143             this.progress.show();
2 26 Feb 07 jari 144             
2 26 Feb 07 jari 145             AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 146             FloatMatrix matrix = experiment.getMatrix();
2 26 Feb 07 jari 147             if(!clusterGenes)
2 26 Feb 07 jari 148                 matrix = matrix.transpose();
2 26 Feb 07 jari 149             data.addMatrix("experiment", matrix);
2 26 Feb 07 jari 150             data.addParam("kmc-cluster-genes", String.valueOf(clusterGenes));
2 26 Feb 07 jari 151             data.addParam("distance-factor", String.valueOf(1.0f));
2 26 Feb 07 jari 152            
2 26 Feb 07 jari 153             function = kmcsDialog.getDistanceMetric();
2 26 Feb 07 jari 154             data.addParam("distance-absolute", String.valueOf(kmcsDialog.getAbsoluteSelection()));
2 26 Feb 07 jari 155             data.addParam("distance-function", String.valueOf(function));
2 26 Feb 07 jari 156             data.addParam("number-of-desired-clusters", String.valueOf(numClusters));            
2 26 Feb 07 jari 157             data.addParam("number-of-iterations", String.valueOf(iterations));
2 26 Feb 07 jari 158             data.addParam("number-of-repetitions", String.valueOf(numReps));
2 26 Feb 07 jari 159             data.addParam("threshold-percent", String.valueOf(thresholdPercent));
2 26 Feb 07 jari 160             data.addParam("calculate-means", String.valueOf(calculateMeans));
2 26 Feb 07 jari 161             // hcl parameters
2 26 Feb 07 jari 162             if (isHierarchicalTree) {
2 26 Feb 07 jari 163                 data.addParam("hierarchical-tree", String.valueOf(true));
2 26 Feb 07 jari 164                 data.addParam("method-linkage", String.valueOf(hcl_method));
2 26 Feb 07 jari 165                 data.addParam("calculate-genes", String.valueOf(hcl_genes));
2 26 Feb 07 jari 166                 data.addParam("calculate-experiments", String.valueOf(hcl_samples));
2 26 Feb 07 jari 167                 data.addParam("hcl-distance-function", String.valueOf(hcl_function));
2 26 Feb 07 jari 168                 data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute));                
2 26 Feb 07 jari 169             }
2 26 Feb 07 jari 170             
2 26 Feb 07 jari 171             long start = System.currentTimeMillis();
2 26 Feb 07 jari 172             AlgorithmData result = algorithm.execute(data);
2 26 Feb 07 jari 173             long time = System.currentTimeMillis() - start;
2 26 Feb 07 jari 174             // getting the results
2 26 Feb 07 jari 175             Cluster result_cluster = result.getCluster("cluster");
2 26 Feb 07 jari 176             NodeList nodeList = result_cluster.getNodeList();
2 26 Feb 07 jari 177             AlgorithmParameters resultMap = result.getParams();
2 26 Feb 07 jari 178             k = resultMap.getInt("number-of-clusters"); // NEED THIS TO GET THE VALUE OF NUMBER-OF-CLUSTERS
2 26 Feb 07 jari 179             unassignedExists = resultMap.getBoolean("unassigned-genes-exist");
2 26 Feb 07 jari 180             this.clusters = new int[k][];
2 26 Feb 07 jari 181             for (int i=0; i<k; i++) {
2 26 Feb 07 jari 182                 clusters[i] = nodeList.getNode(i).getFeaturesIndexes();
2 26 Feb 07 jari 183             }
2 26 Feb 07 jari 184             this.means = result.getMatrix("clusters_means");
2 26 Feb 07 jari 185             this.variances = result.getMatrix("clusters_variances");
2 26 Feb 07 jari 186             
2 26 Feb 07 jari 187             GeneralInfo info = new GeneralInfo();
2 26 Feb 07 jari 188             if (unassignedExists) {
2 26 Feb 07 jari 189                 info.clusters = k - 1;
2 26 Feb 07 jari 190             } else {
2 26 Feb 07 jari 191                 info.clusters = k;
2 26 Feb 07 jari 192             }
2 26 Feb 07 jari 193             info.userNumClusters = numClusters;
2 26 Feb 07 jari 194             if (calculateMeans) {
2 26 Feb 07 jari 195                 info.meansOrMedians = "K-Means";
2 26 Feb 07 jari 196             } else {
2 26 Feb 07 jari 197                 info.meansOrMedians = "K-Medians";
2 26 Feb 07 jari 198             }
2 26 Feb 07 jari 199             //info.converged = result.getParams().getBoolean("converged");
2 26 Feb 07 jari 200             info.iterations = iterations;//result.getParams().getInt("iterations");
2 26 Feb 07 jari 201             info.time = time;
2 26 Feb 07 jari 202             info.numReps = numReps;
2 26 Feb 07 jari 203             info.thresholdPercent = thresholdPercent;
2 26 Feb 07 jari 204             info.function = menu.getFunctionName(function);
2 26 Feb 07 jari 205             info.hcl = isHierarchicalTree;
2 26 Feb 07 jari 206             info.hcl_genes = hcl_genes;
2 26 Feb 07 jari 207             info.hcl_samples = hcl_samples;
2 26 Feb 07 jari 208             info.hcl_method = hcl_method;
2 26 Feb 07 jari 209             return createResultTree(result_cluster, info);
2 26 Feb 07 jari 210             
2 26 Feb 07 jari 211         } finally {
2 26 Feb 07 jari 212             if (algorithm != null) {
2 26 Feb 07 jari 213                 algorithm.removeAlgorithmListener(listener);
2 26 Feb 07 jari 214             }
2 26 Feb 07 jari 215             if (progress != null) {
2 26 Feb 07 jari 216                 progress.dispose();
2 26 Feb 07 jari 217             }
2 26 Feb 07 jari 218             /*
2 26 Feb 07 jari 219             if (monitor != null) {
2 26 Feb 07 jari 220                 monitor.dispose();
2 26 Feb 07 jari 221             }
2 26 Feb 07 jari 222              */
2 26 Feb 07 jari 223         }
2 26 Feb 07 jari 224     }
2 26 Feb 07 jari 225     
2 26 Feb 07 jari 226     public DefaultMutableTreeNode executeScript(IFramework framework, AlgorithmData algData, Experiment experiment) throws AlgorithmException {
2 26 Feb 07 jari 227         this.experiment = experiment;
2 26 Feb 07 jari 228         this.data = framework.getData();
2 26 Feb 07 jari 229         this.clusterGenes = algData.getParams().getBoolean("kmc-cluster-genes");
2 26 Feb 07 jari 230         boolean calculateMeans = algData.getParams().getBoolean("calculate-means");
2 26 Feb 07 jari 231         
2 26 Feb 07 jari 232         Listener listener = new Listener();
2 26 Feb 07 jari 233         try {
2 26 Feb 07 jari 234             algorithm = framework.getAlgorithmFactory().getAlgorithm("KMCS");
2 26 Feb 07 jari 235             algorithm.addAlgorithmListener(listener);
2 26 Feb 07 jari 236             
2 26 Feb 07 jari 237             int genes = experiment.getNumberOfGenes();
2 26 Feb 07 jari 238             this.progress = new Progress(framework.getFrame(), "Calculating clusters", listener);
2 26 Feb 07 jari 239             this.progress.show();
2 26 Feb 07 jari 240             
2 26 Feb 07 jari 241             AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 242             FloatMatrix matrix = experiment.getMatrix();
2 26 Feb 07 jari 243             if(!clusterGenes)
2 26 Feb 07 jari 244                 matrix = matrix.transpose();
2 26 Feb 07 jari 245             algData.addMatrix("experiment", matrix);
2 26 Feb 07 jari 246             
2 26 Feb 07 jari 247             long start = System.currentTimeMillis();
2 26 Feb 07 jari 248             AlgorithmData result = algorithm.execute(algData);
2 26 Feb 07 jari 249             long time = System.currentTimeMillis() - start;
2 26 Feb 07 jari 250             // getting the results
2 26 Feb 07 jari 251             Cluster result_cluster = result.getCluster("cluster");
2 26 Feb 07 jari 252             NodeList nodeList = result_cluster.getNodeList();
2 26 Feb 07 jari 253             AlgorithmParameters resultMap = result.getParams();
2 26 Feb 07 jari 254             k = resultMap.getInt("number-of-clusters"); // NEED THIS TO GET THE VALUE OF NUMBER-OF-CLUSTERS
2 26 Feb 07 jari 255             unassignedExists = resultMap.getBoolean("unassigned-genes-exist");
2 26 Feb 07 jari 256             this.clusters = new int[k][];
2 26 Feb 07 jari 257             for (int i=0; i<k; i++) {
2 26 Feb 07 jari 258                 clusters[i] = nodeList.getNode(i).getFeaturesIndexes();
2 26 Feb 07 jari 259             }
2 26 Feb 07 jari 260             this.means = result.getMatrix("clusters_means");
2 26 Feb 07 jari 261             this.variances = result.getMatrix("clusters_variances");
2 26 Feb 07 jari 262             AlgorithmParameters params = algData.getParams();
2 26 Feb 07 jari 263             
2 26 Feb 07 jari 264             GeneralInfo info = new GeneralInfo();
2 26 Feb 07 jari 265             if (unassignedExists) {
2 26 Feb 07 jari 266                 info.clusters = k - 1;
2 26 Feb 07 jari 267             } else {
2 26 Feb 07 jari 268                 info.clusters = k;
2 26 Feb 07 jari 269             }
2 26 Feb 07 jari 270             info.userNumClusters = params.getInt("number-of-desired-clusters");;
2 26 Feb 07 jari 271             if (calculateMeans) {
2 26 Feb 07 jari 272                 info.meansOrMedians = "K-Means";
2 26 Feb 07 jari 273             } else {
2 26 Feb 07 jari 274                 info.meansOrMedians = "K-Medians";
2 26 Feb 07 jari 275             }
2 26 Feb 07 jari 276             //info.converged = result.getParams().getBoolean("converged");
2 26 Feb 07 jari 277             info.iterations = params.getInt("number-of-iterations");
2 26 Feb 07 jari 278             info.time = time;              
2 26 Feb 07 jari 279             info.numReps = params.getInt("number-of-repetitions");
2 26 Feb 07 jari 280             info.thresholdPercent = params.getFloat("threshold-percent");
2 26 Feb 07 jari 281             int function = params.getInt("distance-function");
2 26 Feb 07 jari 282             
2 26 Feb 07 jari 283             info.function = framework.getDistanceMenu().getFunctionName(function);
2 26 Feb 07 jari 284             info.hcl = params.getBoolean("hierarchical-tree");
2 26 Feb 07 jari 285             info.hcl_genes = params.getBoolean("calculate-genes");
2 26 Feb 07 jari 286             info.hcl_samples = params.getBoolean("calculate-experiments");
2 26 Feb 07 jari 287             if(info.hcl)
2 26 Feb 07 jari 288                 info.hcl_method = params.getInt("method-linkage");
2 26 Feb 07 jari 289             return createResultTree(result_cluster, info);
2 26 Feb 07 jari 290             
2 26 Feb 07 jari 291         } finally {
2 26 Feb 07 jari 292             if (algorithm != null) {
2 26 Feb 07 jari 293                 algorithm.removeAlgorithmListener(listener);
2 26 Feb 07 jari 294             }
2 26 Feb 07 jari 295             if (progress != null) {
2 26 Feb 07 jari 296                 progress.dispose();
2 26 Feb 07 jari 297             }
2 26 Feb 07 jari 298         }
2 26 Feb 07 jari 299     }
2 26 Feb 07 jari 300     
2 26 Feb 07 jari 301     
2 26 Feb 07 jari 302     public AlgorithmData getScriptParameters(IFramework framework) {
2 26 Feb 07 jari 303         // the default values
2 26 Feb 07 jari 304         int numClusters = 10;
2 26 Feb 07 jari 305         int iterations = 50;
2 26 Feb 07 jari 306         data = framework.getData();
2 26 Feb 07 jari 307         
2 26 Feb 07 jari 308         IDistanceMenu menu = framework.getDistanceMenu();
2 26 Feb 07 jari 309         int function = menu.getDistanceFunction();
2 26 Feb 07 jari 310         if (function == Algorithm.DEFAULT) {
2 26 Feb 07 jari 311             function = Algorithm.EUCLIDEAN;
2 26 Feb 07 jari 312         }
2 26 Feb 07 jari 313             
2 26 Feb 07 jari 314         KMCSupportDialog kmcsDialog = new KMCSupportDialog((JFrame) framework.getFrame(), true, menu.getFunctionName(function), menu.isAbsoluteDistance());
2 26 Feb 07 jari 315   
2 26 Feb 07 jari 316         kmcsDialog.setVisible(true);
2 26 Feb 07 jari 317         
2 26 Feb 07 jari 318         if (!kmcsDialog.isOkPressed()) return null;
2 26 Feb 07 jari 319         int numReps = 0;
2 26 Feb 07 jari 320         double thresholdPercent = 0.0;
2 26 Feb 07 jari 321         try {
2 26 Feb 07 jari 322             numClusters = kmcsDialog.getNumClusters();
2 26 Feb 07 jari 323             iterations = kmcsDialog.getIterations();
2 26 Feb 07 jari 324             numReps = kmcsDialog.getNumReps();
2 26 Feb 07 jari 325             thresholdPercent = kmcsDialog.getThresholdPercent();
2 26 Feb 07 jari 326             clusterGenes = kmcsDialog.isClusterGenes();
2 26 Feb 07 jari 327         } catch (NumberFormatException nfe) {
2 26 Feb 07 jari 328             JOptionPane.showMessageDialog(framework.getFrame(), "Invalid input parameters!", "Error", JOptionPane.ERROR_MESSAGE);
2 26 Feb 07 jari 329             return null;
2 26 Feb 07 jari 330         }
2 26 Feb 07 jari 331         
2 26 Feb 07 jari 332         boolean isHierarchicalTree = kmcsDialog.isDrawTrees();
2 26 Feb 07 jari 333         boolean calculateMeans = kmcsDialog.meansChosen();
2 26 Feb 07 jari 334         // hcl init
2 26 Feb 07 jari 335         int hcl_method = 0;
2 26 Feb 07 jari 336         boolean hcl_samples = false;
2 26 Feb 07 jari 337         boolean hcl_genes = false;
2 26 Feb 07 jari 338         int hcl_function = kmcsDialog.getDistanceMetric();
2 26 Feb 07 jari 339         boolean hcl_absolute = kmcsDialog.getAbsoluteSelection();
2 26 Feb 07 jari 340         if (isHierarchicalTree) {
2 26 Feb 07 jari 341             HCLInitDialog hcl_dialog = new HCLInitDialog(framework.getFrame(), menu.getFunctionName(kmcsDialog.getDistanceMetric()), kmcsDialog.getAbsoluteSelection(), true);
2 26 Feb 07 jari 342           
2 26 Feb 07 jari 343             if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 344                 return null;
2 26 Feb 07 jari 345             }
2 26 Feb 07 jari 346             hcl_method = hcl_dialog.getMethod();
2 26 Feb 07 jari 347             hcl_samples = hcl_dialog.isClusterExperiments();
2 26 Feb 07 jari 348             hcl_genes = hcl_dialog.isClusterGenes();
2 26 Feb 07 jari 349             hcl_function = hcl_dialog.getDistanceMetric();
2 26 Feb 07 jari 350             hcl_absolute = hcl_dialog.getAbsoluteSelection();
2 26 Feb 07 jari 351         }
2 26 Feb 07 jari 352         this.experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 353         
2 26 Feb 07 jari 354         int genes = experiment.getNumberOfGenes();
2 26 Feb 07 jari 355         
2 26 Feb 07 jari 356         AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 357         data.addParam("kmc-cluster-genes", String.valueOf(clusterGenes));
2 26 Feb 07 jari 358         data.addParam("distance-factor", String.valueOf(1.0f));
2 26 Feb 07 jari 359         
2 26 Feb 07 jari 360
2 26 Feb 07 jari 361         function = kmcsDialog.getDistanceMetric();        
2 26 Feb 07 jari 362         data.addParam("distance-absolute", String.valueOf(kmcsDialog.getAbsoluteSelection()));
2 26 Feb 07 jari 363         
2 26 Feb 07 jari 364         data.addParam("distance-function", String.valueOf(function));
2 26 Feb 07 jari 365         data.addParam("number-of-desired-clusters", String.valueOf(numClusters));
2 26 Feb 07 jari 366         data.addParam("number-of-iterations", String.valueOf(iterations));
2 26 Feb 07 jari 367         data.addParam("number-of-repetitions", String.valueOf(numReps));
2 26 Feb 07 jari 368         data.addParam("threshold-percent", String.valueOf(thresholdPercent));
2 26 Feb 07 jari 369         data.addParam("calculate-means", String.valueOf(calculateMeans));
2 26 Feb 07 jari 370         // hcl parameters
2 26 Feb 07 jari 371         if (isHierarchicalTree) {
2 26 Feb 07 jari 372             data.addParam("hierarchical-tree", String.valueOf(true));
2 26 Feb 07 jari 373             data.addParam("method-linkage", String.valueOf(hcl_method));
2 26 Feb 07 jari 374             data.addParam("calculate-genes", String.valueOf(hcl_genes));
2 26 Feb 07 jari 375             data.addParam("calculate-experiments", String.valueOf(hcl_samples));
2 26 Feb 07 jari 376             data.addParam("hcl-distance-function", String.valueOf(hcl_function));
2 26 Feb 07 jari 377             data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute));
2 26 Feb 07 jari 378         }
2 26 Feb 07 jari 379         //script control parameters
2 26 Feb 07 jari 380         
2 26 Feb 07 jari 381         // alg name
2 26 Feb 07 jari 382         data.addParam("name", "KMS");
2 26 Feb 07 jari 383         
2 26 Feb 07 jari 384         // alg type
2 26 Feb 07 jari 385         if(clusterGenes)
2 26 Feb 07 jari 386             data.addParam("alg-type", "cluster-genes");
2 26 Feb 07 jari 387         else
2 26 Feb 07 jari 388             data.addParam("alg-type", "cluster-experiments");
2 26 Feb 07 jari 389         
2 26 Feb 07 jari 390         // output class
2 26 Feb 07 jari 391         if(clusterGenes)
2 26 Feb 07 jari 392             data.addParam("output-class", "multi-gene-cluster-output");
2 26 Feb 07 jari 393         else
2 26 Feb 07 jari 394             data.addParam("output-class", "multi-experiment-cluster-output");
2 26 Feb 07 jari 395         
2 26 Feb 07 jari 396         //output nodes
2 26 Feb 07 jari 397         String [] outputNodes = new String[1];
2 26 Feb 07 jari 398         outputNodes[0] = "Multi-cluster";
2 26 Feb 07 jari 399         data.addStringArray("output-nodes", outputNodes);
2 26 Feb 07 jari 400         
2 26 Feb 07 jari 401         return data;
2 26 Feb 07 jari 402     }
2 26 Feb 07 jari 403     
2 26 Feb 07 jari 404     
2 26 Feb 07 jari 405     /**
2 26 Feb 07 jari 406      * Creates a result tree to be inserted into the framework analysis node.
2 26 Feb 07 jari 407      */
2 26 Feb 07 jari 408     private DefaultMutableTreeNode createResultTree(Cluster result_cluster, GeneralInfo info) {
2 26 Feb 07 jari 409         DefaultMutableTreeNode root;
2 26 Feb 07 jari 410         if(this.clusterGenes)
2 26 Feb 07 jari 411             root = new DefaultMutableTreeNode("KMS - genes");
2 26 Feb 07 jari 412         else
2 26 Feb 07 jari 413             root = new DefaultMutableTreeNode("KMS - samples");
2 26 Feb 07 jari 414         addResultNodes(root, result_cluster, info);
2 26 Feb 07 jari 415         return root;
2 26 Feb 07 jari 416     }
2 26 Feb 07 jari 417     
2 26 Feb 07 jari 418     /**
2 26 Feb 07 jari 419      * Adds result nodes into the tree root.
2 26 Feb 07 jari 420      */
2 26 Feb 07 jari 421     private void addResultNodes(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) {
2 26 Feb 07 jari 422         addExpressionImages(root);
2 26 Feb 07 jari 423         addHierarchicalTrees(root, result_cluster, info);
2 26 Feb 07 jari 424         addCentroidViews(root);
2 26 Feb 07 jari 425         addTableViews(root);
2 26 Feb 07 jari 426         addClusterInfo(root);
2 26 Feb 07 jari 427         addGeneralInfo(root, info);
2 26 Feb 07 jari 428     }
2 26 Feb 07 jari 429     
2 26 Feb 07 jari 430     private void addTableViews(DefaultMutableTreeNode root) {
2 26 Feb 07 jari 431         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Table views");
2 26 Feb 07 jari 432         IViewer tabViewer;
2 26 Feb 07 jari 433         if(clusterGenes)
2 26 Feb 07 jari 434             tabViewer = new ClusterTableViewer(this.experiment, this.clusters, this.data);
2 26 Feb 07 jari 435         else
2 26 Feb 07 jari 436             tabViewer = new ExperimentClusterTableViewer(this.experiment, this.clusters, this.data);
2 26 Feb 07 jari 437         //return; // placeholder for ExptClusterTableViewer
2 26 Feb 07 jari 438         //expViewer = new KMCSuppExperimentClusterViewer(this.experiment, this.clusters);
2 26 Feb 07 jari 439         
2 26 Feb 07 jari 440         if (!unassignedExists) {
2 26 Feb 07 jari 441             for (int i=0; i<this.clusters.length; i++) {
2 26 Feb 07 jari 442                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), tabViewer, new Integer(i))));
2 26 Feb 07 jari 443             }
2 26 Feb 07 jari 444         } else {
2 26 Feb 07 jari 445             for (int i=0; i<(this.clusters.length - 1); i++) {
2 26 Feb 07 jari 446                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), tabViewer, new Integer(i))));
2 26 Feb 07 jari 447             }
2 26 Feb 07 jari 448             //if(clusterGenes)
2 26 Feb 07 jari 449             node.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned ", tabViewer, new Integer(clusters.length - 1))));
2 26 Feb 07 jari 450             //else
2 26 Feb 07 jari 451             //node.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned experiments ", expViewer, new Integer(clusters.length - 1))));
2 26 Feb 07 jari 452             
2 26 Feb 07 jari 453         }
2 26 Feb 07 jari 454         root.add(node);
2 26 Feb 07 jari 455     }
2 26 Feb 07 jari 456     
2 26 Feb 07 jari 457     /**
2 26 Feb 07 jari 458      * Adds nodes to display clusters data.
2 26 Feb 07 jari 459      */
2 26 Feb 07 jari 460     private void addExpressionImages(DefaultMutableTreeNode root) {
2 26 Feb 07 jari 461         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images");
2 26 Feb 07 jari 462         IViewer expViewer;
2 26 Feb 07 jari 463         if(clusterGenes)
2 26 Feb 07 jari 464             expViewer = new KMCSuppExperimentViewer(this.experiment, this.clusters);
2 26 Feb 07 jari 465         else
2 26 Feb 07 jari 466             expViewer = new KMCSuppExperimentClusterViewer(this.experiment, this.clusters);
2 26 Feb 07 jari 467         
2 26 Feb 07 jari 468         if (!unassignedExists) {
2 26 Feb 07 jari 469             for (int i=0; i<this.clusters.length; i++) {
2 26 Feb 07 jari 470                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expViewer, new Integer(i))));
2 26 Feb 07 jari 471             }
2 26 Feb 07 jari 472         } else {
2 26 Feb 07 jari 473             for (int i=0; i<(this.clusters.length - 1); i++) {
2 26 Feb 07 jari 474                 node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expViewer, new Integer(i))));
2 26 Feb 07 jari 475             }
2 26 Feb 07 jari 476             if(clusterGenes)
2 26 Feb 07 jari 477                 node.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned genes ", expViewer, new Integer(clusters.length - 1))));
2 26 Feb 07 jari 478             else
2 26 Feb 07 jari 479                 node.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned experiments ", expViewer, new Integer(clusters.length - 1))));
2 26 Feb 07 jari 480             
2 26 Feb 07 jari 481         }
2 26 Feb 07 jari 482         root.add(node);
2 26 Feb 07 jari 483     }
2 26 Feb 07 jari 484     
2 26 Feb 07 jari 485     /**
2 26 Feb 07 jari 486      * Adds nodes to display hierarchical trees.
2 26 Feb 07 jari 487      */
2 26 Feb 07 jari 488     private void addHierarchicalTrees(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) {
2 26 Feb 07 jari 489         if (!info.hcl) {
2 26 Feb 07 jari 490             return;
2 26 Feb 07 jari 491         }
2 26 Feb 07 jari 492         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Hierarchical Trees");
2 26 Feb 07 jari 493         NodeList nodeList = result_cluster.getNodeList();
2 26 Feb 07 jari 494         int [][] clusters = null;
2 26 Feb 07 jari 495         int i;
2 26 Feb 07 jari 496         
2 26 Feb 07 jari 497         if(this.clusterGenes){
2 26 Feb 07 jari 498             if (!unassignedExists) {
2 26 Feb 07 jari 499                 for (i=0; i<nodeList.getSize(); i++) {
2 26 Feb 07 jari 500                     node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), createHCLViewer(nodeList.getNode(i), info, clusters))));
2 26 Feb 07 jari 501                 }
2 26 Feb 07 jari 502             } else {
2 26 Feb 07 jari 503                 for (i=0; i<(nodeList.getSize() - 1); i++) {
2 26 Feb 07 jari 504                     node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), createHCLViewer(nodeList.getNode(i), info, clusters))));
2 26 Feb 07 jari 505                 }
2 26 Feb 07 jari 506                 node.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned genes ", createHCLViewer(nodeList.getNode(nodeList.getSize() - 1), info, clusters))));
2 26 Feb 07 jari 507             }
2 26 Feb 07 jari 508         }
2 26 Feb 07 jari 509         //clusterExperiments
2 26 Feb 07 jari 510         else {
2 26 Feb 07 jari 511             clusters = new int[k][];
2 26 Feb 07 jari 512             for (i=0; i<k; i++) {
2 26 Feb 07 jari 513                 clusters[i] = nodeList.getNode(i).getFeaturesIndexes();
2 26 Feb 07 jari 514             }
2 26 Feb 07 jari 515             if(info.hcl_samples)
2 26 Feb 07 jari 516                 clusters = getOrderedIndices(nodeList, clusters, info.hcl_genes);
2 26 Feb 07 jari 517             if(!unassignedExists){
2 26 Feb 07 jari 518                 for (i=0; i<nodeList.getSize(); i++) {
2 26 Feb 07 jari 519                     node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), createHCLViewer(nodeList.getNode(i), info, clusters), new Integer(i))));
2 26 Feb 07 jari 520                 }
2 26 Feb 07 jari 521             } else {
2 26 Feb 07 jari 522                 for (i=0; i<(nodeList.getSize() - 1); i++) {
2 26 Feb 07 jari 523                     node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), createHCLViewer(nodeList.getNode(i), info, clusters), new Integer(i))));
2 26 Feb 07 jari 524                 }
2 26 Feb 07 jari 525                 node.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned experiments ", createHCLViewer(nodeList.getNode(nodeList.getSize() - 1), info, clusters), new Integer(i))));
2 26 Feb 07 jari 526             }
2 26 Feb 07 jari 527         }
2 26 Feb 07 jari 528         root.add(node);
2 26 Feb 07 jari 529     }
2 26 Feb 07 jari 530     
2 26 Feb 07 jari 531     /**
2 26 Feb 07 jari 532      * Creates an <code>HCLViewer</code>.
2 26 Feb 07 jari 533      */
2 26 Feb 07 jari 534     private IViewer createHCLViewer(Node clusterNode, GeneralInfo info, int [][] sampleClusters) {
2 26 Feb 07 jari 535         HCLTreeData genes_result = info.hcl_genes ? getResult(clusterNode, 0) : null;
2 26 Feb 07 jari 536         HCLTreeData samples_result = info.hcl_samples ? getResult(clusterNode, info.hcl_genes ? 4 : 0) : null;
2 26 Feb 07 jari 537         if(this.clusterGenes)
2 26 Feb 07 jari 538             return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result);
2 26 Feb 07 jari 539         else
2 26 Feb 07 jari 540             return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result, sampleClusters, true);
2 26 Feb 07 jari 541     }
2 26 Feb 07 jari 542     
2 26 Feb 07 jari 543     /**
2 26 Feb 07 jari 544      * Returns a hcl tree data from the specified cluster node.
2 26 Feb 07 jari 545      */
2 26 Feb 07 jari 546     private HCLTreeData getResult(Node clusterNode, int pos) {
2 26 Feb 07 jari 547         HCLTreeData data = new HCLTreeData();
2 26 Feb 07 jari 548         NodeValueList valueList = clusterNode.getValues();
2 26 Feb 07 jari 549         data.child_1_array = (int[])valueList.getNodeValue(pos).value;
2 26 Feb 07 jari 550         data.child_2_array = (int[])valueList.getNodeValue(pos+1).value;
2 26 Feb 07 jari 551         data.node_order = (int[])valueList.getNodeValue(pos+2).value;
2 26 Feb 07 jari 552         data.height = (float[])valueList.getNodeValue(pos+3).value;
2 26 Feb 07 jari 553         return data;
2 26 Feb 07 jari 554     }
2 26 Feb 07 jari 555     
2 26 Feb 07 jari 556     /**
2 26 Feb 07 jari 557      * Adds node with cluster information.
2 26 Feb 07 jari 558      */
2 26 Feb 07 jari 559     private void addClusterInfo(DefaultMutableTreeNode root) {
2 26 Feb 07 jari 560         DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information");
2 26 Feb 07 jari 561         if(clusterGenes)
2 26 Feb 07 jari 562             node.add(new DefaultMutableTreeNode(new LeafInfo("Genes in Clusters (#,%)", new KMCSuppInfoViewer(this.clusters, this.experiment.getNumberOfGenes(), this.unassignedExists, this.clusterGenes))));
2 26 Feb 07 jari 563         else
2 26 Feb 07 jari 564             node.add(new DefaultMutableTreeNode(new LeafInfo("Samples in Clusters (#,%)", new KMCSuppInfoViewer(this.clusters, this.experiment.getNumberOfSamples(), this.unassignedExists, this.clusterGenes))));
2 26 Feb 07 jari 565         root.add(node);
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 nodes to display centroid charts.
2 26 Feb 07 jari 570      */
2 26 Feb 07 jari 571     private void addCentroidViews(DefaultMutableTreeNode root) {
2 26 Feb 07 jari 572         DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs");
2 26 Feb 07 jari 573         DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs");
2 26 Feb 07 jari 574         int i;
2 26 Feb 07 jari 575         KMCSuppCentroidViewer centroidViewer;
2 26 Feb 07 jari 576         KMCSuppExperimentCentroidViewer expCentroidViewer;
2 26 Feb 07 jari 577         
2 26 Feb 07 jari 578         if(clusterGenes){
2 26 Feb 07 jari 579             centroidViewer = new KMCSuppCentroidViewer(this.experiment, clusters);
2 26 Feb 07 jari 580             centroidViewer.setMeans(this.means.A);
2 26 Feb 07 jari 581             centroidViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 582             if(!unassignedExists){
2 26 Feb 07 jari 583                 for (i=0; i<this.clusters.length; i++) {
2 26 Feb 07 jari 584                     centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 585                     expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 586                 }
2 26 Feb 07 jari 587             } else {
2 26 Feb 07 jari 588                 for (i=0; i<this.clusters.length-1; i++) {
2 26 Feb 07 jari 589                     centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 590                     expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 591                 }
2 26 Feb 07 jari 592                 centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned genes ", centroidViewer, new CentroidUserObject(this.clusters.length - 1, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 593                 expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned genes ", centroidViewer, new CentroidUserObject(this.clusters.length - 1, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 594             }
2 26 Feb 07 jari 595             
2 26 Feb 07 jari 596             
2 26 Feb 07 jari 597             KMCSuppCentroidsViewer centroidsViewer = new KMCSuppCentroidsViewer(this.experiment, clusters);
2 26 Feb 07 jari 598             centroidsViewer.setMeans(this.means.A);
2 26 Feb 07 jari 599             centroidsViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 600             
2 26 Feb 07 jari 601             centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 602             expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 603             
2 26 Feb 07 jari 604         }
2 26 Feb 07 jari 605         else{
2 26 Feb 07 jari 606             expCentroidViewer = new KMCSuppExperimentCentroidViewer(this.experiment, clusters);
2 26 Feb 07 jari 607             
2 26 Feb 07 jari 608             expCentroidViewer.setMeans(this.means.A);
2 26 Feb 07 jari 609             expCentroidViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 610             if(!unassignedExists){
2 26 Feb 07 jari 611                 for (i=0; i<this.clusters.length; i++) {
2 26 Feb 07 jari 612                     centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 613                     expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 614                 }
2 26 Feb 07 jari 615             } else {
2 26 Feb 07 jari 616                 for (i=0; i<this.clusters.length-1; i++) {
2 26 Feb 07 jari 617                     centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 618                     expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 619                 }
2 26 Feb 07 jari 620                 centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned Experiments ", expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 621                 expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Unassigned Experiments ", expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 622                 
2 26 Feb 07 jari 623             }
2 26 Feb 07 jari 624             
2 26 Feb 07 jari 625             KMCSuppExperimentCentroidsViewer expCentroidsViewer = new KMCSuppExperimentCentroidsViewer(this.experiment, clusters);
2 26 Feb 07 jari 626             expCentroidsViewer.setMeans(this.means.A);
2 26 Feb 07 jari 627             expCentroidsViewer.setVariances(this.variances.A);
2 26 Feb 07 jari 628             
2 26 Feb 07 jari 629             centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE))));
2 26 Feb 07 jari 630             expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE))));
2 26 Feb 07 jari 631         }
2 26 Feb 07 jari 632         root.add(centroidNode);
2 26 Feb 07 jari 633         root.add(expressionNode);
2 26 Feb 07 jari 634     }
2 26 Feb 07 jari 635     
2 26 Feb 07 jari 636     /**
2 26 Feb 07 jari 637      * Adds node with general iformation.
2 26 Feb 07 jari 638      */
2 26 Feb 07 jari 639     private void addGeneralInfo(DefaultMutableTreeNode root, GeneralInfo info) {
2 26 Feb 07 jari 640         DefaultMutableTreeNode node = new DefaultMutableTreeNode("General Information");
2 26 Feb 07 jari 641         node.add(new DefaultMutableTreeNode("K-Means or K-Medians: "+info.meansOrMedians));
2 26 Feb 07 jari 642         node.add(new DefaultMutableTreeNode("Number of consensus clusters: "+String.valueOf(info.clusters)));
2 26 Feb 07 jari 643         //node.add(new DefaultMutableTreeNode("Converged: "+String.valueOf(info.converged)));
2 26 Feb 07 jari 644         node.add(new DefaultMutableTreeNode("Clusters per K-means / K-medians run: "+String.valueOf(info.userNumClusters)));
2 26 Feb 07 jari 645         node.add(new DefaultMutableTreeNode("Iterations per K-means / K-Medians run: "+String.valueOf(info.iterations)));
2 26 Feb 07 jari 646         node.add(new DefaultMutableTreeNode("Number of K-Means / K-Medians runs: "+String.valueOf(info.numReps)));
2 26 Feb 07 jari 647         node.add(new DefaultMutableTreeNode("Threshold co-occurrence %: "+String.valueOf(info.thresholdPercent)));
2 26 Feb 07 jari 648         node.add(new DefaultMutableTreeNode("HCL: "+info.getMethodName()));
2 26 Feb 07 jari 649         node.add(new DefaultMutableTreeNode("Time: "+String.valueOf(info.time)+" ms"));
2 26 Feb 07 jari 650         node.add(new DefaultMutableTreeNode(info.function));
2 26 Feb 07 jari 651         root.add(node);
2 26 Feb 07 jari 652     }
2 26 Feb 07 jari 653     
2 26 Feb 07 jari 654     /***************************************************************************************
2 26 Feb 07 jari 655      * Code to order sample clustering results based on HCL runs.  sampleClusters contain an array
2 26 Feb 07 jari 656      * of sample indices for each experiment cluster.  Note that these indicies are ordered in
2 26 Feb 07 jari 657      * an order which matches HCL input matrix sample order so that HCL results (node-order) can
2 26 Feb 07 jari 658      * be used to order leaf indices to match HCL samples results
2 26 Feb 07 jari 659      */
2 26 Feb 07 jari 660     private int [][] getOrderedIndices(NodeList nodeList, int [][] sampleClusters, boolean calcGeneHCL){
2 26 Feb 07 jari 661         HCLTreeData result;
2 26 Feb 07 jari 662         for(int i = 0; i < sampleClusters.length ; i++){
2 26 Feb 07 jari 663             if(sampleClusters[i].length > 0){
2 26 Feb 07 jari 664                 result = getResult(nodeList.getNode(i), calcGeneHCL ? 4 : 0);  //get sample Result
2 26 Feb 07 jari 665                 sampleClusters[i] = getSampleOrder(result, sampleClusters[i]);
2 26 Feb 07 jari 666             }
2 26 Feb 07 jari 667         }
2 26 Feb 07 jari 668         return sampleClusters;
2 26 Feb 07 jari 669     }
2 26 Feb 07 jari 670     
2 26 Feb 07 jari 671     private int[] getSampleOrder(HCLTreeData result, int[] indices) {
2 26 Feb 07 jari 672         return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices);
2 26 Feb 07 jari 673     }
2 26 Feb 07 jari 674     
2 26 Feb 07 jari 675     private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) {
2 26 Feb 07 jari 676         int[] leafOrder = new int[nodeOrder.length];
2 26 Feb 07 jari 677         Arrays.fill(leafOrder, -1);
2 26 Feb 07 jari 678         fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices);
2 26 Feb 07 jari 679         return leafOrder;
2 26 Feb 07 jari 680     }
2 26 Feb 07 jari 681     
2 26 Feb 07 jari 682     private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) {
2 26 Feb 07 jari 683         if (child1[index] != -1) {
2 26 Feb 07 jari 684             pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices);
2 26 Feb 07 jari 685         }
2 26 Feb 07 jari 686         if (child2[index] != -1) {
2 26 Feb 07 jari 687             pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices);
2 26 Feb 07 jari 688         } else {
2 26 Feb 07 jari 689             leafOrder[pos] = indices == null ? index : indices[index];
2 26 Feb 07 jari 690             pos++;
2 26 Feb 07 jari 691         }
2 26 Feb 07 jari 692         return pos;
2 26 Feb 07 jari 693     }
2 26 Feb 07 jari 694     
2 26 Feb 07 jari 695     
2 26 Feb 07 jari 696     
2 26 Feb 07 jari 697     /****************************************************************************************
2 26 Feb 07 jari 698      * End of Sample Cluster index ordering code
2 26 Feb 07 jari 699      */
2 26 Feb 07 jari 700     
2 26 Feb 07 jari 701     
2 26 Feb 07 jari 702     
2 26 Feb 07 jari 703     /**
2 26 Feb 07 jari 704      * The class to listen to progress, monitor and algorithms events.
2 26 Feb 07 jari 705      */
2 26 Feb 07 jari 706     private class Listener extends DialogListener implements AlgorithmListener {
2 26 Feb 07 jari 707         
2 26 Feb 07 jari 708         public void valueChanged(AlgorithmEvent event) {
2 26 Feb 07 jari 709             switch (event.getId()) {
2 26 Feb 07 jari 710                 case AlgorithmEvent.SET_UNITS:
2 26 Feb 07 jari 711                     progress.setUnits(event.getIntValue());
2 26 Feb 07 jari 712                     progress.setDescription(event.getDescription());
2 26 Feb 07 jari 713                     break;
2 26 Feb 07 jari 714                 case AlgorithmEvent.PROGRESS_VALUE:
2 26 Feb 07 jari 715                     progress.setValue(event.getIntValue());
2 26 Feb 07 jari 716                     progress.setDescription(event.getDescription());
2 26 Feb 07 jari 717                     break;
2 26 Feb 07 jari 718                 case AlgorithmEvent.MONITOR_VALUE:
2 26 Feb 07 jari 719                     int value = event.getIntValue();
2 26 Feb 07 jari 720                     if (value == -1) {
2 26 Feb 07 jari 721                         //monitor.dispose();
2 26 Feb 07 jari 722                     } else {
2 26 Feb 07 jari 723                         //monitor.update(value);
2 26 Feb 07 jari 724                     }
2 26 Feb 07 jari 725                     break;
2 26 Feb 07 jari 726             }
2 26 Feb 07 jari 727         }
2 26 Feb 07 jari 728         
2 26 Feb 07 jari 729         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 730             String command = e.getActionCommand();
2 26 Feb 07 jari 731             if (command.equals("cancel-command")) {
2 26 Feb 07 jari 732                 algorithm.abort();
2 26 Feb 07 jari 733                 progress.dispose();
2 26 Feb 07 jari 734                 //monitor.dispose();
2 26 Feb 07 jari 735             }
2 26 Feb 07 jari 736         }
2 26 Feb 07 jari 737         
2 26 Feb 07 jari 738         public void windowClosing(WindowEvent e) {
2 26 Feb 07 jari 739             algorithm.abort();
2 26 Feb 07 jari 740             progress.dispose();
2 26 Feb 07 jari 741             //monitor.dispose();
2 26 Feb 07 jari 742         }
2 26 Feb 07 jari 743     }
2 26 Feb 07 jari 744     
2 26 Feb 07 jari 745     private class GeneralInfo {
2 26 Feb 07 jari 746         public int clusters;
2 26 Feb 07 jari 747         public String meansOrMedians;
2 26 Feb 07 jari 748         //public boolean converged;
2 26 Feb 07 jari 749         public int iterations;
2 26 Feb 07 jari 750         public int userNumClusters;
2 26 Feb 07 jari 751         public long time;
2 26 Feb 07 jari 752         public String function;
2 26 Feb 07 jari 753         public int numReps;
2 26 Feb 07 jari 754         public double thresholdPercent;
2 26 Feb 07 jari 755         
2 26 Feb 07 jari 756         private boolean hcl;
2 26 Feb 07 jari 757         private int hcl_method;
2 26 Feb 07 jari 758         private boolean hcl_genes;
2 26 Feb 07 jari 759         private boolean hcl_samples;
2 26 Feb 07 jari 760         
2 26 Feb 07 jari 761         public String getMethodName() {
2 26 Feb 07 jari 762             return hcl ? HCLGUI.GeneralInfo.getMethodName(hcl_method) : "no linkage";
2 26 Feb 07 jari 763         }
2 26 Feb 07 jari 764         
2 26 Feb 07 jari 765     }
2 26 Feb 07 jari 766     
2 26 Feb 07 jari 767 }
2 26 Feb 07 jari 768
2 26 Feb 07 jari 769
2 26 Feb 07 jari 770
2 26 Feb 07 jari 771
2 26 Feb 07 jari 772
2 26 Feb 07 jari 773
2 26 Feb 07 jari 774
2 26 Feb 07 jari 775
2 26 Feb 07 jari 776
2 26 Feb 07 jari 777
2 26 Feb 07 jari 778
2 26 Feb 07 jari 779
2 26 Feb 07 jari 780
2 26 Feb 07 jari 781
2 26 Feb 07 jari 782
2 26 Feb 07 jari 783
2 26 Feb 07 jari 784
2 26 Feb 07 jari 785
2 26 Feb 07 jari 786
2 26 Feb 07 jari 787
2 26 Feb 07 jari 788
2 26 Feb 07 jari 789
2 26 Feb 07 jari 790
2 26 Feb 07 jari 791