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: ExperimentClusterCentroidViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.8 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 16:56:57 $ |
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 |
package org.tigr.microarray.mev.cluster.gui.helpers; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.FontMetrics; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Rectangle; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.RenderingHints; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
23 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.clusterUtil.Cluster; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.clusterUtil.ClusterRepository; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
public class ExperimentClusterCentroidViewer extends JPanel implements IViewer { |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
public static final Color DEF_CLUSTER_COLOR = Color.lightGray; |
2 |
26 Feb 07 |
jari |
44 |
protected static final Color bColor = new Color(0, 0, 128); |
2 |
26 Feb 07 |
jari |
45 |
|
2 |
26 Feb 07 |
jari |
46 |
protected JMenuItem setOverallMaxMenuItem; |
2 |
26 Feb 07 |
jari |
47 |
protected JMenuItem setClusterMaxMenuItem; |
2 |
26 Feb 07 |
jari |
48 |
protected static final String STORE_CLUSTER_CMD = "store-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
49 |
protected static final String SET_DEF_COLOR_CMD = "set-def-color-cmd"; |
2 |
26 Feb 07 |
jari |
50 |
protected static final String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
51 |
protected static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
52 |
protected static final String SET_Y_TO_EXPERIMENT_MAX_CMD = "set-y-to-exp-max-cmd"; |
2 |
26 Feb 07 |
jari |
53 |
protected static final String SET_Y_TO_CLUSTER_MAX_CMD = "set-y-to-cluster-max-cmd"; |
2 |
26 Feb 07 |
jari |
54 |
protected static final String LAUNCH_NEW_SESSION_CMD = "launch-new-session-cmd"; |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
protected Experiment experiment; |
2 |
26 Feb 07 |
jari |
57 |
protected IData data; |
2 |
26 Feb 07 |
jari |
58 |
protected IFramework framework; |
2 |
26 Feb 07 |
jari |
59 |
protected int clusterIndex = 0; |
2 |
26 Feb 07 |
jari |
60 |
protected int[][] clusters; |
2 |
26 Feb 07 |
jari |
61 |
protected float maxYValue; //current max y range set for graph, from y = 0 |
2 |
26 Feb 07 |
jari |
62 |
protected float maxClusterValue; //max abs. value in current cluster |
2 |
26 Feb 07 |
jari |
63 |
protected float maxExperimentValue; //max abs. value in all clusters |
2 |
26 Feb 07 |
jari |
64 |
protected float minValue, maxValue, midValue = 0.0f; |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
protected int yRangeOption; |
2 |
26 Feb 07 |
jari |
68 |
public static int USE_EXPERIMENT_MAX = 0; |
2 |
26 Feb 07 |
jari |
69 |
public static int USE_CLUSTER_MAX = 1; |
2 |
26 Feb 07 |
jari |
70 |
|
2 |
26 Feb 07 |
jari |
71 |
protected boolean drawValues = true; |
2 |
26 Feb 07 |
jari |
72 |
protected boolean drawVariances = true; |
2 |
26 Feb 07 |
jari |
73 |
protected boolean drawCodes = true; |
2 |
26 Feb 07 |
jari |
74 |
public static Color missingColor = new Color(128, 128, 128); |
2 |
26 Feb 07 |
jari |
75 |
private boolean drawMarks = false; |
2 |
26 Feb 07 |
jari |
76 |
protected boolean gradientColors; |
2 |
26 Feb 07 |
jari |
77 |
protected boolean isAntiAliasing = false; |
2 |
26 Feb 07 |
jari |
78 |
protected float[][] means; |
2 |
26 Feb 07 |
jari |
79 |
protected float[][] variances; |
2 |
26 Feb 07 |
jari |
80 |
protected float[][] codes; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
protected int numberOfGenes; |
2 |
26 Feb 07 |
jari |
83 |
public static BufferedImage posColorImage; // = createGradientImage(Color.black, Color.red); |
2 |
26 Feb 07 |
jari |
84 |
public static BufferedImage negColorImage; // = createGradientImage(Color.green, Color.black); |
2 |
26 Feb 07 |
jari |
85 |
protected boolean showRefLine = false; |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
private boolean useDoubleGradient = true; |
2 |
26 Feb 07 |
jari |
88 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
/** |
2 |
26 Feb 07 |
jari |
* This constructor is used by XMLEncoder/Decoder and IViewerPersistenceDelegate |
2 |
26 Feb 07 |
jari |
* to re-create an ExperimentClusterCentroidViewer from a saved xml file |
2 |
26 Feb 07 |
jari |
* @param e |
2 |
26 Feb 07 |
jari |
94 |
*/ |
2 |
26 Feb 07 |
jari |
95 |
public ExperimentClusterCentroidViewer(Experiment e, int[][] clusters, Integer clusterIndex, float[][] means, float[][] variances, float[][] codes){ |
2 |
26 Feb 07 |
jari |
96 |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
97 |
this.clusterIndex = clusterIndex.intValue(); |
2 |
26 Feb 07 |
jari |
98 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
99 |
numberOfGenes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
100 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
101 |
setFont(new Font("monospaced", Font.BOLD, 10)); |
2 |
26 Feb 07 |
jari |
102 |
this.means = means; |
2 |
26 Feb 07 |
jari |
103 |
this.variances = variances; |
2 |
26 Feb 07 |
jari |
104 |
this.codes = codes; |
2 |
26 Feb 07 |
jari |
105 |
this.maxExperimentValue = experiment.getMaxAbsValue(); |
2 |
26 Feb 07 |
jari |
106 |
this.yRangeOption = ExperimentClusterCentroidViewer.USE_EXPERIMENT_MAX; |
2 |
26 Feb 07 |
jari |
107 |
} |
2 |
26 Feb 07 |
jari |
108 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
109 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
110 |
new Object[]{this.experiment, this.clusters, new Integer(this.clusterIndex), this.means, this.variances, this.codes}); |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>ExperimentClusterCentroidViewer</code> for specified |
2 |
26 Feb 07 |
jari |
* experiment and clusters. |
2 |
26 Feb 07 |
jari |
117 |
* |
2 |
26 Feb 07 |
jari |
* @param experiment the data of an experiment. |
2 |
26 Feb 07 |
jari |
* @param clusters the array of clusters. |
2 |
26 Feb 07 |
jari |
120 |
*/ |
2 |
26 Feb 07 |
jari |
121 |
public ExperimentClusterCentroidViewer(Experiment experiment, int[][] clusters) { |
2 |
26 Feb 07 |
jari |
122 |
if (experiment == null) { |
2 |
26 Feb 07 |
jari |
123 |
throw new IllegalArgumentException("experiment == null"); |
2 |
26 Feb 07 |
jari |
124 |
} |
2 |
26 Feb 07 |
jari |
125 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
126 |
numberOfGenes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
127 |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
128 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
129 |
setFont(new Font("monospaced", Font.BOLD, 10)); |
2 |
26 Feb 07 |
jari |
130 |
this.maxExperimentValue = experiment.getMaxAbsValue(); |
2 |
26 Feb 07 |
jari |
131 |
this.yRangeOption = ExperimentClusterCentroidViewer.USE_EXPERIMENT_MAX; |
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
/** |
2 |
26 Feb 07 |
jari |
* Determines whether any clusters are set |
2 |
26 Feb 07 |
jari |
136 |
*/ |
2 |
26 Feb 07 |
jari |
137 |
public boolean checkGradient() { |
2 |
26 Feb 07 |
jari |
138 |
boolean temp = true; |
2 |
26 Feb 07 |
jari |
139 |
for (int i = 0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
140 |
for (int j = 0; j<clusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
141 |
try { |
2 |
26 Feb 07 |
jari |
142 |
if (this.data.getExperimentColor(clusters[i][j]) != null) { |
2 |
26 Feb 07 |
jari |
143 |
temp = false; |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
} |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
return temp; |
2 |
26 Feb 07 |
jari |
150 |
} |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
/** |
2 |
26 Feb 07 |
jari |
* Calculates color for passed expression value. |
2 |
26 Feb 07 |
jari |
154 |
*/ |
2 |
26 Feb 07 |
jari |
155 |
private Color getColor(float value) { |
2 |
26 Feb 07 |
jari |
156 |
if (Float.isNaN(value)) { |
2 |
26 Feb 07 |
jari |
157 |
return missingColor; |
2 |
26 Feb 07 |
jari |
158 |
} |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
float maximum; |
2 |
26 Feb 07 |
jari |
161 |
int colorIndex, rgb; |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
163 |
if(useDoubleGradient) { |
2 |
26 Feb 07 |
jari |
164 |
maximum = value < midValue ? this.minValue : this.maxValue; |
2 |
26 Feb 07 |
jari |
165 |
colorIndex = (int) (255 * (value-midValue) / (maximum - midValue)); |
2 |
26 Feb 07 |
jari |
166 |
colorIndex = colorIndex > 255 ? 255 : colorIndex; |
2 |
26 Feb 07 |
jari |
167 |
rgb = value < midValue ? negColorImage.getRGB(255 - colorIndex, 0) |
2 |
26 Feb 07 |
jari |
168 |
: posColorImage.getRGB(colorIndex, 0); |
2 |
26 Feb 07 |
jari |
169 |
} else { |
2 |
26 Feb 07 |
jari |
170 |
float span = this.maxValue - this.minValue; |
2 |
26 Feb 07 |
jari |
171 |
if(value <= minValue) |
2 |
26 Feb 07 |
jari |
172 |
colorIndex = 0; |
2 |
26 Feb 07 |
jari |
173 |
else if(value >= maxValue) |
2 |
26 Feb 07 |
jari |
174 |
colorIndex = 255; |
2 |
26 Feb 07 |
jari |
175 |
else |
2 |
26 Feb 07 |
jari |
176 |
colorIndex = (int)(((value - this.minValue)/span) * 255); |
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
rgb = posColorImage.getRGB(colorIndex,0); |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
return new Color(rgb); |
2 |
26 Feb 07 |
jari |
181 |
} |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
public void setGradient(boolean g) { |
2 |
26 Feb 07 |
jari |
184 |
this.gradientColors = g; |
2 |
26 Feb 07 |
jari |
185 |
} |
2 |
26 Feb 07 |
jari |
186 |
|
2 |
26 Feb 07 |
jari |
187 |
/** |
2 |
26 Feb 07 |
jari |
* Sets means values. |
2 |
26 Feb 07 |
jari |
189 |
*/ |
2 |
26 Feb 07 |
jari |
190 |
public void setMeans(float[][] means) { |
2 |
26 Feb 07 |
jari |
191 |
this.means = means; |
2 |
26 Feb 07 |
jari |
192 |
} |
2 |
26 Feb 07 |
jari |
193 |
|
2 |
26 Feb 07 |
jari |
194 |
/** |
2 |
26 Feb 07 |
jari |
* Sets variances values. |
2 |
26 Feb 07 |
jari |
196 |
*/ |
2 |
26 Feb 07 |
jari |
197 |
public void setVariances(float[][] variances) { |
2 |
26 Feb 07 |
jari |
198 |
this.variances = variances; |
2 |
26 Feb 07 |
jari |
199 |
} |
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
/** |
2 |
26 Feb 07 |
jari |
* Sets codes. |
2 |
26 Feb 07 |
jari |
203 |
*/ |
2 |
26 Feb 07 |
jari |
204 |
public void setCodes(float[][] codes) { |
2 |
26 Feb 07 |
jari |
205 |
this.codes = codes; |
2 |
26 Feb 07 |
jari |
206 |
} |
2 |
26 Feb 07 |
jari |
207 |
|
2 |
26 Feb 07 |
jari |
208 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the draw marks attribute. |
2 |
26 Feb 07 |
jari |
210 |
*/ |
2 |
26 Feb 07 |
jari |
211 |
public void setDrawMarks(boolean draw) { |
2 |
26 Feb 07 |
jari |
212 |
this.drawMarks = draw; |
2 |
26 Feb 07 |
jari |
213 |
} |
2 |
26 Feb 07 |
jari |
214 |
|
2 |
26 Feb 07 |
jari |
215 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the draw variances attribute. |
2 |
26 Feb 07 |
jari |
217 |
*/ |
2 |
26 Feb 07 |
jari |
218 |
public void setDrawVariances(boolean draw) { |
2 |
26 Feb 07 |
jari |
219 |
this.drawVariances = draw; |
2 |
26 Feb 07 |
jari |
220 |
} |
2 |
26 Feb 07 |
jari |
221 |
|
2 |
26 Feb 07 |
jari |
222 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the draw values attribute. |
2 |
26 Feb 07 |
jari |
224 |
*/ |
2 |
26 Feb 07 |
jari |
225 |
public void setDrawValues(boolean draw) { |
2 |
26 Feb 07 |
jari |
226 |
this.drawValues = draw; |
2 |
26 Feb 07 |
jari |
227 |
} |
2 |
26 Feb 07 |
jari |
228 |
|
2 |
26 Feb 07 |
jari |
229 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the draw codes attribute. |
2 |
26 Feb 07 |
jari |
231 |
*/ |
2 |
26 Feb 07 |
jari |
232 |
public void setDrawCodes(boolean draw) { |
2 |
26 Feb 07 |
jari |
233 |
this.drawCodes = draw; |
2 |
26 Feb 07 |
jari |
234 |
} |
2 |
26 Feb 07 |
jari |
235 |
|
2 |
26 Feb 07 |
jari |
236 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the anti-aliasing attribute. |
2 |
26 Feb 07 |
jari |
238 |
*/ |
2 |
26 Feb 07 |
jari |
239 |
public void setAntiAliasing(boolean value) { |
2 |
26 Feb 07 |
jari |
240 |
this.isAntiAliasing = value; |
2 |
26 Feb 07 |
jari |
241 |
} |
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
/** |
2 |
26 Feb 07 |
jari |
* Updates data, mode and some the viewer attributes. |
2 |
26 Feb 07 |
jari |
245 |
*/ |
2 |
26 Feb 07 |
jari |
246 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
247 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
248 |
setData(framework.getData()); |
2 |
26 Feb 07 |
jari |
249 |
setAntiAliasing(framework.getDisplayMenu().isAntiAliasing()); |
2 |
26 Feb 07 |
jari |
250 |
Object userObject = framework.getUserObject(); |
2 |
26 Feb 07 |
jari |
251 |
if (userObject instanceof CentroidUserObject) { |
2 |
26 Feb 07 |
jari |
252 |
setClusterIndex(((CentroidUserObject)userObject).getClusterIndex()); |
2 |
26 Feb 07 |
jari |
253 |
setMode(((CentroidUserObject)userObject).getMode()); |
2 |
26 Feb 07 |
jari |
254 |
} else { |
2 |
26 Feb 07 |
jari |
255 |
setClusterIndex(((Integer)userObject).intValue()); |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
updateValues(getCluster()); |
2 |
26 Feb 07 |
jari |
258 |
this.maxValue = framework.getDisplayMenu().getMaxRatioScale(); |
2 |
26 Feb 07 |
jari |
259 |
this.minValue = framework.getDisplayMenu().getMinRatioScale(); |
2 |
26 Feb 07 |
jari |
260 |
this.midValue = framework.getDisplayMenu().getMidRatioValue(); |
2 |
26 Feb 07 |
jari |
261 |
ExperimentClusterCentroidViewer.posColorImage = framework.getDisplayMenu().getPositiveGradientImage(); |
2 |
26 Feb 07 |
jari |
262 |
ExperimentClusterCentroidViewer.negColorImage = framework.getDisplayMenu().getNegativeGradientImage(); |
2 |
26 Feb 07 |
jari |
263 |
this.gradientColors = framework.getDisplayMenu().getColorGradientState(); |
2 |
26 Feb 07 |
jari |
264 |
} |
2 |
26 Feb 07 |
jari |
265 |
|
2 |
26 Feb 07 |
jari |
266 |
/** |
2 |
26 Feb 07 |
jari |
* Sets data. |
2 |
26 Feb 07 |
jari |
268 |
*/ |
2 |
26 Feb 07 |
jari |
269 |
public void setData(IData data) { |
2 |
26 Feb 07 |
jari |
270 |
this.data = data; |
2 |
26 Feb 07 |
jari |
271 |
} |
2 |
26 Feb 07 |
jari |
272 |
|
2 |
26 Feb 07 |
jari |
273 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a cluster index. |
2 |
26 Feb 07 |
jari |
275 |
*/ |
2 |
26 Feb 07 |
jari |
276 |
public void setClusterIndex(int clusterIndex) { |
2 |
26 Feb 07 |
jari |
277 |
this.clusterIndex = clusterIndex; |
2 |
26 Feb 07 |
jari |
278 |
updateValues(getCluster()); |
2 |
26 Feb 07 |
jari |
279 |
} |
2 |
26 Feb 07 |
jari |
280 |
|
2 |
26 Feb 07 |
jari |
281 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a current cluster. |
2 |
26 Feb 07 |
jari |
283 |
*/ |
2 |
26 Feb 07 |
jari |
284 |
public int[] getCluster() { |
2 |
26 Feb 07 |
jari |
285 |
return this.clusters[this.clusterIndex]; |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
/** |
2 |
26 Feb 07 |
jari |
* Returns all clusters. |
2 |
26 Feb 07 |
jari |
290 |
*/ |
2 |
26 Feb 07 |
jari |
291 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
292 |
return clusters; |
2 |
26 Feb 07 |
jari |
293 |
} |
2 |
26 Feb 07 |
jari |
294 |
|
2 |
26 Feb 07 |
jari |
295 |
/** |
2 |
26 Feb 07 |
jari |
* Returns index of a gene in the current cluster. |
2 |
26 Feb 07 |
jari |
297 |
*/ |
2 |
26 Feb 07 |
jari |
298 |
protected int getProbe(int row) { |
2 |
26 Feb 07 |
jari |
299 |
return this.experiment.getGeneIndexMappedToData(row); |
2 |
26 Feb 07 |
jari |
300 |
} |
2 |
26 Feb 07 |
jari |
301 |
|
2 |
26 Feb 07 |
jari |
302 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the viewer mode. |
2 |
26 Feb 07 |
jari |
304 |
*/ |
2 |
26 Feb 07 |
jari |
305 |
public void setMode(int mode) { |
2 |
26 Feb 07 |
jari |
306 |
switch (mode) { |
2 |
26 Feb 07 |
jari |
307 |
case CentroidUserObject.VARIANCES_MODE: |
2 |
26 Feb 07 |
jari |
308 |
setDrawVariances(true); |
2 |
26 Feb 07 |
jari |
309 |
setDrawValues(false); |
2 |
26 Feb 07 |
jari |
310 |
break; |
2 |
26 Feb 07 |
jari |
311 |
case CentroidUserObject.VALUES_MODE: |
2 |
26 Feb 07 |
jari |
312 |
setDrawVariances(false); |
2 |
26 Feb 07 |
jari |
313 |
setDrawValues(true); |
2 |
26 Feb 07 |
jari |
314 |
break; |
2 |
26 Feb 07 |
jari |
315 |
} |
2 |
26 Feb 07 |
jari |
316 |
} |
2 |
26 Feb 07 |
jari |
317 |
|
2 |
26 Feb 07 |
jari |
318 |
/** |
2 |
26 Feb 07 |
jari |
* Updates max value. |
2 |
26 Feb 07 |
jari |
320 |
*/ |
2 |
26 Feb 07 |
jari |
321 |
private void updateValues(int[] cluster) { |
2 |
26 Feb 07 |
jari |
322 |
this.maxClusterValue = calculateMaxValue(cluster); |
2 |
26 Feb 07 |
jari |
323 |
} |
2 |
26 Feb 07 |
jari |
324 |
|
2 |
26 Feb 07 |
jari |
325 |
/** |
2 |
26 Feb 07 |
jari |
* Sets public color for the current cluster. |
2 |
26 Feb 07 |
jari |
327 |
*/ |
2 |
26 Feb 07 |
jari |
328 |
public void setClusterColor(Color color) { |
2 |
26 Feb 07 |
jari |
329 |
if(color ==null){ //indicates removal of cluster |
2 |
26 Feb 07 |
jari |
330 |
framework.removeCluster(getCluster(), experiment, ClusterRepository.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
331 |
} |
2 |
26 Feb 07 |
jari |
332 |
} |
2 |
26 Feb 07 |
jari |
333 |
|
2 |
26 Feb 07 |
jari |
334 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster color |
2 |
26 Feb 07 |
jari |
336 |
*/ |
2 |
26 Feb 07 |
jari |
337 |
public void storeCluster(){ |
2 |
26 Feb 07 |
jari |
338 |
framework.storeCluster(getCluster(), experiment, ClusterRepository.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
339 |
onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
342 |
/** |
2 |
26 Feb 07 |
jari |
* Launches a new <code>MultipleExperimentViewer</code> containing the current cluster |
2 |
26 Feb 07 |
jari |
344 |
*/ |
2 |
26 Feb 07 |
jari |
345 |
public void launchNewSession(){ |
2 |
26 Feb 07 |
jari |
346 |
framework.launchNewMAV(getCluster(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
347 |
} |
2 |
26 Feb 07 |
jari |
348 |
|
2 |
26 Feb 07 |
jari |
349 |
private int [] getArrayMappedToData(){ |
2 |
26 Feb 07 |
jari |
350 |
int [] clusterIndices = getCluster(); |
2 |
26 Feb 07 |
jari |
351 |
if( clusterIndices == null || clusterIndices.length < 1) |
2 |
26 Feb 07 |
jari |
352 |
return clusterIndices; |
2 |
26 Feb 07 |
jari |
353 |
|
2 |
26 Feb 07 |
jari |
354 |
int [] dataIndices = new int [clusterIndices.length]; |
2 |
26 Feb 07 |
jari |
355 |
for(int i = 0; i < clusterIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
356 |
dataIndices[i] = this.experiment.getGeneIndexMappedToData(clusterIndices[i]); |
2 |
26 Feb 07 |
jari |
357 |
} |
2 |
26 Feb 07 |
jari |
358 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
359 |
} |
2 |
26 Feb 07 |
jari |
360 |
|
2 |
26 Feb 07 |
jari |
361 |
|
2 |
26 Feb 07 |
jari |
362 |
/** |
2 |
26 Feb 07 |
jari |
* Sets Y range scaling option |
2 |
26 Feb 07 |
jari |
364 |
*/ |
2 |
26 Feb 07 |
jari |
365 |
public void setYRangeOption(int option){ |
2 |
26 Feb 07 |
jari |
366 |
if(option != ExperimentClusterCentroidViewer.USE_EXPERIMENT_MAX && option != ExperimentClusterCentroidViewer.USE_CLUSTER_MAX) |
2 |
26 Feb 07 |
jari |
367 |
this.yRangeOption = USE_EXPERIMENT_MAX; |
2 |
26 Feb 07 |
jari |
368 |
else |
2 |
26 Feb 07 |
jari |
369 |
yRangeOption = option; |
2 |
26 Feb 07 |
jari |
370 |
} |
2 |
26 Feb 07 |
jari |
371 |
|
2 |
26 Feb 07 |
jari |
372 |
|
2 |
26 Feb 07 |
jari |
373 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the experiment data (ratio values). |
2 |
26 Feb 07 |
jari |
375 |
*/ |
2 |
26 Feb 07 |
jari |
376 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
377 |
return experiment; |
2 |
26 Feb 07 |
jari |
378 |
} |
2 |
26 Feb 07 |
jari |
379 |
|
2 |
26 Feb 07 |
jari |
380 |
/** |
2 |
26 Feb 07 |
jari |
* Returns data values. |
2 |
26 Feb 07 |
jari |
382 |
*/ |
2 |
26 Feb 07 |
jari |
383 |
public IData getData() { |
2 |
26 Feb 07 |
jari |
384 |
return data; |
2 |
26 Feb 07 |
jari |
385 |
} |
2 |
26 Feb 07 |
jari |
386 |
|
2 |
26 Feb 07 |
jari |
387 |
/** |
2 |
26 Feb 07 |
jari |
* Returns component to be displayed in the framework scroll pane. |
2 |
26 Feb 07 |
jari |
389 |
*/ |
2 |
26 Feb 07 |
jari |
390 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
391 |
return this; |
2 |
26 Feb 07 |
jari |
392 |
} |
2 |
26 Feb 07 |
jari |
393 |
|
2 |
26 Feb 07 |
jari |
394 |
/** |
2 |
26 Feb 07 |
jari |
* Paints chart into specified graphics. |
2 |
26 Feb 07 |
jari |
396 |
*/ |
2 |
26 Feb 07 |
jari |
397 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
398 |
FontMetrics metrics = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
399 |
Rectangle rect = new Rectangle(40, 20, getWidth()-80, getHeight() - 40 - getNamesWidth(metrics)); |
2 |
26 Feb 07 |
jari |
400 |
paint((Graphics2D)g, rect, true); |
2 |
26 Feb 07 |
jari |
401 |
} |
2 |
26 Feb 07 |
jari |
402 |
|
2 |
26 Feb 07 |
jari |
403 |
public void subPaint(Graphics2D g, Rectangle rect, boolean drawMarks) { |
2 |
26 Feb 07 |
jari |
404 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
405 |
} |
2 |
26 Feb 07 |
jari |
406 |
|
2 |
26 Feb 07 |
jari |
407 |
/** |
2 |
26 Feb 07 |
jari |
* Paints chart into specified graphics and with specified bounds. |
2 |
26 Feb 07 |
jari |
409 |
*/ |
2 |
26 Feb 07 |
jari |
410 |
public void paint(Graphics2D g, Rectangle rect, boolean drawMarks) { |
2 |
26 Feb 07 |
jari |
411 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
412 |
|
2 |
26 Feb 07 |
jari |
413 |
if (isAntiAliasing) { |
2 |
26 Feb 07 |
jari |
414 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
415 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
416 |
} |
2 |
26 Feb 07 |
jari |
417 |
|
2 |
26 Feb 07 |
jari |
418 |
final int left = rect.x; |
2 |
26 Feb 07 |
jari |
419 |
final int top = rect.y; |
2 |
26 Feb 07 |
jari |
420 |
final int width = rect.width; |
2 |
26 Feb 07 |
jari |
421 |
final int height = rect.height; |
2 |
26 Feb 07 |
jari |
422 |
|
2 |
26 Feb 07 |
jari |
423 |
if (width < 5 || height < 5) { |
2 |
26 Feb 07 |
jari |
424 |
return; |
2 |
26 Feb 07 |
jari |
425 |
} |
2 |
26 Feb 07 |
jari |
426 |
|
2 |
26 Feb 07 |
jari |
427 |
final int zeroValue = top + (int)Math.round(height/2f); |
2 |
26 Feb 07 |
jari |
428 |
final int numberOfSamples = this.getCluster().length; |
2 |
26 Feb 07 |
jari |
429 |
|
2 |
26 Feb 07 |
jari |
//do this outside paint once menu is set up |
2 |
26 Feb 07 |
jari |
431 |
if(this.yRangeOption == ExperimentClusterCentroidViewer.USE_EXPERIMENT_MAX) |
2 |
26 Feb 07 |
jari |
432 |
maxYValue = this.maxExperimentValue; |
2 |
26 Feb 07 |
jari |
433 |
else if(this.yRangeOption == ExperimentClusterCentroidViewer.USE_CLUSTER_MAX) |
2 |
26 Feb 07 |
jari |
434 |
maxYValue = this.maxClusterValue; |
2 |
26 Feb 07 |
jari |
435 |
|
2 |
26 Feb 07 |
jari |
436 |
if (maxYValue == 0.0f) { |
2 |
26 Feb 07 |
jari |
437 |
maxYValue = 1.0f; |
2 |
26 Feb 07 |
jari |
438 |
} |
2 |
26 Feb 07 |
jari |
// this.setGradient(this.checkGradient()); |
2 |
26 Feb 07 |
jari |
440 |
final float factor = height/(2f*maxYValue); |
2 |
26 Feb 07 |
jari |
441 |
final float stepX = width/(float)(numberOfGenes-1); |
2 |
26 Feb 07 |
jari |
442 |
final int stepsY = (int)maxYValue+1; |
2 |
26 Feb 07 |
jari |
443 |
|
2 |
26 Feb 07 |
jari |
444 |
if (this.drawVariances) { |
2 |
26 Feb 07 |
jari |
// draw variances |
2 |
26 Feb 07 |
jari |
446 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
447 |
for (int i=0; i<numberOfGenes; i++) { |
2 |
26 Feb 07 |
jari |
448 |
if(Float.isNaN(this.means[this.clusterIndex][i]) || Float.isNaN(this.variances[this.clusterIndex][i]) || (this.variances[this.clusterIndex][i] < 0.0f)) { |
2 |
26 Feb 07 |
jari |
449 |
continue; |
2 |
26 Feb 07 |
jari |
450 |
} |
2 |
26 Feb 07 |
jari |
451 |
g.drawLine(left+(int)Math.round(i*stepX) , zeroValue - (int)Math.round((this.means[this.clusterIndex][i]-this.variances[this.clusterIndex][i])*factor), |
2 |
26 Feb 07 |
jari |
452 |
left+(int)Math.round(i*stepX) , zeroValue - (int)Math.round((this.means[this.clusterIndex][i]+this.variances[this.clusterIndex][i])*factor)); |
2 |
26 Feb 07 |
jari |
453 |
g.drawLine(left+(int)Math.round(i*stepX)-3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]-this.variances[this.clusterIndex][i])*factor), |
2 |
26 Feb 07 |
jari |
454 |
left+(int)Math.round(i*stepX)+3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]-this.variances[this.clusterIndex][i])*factor)); |
2 |
26 Feb 07 |
jari |
455 |
g.drawLine(left+(int)Math.round(i*stepX)-3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]+this.variances[this.clusterIndex][i])*factor), |
2 |
26 Feb 07 |
jari |
456 |
left+(int)Math.round(i*stepX)+3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]+this.variances[this.clusterIndex][i])*factor)); |
2 |
26 Feb 07 |
jari |
457 |
} |
2 |
26 Feb 07 |
jari |
458 |
} |
2 |
26 Feb 07 |
jari |
459 |
if (this.drawValues) { |
2 |
26 Feb 07 |
jari |
// draw values |
2 |
26 Feb 07 |
jari |
461 |
boolean coloredClusters = false; |
2 |
26 Feb 07 |
jari |
462 |
float fValue, sValue, yInterval, lineHeight; |
2 |
26 Feb 07 |
jari |
463 |
Color color = null; |
2 |
26 Feb 07 |
jari |
464 |
float maxLineHeight = (maxExperimentValue*factor) / 20; //maxExperimentValue is an expression value - not a coordinate length |
2 |
26 Feb 07 |
jari |
465 |
int R=0, G=0, B = 0, intervalNumber; |
2 |
26 Feb 07 |
jari |
466 |
|
2 |
26 Feb 07 |
jari |
467 |
for (int sample=0; sample<getCluster().length; sample++) { |
2 |
26 Feb 07 |
jari |
468 |
for (int probe=0; probe<numberOfGenes-1; probe++) { |
2 |
26 Feb 07 |
jari |
469 |
fValue = this.experiment.get(probe, getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
470 |
sValue = this.experiment.get(probe+1, getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
471 |
if (Float.isNaN(fValue) || Float.isNaN(sValue)) { |
2 |
26 Feb 07 |
jari |
472 |
continue; |
2 |
26 Feb 07 |
jari |
473 |
} |
2 |
26 Feb 07 |
jari |
474 |
if(!gradientColors) { |
2 |
26 Feb 07 |
jari |
475 |
color = this.data.getExperimentColor(getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
476 |
color = color == null ? DEF_CLUSTER_COLOR : color; |
2 |
26 Feb 07 |
jari |
477 |
g.setColor(color); |
2 |
26 Feb 07 |
jari |
478 |
g.drawLine(left+(int)Math.round(probe*stepX), zeroValue - (int)Math.round(fValue*factor), |
2 |
26 Feb 07 |
jari |
479 |
left+(int)Math.round((probe+1)*stepX), zeroValue - (int)Math.round(sValue*factor)); |
2 |
26 Feb 07 |
jari |
480 |
} else { |
2 |
26 Feb 07 |
jari |
481 |
lineHeight = (sValue - fValue)*factor; |
2 |
26 Feb 07 |
jari |
482 |
if (Math.abs(lineHeight) > maxLineHeight) { |
2 |
26 Feb 07 |
jari |
483 |
intervalNumber = Math.abs((int)(lineHeight / maxLineHeight)); |
2 |
26 Feb 07 |
jari |
484 |
} else { |
2 |
26 Feb 07 |
jari |
485 |
intervalNumber = 1; |
2 |
26 Feb 07 |
jari |
486 |
} |
2 |
26 Feb 07 |
jari |
487 |
yInterval = lineHeight/intervalNumber; |
2 |
26 Feb 07 |
jari |
488 |
for(int i=0; i<intervalNumber; i++) { |
2 |
26 Feb 07 |
jari |
489 |
g.setColor(getColor(fValue + (float)(i)*yInterval/factor)); |
2 |
26 Feb 07 |
jari |
490 |
g.drawLine(left+(int)Math.round(probe*stepX + ((float)i/intervalNumber)*stepX), zeroValue - (int)Math.round(fValue*factor + (float)i*yInterval), |
2 |
26 Feb 07 |
jari |
491 |
left+(int)Math.round((probe)*stepX + (((float)i+1)/intervalNumber)*stepX), zeroValue - (int)Math.round(fValue*factor + ((float)i+1)*yInterval)); |
2 |
26 Feb 07 |
jari |
492 |
} |
2 |
26 Feb 07 |
jari |
493 |
} |
2 |
26 Feb 07 |
jari |
494 |
} |
2 |
26 Feb 07 |
jari |
495 |
} |
2 |
26 Feb 07 |
jari |
496 |
} |
2 |
26 Feb 07 |
jari |
/* if (this.drawValues) { |
2 |
26 Feb 07 |
jari |
// draw values |
2 |
26 Feb 07 |
jari |
float fValue, sValue; |
2 |
26 Feb 07 |
jari |
Color color; |
2 |
26 Feb 07 |
jari |
for (int sample=0; sample<getCluster().length; sample++) { |
2 |
26 Feb 07 |
jari |
for (int probe=0; probe<numberOfGenes-1; probe++) { |
2 |
26 Feb 07 |
jari |
fValue = this.experiment.get(probe, getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
sValue = this.experiment.get(probe+1, getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
if (Float.isNaN(fValue) || Float.isNaN(sValue)) { |
2 |
26 Feb 07 |
jari |
continue; |
2 |
26 Feb 07 |
jari |
507 |
} |
2 |
26 Feb 07 |
jari |
color = this.data.getExperimentColor(getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
color = color == null ? DEF_CLUSTER_COLOR : color; |
2 |
26 Feb 07 |
jari |
g.setColor(color); |
2 |
26 Feb 07 |
jari |
g.drawLine(left+(int)Math.round(probe*stepX) , zeroValue - (int)Math.round(fValue*factor), |
2 |
26 Feb 07 |
jari |
left+(int)Math.round((probe+1)*stepX), zeroValue - (int)Math.round(sValue*factor)); |
2 |
26 Feb 07 |
jari |
513 |
} |
2 |
26 Feb 07 |
jari |
514 |
} |
2 |
26 Feb 07 |
jari |
515 |
} |
2 |
26 Feb 07 |
jari |
516 |
*/ |
2 |
26 Feb 07 |
jari |
517 |
if (this.drawCodes && this.codes != null && clusters[clusterIndex].length > 0) { |
2 |
26 Feb 07 |
jari |
518 |
g.setColor(Color.gray); |
2 |
26 Feb 07 |
jari |
519 |
for (int i=0; i<numberOfGenes-1; i++) { |
2 |
26 Feb 07 |
jari |
520 |
g.drawLine(left+(int)Math.round(i*stepX), zeroValue-(int)Math.round(this.codes[this.clusterIndex][i]*factor), left+(int)Math.round((i+1)*stepX), zeroValue-(int)Math.round(this.codes[this.clusterIndex][i+1]*factor)); |
2 |
26 Feb 07 |
jari |
521 |
} |
2 |
26 Feb 07 |
jari |
522 |
} |
2 |
26 Feb 07 |
jari |
523 |
|
2 |
26 Feb 07 |
jari |
// draw zero line |
2 |
26 Feb 07 |
jari |
525 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
526 |
g.drawLine(left, zeroValue, left+width, zeroValue); |
2 |
26 Feb 07 |
jari |
// draw magenta line |
2 |
26 Feb 07 |
jari |
528 |
if (getCluster() != null && getCluster().length > 0) { |
2 |
26 Feb 07 |
jari |
529 |
g.setColor(Color.magenta); |
2 |
26 Feb 07 |
jari |
530 |
for (int i=0; i<numberOfGenes-1; i++) { |
2 |
26 Feb 07 |
jari |
531 |
if (Float.isNaN(this.means[this.clusterIndex][i]) || Float.isNaN(this.means[this.clusterIndex][i+1])) { |
2 |
26 Feb 07 |
jari |
532 |
continue; |
2 |
26 Feb 07 |
jari |
533 |
} |
2 |
26 Feb 07 |
jari |
534 |
g.drawLine(left+(int)Math.round(i*stepX), zeroValue-(int)Math.round(this.means[this.clusterIndex][i]*factor), left+(int)Math.round((i+1)*stepX), zeroValue-(int)Math.round(this.means[this.clusterIndex][i+1]*factor)); |
2 |
26 Feb 07 |
jari |
535 |
} |
2 |
26 Feb 07 |
jari |
536 |
} |
2 |
26 Feb 07 |
jari |
// draw rectangle |
2 |
26 Feb 07 |
jari |
538 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
539 |
g.drawRect(left, top, width, height); |
2 |
26 Feb 07 |
jari |
// draw X items |
2 |
26 Feb 07 |
jari |
541 |
for (int i=1; i<numberOfGenes-1; i++) { |
2 |
26 Feb 07 |
jari |
542 |
g.drawLine(left+(int)Math.round(i*stepX), top+height-5, left+(int)Math.round(i*stepX), top+height); |
2 |
26 Feb 07 |
jari |
543 |
} |
2 |
26 Feb 07 |
jari |
//draw Y items |
2 |
26 Feb 07 |
jari |
545 |
for (int i=1; i<stepsY; i++) { |
2 |
26 Feb 07 |
jari |
546 |
g.drawLine(left, zeroValue-(int)Math.round(i*factor), left+5, zeroValue-(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
547 |
g.drawLine(left, zeroValue+(int)Math.round(i*factor), left+5, zeroValue+(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
// draw genes info |
2 |
26 Feb 07 |
jari |
550 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
/* if (drawMarks) { |
2 |
26 Feb 07 |
jari |
FontMetrics metrics = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
String str; |
2 |
26 Feb 07 |
jari |
int strWidth; |
2 |
26 Feb 07 |
jari |
//draw Y digits |
2 |
26 Feb 07 |
jari |
for (int i=1; i<stepsY; i++) { |
2 |
26 Feb 07 |
jari |
str = String.valueOf(i); |
2 |
26 Feb 07 |
jari |
strWidth = metrics.stringWidth(str); |
2 |
26 Feb 07 |
jari |
g.drawString(str, left-10-strWidth, zeroValue+5-(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
str = String.valueOf(-i); |
2 |
26 Feb 07 |
jari |
strWidth = metrics.stringWidth(str); |
2 |
26 Feb 07 |
jari |
g.drawString(str, left-10-strWidth, zeroValue+5+(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
563 |
} |
2 |
26 Feb 07 |
jari |
// draw X samples names |
2 |
26 Feb 07 |
jari |
g.rotate(-Math.PI/2.0); |
2 |
26 Feb 07 |
jari |
final int max_name_width = getNamesWidth(metrics); |
2 |
26 Feb 07 |
jari |
for (int i=0; i<numberOfSamples; i++) { |
2 |
26 Feb 07 |
jari |
g.drawString(data.getSampleName(experiment.getSampleIndex(getCluster()[i])), -height-top-10-max_name_width, left+(int)Math.round(i*stepX)+3); |
2 |
26 Feb 07 |
jari |
569 |
} |
2 |
26 Feb 07 |
jari |
g.rotate(Math.PI/2.0); |
2 |
26 Feb 07 |
jari |
571 |
} |
2 |
26 Feb 07 |
jari |
572 |
*/ |
2 |
26 Feb 07 |
jari |
573 |
if (getCluster() != null && getCluster().length > 0 && this.drawVariances) { |
2 |
26 Feb 07 |
jari |
// draw points |
2 |
26 Feb 07 |
jari |
575 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
576 |
for (int i=0; i<numberOfGenes; i++) { |
2 |
26 Feb 07 |
jari |
577 |
if (Float.isNaN(this.means[this.clusterIndex][i])) { |
2 |
26 Feb 07 |
jari |
578 |
continue; |
2 |
26 Feb 07 |
jari |
579 |
} |
2 |
26 Feb 07 |
jari |
580 |
g.fillOval(left+(int)Math.round(i*stepX)-3, zeroValue-(int)Math.round(this.means[this.clusterIndex][i]*factor)-3, 6, 6); |
2 |
26 Feb 07 |
jari |
581 |
} |
2 |
26 Feb 07 |
jari |
582 |
} |
2 |
26 Feb 07 |
jari |
583 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
584 |
if (getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
585 |
g.drawString("No Experiments In Cluster", left+10, top+20); |
2 |
26 Feb 07 |
jari |
586 |
} else { |
2 |
26 Feb 07 |
jari |
587 |
if(getCluster().length == 1) |
2 |
26 Feb 07 |
jari |
588 |
g.drawString(1 + " Experiment", left+10, top+20); |
2 |
26 Feb 07 |
jari |
589 |
else |
2 |
26 Feb 07 |
jari |
590 |
g.drawString(getCluster().length+" Experiments", left+10, top+20); |
2 |
26 Feb 07 |
jari |
591 |
} |
2 |
26 Feb 07 |
jari |
592 |
} |
2 |
26 Feb 07 |
jari |
593 |
|
2 |
26 Feb 07 |
jari |
594 |
/** |
2 |
26 Feb 07 |
jari |
* @return null |
2 |
26 Feb 07 |
jari |
596 |
*/ |
2 |
26 Feb 07 |
jari |
597 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
598 |
return null; |
2 |
26 Feb 07 |
jari |
599 |
} |
2 |
26 Feb 07 |
jari |
600 |
|
2 |
26 Feb 07 |
jari |
601 |
/** |
2 |
26 Feb 07 |
jari |
* Updates the viewer data. |
2 |
26 Feb 07 |
jari |
603 |
*/ |
2 |
26 Feb 07 |
jari |
604 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
605 |
setData(data); |
2 |
26 Feb 07 |
jari |
606 |
} |
2 |
26 Feb 07 |
jari |
607 |
|
2 |
26 Feb 07 |
jari |
608 |
/** |
2 |
26 Feb 07 |
jari |
* Updates some viewer attributes. |
2 |
26 Feb 07 |
jari |
610 |
*/ |
2 |
26 Feb 07 |
jari |
611 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
612 |
setAntiAliasing(menu.isAntiAliasing()); |
2 |
26 Feb 07 |
jari |
613 |
this.maxValue = menu.getMaxRatioScale(); |
2 |
26 Feb 07 |
jari |
614 |
this.minValue = menu.getMinRatioScale(); |
2 |
26 Feb 07 |
jari |
615 |
this.midValue = menu.getMidRatioValue(); |
2 |
26 Feb 07 |
jari |
616 |
ExperimentClusterCentroidViewer.posColorImage = menu.getPositiveGradientImage(); |
2 |
26 Feb 07 |
jari |
617 |
ExperimentClusterCentroidViewer.negColorImage = menu.getNegativeGradientImage(); |
2 |
26 Feb 07 |
jari |
618 |
this.gradientColors = menu.getColorGradientState(); |
2 |
26 Feb 07 |
jari |
619 |
} |
2 |
26 Feb 07 |
jari |
620 |
|
2 |
26 Feb 07 |
jari |
621 |
public void onDeselected() {} |
2 |
26 Feb 07 |
jari |
622 |
public void onClosed() {} |
2 |
26 Feb 07 |
jari |
623 |
|
2 |
26 Feb 07 |
jari |
624 |
/** |
2 |
26 Feb 07 |
jari |
* @return null |
2 |
26 Feb 07 |
jari |
626 |
*/ |
2 |
26 Feb 07 |
jari |
627 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
628 |
return null; |
2 |
26 Feb 07 |
jari |
629 |
} |
2 |
26 Feb 07 |
jari |
630 |
|
2 |
26 Feb 07 |
jari |
631 |
/** |
2 |
26 Feb 07 |
jari |
* Calculate experiment max value for scale purpose. |
2 |
26 Feb 07 |
jari |
633 |
*/ |
2 |
26 Feb 07 |
jari |
634 |
private float calculateMaxValue(int[] samples) { |
2 |
26 Feb 07 |
jari |
635 |
float max = 0f; |
2 |
26 Feb 07 |
jari |
636 |
float value; |
2 |
26 Feb 07 |
jari |
637 |
final int numGenes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
638 |
for (int gene=0; gene<numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
639 |
for (int sample=0; sample<samples.length; sample++) { |
2 |
26 Feb 07 |
jari |
640 |
value = experiment.get(gene, samples[sample]); |
2 |
26 Feb 07 |
jari |
641 |
if (!Float.isNaN(value)) { |
2 |
26 Feb 07 |
jari |
642 |
max = Math.max(max, Math.abs(value)); |
2 |
26 Feb 07 |
jari |
643 |
} |
2 |
26 Feb 07 |
jari |
644 |
} |
2 |
26 Feb 07 |
jari |
645 |
} |
2 |
26 Feb 07 |
jari |
646 |
return max; |
2 |
26 Feb 07 |
jari |
647 |
} |
2 |
26 Feb 07 |
jari |
648 |
|
2 |
26 Feb 07 |
jari |
649 |
/** |
2 |
26 Feb 07 |
jari |
* Returns max width of experiment names. |
2 |
26 Feb 07 |
jari |
651 |
*/ |
2 |
26 Feb 07 |
jari |
652 |
protected int getNamesWidth(FontMetrics metrics) { |
2 |
26 Feb 07 |
jari |
653 |
int maxWidth = 0; |
2 |
26 Feb 07 |
jari |
654 |
for (int i=0; i<experiment.getNumberOfSamples(); i++) { |
2 |
26 Feb 07 |
jari |
655 |
maxWidth = Math.max(maxWidth, metrics.stringWidth(data.getSampleName(experiment.getSampleIndex(i)))); |
2 |
26 Feb 07 |
jari |
656 |
} |
2 |
26 Feb 07 |
jari |
657 |
return maxWidth; |
2 |
26 Feb 07 |
jari |
658 |
} |
2 |
26 Feb 07 |
jari |
659 |
|
2 |
26 Feb 07 |
jari |
660 |
/** |
2 |
26 Feb 07 |
jari |
* Adds viewer specific menu items. |
2 |
26 Feb 07 |
jari |
662 |
*/ |
2 |
26 Feb 07 |
jari |
663 |
protected void addMenuItems(JPopupMenu menu, ActionListener listener) { |
2 |
26 Feb 07 |
jari |
664 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
665 |
menuItem = new JMenuItem("Store cluster", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
666 |
menuItem.setActionCommand(STORE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
667 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
668 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
669 |
|
2 |
26 Feb 07 |
jari |
670 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
671 |
|
2 |
26 Feb 07 |
jari |
672 |
menuItem = new JMenuItem("Launch new session", GUIFactory.getIcon("lanuch_new_mav.gif")); |
2 |
26 Feb 07 |
jari |
673 |
menuItem.setActionCommand(LAUNCH_NEW_SESSION_CMD); |
2 |
26 Feb 07 |
jari |
674 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
675 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
676 |
|
2 |
26 Feb 07 |
jari |
677 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
678 |
|
2 |
26 Feb 07 |
jari |
679 |
menuItem = new JMenuItem("Delete public cluster", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
680 |
menuItem.setActionCommand(SET_DEF_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
681 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
682 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
683 |
|
2 |
26 Feb 07 |
jari |
684 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
685 |
|
2 |
26 Feb 07 |
jari |
686 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
687 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
688 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
689 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
690 |
|
2 |
26 Feb 07 |
jari |
691 |
menuItem = new JMenuItem("Save all clusters...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
692 |
menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
693 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
694 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
695 |
|
2 |
26 Feb 07 |
jari |
696 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
697 |
|
2 |
26 Feb 07 |
jari |
698 |
setOverallMaxMenuItem = new JMenuItem("Set Y to overall max...", GUIFactory.getIcon("Y_range_expand.gif")); |
2 |
26 Feb 07 |
jari |
699 |
setOverallMaxMenuItem.setActionCommand(SET_Y_TO_EXPERIMENT_MAX_CMD); |
2 |
26 Feb 07 |
jari |
700 |
setOverallMaxMenuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
701 |
setOverallMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
702 |
menu.add(setOverallMaxMenuItem); |
2 |
26 Feb 07 |
jari |
703 |
|
2 |
26 Feb 07 |
jari |
704 |
setClusterMaxMenuItem = new JMenuItem("Set Y to cluster max...", GUIFactory.getIcon("Y_range_expand.gif")); |
2 |
26 Feb 07 |
jari |
705 |
setClusterMaxMenuItem.setActionCommand(SET_Y_TO_CLUSTER_MAX_CMD); |
2 |
26 Feb 07 |
jari |
706 |
setClusterMaxMenuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
707 |
menu.add(setClusterMaxMenuItem); |
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
// menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
710 |
|
2 |
26 Feb 07 |
jari |
// menuItem = new JMenuItem("Toggle reference line..."); |
2 |
26 Feb 07 |
jari |
// menuItem.setActionCommand(TOGGLE_REF_LINE_CMD); |
2 |
26 Feb 07 |
jari |
// menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
// menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
715 |
} |
2 |
26 Feb 07 |
jari |
716 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
718 |
*/ |
2 |
26 Feb 07 |
jari |
719 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
720 |
return null; |
2 |
26 Feb 07 |
jari |
721 |
} |
2 |
26 Feb 07 |
jari |
722 |
|
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 |
725 |
*/ |
2 |
26 Feb 07 |
jari |
726 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
727 |
return null; |
2 |
26 Feb 07 |
jari |
728 |
} |
2 |
26 Feb 07 |
jari |
729 |
|
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 |
732 |
*/ |
2 |
26 Feb 07 |
jari |
733 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
734 |
return Cluster.EXPERIMENT_CLUSTER; |
2 |
26 Feb 07 |
jari |
735 |
} |
2 |
26 Feb 07 |
jari |
736 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperiment(org.tigr.microarray.mev.cluster.gui.Experiment) |
2 |
26 Feb 07 |
jari |
739 |
*/ |
2 |
26 Feb 07 |
jari |
740 |
public void setExperiment(Experiment e) { |
2 |
26 Feb 07 |
jari |
741 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
742 |
this.exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
743 |
numberOfGenes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
744 |
this.maxExperimentValue = experiment.getMaxAbsValue(); |
2 |
26 Feb 07 |
jari |
745 |
} |
2 |
26 Feb 07 |
jari |
746 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#getExperimentID() |
2 |
26 Feb 07 |
jari |
749 |
*/ |
2 |
26 Feb 07 |
jari |
750 |
public int getExperimentID() { |
2 |
26 Feb 07 |
jari |
751 |
return exptID; |
2 |
26 Feb 07 |
jari |
752 |
} |
2 |
26 Feb 07 |
jari |
753 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperimentID(int) |
2 |
26 Feb 07 |
jari |
756 |
*/ |
2 |
26 Feb 07 |
jari |
757 |
public void setExperimentID(int id) { |
2 |
26 Feb 07 |
jari |
758 |
this.exptID = id; |
2 |
26 Feb 07 |
jari |
759 |
} |
2 |
26 Feb 07 |
jari |
760 |
|
2 |
26 Feb 07 |
jari |
761 |
} |
2 |
26 Feb 07 |
jari |
762 |
|