2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2004, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: HCLViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.18 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/07/13 16:14:25 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
/* |
2 |
26 Feb 07 |
jari |
*Note from N. Bhagabati, 8/7/2002: I have commented out the statement in the addComponents() method that would add the HCL annotation bar to the viewer, |
2 |
26 Feb 07 |
jari |
*as we are now using the Labels as displayed by the ExperimentViewer class, giving us more flexibility to change the label displays as desired. I have, |
2 |
26 Feb 07 |
jari |
*however, left in the code dealing with the HCL annotation bar itself, as this was the least intrusive way to make changes to the code, so as not to set |
2 |
26 Feb 07 |
jari |
off a whole series of unanticipated (and perhaps undesired) consequences |
2 |
26 Feb 07 |
jari |
17 |
* |
2 |
26 Feb 07 |
jari |
18 |
*/ |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
package org.tigr.microarray.mev.cluster.gui.impl.hcl; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.Component; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
26 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
27 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
28 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
29 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
30 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
31 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
32 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
33 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
34 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
37 |
import java.io.ObjectInputStream; |
2 |
26 Feb 07 |
jari |
38 |
import java.io.ObjectOutputStream; |
2 |
26 Feb 07 |
jari |
39 |
import java.util.ArrayList; |
2 |
26 Feb 07 |
jari |
40 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
43 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
44 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
45 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
46 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
47 |
import javax.swing.SwingUtilities; |
2 |
26 Feb 07 |
jari |
48 |
import javax.swing.tree.DefaultMutableTreeNode; |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.microarray.mev.cluster.clusterUtil.Cluster; |
2 |
26 Feb 07 |
jari |
51 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
52 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
53 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
54 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
55 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
56 |
import org.tigr.microarray.mev.cluster.gui.LeafInfo; |
2 |
26 Feb 07 |
jari |
57 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject; |
2 |
26 Feb 07 |
jari |
58 |
import org.tigr.microarray.mev.cluster.gui.helpers.ClusterTableViewer; |
2 |
26 Feb 07 |
jari |
59 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterCentroidViewer; |
2 |
26 Feb 07 |
jari |
60 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterTableViewer; |
2 |
26 Feb 07 |
jari |
61 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterViewer; |
2 |
26 Feb 07 |
jari |
62 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentUtil; |
2 |
26 Feb 07 |
jari |
63 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentViewer; |
2 |
26 Feb 07 |
jari |
64 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
65 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
public class HCLViewer extends JPanel implements IViewer { |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
protected static final String STORE_CLUSTER_CMD = "store-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
70 |
protected static final String LAUNCH_NEW_SESSION_CMD = "launch-new-session-cmd"; |
2 |
26 Feb 07 |
jari |
71 |
protected static final String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
72 |
protected static final String DELETE_CLUSTER_CMD = "delete-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
73 |
protected static final String DELETE_ALL_CLUSTERS_CMD = "delete-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
74 |
protected static final String GENE_TREE_PROPERTIES_CMD = "gene-tree-properties-cmd"; |
2 |
26 Feb 07 |
jari |
75 |
protected static final String SAMPLE_TREE_PROPERTIES_CMD = "sample-tree-properties-cmd"; |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
protected static final String SAVE_GENE_ORDER_CMD = "save-gene-order-cmd"; |
2 |
26 Feb 07 |
jari |
78 |
protected static final String SAVE_EXP_ORDER_CMD = "save-exp-order-cmd"; |
2 |
26 Feb 07 |
jari |
79 |
protected static final String SAVE_GENE_HEIGHT_CMD = "save-gene-height-cmd"; |
2 |
26 Feb 07 |
jari |
80 |
protected static final String SAVE_EXP_HEIGHT_CMD = "save-exp-height-cmd"; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
protected static final String SAVE_GENE_NEWICK_CMD = "save-gene-newick-cmd"; |
2 |
26 Feb 07 |
jari |
83 |
protected static final String SAVE_SAMPLE_NEWICK_CMD = "save-sample-newick-cmd"; |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
// wrapped viewers |
2 |
26 Feb 07 |
jari |
/** component to draw an experiment data */ |
2 |
26 Feb 07 |
jari |
87 |
protected IViewer expViewer; |
2 |
26 Feb 07 |
jari |
/** component to draw an experiment header */ |
2 |
26 Feb 07 |
jari |
89 |
protected HCLExperimentHeader header; |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
/** component to draw genes tree */ |
2 |
26 Feb 07 |
jari |
92 |
protected HCLTree genesTree; |
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
/** component to draw samples tree */ |
2 |
26 Feb 07 |
jari |
95 |
protected HCLTree sampleTree; |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
/** component to draw hcl clusters colors and descriptions */ |
2 |
26 Feb 07 |
jari |
98 |
protected HCLColorBar colorBar; |
2 |
26 Feb 07 |
jari |
/** component to draw an experiment annotations */ |
2 |
26 Feb 07 |
jari |
100 |
protected HCLAnnotationBar annotationBar; |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
102 |
protected HCLTreeData genes_result; |
2 |
26 Feb 07 |
jari |
103 |
protected HCLTreeData samples_result; |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
protected IData data; |
2 |
26 Feb 07 |
jari |
106 |
protected Experiment experiment; |
2 |
26 Feb 07 |
jari |
107 |
protected ArrayList clusters = new ArrayList(); |
2 |
26 Feb 07 |
jari |
108 |
protected ArrayList experimentClusters = new ArrayList(); |
2 |
26 Feb 07 |
jari |
109 |
protected int [][] sampleClusters; |
2 |
26 Feb 07 |
jari |
110 |
public HCLCluster selectedCluster; |
2 |
26 Feb 07 |
jari |
111 |
protected int[] genesOrder; |
2 |
26 Feb 07 |
jari |
112 |
protected int[] samplesOrder; |
2 |
26 Feb 07 |
jari |
113 |
protected boolean isExperimentCluster = false; |
2 |
26 Feb 07 |
jari |
114 |
protected boolean featureListIsEmpty = false; |
2 |
26 Feb 07 |
jari |
115 |
protected Dimension elementSize; |
2 |
26 Feb 07 |
jari |
116 |
protected int numberOfSamples; |
2 |
26 Feb 07 |
jari |
117 |
protected int offset = 0; |
2 |
26 Feb 07 |
jari |
118 |
protected int clusterIndex = 0; |
2 |
26 Feb 07 |
jari |
119 |
protected Listener listener; |
2 |
26 Feb 07 |
jari |
120 |
protected JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
121 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
122 |
protected int[] features; |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
protected DefaultMutableTreeNode node; |
2 |
26 Feb 07 |
jari |
125 |
protected IFramework framework; |
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
127 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>HCLViewer</code> for specified results. |
2 |
26 Feb 07 |
jari |
129 |
*/ |
2 |
26 Feb 07 |
jari |
130 |
public HCLViewer(Experiment experiment, int[] features, HCLTreeData genes_result, HCLTreeData samples_result) { |
2 |
26 Feb 07 |
jari |
131 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
132 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
133 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
134 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
135 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
136 |
this.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
137 |
features = features == null ? createDefaultFeatures(experiment) : features; |
2 |
26 Feb 07 |
jari |
138 |
this.expViewer = createExperimentViewer(experiment, features, genes_result, samples_result); |
2 |
26 Feb 07 |
jari |
139 |
this.expViewer.getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
140 |
this.header = new HCLExperimentHeader(this.expViewer.getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
141 |
this.header.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
142 |
this.colorBar = new HCLColorBar(this.clusters, features.length); |
2 |
26 Feb 07 |
jari |
143 |
this.colorBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
144 |
this.genesOrder = createGenesOrder(experiment, features, genes_result); |
2 |
26 Feb 07 |
jari |
145 |
this.annotationBar = new HCLAnnotationBar(this.genesOrder); |
2 |
26 Feb 07 |
jari |
146 |
this.annotationBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
147 |
if (genes_result != null && experiment.getNumberOfGenes() > 1 && genes_result.node_order.length > 1) { |
2 |
26 Feb 07 |
jari |
148 |
this.genesTree = new HCLTree(genes_result, HCLTree.HORIZONTAL); |
2 |
26 Feb 07 |
jari |
149 |
this.genesTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
150 |
this.genesTree.setListener(listener); |
2 |
26 Feb 07 |
jari |
151 |
this.genes_result = genes_result; |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
if (samples_result != null && experiment.getNumberOfSamples() > 1 && samples_result.node_order.length > 1) { |
2 |
26 Feb 07 |
jari |
154 |
this.sampleTree = new HCLTree(samples_result, HCLTree.VERTICAL); |
2 |
26 Feb 07 |
jari |
155 |
this.samplesOrder = createSamplesOrder(samples_result); |
2 |
26 Feb 07 |
jari |
156 |
if(genes_result == null) |
2 |
26 Feb 07 |
jari |
157 |
this.sampleTree.setHorizontalOffset(10); |
2 |
26 Feb 07 |
jari |
158 |
this.sampleTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
159 |
this.sampleTree.setListener(listener); //added for selection of experiment hcl nodes |
2 |
26 Feb 07 |
jari |
160 |
this.samples_result = samples_result; |
2 |
26 Feb 07 |
jari |
161 |
} |
2 |
26 Feb 07 |
jari |
162 |
this.isExperimentCluster = false; |
2 |
26 Feb 07 |
jari |
163 |
this.numberOfSamples = experiment.getNumberOfSamples(); //know this is correct for gene clustering constructor |
2 |
26 Feb 07 |
jari |
164 |
addComponents(this.sampleTree, this.genesTree, this.expViewer.getContentComponent(), this.colorBar, this.annotationBar); |
2 |
26 Feb 07 |
jari |
165 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
168 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
169 |
new Object[]{this.experiment, this.createDefaultFeatures(this.experiment), this.genes_result, this.samples_result, this.sampleClusters, new Boolean(this.isExperimentCluster), this.genesTree, this.sampleTree, new Integer(this.offset), (ExperimentViewer)this.expViewer}); |
2 |
26 Feb 07 |
jari |
170 |
} |
2 |
26 Feb 07 |
jari |
171 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>HCLViewer</code> for specified results |
2 |
26 Feb 07 |
jari |
* This is the XMLEncoder/Decoder constructor |
2 |
26 Feb 07 |
jari |
174 |
*/ |
2 |
26 Feb 07 |
jari |
175 |
public HCLViewer(Experiment e, int[] features, HCLTreeData genesResult, HCLTreeData samplesResult, int [][] sampleClusters, boolean isExperimentCluster, HCLTree genesTree, HCLTree sampleTree, Integer offset, ExperimentViewer expViewer) { |
2 |
26 Feb 07 |
jari |
176 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
177 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
//this.exptID = exptID.intValue(); |
2 |
26 Feb 07 |
jari |
179 |
this.offset = offset.intValue(); |
2 |
26 Feb 07 |
jari |
180 |
this.expViewer = expViewer; |
2 |
26 Feb 07 |
jari |
181 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
182 |
this.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
183 |
this.features = features; |
2 |
26 Feb 07 |
jari |
184 |
this.isExperimentCluster = isExperimentCluster; |
2 |
26 Feb 07 |
jari |
185 |
this.sampleClusters = sampleClusters; |
2 |
26 Feb 07 |
jari |
186 |
this.genes_result = genesResult; |
2 |
26 Feb 07 |
jari |
187 |
this.samples_result = samplesResult; |
2 |
26 Feb 07 |
jari |
188 |
this.genesTree = genesTree; |
2 |
26 Feb 07 |
jari |
189 |
this.sampleTree = sampleTree; |
2 |
26 Feb 07 |
jari |
190 |
if(genesTree != null) { |
2 |
26 Feb 07 |
jari |
191 |
this.offset = 0; |
2 |
26 Feb 07 |
jari |
192 |
expViewer.setLeftInset(0); |
2 |
26 Feb 07 |
jari |
193 |
expViewer.setInsets(new Insets(0,0,0,0)); |
2 |
26 Feb 07 |
jari |
194 |
} else { |
2 |
26 Feb 07 |
jari |
195 |
sampleTree.setHorizontalOffset(10); |
2 |
26 Feb 07 |
jari |
196 |
} |
2 |
26 Feb 07 |
jari |
197 |
setExperiment(e); |
2 |
26 Feb 07 |
jari |
198 |
} |
2 |
26 Feb 07 |
jari |
199 |
|
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>HCLViewer</code> for specified results |
2 |
26 Feb 07 |
jari |
203 |
*/ |
2 |
26 Feb 07 |
jari |
204 |
public HCLViewer(Experiment experiment, int[] features, HCLTreeData genes_result, HCLTreeData samples_result, int [][] sampleClusters, boolean isExperimentCluster) { |
2 |
26 Feb 07 |
jari |
205 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
206 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
207 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
208 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
209 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
210 |
this.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
211 |
features = features == null ? createDefaultFeatures(experiment) : features; |
2 |
26 Feb 07 |
jari |
212 |
this.isExperimentCluster = isExperimentCluster; |
2 |
26 Feb 07 |
jari |
213 |
if(this.isExperimentCluster) |
2 |
26 Feb 07 |
jari |
214 |
this.numberOfSamples = sampleClusters[0].length; //initial sample count of first cluster |
2 |
26 Feb 07 |
jari |
215 |
else |
2 |
26 Feb 07 |
jari |
216 |
this.numberOfSamples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
217 |
this.genesOrder = createGenesOrder(experiment, createDefaultFeatures(experiment), genes_result); |
2 |
26 Feb 07 |
jari |
218 |
this.sampleClusters = sampleClusters; |
2 |
26 Feb 07 |
jari |
219 |
this.genes_result = genes_result; |
2 |
26 Feb 07 |
jari |
220 |
this.samples_result = samples_result; |
2 |
26 Feb 07 |
jari |
221 |
if(this.isExperimentCluster){ |
2 |
26 Feb 07 |
jari |
222 |
if(genes_result != null){ |
2 |
26 Feb 07 |
jari |
223 |
offset = 0; |
2 |
26 Feb 07 |
jari |
224 |
this.expViewer = new ExperimentClusterViewer(experiment, sampleClusters, genesOrder, true, offset); |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
226 |
else{ |
2 |
26 Feb 07 |
jari |
227 |
offset = 10; |
2 |
26 Feb 07 |
jari |
228 |
this.expViewer = new ExperimentClusterViewer(experiment, sampleClusters, genesOrder, true, offset); |
2 |
26 Feb 07 |
jari |
229 |
} |
2 |
26 Feb 07 |
jari |
230 |
} |
2 |
26 Feb 07 |
jari |
231 |
else { |
2 |
26 Feb 07 |
jari |
232 |
this.expViewer = createExperimentViewer(experiment, features, genes_result, samples_result); |
2 |
26 Feb 07 |
jari |
233 |
} |
2 |
26 Feb 07 |
jari |
234 |
this.expViewer.getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
235 |
this.header = new HCLExperimentHeader(this.expViewer.getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
236 |
this.header.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
237 |
this.colorBar = new HCLColorBar(this.clusters, features.length); |
2 |
26 Feb 07 |
jari |
238 |
this.colorBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
239 |
this.annotationBar = new HCLAnnotationBar(this.genesOrder); |
2 |
26 Feb 07 |
jari |
240 |
this.annotationBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
/*EH |
2 |
26 Feb 07 |
jari |
if (genes_result != null && experiment.getNumberOfGenes() > 1) { |
2 |
26 Feb 07 |
jari |
this.genesTree = new HCLTree(genes_result, HCLTree.HORIZONTAL); |
2 |
26 Feb 07 |
jari |
this.genesTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
this.genesTree.setListener(listener); |
2 |
26 Feb 07 |
jari |
246 |
} |
2 |
26 Feb 07 |
jari |
if (samples_result != null && experiment.getNumberOfSamples() > 1) { |
2 |
26 Feb 07 |
jari |
this.sampleTree = new HCLTree(samples_result, HCLTree.VERTICAL); |
2 |
26 Feb 07 |
jari |
// this.samplesOrder = createSamplesOrder(samples_result, sampleClusters[0]); |
2 |
26 Feb 07 |
jari |
if(genes_result == null) |
2 |
26 Feb 07 |
jari |
this.sampleTree.setHorizontalOffset(10); |
2 |
26 Feb 07 |
jari |
this.sampleTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
this.sampleTree.setListener(listener); |
2 |
26 Feb 07 |
jari |
254 |
} |
2 |
26 Feb 07 |
jari |
255 |
*/ |
2 |
26 Feb 07 |
jari |
256 |
addComponents(this.sampleTree, this.genesTree, this.expViewer.getContentComponent(), this.colorBar, this.annotationBar); |
2 |
26 Feb 07 |
jari |
257 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
258 |
} |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
260 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>HCLViewer</code> for specified results. |
2 |
26 Feb 07 |
jari |
262 |
*/ |
2 |
26 Feb 07 |
jari |
263 |
public HCLViewer(Experiment experiment, int[] features, HCLTreeData genes_result, HCLTreeData samples_result, DefaultMutableTreeNode node) { |
2 |
26 Feb 07 |
jari |
264 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
265 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
266 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
267 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
268 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
269 |
this.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
270 |
this.node = node; |
2 |
26 Feb 07 |
jari |
271 |
features = features == null ? createDefaultFeatures(experiment) : features; |
2 |
26 Feb 07 |
jari |
272 |
this.expViewer = createExperimentViewer(experiment, features, genes_result, samples_result); |
2 |
26 Feb 07 |
jari |
273 |
this.expViewer.getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
274 |
this.header = new HCLExperimentHeader(this.expViewer.getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
275 |
this.header.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
276 |
this.colorBar = new HCLColorBar(this.clusters, features.length); |
2 |
26 Feb 07 |
jari |
277 |
this.colorBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
278 |
this.genesOrder = createGenesOrder(experiment, features, genes_result); |
2 |
26 Feb 07 |
jari |
279 |
this.annotationBar = new HCLAnnotationBar(this.genesOrder); |
2 |
26 Feb 07 |
jari |
280 |
this.annotationBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
281 |
if (genes_result != null && experiment.getNumberOfGenes() > 1 && genes_result.node_order.length > 1) { |
2 |
26 Feb 07 |
jari |
282 |
this.genesTree = new HCLTree(genes_result, HCLTree.HORIZONTAL); |
2 |
26 Feb 07 |
jari |
283 |
this.genesTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
284 |
this.genesTree.setListener(listener); |
2 |
26 Feb 07 |
jari |
285 |
this.genes_result = genes_result; |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
if (samples_result != null && experiment.getNumberOfSamples() > 1 && samples_result.node_order.length > 1) { |
2 |
26 Feb 07 |
jari |
288 |
this.sampleTree = new HCLTree(samples_result, HCLTree.VERTICAL); |
2 |
26 Feb 07 |
jari |
289 |
this.samplesOrder = createSamplesOrder(samples_result); |
2 |
26 Feb 07 |
jari |
290 |
if(genes_result == null) |
2 |
26 Feb 07 |
jari |
291 |
this.sampleTree.setHorizontalOffset(10); |
2 |
26 Feb 07 |
jari |
292 |
this.sampleTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
293 |
this.sampleTree.setListener(listener); //added for selection of experiment hcl nodes |
2 |
26 Feb 07 |
jari |
294 |
this.samples_result = samples_result; |
2 |
26 Feb 07 |
jari |
295 |
} |
2 |
26 Feb 07 |
jari |
296 |
this.isExperimentCluster = false; |
2 |
26 Feb 07 |
jari |
297 |
this.numberOfSamples = experiment.getNumberOfSamples(); //know this is correct for gene clustering constructor |
2 |
26 Feb 07 |
jari |
298 |
addComponents(this.sampleTree, this.genesTree, this.expViewer.getContentComponent(), this.colorBar, this.annotationBar); |
2 |
26 Feb 07 |
jari |
299 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
300 |
} |
2 |
26 Feb 07 |
jari |
301 |
|
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
303 |
public void setExperiment(Experiment e) { |
2 |
26 Feb 07 |
jari |
304 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
305 |
this.exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
306 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
307 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
308 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
309 |
this.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
310 |
features = features == null ? createDefaultFeatures(experiment) : features; |
2 |
26 Feb 07 |
jari |
311 |
this.expViewer.getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
312 |
this.expViewer.setExperiment(this.experiment); |
2 |
26 Feb 07 |
jari |
313 |
this.header = new HCLExperimentHeader(this.expViewer.getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
314 |
this.header.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
315 |
this.colorBar = new HCLColorBar(this.clusters, features.length); |
2 |
26 Feb 07 |
jari |
316 |
this.colorBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
317 |
this.genesOrder = createGenesOrder(experiment, features, genes_result); |
2 |
26 Feb 07 |
jari |
318 |
this.annotationBar = new HCLAnnotationBar(this.genesOrder); |
2 |
26 Feb 07 |
jari |
319 |
this.annotationBar.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
320 |
if (genes_result != null && experiment.getNumberOfGenes() > 1 && genes_result.node_order.length > 1) { |
2 |
26 Feb 07 |
jari |
321 |
this.genesTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
322 |
this.genesTree.setListener(listener); |
2 |
26 Feb 07 |
jari |
323 |
this.genesTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
if (samples_result != null && experiment.getNumberOfSamples() > 1 && samples_result.node_order.length > 1) { |
2 |
26 Feb 07 |
jari |
326 |
this.samplesOrder = createSamplesOrder(samples_result); |
2 |
26 Feb 07 |
jari |
327 |
if(genes_result == null) |
2 |
26 Feb 07 |
jari |
328 |
this.sampleTree.setHorizontalOffset(10); |
2 |
26 Feb 07 |
jari |
329 |
this.sampleTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
330 |
this.sampleTree.setListener(listener); //added for selection of experiment hcl nodes |
2 |
26 Feb 07 |
jari |
331 |
this.sampleTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
332 |
} |
2 |
26 Feb 07 |
jari |
333 |
this.isExperimentCluster = false; |
2 |
26 Feb 07 |
jari |
334 |
this.numberOfSamples = experiment.getNumberOfSamples(); //know this is correct for gene clustering constructor |
2 |
26 Feb 07 |
jari |
335 |
addComponents(this.sampleTree, this.genesTree, this.expViewer.getContentComponent(), this.colorBar, this.annotationBar); |
2 |
26 Feb 07 |
jari |
336 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
337 |
|
2 |
26 Feb 07 |
jari |
338 |
} |
2 |
26 Feb 07 |
jari |
339 |
public void setExperimentID(int id) { |
2 |
26 Feb 07 |
jari |
340 |
this.exptID = id; |
2 |
26 Feb 07 |
jari |
341 |
} |
2 |
26 Feb 07 |
jari |
342 |
public int getExperimentID() {return this.exptID;} |
2 |
26 Feb 07 |
jari |
343 |
|
2 |
26 Feb 07 |
jari |
344 |
/** |
2 |
26 Feb 07 |
jari |
* Adds wrapped viewers. |
2 |
26 Feb 07 |
jari |
346 |
*/ |
2 |
26 Feb 07 |
jari |
347 |
protected void addComponents(JComponent sTree, JComponent gTree, JComponent exp, JComponent cBar, JComponent aBar) { |
2 |
26 Feb 07 |
jari |
348 |
final int rows = sTree == null ? 1 : 2; |
2 |
26 Feb 07 |
jari |
349 |
final int cols = gTree == null ? 3 : 4; |
2 |
26 Feb 07 |
jari |
350 |
if (sTree != null) { |
2 |
26 Feb 07 |
jari |
351 |
add(sTree, new GridBagConstraints(cols-3, rows-2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
352 |
} |
2 |
26 Feb 07 |
jari |
353 |
if (gTree != null) { |
2 |
26 Feb 07 |
jari |
354 |
add(gTree, new GridBagConstraints(cols-4, rows-1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
355 |
} |
2 |
26 Feb 07 |
jari |
356 |
add(exp, new GridBagConstraints(cols-3, rows-1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
357 |
} |
2 |
26 Feb 07 |
jari |
358 |
|
2 |
26 Feb 07 |
jari |
359 |
|
2 |
26 Feb 07 |
jari |
360 |
|
2 |
26 Feb 07 |
jari |
361 |
protected IViewer createExperimentViewer(Experiment experiment, int[] features, HCLTreeData genes_result, HCLTreeData samples_result) { |
2 |
26 Feb 07 |
jari |
362 |
int[][] clusters = createClusters(experiment, features, genes_result); |
2 |
26 Feb 07 |
jari |
363 |
int [] samples = getLeafOrder(samples_result, null); |
2 |
26 Feb 07 |
jari |
364 |
IViewer viewer; |
2 |
26 Feb 07 |
jari |
365 |
if(genes_result != null){ |
2 |
26 Feb 07 |
jari |
366 |
offset = 0; |
2 |
26 Feb 07 |
jari |
367 |
viewer = new ExperimentViewer(experiment, clusters, samples, true, offset); |
2 |
26 Feb 07 |
jari |
368 |
} |
2 |
26 Feb 07 |
jari |
369 |
else{ |
2 |
26 Feb 07 |
jari |
370 |
offset = 10; |
2 |
26 Feb 07 |
jari |
371 |
viewer = new ExperimentViewer(experiment, clusters, samples, true, offset); |
2 |
26 Feb 07 |
jari |
372 |
} |
2 |
26 Feb 07 |
jari |
373 |
return viewer; |
2 |
26 Feb 07 |
jari |
374 |
} |
2 |
26 Feb 07 |
jari |
375 |
|
2 |
26 Feb 07 |
jari |
376 |
|
2 |
26 Feb 07 |
jari |
377 |
protected int[] createDefaultFeatures(Experiment experiment) { |
2 |
26 Feb 07 |
jari |
378 |
int[] features = new int[experiment.getNumberOfGenes()]; |
2 |
26 Feb 07 |
jari |
379 |
for (int i=0; i<features.length; i++) { |
2 |
26 Feb 07 |
jari |
380 |
features[i] = i; |
2 |
26 Feb 07 |
jari |
381 |
} |
2 |
26 Feb 07 |
jari |
382 |
return features; |
2 |
26 Feb 07 |
jari |
383 |
} |
2 |
26 Feb 07 |
jari |
384 |
|
2 |
26 Feb 07 |
jari |
385 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a cluster for wrapped experiment viewer. |
2 |
26 Feb 07 |
jari |
387 |
*/ |
2 |
26 Feb 07 |
jari |
388 |
private int[][] createClusters(Experiment experiment, int[] features, HCLTreeData genes_result) { |
2 |
26 Feb 07 |
jari |
389 |
int [][] clusters = new int[1][features.length]; |
2 |
26 Feb 07 |
jari |
390 |
clusters[0] = createGenesOrder(experiment, features, genes_result); |
2 |
26 Feb 07 |
jari |
391 |
return clusters; |
2 |
26 Feb 07 |
jari |
392 |
} |
2 |
26 Feb 07 |
jari |
393 |
|
2 |
26 Feb 07 |
jari |
394 |
protected int [] createSamplesOrder(HCLTreeData samples_result){ |
2 |
26 Feb 07 |
jari |
395 |
return createSamplesOrder(samples_result, null); |
2 |
26 Feb 07 |
jari |
396 |
} |
2 |
26 Feb 07 |
jari |
397 |
|
2 |
26 Feb 07 |
jari |
398 |
protected int [] createSamplesOrder(HCLTreeData samples_result, int [] indices){ |
2 |
26 Feb 07 |
jari |
399 |
return getLeafOrder(samples_result, indices); |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
|
2 |
26 Feb 07 |
jari |
402 |
protected int[] createGenesOrder(Experiment experiment, int[] features, HCLTreeData genes_result) { |
2 |
26 Feb 07 |
jari |
403 |
int[] order = getLeafOrder(genes_result, features); |
2 |
26 Feb 07 |
jari |
404 |
if (order == null) { |
2 |
26 Feb 07 |
jari |
405 |
order = features; |
2 |
26 Feb 07 |
jari |
406 |
} |
2 |
26 Feb 07 |
jari |
407 |
return order; |
2 |
26 Feb 07 |
jari |
408 |
} |
2 |
26 Feb 07 |
jari |
409 |
|
2 |
26 Feb 07 |
jari |
410 |
private int[] getLeafOrder(HCLTreeData result, int[] indices) { |
2 |
26 Feb 07 |
jari |
411 |
if (result == null || result.node_order.length < 2) { |
2 |
26 Feb 07 |
jari |
412 |
return null; |
2 |
26 Feb 07 |
jari |
413 |
} |
2 |
26 Feb 07 |
jari |
414 |
return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices); |
2 |
26 Feb 07 |
jari |
415 |
} |
2 |
26 Feb 07 |
jari |
416 |
|
2 |
26 Feb 07 |
jari |
417 |
private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) { |
2 |
26 Feb 07 |
jari |
418 |
int[] leafOrder = new int[nodeOrder.length]; |
2 |
26 Feb 07 |
jari |
419 |
Arrays.fill(leafOrder, -1); |
2 |
26 Feb 07 |
jari |
420 |
|
2 |
26 Feb 07 |
jari |
421 |
fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices); |
2 |
26 Feb 07 |
jari |
422 |
return leafOrder; |
2 |
26 Feb 07 |
jari |
423 |
} |
2 |
26 Feb 07 |
jari |
424 |
|
2 |
26 Feb 07 |
jari |
425 |
private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) { |
2 |
26 Feb 07 |
jari |
426 |
if (child1[index] != -1) { |
2 |
26 Feb 07 |
jari |
427 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices); |
2 |
26 Feb 07 |
jari |
428 |
} |
2 |
26 Feb 07 |
jari |
429 |
if (child2[index] != -1) { |
2 |
26 Feb 07 |
jari |
430 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices); |
2 |
26 Feb 07 |
jari |
431 |
} else { |
2 |
26 Feb 07 |
jari |
432 |
leafOrder[pos] = indices == null ? index : indices[index]; |
2 |
26 Feb 07 |
jari |
433 |
pos++; |
2 |
26 Feb 07 |
jari |
434 |
} |
2 |
26 Feb 07 |
jari |
435 |
return pos; |
2 |
26 Feb 07 |
jari |
436 |
} |
2 |
26 Feb 07 |
jari |
437 |
|
2 |
26 Feb 07 |
jari |
438 |
/** |
2 |
26 Feb 07 |
jari |
* Returns this viewer to be inserted into the framework scroll pane. |
2 |
26 Feb 07 |
jari |
440 |
*/ |
2 |
26 Feb 07 |
jari |
441 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
442 |
return this; |
2 |
26 Feb 07 |
jari |
443 |
} |
2 |
26 Feb 07 |
jari |
444 |
|
2 |
26 Feb 07 |
jari |
445 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer header. |
2 |
26 Feb 07 |
jari |
447 |
*/ |
2 |
26 Feb 07 |
jari |
448 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
449 |
return this.header; |
2 |
26 Feb 07 |
jari |
450 |
} |
2 |
26 Feb 07 |
jari |
451 |
|
2 |
26 Feb 07 |
jari |
452 |
/** |
2 |
26 Feb 07 |
jari |
* Updates all wrapped viewers. |
2 |
26 Feb 07 |
jari |
454 |
*/ |
2 |
26 Feb 07 |
jari |
455 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
456 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
457 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
458 |
this.expViewer.onSelected(framework); |
2 |
26 Feb 07 |
jari |
459 |
|
2 |
26 Feb 07 |
jari |
// onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
461 |
|
2 |
26 Feb 07 |
jari |
462 |
Object userObject = framework.getUserObject(); |
2 |
26 Feb 07 |
jari |
463 |
this.clusterIndex = (userObject != null ? ((Integer)userObject).intValue():0); |
2 |
26 Feb 07 |
jari |
464 |
if (this.genesTree != null) { |
2 |
26 Feb 07 |
jari |
465 |
this.genesTree.onSelected(framework); |
2 |
26 Feb 07 |
jari |
466 |
} |
2 |
26 Feb 07 |
jari |
467 |
if (this.sampleTree != null) { |
2 |
26 Feb 07 |
jari |
468 |
this.sampleTree.onSelected(framework); |
2 |
26 Feb 07 |
jari |
469 |
} |
2 |
26 Feb 07 |
jari |
470 |
this.annotationBar.onSelected(framework); |
2 |
26 Feb 07 |
jari |
471 |
this.colorBar.onSelected(framework); |
2 |
26 Feb 07 |
jari |
// set expression header position |
2 |
26 Feb 07 |
jari |
473 |
if (this.genesTree != null) { |
2 |
26 Feb 07 |
jari |
474 |
this.header.setHeaderPosition(this.genesTree.getWidth()); |
2 |
26 Feb 07 |
jari |
475 |
} |
2 |
26 Feb 07 |
jari |
476 |
this.elementSize = framework.getDisplayMenu().getElementSize(); |
2 |
26 Feb 07 |
jari |
477 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
478 |
|
2 |
26 Feb 07 |
jari |
479 |
if(this.node == null) |
2 |
26 Feb 07 |
jari |
480 |
this.node = (DefaultMutableTreeNode)(framework.getCurrentNode().getParent()); |
2 |
26 Feb 07 |
jari |
481 |
|
2 |
26 Feb 07 |
jari |
482 |
verifyClusterExistence(this.data); |
2 |
26 Feb 07 |
jari |
483 |
updateTrees(); |
2 |
26 Feb 07 |
jari |
484 |
refreshViewer(); |
2 |
26 Feb 07 |
jari |
485 |
} |
2 |
26 Feb 07 |
jari |
486 |
|
2 |
26 Feb 07 |
jari |
487 |
/** |
2 |
26 Feb 07 |
jari |
* Calculate the viewer width. |
2 |
26 Feb 07 |
jari |
489 |
*/ |
2 |
26 Feb 07 |
jari |
490 |
protected int getCommonWidth() { |
2 |
26 Feb 07 |
jari |
491 |
int width = 0; |
2 |
26 Feb 07 |
jari |
492 |
if (this.genesTree != null) { |
2 |
26 Feb 07 |
jari |
493 |
width += this.genesTree.getWidth(); |
2 |
26 Feb 07 |
jari |
494 |
} |
2 |
26 Feb 07 |
jari |
495 |
if(this.isExperimentCluster) |
2 |
26 Feb 07 |
jari |
496 |
width += ((ExperimentClusterViewer)this.expViewer).getWidth(); |
2 |
26 Feb 07 |
jari |
497 |
else |
2 |
26 Feb 07 |
jari |
498 |
width += ((ExperimentViewer)this.expViewer).getWidth(); |
2 |
26 Feb 07 |
jari |
499 |
width += this.colorBar.getWidth(); |
2 |
26 Feb 07 |
jari |
500 |
width += this.annotationBar.getWidth(); |
2 |
26 Feb 07 |
jari |
501 |
return width + offset; |
2 |
26 Feb 07 |
jari |
502 |
} |
2 |
26 Feb 07 |
jari |
503 |
|
2 |
26 Feb 07 |
jari |
504 |
/** |
2 |
26 Feb 07 |
jari |
* Delegates this invokation to the wrapped experiment viewer. |
2 |
26 Feb 07 |
jari |
506 |
*/ |
2 |
26 Feb 07 |
jari |
507 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
508 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
509 |
this.data = data; |
2 |
26 Feb 07 |
jari |
510 |
updateTrees(); |
2 |
26 Feb 07 |
jari |
511 |
} |
2 |
26 Feb 07 |
jari |
512 |
|
2 |
26 Feb 07 |
jari |
513 |
|
2 |
26 Feb 07 |
jari |
514 |
/** |
2 |
26 Feb 07 |
jari |
* Delegates this invokation to wrapped viewers. |
2 |
26 Feb 07 |
jari |
516 |
*/ |
2 |
26 Feb 07 |
jari |
517 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
518 |
this.expViewer.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
519 |
if (this.genesTree != null) { |
2 |
26 Feb 07 |
jari |
520 |
this.genesTree.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
521 |
} |
2 |
26 Feb 07 |
jari |
522 |
if (this.sampleTree != null) { |
2 |
26 Feb 07 |
jari |
523 |
this.sampleTree.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
524 |
} |
2 |
26 Feb 07 |
jari |
525 |
this.annotationBar.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
526 |
this.colorBar.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
// expression header can change its size |
2 |
26 Feb 07 |
jari |
528 |
this.elementSize = menu.getElementSize(); |
2 |
26 Feb 07 |
jari |
529 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
530 |
} |
2 |
26 Feb 07 |
jari |
531 |
|
2 |
26 Feb 07 |
jari |
532 |
public void onDeselected() {} |
2 |
26 Feb 07 |
jari |
533 |
public void onClosed() {} |
2 |
26 Feb 07 |
jari |
534 |
|
2 |
26 Feb 07 |
jari |
535 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
536 |
return null; |
2 |
26 Feb 07 |
jari |
537 |
} |
2 |
26 Feb 07 |
jari |
538 |
|
2 |
26 Feb 07 |
jari |
539 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
541 |
*/ |
2 |
26 Feb 07 |
jari |
542 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
543 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
544 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
545 |
return popup; |
2 |
26 Feb 07 |
jari |
546 |
} |
2 |
26 Feb 07 |
jari |
547 |
|
2 |
26 Feb 07 |
jari |
548 |
/** |
2 |
26 Feb 07 |
jari |
* Adds menu items to the specified popup menu. |
2 |
26 Feb 07 |
jari |
550 |
*/ |
2 |
26 Feb 07 |
jari |
551 |
protected void addMenuItems(JPopupMenu menu, Listener listener) { |
2 |
26 Feb 07 |
jari |
552 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
553 |
menuItem = new JMenuItem("Store Cluster", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
554 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
555 |
menuItem.setActionCommand(STORE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
556 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
557 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
558 |
|
2 |
26 Feb 07 |
jari |
559 |
menuItem = new JMenuItem("Launch new session", GUIFactory.getIcon("launch_new_mav.gif")); |
2 |
26 Feb 07 |
jari |
560 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
561 |
menuItem.setActionCommand(LAUNCH_NEW_SESSION_CMD); |
2 |
26 Feb 07 |
jari |
562 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
563 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
564 |
|
2 |
26 Feb 07 |
jari |
565 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
566 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
567 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
568 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
569 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
570 |
|
2 |
26 Feb 07 |
jari |
571 |
menuItem = new JMenuItem("Delete cluster", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
572 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
573 |
menuItem.setActionCommand(DELETE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
574 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
575 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
576 |
|
2 |
26 Feb 07 |
jari |
577 |
menuItem = new JMenuItem("Delete all clusters", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
578 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
579 |
menuItem.setActionCommand(DELETE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
580 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
581 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
582 |
|
2 |
26 Feb 07 |
jari |
583 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
584 |
|
2 |
26 Feb 07 |
jari |
585 |
menuItem = new JMenuItem("GeneTree properties...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
586 |
menuItem.setEnabled(this.genesTree != null); |
2 |
26 Feb 07 |
jari |
587 |
menuItem.setActionCommand(GENE_TREE_PROPERTIES_CMD); |
2 |
26 Feb 07 |
jari |
588 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
589 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
590 |
|
2 |
26 Feb 07 |
jari |
591 |
menuItem = new JMenuItem("SampleTree properties...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
592 |
menuItem.setEnabled(this.sampleTree != null); |
2 |
26 Feb 07 |
jari |
593 |
menuItem.setActionCommand(SAMPLE_TREE_PROPERTIES_CMD); |
2 |
26 Feb 07 |
jari |
594 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
595 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
596 |
|
2 |
26 Feb 07 |
jari |
597 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
598 |
|
2 |
26 Feb 07 |
jari |
599 |
menuItem = new JMenuItem("Save Gene Node Heights", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
600 |
menuItem.setEnabled(this.genesTree != null); |
2 |
26 Feb 07 |
jari |
601 |
menuItem.setActionCommand(SAVE_GENE_HEIGHT_CMD); |
2 |
26 Feb 07 |
jari |
602 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
603 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
604 |
|
2 |
26 Feb 07 |
jari |
605 |
menuItem = new JMenuItem("Save Gene Order", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
606 |
menuItem.setEnabled(this.genesTree != null); |
2 |
26 Feb 07 |
jari |
607 |
menuItem.setActionCommand(SAVE_GENE_ORDER_CMD); |
2 |
26 Feb 07 |
jari |
608 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
609 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
610 |
|
2 |
26 Feb 07 |
jari |
611 |
menuItem = new JMenuItem("Save Sample Node Heights", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
612 |
menuItem.setEnabled(this.sampleTree != null); |
2 |
26 Feb 07 |
jari |
613 |
menuItem.setActionCommand(SAVE_EXP_HEIGHT_CMD); |
2 |
26 Feb 07 |
jari |
614 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
615 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
616 |
|
2 |
26 Feb 07 |
jari |
617 |
menuItem = new JMenuItem("Save Sample Order", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
618 |
menuItem.setEnabled(this.sampleTree != null); |
2 |
26 Feb 07 |
jari |
619 |
menuItem.setActionCommand(SAVE_EXP_ORDER_CMD); |
2 |
26 Feb 07 |
jari |
620 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
621 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
622 |
|
2 |
26 Feb 07 |
jari |
623 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
624 |
|
2 |
26 Feb 07 |
jari |
625 |
if(this.genesTree != null) { |
2 |
26 Feb 07 |
jari |
626 |
menuItem = new JMenuItem("Save Gene Tree To Newick File", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
627 |
menuItem.setActionCommand(SAVE_GENE_NEWICK_CMD); |
2 |
26 Feb 07 |
jari |
628 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
629 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
630 |
} |
2 |
26 Feb 07 |
jari |
631 |
|
2 |
26 Feb 07 |
jari |
632 |
if(this.sampleTree != null) { |
2 |
26 Feb 07 |
jari |
633 |
menuItem = new JMenuItem("Save Sample Tree to Newick File", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
634 |
menuItem.setActionCommand(SAVE_SAMPLE_NEWICK_CMD); |
2 |
26 Feb 07 |
jari |
635 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
636 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
637 |
} |
2 |
26 Feb 07 |
jari |
638 |
} |
2 |
26 Feb 07 |
jari |
639 |
|
2 |
26 Feb 07 |
jari |
640 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a menu item by specified action command. |
2 |
26 Feb 07 |
jari |
* @return null, if menu item was not found. |
2 |
26 Feb 07 |
jari |
643 |
*/ |
2 |
26 Feb 07 |
jari |
644 |
protected JMenuItem getJMenuItem(String command) { |
2 |
26 Feb 07 |
jari |
645 |
JMenuItem item; |
2 |
26 Feb 07 |
jari |
646 |
Component[] components = popup.getComponents(); |
2 |
26 Feb 07 |
jari |
647 |
for (int i=0; i<components.length; i++) { |
2 |
26 Feb 07 |
jari |
648 |
if (components[i] instanceof JMenuItem) { |
2 |
26 Feb 07 |
jari |
649 |
if (((JMenuItem)components[i]).getActionCommand().equals(command)) |
2 |
26 Feb 07 |
jari |
650 |
return(JMenuItem)components[i]; |
2 |
26 Feb 07 |
jari |
651 |
} |
2 |
26 Feb 07 |
jari |
652 |
} |
2 |
26 Feb 07 |
jari |
653 |
return null; |
2 |
26 Feb 07 |
jari |
654 |
} |
2 |
26 Feb 07 |
jari |
655 |
|
2 |
26 Feb 07 |
jari |
656 |
/** |
2 |
26 Feb 07 |
jari |
* Sets menu enabled flag. |
2 |
26 Feb 07 |
jari |
658 |
*/ |
2 |
26 Feb 07 |
jari |
659 |
protected void setEnableMenuItem(String command, boolean enable) { |
2 |
26 Feb 07 |
jari |
660 |
JMenuItem item = getJMenuItem(command); |
2 |
26 Feb 07 |
jari |
661 |
if (item == null) { |
2 |
26 Feb 07 |
jari |
662 |
return; |
2 |
26 Feb 07 |
jari |
663 |
} |
2 |
26 Feb 07 |
jari |
664 |
item.setEnabled(enable); |
2 |
26 Feb 07 |
jari |
665 |
} |
2 |
26 Feb 07 |
jari |
666 |
|
2 |
26 Feb 07 |
jari |
667 |
/** |
2 |
26 Feb 07 |
jari |
* Selects the specified cluster. |
2 |
26 Feb 07 |
jari |
669 |
*/ |
2 |
26 Feb 07 |
jari |
670 |
protected void setSelectedCluster(HCLCluster cluster) { |
2 |
26 Feb 07 |
jari |
671 |
this.selectedCluster = cluster; |
2 |
26 Feb 07 |
jari |
672 |
if(this.isExperimentCluster){ //viewer type, |
2 |
26 Feb 07 |
jari |
673 |
if(cluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
674 |
((ExperimentClusterViewer)this.expViewer).selectRows(cluster.firstElem, cluster.lastElem); |
2 |
26 Feb 07 |
jari |
675 |
else |
2 |
26 Feb 07 |
jari |
676 |
((ExperimentClusterViewer)this.expViewer).selectColumns(cluster.firstElem, cluster.lastElem); |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
else{ |
2 |
26 Feb 07 |
jari |
679 |
if(cluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
680 |
((ExperimentViewer)this.expViewer).selectRows(cluster.firstElem, cluster.lastElem); |
2 |
26 Feb 07 |
jari |
681 |
else |
2 |
26 Feb 07 |
jari |
682 |
((ExperimentViewer)this.expViewer).selectColumns(cluster.firstElem, cluster.lastElem); |
2 |
26 Feb 07 |
jari |
683 |
} |
2 |
26 Feb 07 |
jari |
684 |
} |
2 |
26 Feb 07 |
jari |
685 |
|
2 |
26 Feb 07 |
jari |
686 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a <code>HCLCluster</code> for specified root node. |
2 |
26 Feb 07 |
jari |
688 |
*/ |
2 |
26 Feb 07 |
jari |
689 |
protected HCLCluster getCluster(HCLCluster selCluster) { |
2 |
26 Feb 07 |
jari |
690 |
int root = selCluster.root; |
2 |
26 Feb 07 |
jari |
691 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
692 |
if(selCluster.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
693 |
for (int i=0; i<this.clusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
694 |
cluster = (HCLCluster)this.clusters.get(i); |
2 |
26 Feb 07 |
jari |
695 |
if (cluster.root == root) { |
2 |
26 Feb 07 |
jari |
696 |
return cluster; |
2 |
26 Feb 07 |
jari |
697 |
} |
2 |
26 Feb 07 |
jari |
698 |
} |
2 |
26 Feb 07 |
jari |
699 |
} |
2 |
26 Feb 07 |
jari |
700 |
else { |
2 |
26 Feb 07 |
jari |
701 |
for (int i=0; i<this.experimentClusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
702 |
cluster = (HCLCluster)this.experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
703 |
if (cluster.root == root) { |
2 |
26 Feb 07 |
jari |
704 |
return cluster; |
2 |
26 Feb 07 |
jari |
705 |
} |
2 |
26 Feb 07 |
jari |
706 |
} |
2 |
26 Feb 07 |
jari |
707 |
} |
2 |
26 Feb 07 |
jari |
708 |
return null; |
2 |
26 Feb 07 |
jari |
709 |
} |
2 |
26 Feb 07 |
jari |
710 |
|
2 |
26 Feb 07 |
jari |
711 |
public void updateTrees(){ |
2 |
26 Feb 07 |
jari |
712 |
if(this.genesTree != null && this.data.getColors().length == 0){ |
2 |
26 Feb 07 |
jari |
713 |
this.genesTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
714 |
this.genesTree.resetNodeColors(); |
2 |
26 Feb 07 |
jari |
715 |
this.clusters.clear(); |
2 |
26 Feb 07 |
jari |
716 |
} |
2 |
26 Feb 07 |
jari |
717 |
if(this.sampleTree != null && this.data.getExperimentColors().length == 0){ |
2 |
26 Feb 07 |
jari |
718 |
this.sampleTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
719 |
this.sampleTree.resetNodeColors(); |
2 |
26 Feb 07 |
jari |
720 |
this.experimentClusters.clear(); |
2 |
26 Feb 07 |
jari |
721 |
} |
2 |
26 Feb 07 |
jari |
722 |
} |
2 |
26 Feb 07 |
jari |
723 |
|
2 |
26 Feb 07 |
jari |
724 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a <code>HCLCluster</code> for specified root node. |
2 |
26 Feb 07 |
jari |
726 |
*/ |
2 |
26 Feb 07 |
jari |
727 |
protected HCLCluster getExperimentCluster(int root) { |
2 |
26 Feb 07 |
jari |
728 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
729 |
for (int i=0; i<this.experimentClusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
730 |
cluster = (HCLCluster)this.experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
731 |
if (cluster.root == root) { |
2 |
26 Feb 07 |
jari |
732 |
return cluster; |
2 |
26 Feb 07 |
jari |
733 |
} |
2 |
26 Feb 07 |
jari |
734 |
} |
2 |
26 Feb 07 |
jari |
735 |
return null; |
2 |
26 Feb 07 |
jari |
736 |
} |
2 |
26 Feb 07 |
jari |
737 |
|
2 |
26 Feb 07 |
jari |
738 |
|
2 |
26 Feb 07 |
jari |
739 |
|
2 |
26 Feb 07 |
jari |
740 |
/** |
2 |
26 Feb 07 |
jari |
* Removes cluster for specified root. |
2 |
26 Feb 07 |
jari |
742 |
*/ |
2 |
26 Feb 07 |
jari |
743 |
protected void removeCluster(HCLCluster oldCluster) { |
2 |
26 Feb 07 |
jari |
744 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
745 |
if(oldCluster.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
746 |
for (int i=this.clusters.size(); --i>=0;) { |
2 |
26 Feb 07 |
jari |
747 |
cluster = (HCLCluster)this.clusters.get(i); |
2 |
26 Feb 07 |
jari |
748 |
if (cluster.root == oldCluster.root) { |
2 |
26 Feb 07 |
jari |
749 |
this.clusters.remove(i); |
2 |
26 Feb 07 |
jari |
750 |
return; |
2 |
26 Feb 07 |
jari |
751 |
} |
2 |
26 Feb 07 |
jari |
752 |
} |
2 |
26 Feb 07 |
jari |
753 |
} |
2 |
26 Feb 07 |
jari |
754 |
else { |
2 |
26 Feb 07 |
jari |
755 |
for (int i=this.experimentClusters.size(); --i>=0;) { |
2 |
26 Feb 07 |
jari |
756 |
cluster = (HCLCluster)this.experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
757 |
if (cluster.root == oldCluster.root) { |
2 |
26 Feb 07 |
jari |
758 |
this.experimentClusters.remove(i); |
2 |
26 Feb 07 |
jari |
759 |
return; |
2 |
26 Feb 07 |
jari |
760 |
} |
2 |
26 Feb 07 |
jari |
761 |
} |
2 |
26 Feb 07 |
jari |
762 |
} |
2 |
26 Feb 07 |
jari |
763 |
} |
2 |
26 Feb 07 |
jari |
764 |
|
2 |
26 Feb 07 |
jari |
765 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true, if there is cluster for selected node. |
2 |
26 Feb 07 |
jari |
767 |
*/ |
2 |
26 Feb 07 |
jari |
768 |
protected boolean doesClusterExist() { |
2 |
26 Feb 07 |
jari |
769 |
if (this.selectedCluster == null) { |
2 |
26 Feb 07 |
jari |
770 |
return false; |
2 |
26 Feb 07 |
jari |
771 |
} |
2 |
26 Feb 07 |
jari |
772 |
return getCluster(this.selectedCluster) != null; |
2 |
26 Feb 07 |
jari |
773 |
} |
2 |
26 Feb 07 |
jari |
774 |
|
2 |
26 Feb 07 |
jari |
775 |
/** |
2 |
26 Feb 07 |
jari |
* Returns count of clusters. |
2 |
26 Feb 07 |
jari |
777 |
*/ |
2 |
26 Feb 07 |
jari |
778 |
protected int getClustersCount() { |
2 |
26 Feb 07 |
jari |
779 |
return this.clusters.size() + this.experimentClusters.size(); |
2 |
26 Feb 07 |
jari |
780 |
} |
2 |
26 Feb 07 |
jari |
781 |
|
2 |
26 Feb 07 |
jari |
782 |
private Frame getFrame() { |
2 |
26 Feb 07 |
jari |
783 |
return JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
784 |
} |
2 |
26 Feb 07 |
jari |
785 |
|
2 |
26 Feb 07 |
jari |
786 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a public color for a selected cluster. |
2 |
26 Feb 07 |
jari |
788 |
*/ |
2 |
26 Feb 07 |
jari |
789 |
public void onSetCluster() { |
2 |
26 Feb 07 |
jari |
//Color newColor = JColorChooser.showDialog(getFrame(), "Choose color", new Color(128, 128, 128)); |
2 |
26 Feb 07 |
jari |
791 |
Color newColor = Color.white; |
2 |
26 Feb 07 |
jari |
792 |
if (newColor == null || this.selectedCluster == null) { |
2 |
26 Feb 07 |
jari |
793 |
return; |
2 |
26 Feb 07 |
jari |
794 |
} |
2 |
26 Feb 07 |
jari |
795 |
HCLCluster cluster = getCluster(this.selectedCluster); |
2 |
26 Feb 07 |
jari |
796 |
boolean notANewNode = true; |
2 |
26 Feb 07 |
jari |
797 |
|
2 |
26 Feb 07 |
jari |
798 |
if (cluster != null) { //cluster already exists |
2 |
26 Feb 07 |
jari |
799 |
this.selectedCluster = cluster; |
2 |
26 Feb 07 |
jari |
800 |
notANewNode = false; |
2 |
26 Feb 07 |
jari |
801 |
} else { //new cluster, add to list |
2 |
26 Feb 07 |
jari |
802 |
if(selectedCluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
803 |
this.clusters.add(this.selectedCluster); |
2 |
26 Feb 07 |
jari |
804 |
else |
2 |
26 Feb 07 |
jari |
805 |
this.experimentClusters.add(this.selectedCluster); |
2 |
26 Feb 07 |
jari |
806 |
} |
2 |
26 Feb 07 |
jari |
807 |
|
2 |
26 Feb 07 |
jari |
808 |
this.selectedCluster.color = newColor; |
2 |
26 Feb 07 |
jari |
809 |
|
2 |
26 Feb 07 |
jari |
810 |
if(!this.isExperimentCluster){ |
2 |
26 Feb 07 |
jari |
811 |
if(!this.selectedCluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
812 |
this.selectedCluster.color = ((ExperimentViewer)(this.expViewer)).setHCLClusterColor(getSubTreeElements(),this.selectedCluster.color, this.selectedCluster.isGeneCluster); |
2 |
26 Feb 07 |
jari |
813 |
else |
2 |
26 Feb 07 |
jari |
814 |
this.selectedCluster.color = ((ExperimentViewer)(this.expViewer)).setHCLClusterColor(getArrayMappedToData(getSubTreeElements()),this.selectedCluster.color, this.selectedCluster.isGeneCluster); |
2 |
26 Feb 07 |
jari |
815 |
} |
2 |
26 Feb 07 |
jari |
816 |
else{ |
2 |
26 Feb 07 |
jari |
817 |
if(!this.selectedCluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
818 |
this.selectedCluster.color = ((ExperimentClusterViewer)(this.expViewer)).setHCLClusterColor(getSubTreeElements(),this.selectedCluster.color, this.selectedCluster.isGeneCluster); |
2 |
26 Feb 07 |
jari |
819 |
else |
2 |
26 Feb 07 |
jari |
820 |
this.selectedCluster.color = ((ExperimentClusterViewer)(this.expViewer)).setHCLClusterColor(getArrayMappedToData(getSubTreeElements()),this.selectedCluster.color, this.selectedCluster.isGeneCluster); |
2 |
26 Feb 07 |
jari |
821 |
} |
2 |
26 Feb 07 |
jari |
822 |
|
2 |
26 Feb 07 |
jari |
// if(!notANewNode) |
2 |
26 Feb 07 |
jari |
824 |
removeSubTreeClusters(this.selectedCluster); //need to remove clusters from the list if they are sub-trees |
2 |
26 Feb 07 |
jari |
825 |
|
2 |
26 Feb 07 |
jari |
826 |
if(selectedCluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
827 |
this.colorBar.onClustersChanged(this.clusters); |
2 |
26 Feb 07 |
jari |
828 |
|
2 |
26 Feb 07 |
jari |
829 |
refreshViewer(); |
2 |
26 Feb 07 |
jari |
830 |
|
2 |
26 Feb 07 |
jari |
831 |
this.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
832 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
833 |
revalidate(); |
2 |
26 Feb 07 |
jari |
834 |
} |
2 |
26 Feb 07 |
jari |
835 |
|
2 |
26 Feb 07 |
jari |
836 |
/** |
2 |
26 Feb 07 |
jari |
* Removes subtree clusters when an enclosing tree |
2 |
26 Feb 07 |
jari |
838 |
*/ |
2 |
26 Feb 07 |
jari |
839 |
private void removeSubTreeClusters(HCLCluster parent){ |
2 |
26 Feb 07 |
jari |
840 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
841 |
if(parent.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
// for(int i = 0; i < this.clusters.size(); i++){ |
2 |
26 Feb 07 |
jari |
843 |
for(int i = this.clusters.size()-1; i >= 0 ; i--){ |
2 |
26 Feb 07 |
jari |
844 |
cluster = (HCLCluster)clusters.get(i); |
2 |
26 Feb 07 |
jari |
845 |
if( !parent.equals(cluster) && isSubTree(parent, cluster) ){ |
2 |
26 Feb 07 |
jari |
846 |
this.removeCluster(cluster); |
2 |
26 Feb 07 |
jari |
847 |
} |
2 |
26 Feb 07 |
jari |
848 |
} |
2 |
26 Feb 07 |
jari |
849 |
} |
2 |
26 Feb 07 |
jari |
850 |
else { |
2 |
26 Feb 07 |
jari |
851 |
for(int i = 0; i < this.experimentClusters.size(); i++){ |
2 |
26 Feb 07 |
jari |
852 |
cluster = (HCLCluster)experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
853 |
if( parent != cluster && isSubTree(parent, cluster) ) |
2 |
26 Feb 07 |
jari |
854 |
this.removeCluster(cluster); |
2 |
26 Feb 07 |
jari |
855 |
} |
2 |
26 Feb 07 |
jari |
856 |
} |
2 |
26 Feb 07 |
jari |
857 |
} |
2 |
26 Feb 07 |
jari |
858 |
|
2 |
26 Feb 07 |
jari |
859 |
private boolean isSubTree(HCLCluster parent, HCLCluster child){ |
2 |
26 Feb 07 |
jari |
860 |
if( parent.size < child.size ) |
2 |
26 Feb 07 |
jari |
861 |
return false; |
2 |
26 Feb 07 |
jari |
862 |
if( child.firstElem >= parent.firstElem && |
2 |
26 Feb 07 |
jari |
863 |
child.firstElem < parent.lastElem) |
2 |
26 Feb 07 |
jari |
864 |
return true; |
2 |
26 Feb 07 |
jari |
865 |
else |
2 |
26 Feb 07 |
jari |
866 |
return false; |
2 |
26 Feb 07 |
jari |
867 |
} |
2 |
26 Feb 07 |
jari |
868 |
|
2 |
26 Feb 07 |
jari |
869 |
|
2 |
26 Feb 07 |
jari |
870 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster description. |
2 |
26 Feb 07 |
jari |
872 |
*/ |
2 |
26 Feb 07 |
jari |
873 |
public void onSetClusterText() { |
2 |
26 Feb 07 |
jari |
874 |
HCLCluster cluster = getCluster(this.selectedCluster); |
2 |
26 Feb 07 |
jari |
875 |
if (cluster == null) { |
2 |
26 Feb 07 |
jari |
876 |
JOptionPane.showMessageDialog(getFrame(), "Not a cluster!", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
877 |
} else { |
2 |
26 Feb 07 |
jari |
878 |
String text = JOptionPane.showInputDialog(getFrame(), "Cluster text"); |
2 |
26 Feb 07 |
jari |
879 |
if (text != null && text.length() > 0) { |
2 |
26 Feb 07 |
jari |
880 |
cluster.text = text; |
2 |
26 Feb 07 |
jari |
881 |
this.colorBar.onClustersChanged(this.clusters); |
2 |
26 Feb 07 |
jari |
882 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
883 |
revalidate(); |
2 |
26 Feb 07 |
jari |
884 |
} |
2 |
26 Feb 07 |
jari |
885 |
} |
2 |
26 Feb 07 |
jari |
886 |
} |
2 |
26 Feb 07 |
jari |
887 |
|
2 |
26 Feb 07 |
jari |
888 |
public void verifyClusterExistence(IData data){ |
2 |
26 Feb 07 |
jari |
889 |
HCLCluster currCluster; |
2 |
26 Feb 07 |
jari |
890 |
int geneIndex; |
2 |
26 Feb 07 |
jari |
891 |
boolean [] clusterGone = new boolean[this.clusters.size()]; |
2 |
26 Feb 07 |
jari |
892 |
boolean [] expClusterGone = new boolean[this.experimentClusters.size()]; |
2 |
26 Feb 07 |
jari |
893 |
|
2 |
26 Feb 07 |
jari |
894 |
for( int i = 0; i < this.clusters.size() ; i++){ |
2 |
26 Feb 07 |
jari |
895 |
currCluster = (HCLCluster)this.clusters.get(i); |
2 |
26 Feb 07 |
jari |
896 |
if(currCluster.firstElem == currCluster.lastElem) |
2 |
26 Feb 07 |
jari |
897 |
continue; |
2 |
26 Feb 07 |
jari |
898 |
geneIndex = experiment.getGeneIndexMappedToData(this.genesOrder[currCluster.firstElem]); |
2 |
26 Feb 07 |
jari |
899 |
if(data.getProbeColor(geneIndex) != currCluster.color){ |
2 |
26 Feb 07 |
jari |
900 |
clusterGone[i] = true; |
2 |
26 Feb 07 |
jari |
901 |
} |
2 |
26 Feb 07 |
jari |
902 |
} |
2 |
26 Feb 07 |
jari |
903 |
for(int i = clusterGone.length-1; i >= 0; i--){ |
2 |
26 Feb 07 |
jari |
904 |
if(clusterGone[i]){ |
2 |
26 Feb 07 |
jari |
905 |
this.genesTree.setNodeColor(((HCLCluster)this.clusters.get(i)).root, null); |
2 |
26 Feb 07 |
jari |
// this.clusters.remove(i); |
2 |
26 Feb 07 |
jari |
907 |
} |
2 |
26 Feb 07 |
jari |
908 |
} |
2 |
26 Feb 07 |
jari |
909 |
int expIndex; |
2 |
26 Feb 07 |
jari |
910 |
for( int i = 0; i < this.experimentClusters.size() ; i++){ |
2 |
26 Feb 07 |
jari |
911 |
currCluster = (HCLCluster)this.experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
912 |
if(currCluster.firstElem == currCluster.lastElem) |
2 |
26 Feb 07 |
jari |
913 |
continue; |
2 |
26 Feb 07 |
jari |
914 |
if(this.isExperimentCluster) |
2 |
26 Feb 07 |
jari |
915 |
expIndex = experiment.getSampleIndex(this.sampleClusters[this.clusterIndex][currCluster.firstElem]); |
2 |
26 Feb 07 |
jari |
916 |
else |
2 |
26 Feb 07 |
jari |
917 |
expIndex = experiment.getSampleIndex(this.samplesOrder[currCluster.firstElem]); |
2 |
26 Feb 07 |
jari |
918 |
if(data.getExperimentColor(expIndex) != currCluster.color){ |
2 |
26 Feb 07 |
jari |
919 |
expClusterGone[i] = true; |
2 |
26 Feb 07 |
jari |
920 |
} |
2 |
26 Feb 07 |
jari |
921 |
} |
2 |
26 Feb 07 |
jari |
922 |
for(int i = expClusterGone.length-1; i >= 0; i--){ |
2 |
26 Feb 07 |
jari |
923 |
if(expClusterGone[i]){ |
2 |
26 Feb 07 |
jari |
924 |
this.sampleTree.setNodeColor(((HCLCluster)this.experimentClusters.get(i)).root, null); |
2 |
26 Feb 07 |
jari |
// this.experimentClusters.remove(i); |
2 |
26 Feb 07 |
jari |
926 |
} |
2 |
26 Feb 07 |
jari |
927 |
} |
2 |
26 Feb 07 |
jari |
928 |
} |
2 |
26 Feb 07 |
jari |
929 |
|
2 |
26 Feb 07 |
jari |
930 |
private int[] getSubTreeElements() { |
2 |
26 Feb 07 |
jari |
931 |
return getSubTreeElements(this.selectedCluster); |
2 |
26 Feb 07 |
jari |
932 |
} |
2 |
26 Feb 07 |
jari |
933 |
|
2 |
26 Feb 07 |
jari |
934 |
private int[] getSubTreeElements(HCLCluster cluster) { |
2 |
26 Feb 07 |
jari |
935 |
int size = cluster.lastElem-cluster.firstElem+1; |
2 |
26 Feb 07 |
jari |
936 |
int[] elements = new int[size]; |
2 |
26 Feb 07 |
jari |
937 |
|
2 |
26 Feb 07 |
jari |
//cluster is a cluster of genes |
2 |
26 Feb 07 |
jari |
939 |
if(cluster.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
940 |
for (int i=0; i<size; i++) { |
2 |
26 Feb 07 |
jari |
941 |
elements[i] = this.genesOrder[cluster.firstElem+i]; |
2 |
26 Feb 07 |
jari |
942 |
} |
2 |
26 Feb 07 |
jari |
943 |
} |
2 |
26 Feb 07 |
jari |
944 |
|
2 |
26 Feb 07 |
jari |
//cluster is a cluster of experiments |
2 |
26 Feb 07 |
jari |
946 |
else { |
2 |
26 Feb 07 |
jari |
947 |
if(!this.isExperimentCluster){ //created by gene clustering algorithm |
2 |
26 Feb 07 |
jari |
948 |
for (int i= 0; i< size ; i++) { |
2 |
26 Feb 07 |
jari |
949 |
elements[i] = this.samplesOrder[cluster.firstElem+i]; |
2 |
26 Feb 07 |
jari |
950 |
} |
2 |
26 Feb 07 |
jari |
951 |
} |
2 |
26 Feb 07 |
jari |
952 |
else { //created by experiment clustering algorthm |
2 |
26 Feb 07 |
jari |
953 |
for (int i= 0; i< size ; i++) { |
2 |
26 Feb 07 |
jari |
954 |
elements[i] = this.sampleClusters[this.clusterIndex][cluster.firstElem+i]; |
2 |
26 Feb 07 |
jari |
955 |
} |
2 |
26 Feb 07 |
jari |
956 |
} |
2 |
26 Feb 07 |
jari |
957 |
} |
2 |
26 Feb 07 |
jari |
958 |
return elements; |
2 |
26 Feb 07 |
jari |
959 |
} |
2 |
26 Feb 07 |
jari |
960 |
|
2 |
26 Feb 07 |
jari |
961 |
public void saveGenesOrder(){ |
2 |
26 Feb 07 |
jari |
962 |
try{ |
2 |
26 Feb 07 |
jari |
963 |
ExperimentUtil.saveExperiment(getFrame(), this.experiment, this.data, this.genesOrder); |
2 |
26 Feb 07 |
jari |
964 |
}catch (Exception e){ |
2 |
26 Feb 07 |
jari |
965 |
JOptionPane.showMessageDialog(getFrame(), "Can not save data!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
966 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
967 |
} |
2 |
26 Feb 07 |
jari |
968 |
} |
2 |
26 Feb 07 |
jari |
969 |
|
2 |
26 Feb 07 |
jari |
970 |
public void saveExperimentOrder(){ |
2 |
26 Feb 07 |
jari |
971 |
try{ |
2 |
26 Feb 07 |
jari |
972 |
if(!this.isExperimentCluster) |
2 |
26 Feb 07 |
jari |
973 |
ExperimentUtil.saveExperimentCluster(getFrame(), this.experiment, this.data, this.samplesOrder); |
2 |
26 Feb 07 |
jari |
974 |
else{ |
2 |
26 Feb 07 |
jari |
975 |
int elements[] = new int[this.sampleClusters[this.clusterIndex].length]; |
2 |
26 Feb 07 |
jari |
976 |
for (int i= 0; i< this.sampleClusters[this.clusterIndex].length ; i++) { |
2 |
26 Feb 07 |
jari |
977 |
elements[i] = this.sampleClusters[this.clusterIndex][i]; |
2 |
26 Feb 07 |
jari |
978 |
} |
2 |
26 Feb 07 |
jari |
979 |
ExperimentUtil.saveExperimentCluster(getFrame(), this.experiment, this.data, elements); |
2 |
26 Feb 07 |
jari |
980 |
} |
2 |
26 Feb 07 |
jari |
981 |
}catch (Exception e){ |
2 |
26 Feb 07 |
jari |
982 |
JOptionPane.showMessageDialog(getFrame(), "Can not save data!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
983 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
984 |
} |
2 |
26 Feb 07 |
jari |
985 |
} |
2 |
26 Feb 07 |
jari |
986 |
|
2 |
26 Feb 07 |
jari |
987 |
/** |
2 |
26 Feb 07 |
jari |
* Saves cluster. |
2 |
26 Feb 07 |
jari |
989 |
*/ |
2 |
26 Feb 07 |
jari |
990 |
public void onSaveCluster() { |
2 |
26 Feb 07 |
jari |
991 |
if(this.selectedCluster == null) |
2 |
26 Feb 07 |
jari |
992 |
return; |
2 |
26 Feb 07 |
jari |
993 |
try { |
2 |
26 Feb 07 |
jari |
994 |
if(this.selectedCluster.isGeneCluster) |
2 |
26 Feb 07 |
jari |
995 |
ExperimentUtil.saveExperiment(getFrame(), this.experiment, this.data, getSubTreeElements()); |
2 |
26 Feb 07 |
jari |
996 |
else |
2 |
26 Feb 07 |
jari |
997 |
ExperimentUtil.saveExperimentCluster(getFrame(), this.experiment, this.data, getSubTreeElements()); |
2 |
26 Feb 07 |
jari |
998 |
|
2 |
26 Feb 07 |
jari |
999 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
1000 |
JOptionPane.showMessageDialog(getFrame(), "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
1001 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
1002 |
} |
2 |
26 Feb 07 |
jari |
1003 |
} |
2 |
26 Feb 07 |
jari |
1004 |
|
2 |
26 Feb 07 |
jari |
1005 |
/** |
2 |
26 Feb 07 |
jari |
* Deletes the selected cluster. |
2 |
26 Feb 07 |
jari |
1007 |
*/ |
2 |
26 Feb 07 |
jari |
1008 |
public void onDeleteCluster() { |
2 |
26 Feb 07 |
jari |
1009 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
1010 |
removeCluster(this.selectedCluster); |
2 |
26 Feb 07 |
jari |
1011 |
|
2 |
26 Feb 07 |
jari |
1012 |
this.colorBar.onClustersChanged(this.clusters); |
2 |
26 Feb 07 |
jari |
1013 |
if(this.selectedCluster.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
1014 |
this.genesTree.setNodeColor(this.selectedCluster.root, null); |
2 |
26 Feb 07 |
jari |
1015 |
this.data.setProbesColor(getArrayMappedToData(getSubTreeElements()), null); |
2 |
26 Feb 07 |
jari |
1016 |
this.framework.removeSubCluster(getArrayMappedToData(getSubTreeElements()), this.experiment, Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
// restore sub tree colors |
2 |
26 Feb 07 |
jari |
1018 |
for (int i=0; i<this.clusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
1019 |
cluster = (HCLCluster)this.clusters.get(i); |
2 |
26 Feb 07 |
jari |
1020 |
this.data.setProbesColor(getArrayMappedToData(getSubTreeElements(cluster)), cluster.color); |
2 |
26 Feb 07 |
jari |
1021 |
this.genesTree.setNodeColor(cluster.root, cluster.color); |
2 |
26 Feb 07 |
jari |
1022 |
} |
2 |
26 Feb 07 |
jari |
1023 |
} |
2 |
26 Feb 07 |
jari |
1024 |
else{ //working on sample tree |
2 |
26 Feb 07 |
jari |
1025 |
this.sampleTree.setNodeColor(this.selectedCluster.root, null); |
2 |
26 Feb 07 |
jari |
1026 |
this.data.setExperimentColor(getSubTreeElements(), null); |
2 |
26 Feb 07 |
jari |
1027 |
this.framework.removeSubCluster(getSubTreeElements(), this.experiment, Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
1028 |
|
2 |
26 Feb 07 |
jari |
// restore sub tree colors |
2 |
26 Feb 07 |
jari |
1030 |
for (int i=0; i<this.experimentClusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
1031 |
cluster = (HCLCluster)this.experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
1032 |
this.data.setExperimentColor(getSubTreeElements(cluster), cluster.color); |
2 |
26 Feb 07 |
jari |
1033 |
this.sampleTree.setNodeColor(cluster.root, cluster.color); |
2 |
26 Feb 07 |
jari |
1034 |
} |
2 |
26 Feb 07 |
jari |
1035 |
} |
2 |
26 Feb 07 |
jari |
1036 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
1037 |
this.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
1038 |
refreshViewer(); |
2 |
26 Feb 07 |
jari |
1039 |
revalidate(); |
2 |
26 Feb 07 |
jari |
1040 |
} |
2 |
26 Feb 07 |
jari |
1041 |
|
2 |
26 Feb 07 |
jari |
1042 |
private void refreshViewer(){ |
2 |
26 Feb 07 |
jari |
1043 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
1044 |
if(this.selectedCluster == null) |
2 |
26 Feb 07 |
jari |
1045 |
return; |
2 |
26 Feb 07 |
jari |
1046 |
|
2 |
26 Feb 07 |
jari |
1047 |
if(selectedCluster.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
1048 |
for (int i=0; i<this.clusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
1049 |
cluster = (HCLCluster)this.clusters.get(i); |
2 |
26 Feb 07 |
jari |
1050 |
this.genesTree.setNodeColor(cluster.root, cluster.color); |
2 |
26 Feb 07 |
jari |
1051 |
this.genesTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1052 |
} |
2 |
26 Feb 07 |
jari |
1053 |
} |
2 |
26 Feb 07 |
jari |
1054 |
else { |
2 |
26 Feb 07 |
jari |
1055 |
for (int i=0; i<this.experimentClusters.size(); i++) { |
2 |
26 Feb 07 |
jari |
1056 |
cluster = (HCLCluster)this.experimentClusters.get(i); |
2 |
26 Feb 07 |
jari |
1057 |
this.sampleTree.setNodeColor(cluster.root, cluster.color); |
2 |
26 Feb 07 |
jari |
1058 |
this.sampleTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1059 |
} |
2 |
26 Feb 07 |
jari |
1060 |
} |
2 |
26 Feb 07 |
jari |
1061 |
|
2 |
26 Feb 07 |
jari |
1062 |
if(this.isExperimentCluster){ |
2 |
26 Feb 07 |
jari |
1063 |
((ExperimentClusterViewer)(this.expViewer)).selectRows(-1,-1); |
2 |
26 Feb 07 |
jari |
1064 |
((ExperimentClusterViewer)(this.expViewer)).selectColumns(-1,-1); |
2 |
26 Feb 07 |
jari |
1065 |
} else { |
2 |
26 Feb 07 |
jari |
1066 |
((ExperimentViewer)(this.expViewer)).selectRows(-1,-1); |
2 |
26 Feb 07 |
jari |
1067 |
((ExperimentViewer)(this.expViewer)).selectColumns(-1,-1); |
2 |
26 Feb 07 |
jari |
1068 |
} |
2 |
26 Feb 07 |
jari |
1069 |
} |
2 |
26 Feb 07 |
jari |
1070 |
|
2 |
26 Feb 07 |
jari |
1071 |
private int [] getArrayMappedToData(int [] clusterIndices){ |
2 |
26 Feb 07 |
jari |
1072 |
if( clusterIndices == null || clusterIndices.length < 1) |
2 |
26 Feb 07 |
jari |
1073 |
return clusterIndices; |
2 |
26 Feb 07 |
jari |
1074 |
|
2 |
26 Feb 07 |
jari |
1075 |
int [] dataIndices = new int [clusterIndices.length]; |
2 |
26 Feb 07 |
jari |
1076 |
for(int i = 0; i < clusterIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
1077 |
dataIndices[i] = this.experiment.getGeneIndexMappedToData(clusterIndices[i]); |
2 |
26 Feb 07 |
jari |
1078 |
} |
2 |
26 Feb 07 |
jari |
1079 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
1080 |
} |
2 |
26 Feb 07 |
jari |
1081 |
|
2 |
26 Feb 07 |
jari |
1082 |
|
2 |
26 Feb 07 |
jari |
1083 |
/** |
2 |
26 Feb 07 |
jari |
* Created viewers for clusters and places them on the analysis tree |
2 |
26 Feb 07 |
jari |
1085 |
*/ |
2 |
26 Feb 07 |
jari |
1086 |
private void createAndAddClusterViews(HCLTree tree){ |
2 |
26 Feb 07 |
jari |
1087 |
int k = tree.getNumberOfTerminalNodes(); |
2 |
26 Feb 07 |
jari |
1088 |
|
2 |
26 Feb 07 |
jari |
1089 |
DefaultMutableTreeNode newNode; |
2 |
26 Feb 07 |
jari |
1090 |
if(tree == this.genesTree) |
2 |
26 Feb 07 |
jari |
1091 |
newNode = new DefaultMutableTreeNode("Gene Tree Cut: "+String.valueOf(k)+" Clusters"); |
2 |
26 Feb 07 |
jari |
1092 |
else |
2 |
26 Feb 07 |
jari |
1093 |
newNode = new DefaultMutableTreeNode("Sample Tree Cut: "+String.valueOf(k)+" Clusters"); |
2 |
26 Feb 07 |
jari |
1094 |
|
2 |
26 Feb 07 |
jari |
1095 |
int [][] clusters = tree.getClusterRowIndices(); |
2 |
26 Feb 07 |
jari |
1096 |
|
2 |
26 Feb 07 |
jari |
1097 |
if(tree == genesTree){ |
2 |
26 Feb 07 |
jari |
1098 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
1099 |
for(int j = 0; j < clusters[i].length; j++) |
2 |
26 Feb 07 |
jari |
1100 |
clusters[i][j] = this.genesOrder[clusters[i][j]]; |
2 |
26 Feb 07 |
jari |
1101 |
} |
2 |
26 Feb 07 |
jari |
1102 |
} else { |
2 |
26 Feb 07 |
jari |
1103 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
1104 |
for(int j = 0; j < clusters[i].length; j++) |
2 |
26 Feb 07 |
jari |
1105 |
clusters[i][j] = this.samplesOrder[clusters[i][j]]; |
2 |
26 Feb 07 |
jari |
1106 |
} |
2 |
26 Feb 07 |
jari |
1107 |
} |
2 |
26 Feb 07 |
jari |
1108 |
|
2 |
26 Feb 07 |
jari |
1109 |
addExpressionImages(newNode, clusters, tree == this.genesTree); |
2 |
26 Feb 07 |
jari |
1110 |
addCentroidViews(newNode, clusters, tree == this.genesTree); |
2 |
26 Feb 07 |
jari |
1111 |
addClusterTableViews(newNode, clusters, tree == this.genesTree); |
2 |
26 Feb 07 |
jari |
1112 |
addClusterInfo(newNode, clusters, tree == this.genesTree, tree.getZeroThreshold()); |
2 |
26 Feb 07 |
jari |
1113 |
addGeneralInfo(newNode, tree.getZeroThreshold(), k, tree == this.genesTree); |
2 |
26 Feb 07 |
jari |
1114 |
this.framework.addNode(this.node, newNode); |
2 |
26 Feb 07 |
jari |
1115 |
} |
2 |
26 Feb 07 |
jari |
1116 |
|
2 |
26 Feb 07 |
jari |
1117 |
private void addClusterTableViews(DefaultMutableTreeNode node, int [][] clusters, boolean geneClusters) { |
2 |
26 Feb 07 |
jari |
1118 |
DefaultMutableTreeNode tabNode = new DefaultMutableTreeNode("Table Views"); |
2 |
26 Feb 07 |
jari |
1119 |
IViewer tabViewer; |
2 |
26 Feb 07 |
jari |
1120 |
if (geneClusters) |
2 |
26 Feb 07 |
jari |
1121 |
tabViewer = new ClusterTableViewer(this.experiment, clusters, this.data); |
2 |
26 Feb 07 |
jari |
1122 |
else |
2 |
26 Feb 07 |
jari |
1123 |
tabViewer = new ExperimentClusterTableViewer(this.experiment, clusters, this.data); |
2 |
26 Feb 07 |
jari |
//return; // placeholder for ExptClusterTableViewer |
2 |
26 Feb 07 |
jari |
1125 |
|
2 |
26 Feb 07 |
jari |
1126 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
1127 |
tabNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), tabViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
1128 |
} |
2 |
26 Feb 07 |
jari |
1129 |
node.add(tabNode); |
2 |
26 Feb 07 |
jari |
1130 |
} |
2 |
26 Feb 07 |
jari |
1131 |
|
2 |
26 Feb 07 |
jari |
1132 |
/** |
2 |
26 Feb 07 |
jari |
* Adds cluster expression images |
2 |
26 Feb 07 |
jari |
1134 |
*/ |
2 |
26 Feb 07 |
jari |
1135 |
private void addExpressionImages(DefaultMutableTreeNode node, int [][] clusters, boolean geneClusters){ |
2 |
26 Feb 07 |
jari |
1136 |
DefaultMutableTreeNode expNode = new DefaultMutableTreeNode("Expression Images"); |
2 |
26 Feb 07 |
jari |
1137 |
|
2 |
26 Feb 07 |
jari |
1138 |
IViewer expViewer; |
2 |
26 Feb 07 |
jari |
1139 |
if(geneClusters) |
2 |
26 Feb 07 |
jari |
1140 |
expViewer = new HCLExperimentViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
1141 |
else |
2 |
26 Feb 07 |
jari |
1142 |
expViewer = new HCLExperimentClusterViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
1143 |
|
2 |
26 Feb 07 |
jari |
1144 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
1145 |
expNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
1146 |
} |
2 |
26 Feb 07 |
jari |
1147 |
node.add(expNode); |
2 |
26 Feb 07 |
jari |
1148 |
} |
2 |
26 Feb 07 |
jari |
1149 |
|
2 |
26 Feb 07 |
jari |
1150 |
|
2 |
26 Feb 07 |
jari |
1151 |
|
2 |
26 Feb 07 |
jari |
1152 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display centroid charts. |
2 |
26 Feb 07 |
jari |
1154 |
*/ |
2 |
26 Feb 07 |
jari |
1155 |
private void addCentroidViews(DefaultMutableTreeNode root, int [][] clusters, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
1156 |
DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs"); |
2 |
26 Feb 07 |
jari |
1157 |
DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs"); |
2 |
26 Feb 07 |
jari |
1158 |
FloatMatrix data = this.experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
1159 |
|
2 |
26 Feb 07 |
jari |
1160 |
if(!clusterGenes){ |
2 |
26 Feb 07 |
jari |
1161 |
data = data.transpose(); |
2 |
26 Feb 07 |
jari |
1162 |
} |
2 |
26 Feb 07 |
jari |
1163 |
|
2 |
26 Feb 07 |
jari |
1164 |
FloatMatrix means = getMeans(data, clusters); |
2 |
26 Feb 07 |
jari |
1165 |
FloatMatrix variances = getVariances(data, means, clusters); |
2 |
26 Feb 07 |
jari |
1166 |
|
2 |
26 Feb 07 |
jari |
1167 |
HCLCentroidViewer centroidViewer; |
2 |
26 Feb 07 |
jari |
1168 |
ExperimentClusterCentroidViewer expCentroidViewer; |
2 |
26 Feb 07 |
jari |
1169 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
1170 |
centroidViewer = new HCLCentroidViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
1171 |
centroidViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
1172 |
centroidViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
1173 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
1174 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
1175 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
1176 |
} |
2 |
26 Feb 07 |
jari |
1177 |
|
2 |
26 Feb 07 |
jari |
1178 |
HCLCentroidsViewer centroidsViewer = new HCLCentroidsViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
1179 |
centroidsViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
1180 |
centroidsViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
1181 |
|
2 |
26 Feb 07 |
jari |
1182 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
1183 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
1184 |
|
2 |
26 Feb 07 |
jari |
1185 |
} |
2 |
26 Feb 07 |
jari |
1186 |
else{ |
2 |
26 Feb 07 |
jari |
1187 |
expCentroidViewer = new HCLExperimentCentroidViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
1188 |
|
2 |
26 Feb 07 |
jari |
1189 |
expCentroidViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
1190 |
expCentroidViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
1191 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
1192 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
1193 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
1194 |
} |
2 |
26 Feb 07 |
jari |
1195 |
HCLExperimentCentroidsViewer expCentroidsViewer = new HCLExperimentCentroidsViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
1196 |
expCentroidsViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
1197 |
expCentroidsViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
1198 |
|
2 |
26 Feb 07 |
jari |
1199 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
1200 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
1201 |
} |
2 |
26 Feb 07 |
jari |
1202 |
root.add(centroidNode); |
2 |
26 Feb 07 |
jari |
1203 |
root.add(expressionNode); |
2 |
26 Feb 07 |
jari |
1204 |
} |
2 |
26 Feb 07 |
jari |
1205 |
|
2 |
26 Feb 07 |
jari |
1206 |
/** |
2 |
26 Feb 07 |
jari |
* Calculates means for the clusters |
2 |
26 Feb 07 |
jari |
1208 |
*/ |
2 |
26 Feb 07 |
jari |
1209 |
private FloatMatrix getMeans(FloatMatrix data, int [][] clusters){ |
2 |
26 Feb 07 |
jari |
1210 |
FloatMatrix means = new FloatMatrix(clusters.length, data.getColumnDimension()); |
2 |
26 Feb 07 |
jari |
1211 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
1212 |
means.A[i] = getMeans(data, clusters[i]); |
2 |
26 Feb 07 |
jari |
1213 |
} |
2 |
26 Feb 07 |
jari |
1214 |
return means; |
2 |
26 Feb 07 |
jari |
1215 |
} |
2 |
26 Feb 07 |
jari |
1216 |
|
2 |
26 Feb 07 |
jari |
1217 |
|
2 |
26 Feb 07 |
jari |
1218 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a set of means for an element |
2 |
26 Feb 07 |
jari |
1220 |
*/ |
2 |
26 Feb 07 |
jari |
1221 |
private float [] getMeans(FloatMatrix data, int [] indices){ |
2 |
26 Feb 07 |
jari |
1222 |
int nSamples = data.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
1223 |
float [] means = new float[nSamples]; |
2 |
26 Feb 07 |
jari |
1224 |
float sum = 0; |
2 |
26 Feb 07 |
jari |
1225 |
float n = 0; |
2 |
26 Feb 07 |
jari |
1226 |
float value; |
2 |
26 Feb 07 |
jari |
1227 |
for(int i = 0; i < nSamples; i++){ |
2 |
26 Feb 07 |
jari |
1228 |
n = 0; |
2 |
26 Feb 07 |
jari |
1229 |
sum = 0; |
2 |
26 Feb 07 |
jari |
1230 |
for(int j = 0; j < indices.length; j++){ |
2 |
26 Feb 07 |
jari |
1231 |
value = data.get(indices[j],i); |
2 |
26 Feb 07 |
jari |
1232 |
if(!Float.isNaN(value)){ |
2 |
26 Feb 07 |
jari |
1233 |
sum += value; |
2 |
26 Feb 07 |
jari |
1234 |
n++; |
2 |
26 Feb 07 |
jari |
1235 |
} |
2 |
26 Feb 07 |
jari |
1236 |
} |
2 |
26 Feb 07 |
jari |
1237 |
if(n > 0) |
2 |
26 Feb 07 |
jari |
1238 |
means[i] = sum/n; |
2 |
26 Feb 07 |
jari |
1239 |
else |
2 |
26 Feb 07 |
jari |
1240 |
means[i] = Float.NaN; |
2 |
26 Feb 07 |
jari |
1241 |
} |
2 |
26 Feb 07 |
jari |
1242 |
return means; |
2 |
26 Feb 07 |
jari |
1243 |
} |
2 |
26 Feb 07 |
jari |
1244 |
|
2 |
26 Feb 07 |
jari |
1245 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a matrix of standard deviations grouped by cluster and element |
2 |
26 Feb 07 |
jari |
1247 |
*/ |
2 |
26 Feb 07 |
jari |
1248 |
private FloatMatrix getVariances(FloatMatrix data, FloatMatrix means, int [][] clusters){ |
2 |
26 Feb 07 |
jari |
1249 |
int nSamples = data.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
1250 |
FloatMatrix variances = new FloatMatrix(clusters.length, nSamples); |
2 |
26 Feb 07 |
jari |
1251 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
1252 |
variances.A[i] = getVariances(data, means, clusters[i], i); |
2 |
26 Feb 07 |
jari |
1253 |
} |
2 |
26 Feb 07 |
jari |
1254 |
return variances; |
2 |
26 Feb 07 |
jari |
1255 |
} |
2 |
26 Feb 07 |
jari |
1256 |
|
2 |
26 Feb 07 |
jari |
1257 |
private float [] getVariances(FloatMatrix data, FloatMatrix means, int [] indices, int clusterIndex){ |
2 |
26 Feb 07 |
jari |
1258 |
int nSamples = data.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
1259 |
float [] variances = new float[nSamples]; |
2 |
26 Feb 07 |
jari |
1260 |
float sse = 0; |
2 |
26 Feb 07 |
jari |
1261 |
float mean; |
2 |
26 Feb 07 |
jari |
1262 |
float value; |
2 |
26 Feb 07 |
jari |
1263 |
int n = 0; |
2 |
26 Feb 07 |
jari |
1264 |
for(int i = 0; i < nSamples; i++){ |
2 |
26 Feb 07 |
jari |
1265 |
mean = means.get(clusterIndex, i); |
2 |
26 Feb 07 |
jari |
1266 |
n = 0; |
2 |
26 Feb 07 |
jari |
1267 |
sse = 0; |
2 |
26 Feb 07 |
jari |
1268 |
for(int j = 0; j < indices.length; j++){ |
2 |
26 Feb 07 |
jari |
1269 |
value = data.get(indices[j], i); |
2 |
26 Feb 07 |
jari |
1270 |
if(!Float.isNaN(value)){ |
2 |
26 Feb 07 |
jari |
1271 |
sse += (float)Math.pow((value - mean),2); |
2 |
26 Feb 07 |
jari |
1272 |
n++; |
2 |
26 Feb 07 |
jari |
1273 |
} |
2 |
26 Feb 07 |
jari |
1274 |
} |
2 |
26 Feb 07 |
jari |
1275 |
if(n > 1) |
2 |
26 Feb 07 |
jari |
1276 |
variances[i] = (float)Math.sqrt(sse/(n-1)); |
2 |
26 Feb 07 |
jari |
1277 |
else |
2 |
26 Feb 07 |
jari |
1278 |
variances[i] = 0.0f; |
2 |
26 Feb 07 |
jari |
1279 |
} |
2 |
26 Feb 07 |
jari |
1280 |
return variances; |
2 |
26 Feb 07 |
jari |
1281 |
} |
2 |
26 Feb 07 |
jari |
1282 |
|
2 |
26 Feb 07 |
jari |
1283 |
/** |
2 |
26 Feb 07 |
jari |
* Adds node with cluster information. |
2 |
26 Feb 07 |
jari |
1285 |
*/ |
2 |
26 Feb 07 |
jari |
1286 |
private void addClusterInfo(DefaultMutableTreeNode root, int [][] clusters, boolean clusterGenes, float zThr) { |
2 |
26 Feb 07 |
jari |
1287 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information"); |
2 |
26 Feb 07 |
jari |
1288 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
1289 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Genes in Clusters (#,%)", new HCLClusterInfoViewer(clusters, this.experiment.getNumberOfGenes(), zThr)))); |
2 |
26 Feb 07 |
jari |
1290 |
else |
2 |
26 Feb 07 |
jari |
1291 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Sammples in Clusters (#,%)", new HCLClusterInfoViewer(clusters, this.experiment.getNumberOfSamples(), false, zThr)))); |
2 |
26 Feb 07 |
jari |
1292 |
root.add(node); |
2 |
26 Feb 07 |
jari |
1293 |
} |
2 |
26 Feb 07 |
jari |
1294 |
|
2 |
26 Feb 07 |
jari |
1295 |
/** |
2 |
26 Feb 07 |
jari |
* Adds node with tree cut parameters |
2 |
26 Feb 07 |
jari |
1297 |
*/ |
2 |
26 Feb 07 |
jari |
1298 |
private void addGeneralInfo(DefaultMutableTreeNode root, float zThr, int k,boolean isGeneTree){ |
2 |
26 Feb 07 |
jari |
1299 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("General Info"); |
2 |
26 Feb 07 |
jari |
1300 |
node.add(new DefaultMutableTreeNode("Cluster Type: "+(isGeneTree ? "Gene Clusters" : "Sample Clusters"))); |
2 |
26 Feb 07 |
jari |
1301 |
node.add(new DefaultMutableTreeNode("Distance Threshold: "+ String.valueOf(zThr))); |
2 |
26 Feb 07 |
jari |
1302 |
node.add(new DefaultMutableTreeNode("Number of Clusters: "+String.valueOf(k))); |
2 |
26 Feb 07 |
jari |
1303 |
root.add(node); |
2 |
26 Feb 07 |
jari |
1304 |
} |
2 |
26 Feb 07 |
jari |
1305 |
|
2 |
26 Feb 07 |
jari |
1306 |
/** |
2 |
26 Feb 07 |
jari |
* Removes all clusters. |
2 |
26 Feb 07 |
jari |
1308 |
*/ |
2 |
26 Feb 07 |
jari |
1309 |
public void onDeleteAllClusters() { |
2 |
26 Feb 07 |
jari |
1310 |
refreshViewer(); |
2 |
26 Feb 07 |
jari |
1311 |
this.clusters.clear(); |
2 |
26 Feb 07 |
jari |
1312 |
this.experimentClusters.clear(); |
2 |
26 Feb 07 |
jari |
1313 |
this.colorBar.onClustersChanged(this.clusters); |
2 |
26 Feb 07 |
jari |
1314 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
1315 |
if(this.genesTree != null) |
2 |
26 Feb 07 |
jari |
1316 |
this.genesTree.resetNodeColors(); |
2 |
26 Feb 07 |
jari |
1317 |
if(this.sampleTree != null) |
2 |
26 Feb 07 |
jari |
1318 |
this.sampleTree.resetNodeColors(); |
2 |
26 Feb 07 |
jari |
1319 |
this.data.deleteColors(); |
2 |
26 Feb 07 |
jari |
1320 |
this.data.deleteExperimentColors(); |
2 |
26 Feb 07 |
jari |
1321 |
this.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
1322 |
revalidate(); |
2 |
26 Feb 07 |
jari |
1323 |
repaint(); |
2 |
26 Feb 07 |
jari |
1324 |
} |
2 |
26 Feb 07 |
jari |
1325 |
|
2 |
26 Feb 07 |
jari |
1326 |
/** |
2 |
26 Feb 07 |
jari |
* Sets genes tree properties. |
2 |
26 Feb 07 |
jari |
1328 |
*/ |
2 |
26 Feb 07 |
jari |
1329 |
public void onGeneTreeProperties() { |
2 |
26 Feb 07 |
jari |
1330 |
setTreeProperties(this.genesTree); |
2 |
26 Feb 07 |
jari |
1331 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
1332 |
this.header.setHeaderPosition(this.genesTree.getWidth()); |
2 |
26 Feb 07 |
jari |
1333 |
revalidate(); |
2 |
26 Feb 07 |
jari |
1334 |
} |
2 |
26 Feb 07 |
jari |
1335 |
|
2 |
26 Feb 07 |
jari |
1336 |
/** |
2 |
26 Feb 07 |
jari |
* Sets samples tree properties. |
2 |
26 Feb 07 |
jari |
1338 |
*/ |
2 |
26 Feb 07 |
jari |
1339 |
public void onSampleTreeProperties() { |
2 |
26 Feb 07 |
jari |
1340 |
setTreeProperties(this.sampleTree); |
2 |
26 Feb 07 |
jari |
1341 |
revalidate(); |
2 |
26 Feb 07 |
jari |
1342 |
} |
2 |
26 Feb 07 |
jari |
1343 |
|
2 |
26 Feb 07 |
jari |
1344 |
private void setTreeProperties(HCLTree tree) { |
2 |
26 Feb 07 |
jari |
1345 |
Frame frame = JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
1346 |
HCLConfigDialog dialog = new HCLConfigDialog(frame, this, tree.getZeroThreshold(), tree.getMinDistance(), tree.getMaxDistance(), tree.getMinNodeDistance(), tree.getMaxNodeDistance()); |
2 |
26 Feb 07 |
jari |
1347 |
dialog.setTree(tree); |
2 |
26 Feb 07 |
jari |
1348 |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
1349 |
tree.setProperties(dialog.getZeroThreshold(), dialog.getMinDistance(), dialog.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
1350 |
if(dialog.isCreateClusterViews()) |
2 |
26 Feb 07 |
jari |
1351 |
createAndAddClusterViews(tree); |
2 |
26 Feb 07 |
jari |
1352 |
} |
2 |
26 Feb 07 |
jari |
1353 |
} |
2 |
26 Feb 07 |
jari |
1354 |
|
2 |
26 Feb 07 |
jari |
1355 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the specified cluster as selected. |
2 |
26 Feb 07 |
jari |
1357 |
*/ |
2 |
26 Feb 07 |
jari |
1358 |
public void valueChanged(HCLTree source, HCLCluster cluster) { |
2 |
26 Feb 07 |
jari |
1359 |
setSelectedCluster(cluster); |
2 |
26 Feb 07 |
jari |
1360 |
} |
2 |
26 Feb 07 |
jari |
1361 |
|
2 |
26 Feb 07 |
jari |
1362 |
/** |
2 |
26 Feb 07 |
jari |
* Revalidates viewer components |
2 |
26 Feb 07 |
jari |
1364 |
*/ |
2 |
26 Feb 07 |
jari |
1365 |
public void revalidateViewer(){ |
2 |
26 Feb 07 |
jari |
1366 |
if(this.genesTree != null){ |
2 |
26 Feb 07 |
jari |
1367 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
1368 |
this.header.setHeaderPosition(this.genesTree.getWidth()); |
2 |
26 Feb 07 |
jari |
1369 |
} |
2 |
26 Feb 07 |
jari |
1370 |
revalidate(); |
2 |
26 Feb 07 |
jari |
1371 |
} |
2 |
26 Feb 07 |
jari |
1372 |
|
2 |
26 Feb 07 |
jari |
1373 |
/** |
2 |
26 Feb 07 |
jari |
* Launches a new <code>MultipleExperimentViewer</code> containing the current cluster |
2 |
26 Feb 07 |
jari |
1375 |
*/ |
2 |
26 Feb 07 |
jari |
1376 |
public void launchNewSession(){ |
2 |
26 Feb 07 |
jari |
1377 |
if(this.selectedCluster == null) |
2 |
26 Feb 07 |
jari |
1378 |
return; |
2 |
26 Feb 07 |
jari |
1379 |
if(this.selectedCluster.isGeneCluster){ |
2 |
26 Feb 07 |
jari |
1380 |
framework.launchNewMAV(getArrayMappedToData(getSubTreeElements()), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
1381 |
} else { |
2 |
26 Feb 07 |
jari |
1382 |
framework.launchNewMAV(getSubTreeElements(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
1383 |
} |
2 |
26 Feb 07 |
jari |
1384 |
} |
2 |
26 Feb 07 |
jari |
1385 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
1387 |
*/ |
2 |
26 Feb 07 |
jari |
1388 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
1389 |
return null; |
2 |
26 Feb 07 |
jari |
1390 |
} |
2 |
26 Feb 07 |
jari |
1391 |
|
2 |
26 Feb 07 |
jari |
/** Returns the corner component corresponding to the indicated corner, |
2 |
26 Feb 07 |
jari |
* posibly null |
2 |
26 Feb 07 |
jari |
1394 |
*/ |
2 |
26 Feb 07 |
jari |
1395 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
1396 |
return null; |
2 |
26 Feb 07 |
jari |
1397 |
} |
2 |
26 Feb 07 |
jari |
1398 |
|
2 |
26 Feb 07 |
jari |
1399 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
1400 |
int [][] leafClusters = new int[2][]; |
2 |
26 Feb 07 |
jari |
1401 |
if(this.genesTree != null) |
2 |
26 Feb 07 |
jari |
1402 |
leafClusters[0] = this.genesOrder; |
2 |
26 Feb 07 |
jari |
1403 |
else |
2 |
26 Feb 07 |
jari |
1404 |
leafClusters[0] = null; |
2 |
26 Feb 07 |
jari |
1405 |
if(this.sampleTree != null) |
2 |
26 Feb 07 |
jari |
1406 |
leafClusters[1] = this.samplesOrder; |
2 |
26 Feb 07 |
jari |
1407 |
else |
2 |
26 Feb 07 |
jari |
1408 |
leafClusters[1] = null; |
2 |
26 Feb 07 |
jari |
1409 |
return leafClusters; |
2 |
26 Feb 07 |
jari |
1410 |
} |
2 |
26 Feb 07 |
jari |
1411 |
|
2 |
26 Feb 07 |
jari |
1412 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
1413 |
return this.experiment; |
2 |
26 Feb 07 |
jari |
1414 |
} |
2 |
26 Feb 07 |
jari |
1415 |
|
2 |
26 Feb 07 |
jari |
/** Returns int value indicating viewer type |
2 |
26 Feb 07 |
jari |
* Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified |
2 |
26 Feb 07 |
jari |
1418 |
*/ |
2 |
26 Feb 07 |
jari |
1419 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
1420 |
return -1; |
2 |
26 Feb 07 |
jari |
1421 |
} |
2 |
26 Feb 07 |
jari |
1422 |
|
2 |
26 Feb 07 |
jari |
/** Prototyping code for saving state as XML |
2 |
26 Feb 07 |
jari |
1424 |
* |
2 |
26 Feb 07 |
jari |
public void writeXML(XMLEncoder enc) { |
2 |
26 Feb 07 |
jari |
enc.setPersistenceDelegate(HCLViewer.class, |
2 |
26 Feb 07 |
jari |
new DefaultPersistenceDelegate( new String[]{ |
2 |
26 Feb 07 |
jari |
"experiment", "features", "genes_result", "samples_result", "node"})); |
2 |
26 Feb 07 |
jari |
1429 |
|
2 |
26 Feb 07 |
jari |
enc.writeObject( new HCLViewer(experiment, features, genes_result, samples_result, node) ); |
2 |
26 Feb 07 |
jari |
1431 |
|
2 |
26 Feb 07 |
jari |
1432 |
} |
2 |
26 Feb 07 |
jari |
1433 |
*/ |
2 |
26 Feb 07 |
jari |
1434 |
|
2 |
26 Feb 07 |
jari |
1435 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse, action and hcl tree events. |
2 |
26 Feb 07 |
jari |
1437 |
*/ |
2 |
26 Feb 07 |
jari |
1438 |
private class Listener extends MouseAdapter implements ActionListener, HCLTreeListener, java.io.Serializable { |
2 |
26 Feb 07 |
jari |
1439 |
|
2 |
26 Feb 07 |
jari |
1440 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
1441 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
1442 |
if(command.equals(STORE_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
1443 |
onSetCluster(); |
2 |
26 Feb 07 |
jari |
1444 |
} else if(command.equals(LAUNCH_NEW_SESSION_CMD)) { |
2 |
26 Feb 07 |
jari |
1445 |
launchNewSession(); |
2 |
26 Feb 07 |
jari |
1446 |
} if (command.equals(SAVE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
1447 |
onSaveCluster(); |
2 |
26 Feb 07 |
jari |
1448 |
} else if (command.equals(DELETE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
1449 |
onDeleteCluster(); |
2 |
26 Feb 07 |
jari |
1450 |
} else if (command.equals(DELETE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
1451 |
onDeleteAllClusters(); |
2 |
26 Feb 07 |
jari |
1452 |
} else if (command.equals(GENE_TREE_PROPERTIES_CMD)) { |
2 |
26 Feb 07 |
jari |
1453 |
onGeneTreeProperties(); |
2 |
26 Feb 07 |
jari |
1454 |
} else if (command.equals(SAMPLE_TREE_PROPERTIES_CMD)) { |
2 |
26 Feb 07 |
jari |
1455 |
onSampleTreeProperties(); |
2 |
26 Feb 07 |
jari |
1456 |
} else if (command.equals(SAVE_GENE_ORDER_CMD)){ |
2 |
26 Feb 07 |
jari |
1457 |
saveGenesOrder(); |
2 |
26 Feb 07 |
jari |
1458 |
} else if (command.equals(SAVE_GENE_HEIGHT_CMD)){ |
2 |
26 Feb 07 |
jari |
1459 |
genesTree.saveGeneNodeHeights(); |
2 |
26 Feb 07 |
jari |
1460 |
} else if (command.equals(SAVE_EXP_ORDER_CMD)){ |
2 |
26 Feb 07 |
jari |
1461 |
saveExperimentOrder(); |
2 |
26 Feb 07 |
jari |
1462 |
} else if (command.equals(SAVE_EXP_HEIGHT_CMD)){ |
2 |
26 Feb 07 |
jari |
1463 |
sampleTree.saveExperimentNodeHeights(); |
2 |
26 Feb 07 |
jari |
1464 |
} else if (command.equals(SAVE_GENE_NEWICK_CMD)) { |
2 |
26 Feb 07 |
jari |
1465 |
genesTree.saveAsNewickFile(); |
2 |
26 Feb 07 |
jari |
1466 |
} else if (command.equals(SAVE_SAMPLE_NEWICK_CMD)) { |
2 |
26 Feb 07 |
jari |
1467 |
sampleTree.saveAsNewickFile(); |
2 |
26 Feb 07 |
jari |
1468 |
} |
2 |
26 Feb 07 |
jari |
1469 |
} |
2 |
26 Feb 07 |
jari |
1470 |
|
2 |
26 Feb 07 |
jari |
1471 |
public void valueChanged(HCLTree source, HCLCluster cluster) { |
2 |
26 Feb 07 |
jari |
1472 |
if(source == sampleTree) |
2 |
26 Feb 07 |
jari |
1473 |
cluster.isGeneCluster = false; |
2 |
26 Feb 07 |
jari |
1474 |
HCLViewer.this.valueChanged(source, cluster); |
2 |
26 Feb 07 |
jari |
1475 |
} |
2 |
26 Feb 07 |
jari |
1476 |
|
2 |
26 Feb 07 |
jari |
1477 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
1478 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
1479 |
} |
2 |
26 Feb 07 |
jari |
1480 |
|
2 |
26 Feb 07 |
jari |
1481 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
1482 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
1483 |
if (SwingUtilities.isRightMouseButton(event)) { |
2 |
26 Feb 07 |
jari |
1484 |
return; |
2 |
26 Feb 07 |
jari |
1485 |
} |
2 |
26 Feb 07 |
jari |
1486 |
deselect(event); |
2 |
26 Feb 07 |
jari |
1487 |
} |
2 |
26 Feb 07 |
jari |
1488 |
|
2 |
26 Feb 07 |
jari |
1489 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
1490 |
if (!e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
1491 |
return; |
2 |
26 Feb 07 |
jari |
1492 |
} |
2 |
26 Feb 07 |
jari |
1493 |
int node = HCLViewer.this.selectedCluster == null ? -1 : HCLViewer.this.selectedCluster.root; |
2 |
26 Feb 07 |
jari |
1494 |
setEnableMenuItem(STORE_CLUSTER_CMD, node >= 0); |
2 |
26 Feb 07 |
jari |
1495 |
setEnableMenuItem(LAUNCH_NEW_SESSION_CMD, node >= 0); |
2 |
26 Feb 07 |
jari |
// setEnableMenuItem(SET_CLUSTER_TEXT_CMD, doesClusterExist() && node != -1 && HCLViewer.this.selectedCluster.isGeneCluster); |
2 |
26 Feb 07 |
jari |
1497 |
setEnableMenuItem(DELETE_CLUSTER_CMD, doesClusterExist()); |
2 |
26 Feb 07 |
jari |
1498 |
setEnableMenuItem(DELETE_ALL_CLUSTERS_CMD, doesClusterExist()); |
2 |
26 Feb 07 |
jari |
1499 |
setEnableMenuItem(SAVE_CLUSTER_CMD, HCLViewer.this.selectedCluster != null && HCLViewer.this.selectedCluster.root != -1); |
2 |
26 Feb 07 |
jari |
1500 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
1501 |
} |
2 |
26 Feb 07 |
jari |
1502 |
|
2 |
26 Feb 07 |
jari |
1503 |
|
2 |
26 Feb 07 |
jari |
1504 |
|
2 |
26 Feb 07 |
jari |
1505 |
private void deselect(MouseEvent e){ |
2 |
26 Feb 07 |
jari |
1506 |
Object source = e.getSource(); |
2 |
26 Feb 07 |
jari |
1507 |
|
2 |
26 Feb 07 |
jari |
1508 |
if(source instanceof HCLTree){ //in a tree don't deselect |
2 |
26 Feb 07 |
jari |
1509 |
if(source == genesTree) { //if colloring rows (genes) |
2 |
26 Feb 07 |
jari |
1510 |
|
2 |
26 Feb 07 |
jari |
1511 |
if(isExperimentCluster){ |
2 |
26 Feb 07 |
jari |
1512 |
((ExperimentClusterViewer)expViewer).selectColumns(-1, -1); |
2 |
26 Feb 07 |
jari |
1513 |
} |
2 |
26 Feb 07 |
jari |
1514 |
else{ |
2 |
26 Feb 07 |
jari |
1515 |
((ExperimentViewer)expViewer).selectColumns(-1, -1); |
2 |
26 Feb 07 |
jari |
1516 |
} |
2 |
26 Feb 07 |
jari |
1517 |
if(sampleTree != null) |
2 |
26 Feb 07 |
jari |
1518 |
sampleTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1519 |
} |
2 |
26 Feb 07 |
jari |
1520 |
else{ // coloring columns (experiment) |
2 |
26 Feb 07 |
jari |
1521 |
|
2 |
26 Feb 07 |
jari |
1522 |
if(isExperimentCluster){ |
2 |
26 Feb 07 |
jari |
1523 |
((ExperimentClusterViewer)expViewer).selectRows(-1, -1); |
2 |
26 Feb 07 |
jari |
1524 |
} |
2 |
26 Feb 07 |
jari |
1525 |
else{ |
2 |
26 Feb 07 |
jari |
1526 |
((ExperimentViewer)expViewer).selectRows(-1, -1); |
2 |
26 Feb 07 |
jari |
1527 |
} |
2 |
26 Feb 07 |
jari |
1528 |
if(genesTree != null) |
2 |
26 Feb 07 |
jari |
1529 |
genesTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1530 |
} |
2 |
26 Feb 07 |
jari |
1531 |
repaint(); |
2 |
26 Feb 07 |
jari |
1532 |
return; |
2 |
26 Feb 07 |
jari |
1533 |
} |
2 |
26 Feb 07 |
jari |
1534 |
|
2 |
26 Feb 07 |
jari |
1535 |
int x = e.getX(); |
2 |
26 Feb 07 |
jari |
1536 |
int y = e.getY(); |
2 |
26 Feb 07 |
jari |
1537 |
|
2 |
26 Feb 07 |
jari |
//now know we are not on a tree |
2 |
26 Feb 07 |
jari |
1539 |
if(!(source instanceof HCLViewer) && (source != expViewer)){ |
2 |
26 Feb 07 |
jari |
1540 |
deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1541 |
repaint(); |
2 |
26 Feb 07 |
jari |
1542 |
} |
2 |
26 Feb 07 |
jari |
//know we are in the HCLViewer but not in the tree areas but above matrix |
2 |
26 Feb 07 |
jari |
1544 |
else if(source instanceof HCLViewer && sampleTree != null && y < sampleTree.getHeight()){ |
2 |
26 Feb 07 |
jari |
1545 |
deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1546 |
repaint(); |
2 |
26 Feb 07 |
jari |
1547 |
} |
2 |
26 Feb 07 |
jari |
1548 |
else if(source == expViewer){ |
2 |
26 Feb 07 |
jari |
1549 |
int numSamples = numberOfSamples; |
2 |
26 Feb 07 |
jari |
1550 |
if(source instanceof ExperimentClusterViewer) |
2 |
26 Feb 07 |
jari |
1551 |
numSamples = ((ExperimentClusterViewer)expViewer).getCurrentNumberOfExperiments(); |
2 |
26 Feb 07 |
jari |
1552 |
if(x > elementSize.width * numSamples + offset || x < offset){ |
2 |
26 Feb 07 |
jari |
1553 |
deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1554 |
repaint(); |
2 |
26 Feb 07 |
jari |
1555 |
} |
2 |
26 Feb 07 |
jari |
1556 |
} |
2 |
26 Feb 07 |
jari |
1557 |
else if(((source == expViewer) || (source instanceof ExperimentClusterViewer)) && x < offset){ |
2 |
26 Feb 07 |
jari |
1558 |
deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1559 |
repaint(); |
2 |
26 Feb 07 |
jari |
1560 |
} |
2 |
26 Feb 07 |
jari |
1561 |
} |
2 |
26 Feb 07 |
jari |
1562 |
|
2 |
26 Feb 07 |
jari |
1563 |
|
2 |
26 Feb 07 |
jari |
1564 |
private void deselectAllNodes(){ |
2 |
26 Feb 07 |
jari |
1565 |
if(genesTree != null) |
2 |
26 Feb 07 |
jari |
1566 |
genesTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1567 |
if(sampleTree != null) |
2 |
26 Feb 07 |
jari |
1568 |
sampleTree.deselectAllNodes(); |
2 |
26 Feb 07 |
jari |
1569 |
if(isExperimentCluster){ |
2 |
26 Feb 07 |
jari |
1570 |
((ExperimentClusterViewer)expViewer).selectRows(-1, -1); |
2 |
26 Feb 07 |
jari |
1571 |
((ExperimentClusterViewer)expViewer).selectColumns(-1, -1); |
2 |
26 Feb 07 |
jari |
1572 |
} |
2 |
26 Feb 07 |
jari |
1573 |
else{ |
2 |
26 Feb 07 |
jari |
1574 |
((ExperimentViewer)expViewer).selectRows(-1, -1); |
2 |
26 Feb 07 |
jari |
1575 |
((ExperimentViewer)expViewer).selectColumns(-1, -1); |
2 |
26 Feb 07 |
jari |
1576 |
} |
2 |
26 Feb 07 |
jari |
1577 |
} |
2 |
26 Feb 07 |
jari |
1578 |
|
2 |
26 Feb 07 |
jari |
1579 |
} |
2 |
26 Feb 07 |
jari |
1580 |
} |