mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/coa/COAGUI.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2  * COAGUI.java
2 26 Feb 07 jari 3  *
2 26 Feb 07 jari 4  * Created on September 16, 2004, 11:22 AM
2 26 Feb 07 jari 5  */
2 26 Feb 07 jari 6
2 26 Feb 07 jari 7 package org.tigr.microarray.mev.cluster.gui.impl.coa;
2 26 Feb 07 jari 8
2 26 Feb 07 jari 9 import java.awt.Frame;
2 26 Feb 07 jari 10 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 11 import java.awt.event.WindowEvent;
2 26 Feb 07 jari 12
2 26 Feb 07 jari 13 import javax.swing.JFrame;
2 26 Feb 07 jari 14 import javax.swing.JMenuItem;
2 26 Feb 07 jari 15 import javax.swing.JPopupMenu;
2 26 Feb 07 jari 16 import javax.swing.tree.DefaultMutableTreeNode;
2 26 Feb 07 jari 17
2 26 Feb 07 jari 18 import org.tigr.microarray.mev.cluster.algorithm.AbortException;
2 26 Feb 07 jari 19 import org.tigr.microarray.mev.cluster.algorithm.Algorithm;
2 26 Feb 07 jari 20 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData;
2 26 Feb 07 jari 21 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent;
2 26 Feb 07 jari 22 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException;
2 26 Feb 07 jari 23 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmListener;
2 26 Feb 07 jari 24 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters;
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.gui.IClusterGUI;
2 26 Feb 07 jari 27 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.gui.LeafInfo;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener;
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.Logger;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI;
2 26 Feb 07 jari 34 import org.tigr.util.FloatMatrix;
2 26 Feb 07 jari 35
2 26 Feb 07 jari 36 /**
2 26 Feb 07 jari 37  *
2 26 Feb 07 jari 38  * @author  nbhagaba
2 26 Feb 07 jari 39  */
2 26 Feb 07 jari 40 public class COAGUI  implements IClusterGUI, IScriptGUI {
2 26 Feb 07 jari 41     
2 26 Feb 07 jari 42     private static final String ADD_NEW_3D_CMD = "add-new-3d-cmd";
2 26 Feb 07 jari 43     private static final String ADD_NEW_2D_CMD = "add-new-2d-cmd";    
2 26 Feb 07 jari 44     
2 26 Feb 07 jari 45     public static final int GENES = 1;
2 26 Feb 07 jari 46     public static final int EXPTS = 2;
2 26 Feb 07 jari 47     public static final int BOTH = 3;
2 26 Feb 07 jari 48     
2 26 Feb 07 jari 49     private Algorithm algorithm;
2 26 Feb 07 jari 50     private Logger logger;    
2 26 Feb 07 jari 51     //private Progress progress;
2 26 Feb 07 jari 52     //private Monitor monitor;
2 26 Feb 07 jari 53     private IData data;
2 26 Feb 07 jari 54     
2 26 Feb 07 jari 55     private Experiment experiment;
2 26 Feb 07 jari 56     private FloatMatrix geneUMatrix, exptUMatrix, lambdaValues;
2 26 Feb 07 jari 57     
2 26 Feb 07 jari 58     private IFramework currFramework;
2 26 Feb 07 jari 59     private DefaultMutableTreeNode projectionNode;    
2 26 Feb 07 jari 60     
2 26 Feb 07 jari 61     private double[] lambdaArray, inertiaVals, cumulativeInertiaVals;
2 26 Feb 07 jari 62     //private int[][] clusters;
2 26 Feb 07 jari 63     //private FloatMatrix means;
2 26 Feb 07 jari 64     //private FloatMatrix variances;    
2 26 Feb 07 jari 65     
2 26 Feb 07 jari 66     /** Creates a new instance of COAGUI */
2 26 Feb 07 jari 67     public COAGUI() {
2 26 Feb 07 jari 68     }
2 26 Feb 07 jari 69     
2 26 Feb 07 jari 70     /** This method should return a tree with calculation results or
2 26 Feb 07 jari 71      * null, if analysis start was canceled.
2 26 Feb 07 jari 72      *
2 26 Feb 07 jari 73      * @param framework the reference to <code>IFramework</code> implementation,
2 26 Feb 07 jari 74      *        which is used to obtain an initial analysis data and parameters.
2 26 Feb 07 jari 75      * @throws AlgorithmException if calculation was failed.
2 26 Feb 07 jari 76      * @throws AbortException if calculation was canceled.
2 26 Feb 07 jari 77      * @see IFramework
2 26 Feb 07 jari 78      */
2 26 Feb 07 jari 79     public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException {
2 26 Feb 07 jari 80         this.experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 81         this.data = framework.getData();        
2 26 Feb 07 jari 82         int number_of_samples = experiment.getNumberOfSamples();
2 26 Feb 07 jari 83         int number_of_genes = experiment.getNumberOfGenes(); 
2 26 Feb 07 jari 84         
2 26 Feb 07 jari 85         COAInitDialog cDialog = new COAInitDialog((JFrame)framework.getFrame(), true);
2 26 Feb 07 jari 86         cDialog.setVisible(true);
2 26 Feb 07 jari 87         
2 26 Feb 07 jari 88         if (!cDialog.isOkPressed()) return null;  
2 26 Feb 07 jari 89         
2 26 Feb 07 jari 90         int numNeibs = cDialog.getNumNeighbors();
2 26 Feb 07 jari 91         
2 26 Feb 07 jari 92         Listener listener = new Listener(); 
2 26 Feb 07 jari 93         try {
2 26 Feb 07 jari 94             algorithm = framework.getAlgorithmFactory().getAlgorithm("COA");
2 26 Feb 07 jari 95             algorithm.addAlgorithmListener(listener);
2 26 Feb 07 jari 96             
2 26 Feb 07 jari 97             //this.progress = new Progress(framework.getFrame(), "Performing correspondence analysis", listener);
2 26 Feb 07 jari 98             //this.progress.show();
2 26 Feb 07 jari 99             logger = new Logger(framework.getFrame(), "COA Log Window", listener);
2 26 Feb 07 jari 100             logger.show();
2 26 Feb 07 jari 101             logger.append("Starting SVD calculation\n");  
2 26 Feb 07 jari 102             
2 26 Feb 07 jari 103             currFramework = framework;            
2 26 Feb 07 jari 104             
2 26 Feb 07 jari 105             AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 106             
2 26 Feb 07 jari 107             data.addMatrix("experiment", experiment.getMatrix()); 
2 26 Feb 07 jari 108             data.addParam("numNeighbors", String.valueOf(numNeibs));
2 26 Feb 07 jari 109             
2 26 Feb 07 jari 110             long start = System.currentTimeMillis();
2 26 Feb 07 jari 111             AlgorithmData result = algorithm.execute(data);
2 26 Feb 07 jari 112             long time = System.currentTimeMillis() - start;  
2 26 Feb 07 jari 113             
2 26 Feb 07 jari 114             geneUMatrix = result.getMatrix("gene");
2 26 Feb 07 jari 115             exptUMatrix = result.getMatrix("expt");
2 26 Feb 07 jari 116             lambdaValues = result.getMatrix("lambdaValues");
2 26 Feb 07 jari 117             calculateInertiaVals();
2 26 Feb 07 jari 118             //System.out.println("geneUMatrix: rowDim = " + geneUMatrix.getRowDimension() + ", colDim = " + geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 119             //System.out.println("exptUMatrix: rowDim = " + exptUMatrix.getRowDimension() + ", colDim = " + exptUMatrix.getColumnDimension());            
2 26 Feb 07 jari 120             
2 26 Feb 07 jari 121             DefaultMutableTreeNode node = new DefaultMutableTreeNode("COA"); 
2 26 Feb 07 jari 122             addResultNodes(framework.getFrame(), node, time, experiment);
2 26 Feb 07 jari 123             return node;            
2 26 Feb 07 jari 124             
2 26 Feb 07 jari 125         }  finally {
2 26 Feb 07 jari 126             if (algorithm != null) {
2 26 Feb 07 jari 127                 algorithm.removeAlgorithmListener(listener);
2 26 Feb 07 jari 128             }
2 26 Feb 07 jari 129             if (logger != null) {
2 26 Feb 07 jari 130                 logger.dispose();
2 26 Feb 07 jari 131             }
2 26 Feb 07 jari 132         }
2 26 Feb 07 jari 133         
2 26 Feb 07 jari 134         //return null; // for now
2 26 Feb 07 jari 135     }
2 26 Feb 07 jari 136     
2 26 Feb 07 jari 137     
2 26 Feb 07 jari 138     private void calculateInertiaVals() {
2 26 Feb 07 jari 139         lambdaArray = new double[lambdaValues.getRowDimension()];
2 26 Feb 07 jari 140         for (int i = 0; i < lambdaArray.length; i++) {
2 26 Feb 07 jari 141             lambdaArray[i] = (double)(lambdaValues.get(i,0));
2 26 Feb 07 jari 142         }
2 26 Feb 07 jari 143         
2 26 Feb 07 jari 144         double totalLambdaSquared = 0d;
2 26 Feb 07 jari 145         for (int i = 0; i < lambdaArray.length; i++) {
2 26 Feb 07 jari 146             totalLambdaSquared += Math.pow(lambdaArray[i], 2);
2 26 Feb 07 jari 147         }
2 26 Feb 07 jari 148         
2 26 Feb 07 jari 149         inertiaVals = new double[lambdaArray.length];
2 26 Feb 07 jari 150         cumulativeInertiaVals = new double[lambdaArray.length];
2 26 Feb 07 jari 151         for (int i = 0; i < inertiaVals.length; i++) {
2 26 Feb 07 jari 152             inertiaVals[i] = Math.pow(lambdaArray[i], 2)*100d/totalLambdaSquared;
2 26 Feb 07 jari 153         }
2 26 Feb 07 jari 154         
2 26 Feb 07 jari 155         cumulativeInertiaVals[0] = inertiaVals[0];
2 26 Feb 07 jari 156         
2 26 Feb 07 jari 157         for (int i = 1; i < cumulativeInertiaVals.length; i++) {
2 26 Feb 07 jari 158             double currCumul = 0d;
2 26 Feb 07 jari 159             for (int j = 0; j <= i; j++){
2 26 Feb 07 jari 160                 currCumul += inertiaVals[j];
2 26 Feb 07 jari 161             }
2 26 Feb 07 jari 162             cumulativeInertiaVals[i] = currCumul;
2 26 Feb 07 jari 163         }
2 26 Feb 07 jari 164     }
2 26 Feb 07 jari 165     
2 26 Feb 07 jari 166    private void addResultNodes(Frame frame, DefaultMutableTreeNode node, long time, Experiment experiment) {
2 26 Feb 07 jari 167        Listener listener = new Listener();
2 26 Feb 07 jari 168        
2 26 Feb 07 jari 169        COADummyViewer cdv = new COADummyViewer(geneUMatrix, exptUMatrix); // needed to make the menu on the projectionNode serializable
2 26 Feb 07 jari 170        
2 26 Feb 07 jari 171        DefaultMutableTreeNode firstNode = new DefaultMutableTreeNode("Components 1, 2, 3");
2 26 Feb 07 jari 172        //DefaultMutableTreeNode firstNode = new DefaultMutableTreeNode(new LeafInfo("Comp"));
2 26 Feb 07 jari 173        DefaultMutableTreeNode threeDNode = new DefaultMutableTreeNode("3D Views");
2 26 Feb 07 jari 174        DefaultMutableTreeNode twoDNode = new DefaultMutableTreeNode("2D Views");
2 26 Feb 07 jari 175        add3DViewNode(frame, threeDNode, experiment, 0, 1, 2); 
2 26 Feb 07 jari 176        add2DViewNode(twoDNode, experiment, 0, 1, 2);
2 26 Feb 07 jari 177        
2 26 Feb 07 jari 178        firstNode.add(threeDNode);
2 26 Feb 07 jari 179        firstNode.add(twoDNode);
2 26 Feb 07 jari 180        
2 26 Feb 07 jari 181         JPopupMenu projMenu = new JPopupMenu();
2 26 Feb 07 jari 182         JMenuItem menuItem;
2 26 Feb 07 jari 183         menuItem = new JMenuItem("Add new 3-axis projections");
2 26 Feb 07 jari 184         menuItem.setActionCommand("add-new-3d-cmd");
2 26 Feb 07 jari 185         menuItem.addActionListener(listener);
2 26 Feb 07 jari 186         projMenu.add(menuItem);
2 26 Feb 07 jari 187                 
2 26 Feb 07 jari 188         menuItem = new JMenuItem("Add new 2-axis projections");
2 26 Feb 07 jari 189         menuItem.setActionCommand("add-new-2d-cmd");
2 26 Feb 07 jari 190         menuItem.addActionListener(listener);        
2 26 Feb 07 jari 191         projMenu.add(menuItem);   
2 26 Feb 07 jari 192         
2 26 Feb 07 jari 193        //projectionNode = new DefaultMutableTreeNode(new LeafInfo("Projections on PC axes", projMenu));       
2 26 Feb 07 jari 194        //DefaultMutableTreeNode subProjNode = new DefaultMutableTreeNode(new LeafInfo("New projections", cdv, cdv.getJPopupMenu()));
2 26 Feb 07 jari 195         projectionNode = new DefaultMutableTreeNode(new LeafInfo("Projections on COA axes", cdv, cdv.getJPopupMenu()));
2 26 Feb 07 jari 196        
2 26 Feb 07 jari 197        //projectionNode.add(subProjNode);
2 26 Feb 07 jari 198        projectionNode.add(firstNode);
2 26 Feb 07 jari 199        node.add(projectionNode);
2 26 Feb 07 jari 200        addCOAInertiaViewer(node);
2 26 Feb 07 jari 201    }
2 26 Feb 07 jari 202    
2 26 Feb 07 jari 203    
2 26 Feb 07 jari 204     private void addCOAInertiaViewer(DefaultMutableTreeNode root) {
2 26 Feb 07 jari 205         IViewer inertiaValsViewer = new COAInertiaValsViewer(inertiaVals, cumulativeInertiaVals);
2 26 Feb 07 jari 206         root.add(new DefaultMutableTreeNode(new LeafInfo("Inertia values", inertiaValsViewer)));
2 26 Feb 07 jari 207     }   
2 26 Feb 07 jari 208    
2 26 Feb 07 jari 209    /**
2 26 Feb 07 jari 210      * Adds node with 3D viewer.
2 26 Feb 07 jari 211      */
2 26 Feb 07 jari 212    private void add3DViewNode(Frame frame, DefaultMutableTreeNode node, Experiment experiment) {
2 26 Feb 07 jari 213        COA3DViewer coa3DGeneViewer, coa3DExptViewer, coa3DBothViewer;
2 26 Feb 07 jari 214        coa3DGeneViewer = new COA3DViewer(frame, geneUMatrix, experiment, GENES, 0, 1, 2);
2 26 Feb 07 jari 215        coa3DExptViewer = new COA3DViewer(frame, exptUMatrix, experiment, EXPTS, 0, 1, 2);
2 26 Feb 07 jari 216        coa3DBothViewer = new COA3DViewer(frame, geneUMatrix, exptUMatrix, experiment, BOTH, 0, 1, 2);
2 26 Feb 07 jari 217        
2 26 Feb 07 jari 218        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - genes", coa3DGeneViewer, coa3DGeneViewer.getJPopupMenu())));
2 26 Feb 07 jari 219        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - expts", coa3DExptViewer, coa3DExptViewer.getJPopupMenu())));
2 26 Feb 07 jari 220        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - both", coa3DBothViewer, coa3DBothViewer.getJPopupMenu())));
2 26 Feb 07 jari 221    } 
2 26 Feb 07 jari 222    
2 26 Feb 07 jari 223    private void add3DViewNode(Frame frame, DefaultMutableTreeNode node, Experiment experiment, int xAxis, int yAxis, int zAxis) {
2 26 Feb 07 jari 224        COA3DViewer coa3DGeneViewer, coa3DExptViewer, coa3DBothViewer;
2 26 Feb 07 jari 225        coa3DGeneViewer = new COA3DViewer(frame, geneUMatrix, experiment, GENES, xAxis, yAxis, zAxis);
2 26 Feb 07 jari 226        coa3DExptViewer = new COA3DViewer(frame, exptUMatrix, experiment, EXPTS, xAxis, yAxis, zAxis);
2 26 Feb 07 jari 227        coa3DBothViewer = new COA3DViewer(frame, geneUMatrix, exptUMatrix, experiment, BOTH, xAxis, yAxis, zAxis);
2 26 Feb 07 jari 228        
2 26 Feb 07 jari 229        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - genes", coa3DGeneViewer, coa3DGeneViewer.getJPopupMenu())));
2 26 Feb 07 jari 230        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - expts", coa3DExptViewer, coa3DExptViewer.getJPopupMenu())));
2 26 Feb 07 jari 231        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - both", coa3DBothViewer, coa3DBothViewer.getJPopupMenu())));
2 26 Feb 07 jari 232    }   
2 26 Feb 07 jari 233    
2 26 Feb 07 jari 234    
2 26 Feb 07 jari 235    private void add2DViewNode(DefaultMutableTreeNode node, Experiment experiment) {
2 26 Feb 07 jari 236        COA2DViewer geneViewer, exptViewer, bothViewer;
2 26 Feb 07 jari 237        DefaultMutableTreeNode genes = new DefaultMutableTreeNode("2D views - genes");
2 26 Feb 07 jari 238        DefaultMutableTreeNode expts = new DefaultMutableTreeNode("2D views - expts");
2 26 Feb 07 jari 239        DefaultMutableTreeNode both = new DefaultMutableTreeNode("2D views - both");
2 26 Feb 07 jari 240        
2 26 Feb 07 jari 241        COA2DViewer coa01 = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, 0, 1);
2 26 Feb 07 jari 242        COA2DViewer coa12 = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, 1, 2);
2 26 Feb 07 jari 243        COA2DViewer coa02 = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, 0, 2);
2 26 Feb 07 jari 244        
2 26 Feb 07 jari 245        genes.add(new DefaultMutableTreeNode(new LeafInfo("1, 2", coa01, coa01.getJPopupMenu())));
2 26 Feb 07 jari 246        genes.add(new DefaultMutableTreeNode(new LeafInfo("2, 3", coa12, coa12.getJPopupMenu())));
2 26 Feb 07 jari 247        genes.add(new DefaultMutableTreeNode(new LeafInfo("1, 3", coa02, coa02.getJPopupMenu())));
2 26 Feb 07 jari 248        
2 26 Feb 07 jari 249        COA2DViewer coaExpts01 = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, 0, 1);
2 26 Feb 07 jari 250        COA2DViewer coaExpts12 = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, 1, 2);
2 26 Feb 07 jari 251        COA2DViewer coaExpts02 = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, 0, 2);
2 26 Feb 07 jari 252        
2 26 Feb 07 jari 253        expts.add(new DefaultMutableTreeNode(new LeafInfo("1, 2", coaExpts01, coaExpts01.getJPopupMenu())));    
2 26 Feb 07 jari 254        expts.add(new DefaultMutableTreeNode(new LeafInfo("2, 3", coaExpts12, coaExpts12.getJPopupMenu()))); 
2 26 Feb 07 jari 255        expts.add(new DefaultMutableTreeNode(new LeafInfo("1, 3", coaExpts02, coaExpts02.getJPopupMenu()))); 
2 26 Feb 07 jari 256        
2 26 Feb 07 jari 257        COA2DViewer both01 = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, 0, 1);
2 26 Feb 07 jari 258        COA2DViewer both12 = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, 1, 2);
2 26 Feb 07 jari 259        COA2DViewer both02 = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, 0, 2);
2 26 Feb 07 jari 260        
2 26 Feb 07 jari 261        both.add(new DefaultMutableTreeNode(new LeafInfo("1, 2", both01, both01.getJPopupMenu())));
2 26 Feb 07 jari 262        both.add(new DefaultMutableTreeNode(new LeafInfo("2, 3", both12, both12.getJPopupMenu())));       
2 26 Feb 07 jari 263        both.add(new DefaultMutableTreeNode(new LeafInfo("1, 3", both02, both02.getJPopupMenu())));    
2 26 Feb 07 jari 264        
2 26 Feb 07 jari 265        node.add(genes);
2 26 Feb 07 jari 266        node.add(expts);
2 26 Feb 07 jari 267        node.add(both);
2 26 Feb 07 jari 268    }
2 26 Feb 07 jari 269    
2 26 Feb 07 jari 270    private void add2DViewNode(DefaultMutableTreeNode node, Experiment experiment, int xAxis, int yAxis, int zAxis) {
2 26 Feb 07 jari 271        COA2DViewer geneViewer, exptViewer, bothViewer;
2 26 Feb 07 jari 272        DefaultMutableTreeNode genes = new DefaultMutableTreeNode("2D views - genes");
2 26 Feb 07 jari 273        DefaultMutableTreeNode expts = new DefaultMutableTreeNode("2D views - expts");
2 26 Feb 07 jari 274        DefaultMutableTreeNode both = new DefaultMutableTreeNode("2D views - both");
2 26 Feb 07 jari 275        
2 26 Feb 07 jari 276        COA2DViewer coaxy = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, xAxis, yAxis);
2 26 Feb 07 jari 277        COA2DViewer coayz = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, yAxis, zAxis);
2 26 Feb 07 jari 278        COA2DViewer coaxz = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, xAxis, zAxis);
2 26 Feb 07 jari 279        
2 26 Feb 07 jari 280        genes.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (yAxis + 1), coaxy, coaxy.getJPopupMenu())));
2 26 Feb 07 jari 281        genes.add(new DefaultMutableTreeNode(new LeafInfo("" + (yAxis + 1) + ", " + (zAxis + 1), coayz, coayz.getJPopupMenu())));
2 26 Feb 07 jari 282        genes.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (zAxis + 1), coaxz, coaxz.getJPopupMenu())));
2 26 Feb 07 jari 283        
2 26 Feb 07 jari 284        COA2DViewer coaExptsxy = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, xAxis, yAxis);
2 26 Feb 07 jari 285        COA2DViewer coaExptsyz = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, yAxis, zAxis);
2 26 Feb 07 jari 286        COA2DViewer coaExptsxz = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, xAxis, zAxis);
2 26 Feb 07 jari 287        
2 26 Feb 07 jari 288        expts.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (yAxis + 1), coaExptsxy, coaExptsxy.getJPopupMenu())));    
2 26 Feb 07 jari 289        expts.add(new DefaultMutableTreeNode(new LeafInfo("" + (yAxis + 1) + ", " + (zAxis + 1), coaExptsyz, coaExptsyz.getJPopupMenu()))); 
2 26 Feb 07 jari 290        expts.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (zAxis + 1), coaExptsxz, coaExptsxz.getJPopupMenu()))); 
2 26 Feb 07 jari 291        
2 26 Feb 07 jari 292        COA2DViewer bothxy = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, xAxis, yAxis);
2 26 Feb 07 jari 293        COA2DViewer bothyz = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, yAxis, zAxis);
2 26 Feb 07 jari 294        COA2DViewer bothxz = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, xAxis, zAxis);
2 26 Feb 07 jari 295        
2 26 Feb 07 jari 296        both.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (yAxis + 1), bothxy, bothxy.getJPopupMenu())));
2 26 Feb 07 jari 297        both.add(new DefaultMutableTreeNode(new LeafInfo("" + (yAxis + 1) + ", " + (zAxis + 1), bothyz, bothyz.getJPopupMenu())));       
2 26 Feb 07 jari 298        both.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (zAxis + 1), bothxz, bothxz.getJPopupMenu())));    
2 26 Feb 07 jari 299        
2 26 Feb 07 jari 300        node.add(genes);
2 26 Feb 07 jari 301        node.add(expts);
2 26 Feb 07 jari 302        node.add(both);
2 26 Feb 07 jari 303    }   
2 26 Feb 07 jari 304    
2 26 Feb 07 jari 305    private float[] getFloatArray(FloatMatrix matrix, int column) {
2 26 Feb 07 jari 306        float[] array = new float[matrix.getRowDimension()];
2 26 Feb 07 jari 307        for (int i = 0; i < array.length; i++) {
2 26 Feb 07 jari 308            array[i] = matrix.A[i][column];
2 26 Feb 07 jari 309        }
2 26 Feb 07 jari 310        return array;
2 26 Feb 07 jari 311    }
2 26 Feb 07 jari 312    
2 26 Feb 07 jari 313    public void addNew3DNode() {
2 26 Feb 07 jari 314         
2 26 Feb 07 jari 315        COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog((JFrame)currFramework.getFrame(), true, geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 316         pd.setVisible(true);      
2 26 Feb 07 jari 317         if (!pd.isOkPressed()) {
2 26 Feb 07 jari 318             return;
2 26 Feb 07 jari 319         } else {
2 26 Feb 07 jari 320             int selectedX = pd.getXAxis();
2 26 Feb 07 jari 321             int selectedY = pd.getYAxis();
2 26 Feb 07 jari 322             int selectedZ = pd.getZAxis();
2 26 Feb 07 jari 323             
2 26 Feb 07 jari 324             DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("Components " + (selectedX + 1) + ", " + (selectedY + 1) + ", " + (selectedZ + 1));
2 26 Feb 07 jari 325             add3DViewNode(currFramework.getFrame(), newNode, currFramework.getData().getExperiment(), selectedX, selectedY, selectedZ);
2 26 Feb 07 jari 326             DefaultMutableTreeNode twoDNode = new DefaultMutableTreeNode("2D Views");
2 26 Feb 07 jari 327             add2DViewNode(twoDNode, currFramework.getData().getExperiment(), selectedX, selectedY, selectedZ);
2 26 Feb 07 jari 328             newNode.add(twoDNode);   
2 26 Feb 07 jari 329             currFramework.addNode(projectionNode, newNode);
2 26 Feb 07 jari 330         }        
2 26 Feb 07 jari 331    }
2 26 Feb 07 jari 332    
2 26 Feb 07 jari 333    public void addNew2DNode() {
2 26 Feb 07 jari 334         COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog((JFrame)currFramework.getFrame(), true, geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 335         pd.setZBoxInvisible(true);
2 26 Feb 07 jari 336         pd.setVisible(true);  
2 26 Feb 07 jari 337         if (!pd.isOkPressed()) {
2 26 Feb 07 jari 338             return;
2 26 Feb 07 jari 339         } else {
2 26 Feb 07 jari 340             int selectedX = pd.getXAxis();
2 26 Feb 07 jari 341             int selectedY = pd.getYAxis();  
2 26 Feb 07 jari 342             
2 26 Feb 07 jari 343             DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("Components " + (selectedX + 1) + ", " + (selectedY + 1));   
2 26 Feb 07 jari 344             COA2DViewer coaGenexy = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, selectedX, selectedY);
2 26 Feb 07 jari 345             COA2DViewer coaExptxy = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, selectedX, selectedY);
2 26 Feb 07 jari 346             COA2DViewer coaBothxy = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, selectedX, selectedY);
2 26 Feb 07 jari 347             newNode.add(new DefaultMutableTreeNode(new LeafInfo("Genes", coaGenexy, coaGenexy.getJPopupMenu())));
2 26 Feb 07 jari 348             newNode.add(new DefaultMutableTreeNode(new LeafInfo("Expts", coaExptxy, coaExptxy.getJPopupMenu())));
2 26 Feb 07 jari 349             newNode.add(new DefaultMutableTreeNode(new LeafInfo("Both", coaBothxy, coaBothxy.getJPopupMenu())));
2 26 Feb 07 jari 350             currFramework.addNode(projectionNode, newNode);
2 26 Feb 07 jari 351             //add2DViewNode(newNode, );
2 26 Feb 07 jari 352         }
2 26 Feb 07 jari 353    }
2 26 Feb 07 jari 354    
2 26 Feb 07 jari 355     /** Excutes algorihtm provided an experiment, parameters, and the framework.
2 26 Feb 07 jari 356      * @param framework <code>IFramework</code> object.
2 26 Feb 07 jari 357      * @param algData Holds parameters
2 26 Feb 07 jari 358      * @param experiment <code>Experiment</code> object wraps <code>FloatMatrix</code>.
2 26 Feb 07 jari 359      *
2 26 Feb 07 jari 360      * @throws AlgorithmException
2 26 Feb 07 jari 361      * @return
2 26 Feb 07 jari 362      */
2 26 Feb 07 jari 363     public DefaultMutableTreeNode executeScript(IFramework framework, AlgorithmData algData, Experiment experiment) throws AlgorithmException {
2 26 Feb 07 jari 364         Listener listener = new Listener();     
2 26 Feb 07 jari 365         try {
2 26 Feb 07 jari 366             algorithm = framework.getAlgorithmFactory().getAlgorithm("COA");
2 26 Feb 07 jari 367             algorithm.addAlgorithmListener(listener);
2 26 Feb 07 jari 368             
2 26 Feb 07 jari 369             //this.progress = new Progress(framework.getFrame(), "Performing correspondence analysis", listener);
2 26 Feb 07 jari 370             //this.progress.show();
2 26 Feb 07 jari 371             logger = new Logger(framework.getFrame(), "COA Log Window", listener);
2 26 Feb 07 jari 372             logger.show();
2 26 Feb 07 jari 373             logger.append("Starting SVD calculation\n");  
2 26 Feb 07 jari 374             
2 26 Feb 07 jari 375             currFramework = framework;            
2 26 Feb 07 jari 376             
2 26 Feb 07 jari 377             //AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 378             AlgorithmParameters params = algData.getParams();            
2 26 Feb 07 jari 379             int numNeibs = params.getInt("numNeighbors");           
2 26 Feb 07 jari 380             
2 26 Feb 07 jari 381             algData.addMatrix("experiment", experiment.getMatrix()); 
2 26 Feb 07 jari 382             
2 26 Feb 07 jari 383             long start = System.currentTimeMillis();
2 26 Feb 07 jari 384             AlgorithmData result = algorithm.execute(algData);
2 26 Feb 07 jari 385             long time = System.currentTimeMillis() - start;  
2 26 Feb 07 jari 386             
2 26 Feb 07 jari 387             geneUMatrix = result.getMatrix("gene");
2 26 Feb 07 jari 388             exptUMatrix = result.getMatrix("expt");
2 26 Feb 07 jari 389             lambdaValues = result.getMatrix("lambdaValues");
2 26 Feb 07 jari 390             calculateInertiaVals();
2 26 Feb 07 jari 391             //System.out.println("geneUMatrix: rowDim = " + geneUMatrix.getRowDimension() + ", colDim = " + geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 392             //System.out.println("exptUMatrix: rowDim = " + exptUMatrix.getRowDimension() + ", colDim = " + exptUMatrix.getColumnDimension());            
2 26 Feb 07 jari 393             
2 26 Feb 07 jari 394             DefaultMutableTreeNode node = new DefaultMutableTreeNode("COA"); 
2 26 Feb 07 jari 395             addResultNodes(framework.getFrame(), node, time, experiment);
2 26 Feb 07 jari 396             return node;            
2 26 Feb 07 jari 397             
2 26 Feb 07 jari 398         }  finally {
2 26 Feb 07 jari 399             if (algorithm != null) {
2 26 Feb 07 jari 400                 algorithm.removeAlgorithmListener(listener);
2 26 Feb 07 jari 401             }
2 26 Feb 07 jari 402             if (logger != null) {
2 26 Feb 07 jari 403                 logger.dispose();
2 26 Feb 07 jari 404             }   
2 26 Feb 07 jari 405         }
2 26 Feb 07 jari 406         //return null; // for now
2 26 Feb 07 jari 407     }
2 26 Feb 07 jari 408     
2 26 Feb 07 jari 409     /** Returns selected parameters for building a script.
2 26 Feb 07 jari 410      * @param framework Framework object to provide IData object.
2 26 Feb 07 jari 411      * @return
2 26 Feb 07 jari 412      */
2 26 Feb 07 jari 413     public AlgorithmData getScriptParameters(IFramework framework) {
2 26 Feb 07 jari 414         this.experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 415         this.data = framework.getData();        
2 26 Feb 07 jari 416         int number_of_samples = experiment.getNumberOfSamples();
2 26 Feb 07 jari 417         int number_of_genes = experiment.getNumberOfGenes(); 
2 26 Feb 07 jari 418         
2 26 Feb 07 jari 419         //currFramework = framework;
2 26 Feb 07 jari 420         
2 26 Feb 07 jari 421         COAInitDialog cDialog = new COAInitDialog((JFrame)framework.getFrame(), true);
2 26 Feb 07 jari 422         cDialog.setVisible(true);
2 26 Feb 07 jari 423         
2 26 Feb 07 jari 424         if (!cDialog.isOkPressed()) return null;  
2 26 Feb 07 jari 425         
2 26 Feb 07 jari 426         int numNeibs = cDialog.getNumNeighbors();  
2 26 Feb 07 jari 427         
2 26 Feb 07 jari 428         AlgorithmData data = new AlgorithmData();
2 26 Feb 07 jari 429
2 26 Feb 07 jari 430         data.addParam("numNeighbors", String.valueOf(numNeibs)); 
2 26 Feb 07 jari 431         
2 26 Feb 07 jari 432         // alg name
2 26 Feb 07 jari 433         data.addParam("name", "COA");
2 26 Feb 07 jari 434         
2 26 Feb 07 jari 435         // alg type
2 26 Feb 07 jari 436         data.addParam("alg-type", "data-visualization");
2 26 Feb 07 jari 437         
2 26 Feb 07 jari 438         // output class
2 26 Feb 07 jari 439         data.addParam("output-class", "single-output");
2 26 Feb 07 jari 440         
2 26 Feb 07 jari 441         //output nodes
2 26 Feb 07 jari 442         String [] outputNodes = new String[1];
2 26 Feb 07 jari 443         outputNodes[0] = "Data Visualization";
2 26 Feb 07 jari 444         data.addStringArray("output-nodes", outputNodes);
2 26 Feb 07 jari 445         
2 26 Feb 07 jari 446         return data;        
2 26 Feb 07 jari 447         //return null; //for now
2 26 Feb 07 jari 448     }
2 26 Feb 07 jari 449     
2 26 Feb 07 jari 450     /**
2 26 Feb 07 jari 451      * The class to listen to progress, monitor and algorithms events.
2 26 Feb 07 jari 452      */
2 26 Feb 07 jari 453     private class Listener extends DialogListener implements AlgorithmListener {
2 26 Feb 07 jari 454         
2 26 Feb 07 jari 455         public void valueChanged(AlgorithmEvent event) {
2 26 Feb 07 jari 456             logger.append(event.getDescription());
2 26 Feb 07 jari 457         }
2 26 Feb 07 jari 458         
2 26 Feb 07 jari 459         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 460             String command = e.getActionCommand();
2 26 Feb 07 jari 461             if (command.equals("cancel-command")) {
2 26 Feb 07 jari 462                 algorithm.abort();
2 26 Feb 07 jari 463                 logger.dispose();
2 26 Feb 07 jari 464                 //monitor.dispose();
2 26 Feb 07 jari 465             } else if (command.equals("add-new-3d-cmd")) {
2 26 Feb 07 jari 466                 addNew3DNode();
2 26 Feb 07 jari 467             } else if (command.equals("add-new-2d-cmd")) {
2 26 Feb 07 jari 468                 addNew2DNode();
2 26 Feb 07 jari 469             }
2 26 Feb 07 jari 470         }
2 26 Feb 07 jari 471         
2 26 Feb 07 jari 472         public void windowClosing(WindowEvent e) {
2 26 Feb 07 jari 473             algorithm.abort();
2 26 Feb 07 jari 474             logger.dispose();
2 26 Feb 07 jari 475             //monitor.dispose();
2 26 Feb 07 jari 476         }
2 26 Feb 07 jari 477     }    
2 26 Feb 07 jari 478     
2 26 Feb 07 jari 479 }