2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, 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: PTMExperimentCentroidViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.7 $ |
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.impl.ptm; |
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.FontMetrics; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Frame; |
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.ActionEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
25 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
26 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JColorChooser; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
31 |
|
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.helpers.CentroidViewer; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterCentroidViewer; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentUtil; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
public class PTMExperimentCentroidViewer extends ExperimentClusterCentroidViewer { |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
42 |
private Vector templateVector; |
2 |
26 Feb 07 |
jari |
43 |
private int numberOfGenes; |
2 |
26 Feb 07 |
jari |
44 |
private String[] auxTitles; |
2 |
26 Feb 07 |
jari |
45 |
private Object[][] auxData; |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
/** |
2 |
26 Feb 07 |
jari |
* Construct a <code>PTMExperimentCentroidViewer</code> with specified experiment |
2 |
26 Feb 07 |
jari |
* and clusters. |
2 |
26 Feb 07 |
jari |
50 |
*/ |
2 |
26 Feb 07 |
jari |
51 |
public PTMExperimentCentroidViewer(Experiment experiment, int[][] clusters, Vector templateVector, String[] auxTitles, Object[][] auxData) { |
2 |
26 Feb 07 |
jari |
52 |
super(experiment, clusters); |
2 |
26 Feb 07 |
jari |
53 |
this.numberOfGenes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
54 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
55 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
56 |
this.templateVector = templateVector; |
2 |
26 Feb 07 |
jari |
57 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
58 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
59 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
/** |
2 |
26 Feb 07 |
jari |
* @inheritDoc |
2 |
26 Feb 07 |
jari |
64 |
*/ |
2 |
26 Feb 07 |
jari |
65 |
public PTMExperimentCentroidViewer(Experiment experiment, int[][] clusters, Integer clusterIndex, float[][] means, float[][] variances, float[][] codes, |
2 |
26 Feb 07 |
jari |
66 |
Vector templateVector, String[] auxTitles, Object[][] auxData){ |
2 |
26 Feb 07 |
jari |
67 |
super(experiment, clusters, clusterIndex, means, variances, codes); |
2 |
26 Feb 07 |
jari |
68 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
69 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
70 |
this.templateVector = templateVector; |
2 |
26 Feb 07 |
jari |
71 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
72 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
73 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
74 |
} |
2 |
26 Feb 07 |
jari |
75 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
76 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
77 |
new Object[]{this.clusters, new Integer(this.getExperimentID()), new Integer(this.clusterIndex), this.means, this.variances, this.codes, this.templateVector, this.auxTitles, this.auxData}); |
2 |
26 Feb 07 |
jari |
78 |
} |
2 |
26 Feb 07 |
jari |
79 |
public void setExperiment(Experiment e){ |
2 |
26 Feb 07 |
jari |
80 |
super.setExperiment(e); |
2 |
26 Feb 07 |
jari |
81 |
this.numberOfGenes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
82 |
} |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
86 |
*/ |
2 |
26 Feb 07 |
jari |
87 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
88 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
89 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
90 |
return popup; |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
94 |
/** |
2 |
26 Feb 07 |
jari |
* Saves all clusters. |
2 |
26 Feb 07 |
jari |
96 |
*/ |
2 |
26 Feb 07 |
jari |
97 |
private void onSaveClusters() { |
2 |
26 Feb 07 |
jari |
98 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
99 |
try { |
2 |
26 Feb 07 |
jari |
100 |
ExperimentUtil.saveAllExperimentClustersWithAux(frame, getExperiment(), getData(), getClusters(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
101 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
102 |
JOptionPane.showMessageDialog(frame, "Can not save clusters!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
103 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
104 |
} |
2 |
26 Feb 07 |
jari |
105 |
} |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
/** |
2 |
26 Feb 07 |
jari |
* Save the viewer cluster. |
2 |
26 Feb 07 |
jari |
109 |
*/ |
2 |
26 Feb 07 |
jari |
110 |
private void onSaveCluster() { |
2 |
26 Feb 07 |
jari |
111 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
112 |
try { |
2 |
26 Feb 07 |
jari |
113 |
ExperimentUtil.saveExperimentClusterWithAux(frame, getExperiment(), getData(), getCluster(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
114 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
115 |
JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
116 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a public color. |
2 |
26 Feb 07 |
jari |
122 |
*/ |
2 |
26 Feb 07 |
jari |
123 |
private void onSetColor() { |
2 |
26 Feb 07 |
jari |
124 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
125 |
Color newColor = JColorChooser.showDialog(frame, "Choose color", DEF_CLUSTER_COLOR); |
2 |
26 Feb 07 |
jari |
126 |
if (newColor != null) { |
2 |
26 Feb 07 |
jari |
127 |
setClusterColor(newColor); |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
} |
2 |
26 Feb 07 |
jari |
130 |
|
2 |
26 Feb 07 |
jari |
131 |
/** |
2 |
26 Feb 07 |
jari |
* Removes a public color. |
2 |
26 Feb 07 |
jari |
133 |
*/ |
2 |
26 Feb 07 |
jari |
134 |
private void onSetDefaultColor() { |
2 |
26 Feb 07 |
jari |
135 |
setClusterColor(null); |
2 |
26 Feb 07 |
jari |
136 |
} |
2 |
26 Feb 07 |
jari |
137 |
|
2 |
26 Feb 07 |
jari |
138 |
/** |
2 |
26 Feb 07 |
jari |
* Paints chart into specified graphics. |
2 |
26 Feb 07 |
jari |
140 |
*/ |
2 |
26 Feb 07 |
jari |
141 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
142 |
FontMetrics metrics = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
143 |
Rectangle rect = new Rectangle(40, 20, getWidth()-80, getHeight() - 40 - getNamesWidth(metrics)); |
2 |
26 Feb 07 |
jari |
144 |
paint((Graphics2D)g, rect, true); |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
/** |
2 |
26 Feb 07 |
jari |
* Paints chart into specified graphics and with specified bounds. |
2 |
26 Feb 07 |
jari |
150 |
*/ |
2 |
26 Feb 07 |
jari |
151 |
public void paint(Graphics2D g, Rectangle rect, boolean drawMarks) { |
2 |
26 Feb 07 |
jari |
152 |
super.subPaint(g,rect,drawMarks); |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
if (isAntiAliasing) { |
2 |
26 Feb 07 |
jari |
155 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
156 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
157 |
} |
2 |
26 Feb 07 |
jari |
158 |
|
2 |
26 Feb 07 |
jari |
159 |
final int left = rect.x; |
2 |
26 Feb 07 |
jari |
160 |
final int top = rect.y; |
2 |
26 Feb 07 |
jari |
161 |
final int width = rect.width; |
2 |
26 Feb 07 |
jari |
162 |
final int height = rect.height; |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
if (width < 5 || height < 5) { |
2 |
26 Feb 07 |
jari |
165 |
return; |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
final int zeroValue = top + (int)Math.round(height/2f); |
2 |
26 Feb 07 |
jari |
169 |
final int numberOfSamples = this.getCluster().length; |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
//do this outside paint once menu is set up |
2 |
26 Feb 07 |
jari |
172 |
if(this.yRangeOption == PTMExperimentCentroidViewer.USE_EXPERIMENT_MAX) |
2 |
26 Feb 07 |
jari |
173 |
maxYValue = this.maxExperimentValue; |
2 |
26 Feb 07 |
jari |
174 |
else if(this.yRangeOption == PTMExperimentCentroidViewer.USE_CLUSTER_MAX) |
2 |
26 Feb 07 |
jari |
175 |
maxYValue = this.maxClusterValue; |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
if (maxYValue == 0.0f) { |
2 |
26 Feb 07 |
jari |
178 |
maxYValue = 1.0f; |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
|
2 |
26 Feb 07 |
jari |
181 |
final float factor = height/(2f*maxYValue); |
2 |
26 Feb 07 |
jari |
182 |
final float stepX = width/(float)(numberOfGenes-1); |
2 |
26 Feb 07 |
jari |
183 |
final int stepsY = (int)maxYValue+1; |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
if (this.drawVariances) { |
2 |
26 Feb 07 |
jari |
// draw variances |
2 |
26 Feb 07 |
jari |
187 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
188 |
for (int i=0; i<numberOfGenes; i++) { |
2 |
26 Feb 07 |
jari |
189 |
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 |
190 |
continue; |
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
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 |
193 |
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 |
194 |
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 |
195 |
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 |
196 |
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 |
197 |
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 |
198 |
} |
2 |
26 Feb 07 |
jari |
199 |
} |
2 |
26 Feb 07 |
jari |
200 |
if (this.drawValues) { |
2 |
26 Feb 07 |
jari |
// draw values |
2 |
26 Feb 07 |
jari |
202 |
float fValue, sValue; |
2 |
26 Feb 07 |
jari |
203 |
Color color; |
2 |
26 Feb 07 |
jari |
204 |
for (int sample=0; sample<getCluster().length; sample++) { |
2 |
26 Feb 07 |
jari |
205 |
for (int probe=0; probe<numberOfGenes-1; probe++) { |
2 |
26 Feb 07 |
jari |
206 |
fValue = this.experiment.get(probe, getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
207 |
sValue = this.experiment.get(probe+1, getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
208 |
if (Float.isNaN(fValue) || Float.isNaN(sValue)) { |
2 |
26 Feb 07 |
jari |
209 |
continue; |
2 |
26 Feb 07 |
jari |
210 |
} |
2 |
26 Feb 07 |
jari |
211 |
color = this.data.getExperimentColor(getCluster()[sample]); |
2 |
26 Feb 07 |
jari |
212 |
color = color == null ? DEF_CLUSTER_COLOR : color; |
2 |
26 Feb 07 |
jari |
213 |
g.setColor(color); |
2 |
26 Feb 07 |
jari |
214 |
g.drawLine(left+(int)Math.round(probe*stepX) , zeroValue - (int)Math.round(fValue*factor), |
2 |
26 Feb 07 |
jari |
215 |
left+(int)Math.round((probe+1)*stepX), zeroValue - (int)Math.round(sValue*factor)); |
2 |
26 Feb 07 |
jari |
216 |
} |
2 |
26 Feb 07 |
jari |
217 |
} |
2 |
26 Feb 07 |
jari |
218 |
} |
2 |
26 Feb 07 |
jari |
219 |
|
2 |
26 Feb 07 |
jari |
220 |
if (this.drawCodes && this.codes != null && clusters[clusterIndex].length > 0) { |
2 |
26 Feb 07 |
jari |
221 |
g.setColor(Color.gray); |
2 |
26 Feb 07 |
jari |
222 |
for (int i=0; i<numberOfGenes-1; i++) { |
2 |
26 Feb 07 |
jari |
223 |
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 |
224 |
} |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
// draw zero line |
2 |
26 Feb 07 |
jari |
228 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
229 |
g.drawLine(left, zeroValue, left+width, zeroValue); |
2 |
26 Feb 07 |
jari |
// draw magenta line |
2 |
26 Feb 07 |
jari |
231 |
if (getCluster() != null && getCluster().length > 0) { |
2 |
26 Feb 07 |
jari |
232 |
g.setColor(Color.magenta); |
2 |
26 Feb 07 |
jari |
233 |
for (int i=0; i<numberOfGenes-1; i++) { |
2 |
26 Feb 07 |
jari |
234 |
if (Float.isNaN(this.means[this.clusterIndex][i]) || Float.isNaN(this.means[this.clusterIndex][i+1])) { |
2 |
26 Feb 07 |
jari |
235 |
continue; |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
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 |
238 |
} |
2 |
26 Feb 07 |
jari |
239 |
} |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
|
2 |
26 Feb 07 |
jari |
//draw template |
2 |
26 Feb 07 |
jari |
245 |
float[] templateArray = new float[templateVector.size()]; |
2 |
26 Feb 07 |
jari |
246 |
|
2 |
26 Feb 07 |
jari |
247 |
for (int i = 0; i < templateArray.length; i++){ |
2 |
26 Feb 07 |
jari |
248 |
templateArray[i] = ((Float)(templateVector.get(i))).floatValue(); |
2 |
26 Feb 07 |
jari |
249 |
} |
2 |
26 Feb 07 |
jari |
250 |
for (int i = 0; i < templateArray.length; i++){ |
2 |
26 Feb 07 |
jari |
251 |
templateArray[i] = templateArray[i] - 0.5f; |
2 |
26 Feb 07 |
jari |
252 |
} |
2 |
26 Feb 07 |
jari |
253 |
|
2 |
26 Feb 07 |
jari |
254 |
for (int i = 0; i < numberOfGenes - 1; i++) { |
2 |
26 Feb 07 |
jari |
255 |
g.setColor(Color.red); |
2 |
26 Feb 07 |
jari |
256 |
if (!Float.isNaN(templateArray[i])) { |
2 |
26 Feb 07 |
jari |
257 |
g.fillOval(left+(int)Math.round(i*stepX) - 2, zeroValue-(int)Math.round(templateArray[i]*factor) - 2, 5, 5); |
2 |
26 Feb 07 |
jari |
258 |
} |
2 |
26 Feb 07 |
jari |
259 |
if (!Float.isNaN(templateArray[i+1])) { |
2 |
26 Feb 07 |
jari |
260 |
g.fillOval(left+(int)Math.round((i+1)*stepX) - 2, zeroValue-(int)Math.round(templateArray[i+1]*factor) - 2, 5, 5); |
2 |
26 Feb 07 |
jari |
261 |
} |
2 |
26 Feb 07 |
jari |
262 |
if (Float.isNaN(templateArray[i]) || Float.isNaN(templateArray[i+1])) { |
2 |
26 Feb 07 |
jari |
263 |
continue; |
2 |
26 Feb 07 |
jari |
264 |
} |
2 |
26 Feb 07 |
jari |
265 |
g.setColor(Color.blue); |
2 |
26 Feb 07 |
jari |
266 |
g.drawLine(left+(int)Math.round(i*stepX), zeroValue-(int)Math.round(templateArray[i]*factor), left+(int)Math.round((i+1)*stepX), zeroValue-(int)Math.round(templateArray[i+1]*factor)); |
2 |
26 Feb 07 |
jari |
267 |
} |
2 |
26 Feb 07 |
jari |
268 |
|
2 |
26 Feb 07 |
jari |
269 |
|
2 |
26 Feb 07 |
jari |
270 |
|
2 |
26 Feb 07 |
jari |
271 |
|
2 |
26 Feb 07 |
jari |
272 |
|
2 |
26 Feb 07 |
jari |
273 |
|
2 |
26 Feb 07 |
jari |
274 |
|
2 |
26 Feb 07 |
jari |
275 |
|
2 |
26 Feb 07 |
jari |
276 |
|
2 |
26 Feb 07 |
jari |
277 |
|
2 |
26 Feb 07 |
jari |
278 |
|
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
280 |
|
2 |
26 Feb 07 |
jari |
281 |
|
2 |
26 Feb 07 |
jari |
// draw rectangle |
2 |
26 Feb 07 |
jari |
283 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
284 |
g.drawRect(left, top, width, height); |
2 |
26 Feb 07 |
jari |
// draw X items |
2 |
26 Feb 07 |
jari |
286 |
for (int i=1; i<numberOfGenes-1; i++) { |
2 |
26 Feb 07 |
jari |
287 |
g.drawLine(left+(int)Math.round(i*stepX), top+height-5, left+(int)Math.round(i*stepX), top+height); |
2 |
26 Feb 07 |
jari |
288 |
} |
2 |
26 Feb 07 |
jari |
//draw Y items |
2 |
26 Feb 07 |
jari |
290 |
for (int i=1; i<stepsY; i++) { |
2 |
26 Feb 07 |
jari |
291 |
g.drawLine(left, zeroValue-(int)Math.round(i*factor), left+5, zeroValue-(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
292 |
g.drawLine(left, zeroValue+(int)Math.round(i*factor), left+5, zeroValue+(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
293 |
} |
2 |
26 Feb 07 |
jari |
// draw genes info |
2 |
26 Feb 07 |
jari |
295 |
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 |
308 |
} |
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 |
314 |
} |
2 |
26 Feb 07 |
jari |
g.rotate(Math.PI/2.0); |
2 |
26 Feb 07 |
jari |
316 |
} |
2 |
26 Feb 07 |
jari |
317 |
*/ |
2 |
26 Feb 07 |
jari |
318 |
if (getCluster() != null && getCluster().length > 0 && this.drawVariances) { |
2 |
26 Feb 07 |
jari |
// draw points |
2 |
26 Feb 07 |
jari |
320 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
321 |
for (int i=0; i<numberOfGenes; i++) { |
2 |
26 Feb 07 |
jari |
322 |
if (Float.isNaN(this.means[this.clusterIndex][i])) { |
2 |
26 Feb 07 |
jari |
323 |
continue; |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
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 |
326 |
} |
2 |
26 Feb 07 |
jari |
327 |
} |
2 |
26 Feb 07 |
jari |
328 |
|
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
330 |
|
2 |
26 Feb 07 |
jari |
331 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
332 |
if (getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
333 |
g.drawString("No Experiments In Cluster", left+10, top+20); |
2 |
26 Feb 07 |
jari |
334 |
} else { |
2 |
26 Feb 07 |
jari |
335 |
if(getCluster().length == 1) |
2 |
26 Feb 07 |
jari |
336 |
g.drawString(1 + " Experiment", left+10, top+20); |
2 |
26 Feb 07 |
jari |
337 |
else |
2 |
26 Feb 07 |
jari |
338 |
g.drawString(getCluster().length+" Experiments", left+10, top+20); |
2 |
26 Feb 07 |
jari |
339 |
} |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
342 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse and action events. |
2 |
26 Feb 07 |
jari |
344 |
*/ |
2 |
26 Feb 07 |
jari |
345 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
346 |
|
2 |
26 Feb 07 |
jari |
347 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
348 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
349 |
if (command.equals(SAVE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
350 |
onSaveCluster(); |
2 |
26 Feb 07 |
jari |
351 |
} else if (command.equals(SAVE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
352 |
onSaveClusters(); |
2 |
26 Feb 07 |
jari |
353 |
} else if (command.equals(SET_DEF_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
354 |
onSetDefaultColor(); |
2 |
26 Feb 07 |
jari |
355 |
} else if(command.equals(SET_Y_TO_EXPERIMENT_MAX_CMD)){ |
2 |
26 Feb 07 |
jari |
356 |
yRangeOption = CentroidViewer.USE_EXPERIMENT_MAX; |
2 |
26 Feb 07 |
jari |
357 |
setClusterMaxMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
358 |
setOverallMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
359 |
repaint(); |
2 |
26 Feb 07 |
jari |
360 |
} else if(command.equals(SET_Y_TO_CLUSTER_MAX_CMD)){ |
2 |
26 Feb 07 |
jari |
361 |
yRangeOption = CentroidViewer.USE_CLUSTER_MAX; |
2 |
26 Feb 07 |
jari |
362 |
setClusterMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
363 |
setOverallMaxMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
364 |
repaint(); |
2 |
26 Feb 07 |
jari |
365 |
} else if (command.equals(STORE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
366 |
storeCluster(); |
2 |
26 Feb 07 |
jari |
367 |
} else if(command.equals(LAUNCH_NEW_SESSION_CMD)){ |
2 |
26 Feb 07 |
jari |
368 |
launchNewSession(); |
2 |
26 Feb 07 |
jari |
369 |
} |
2 |
26 Feb 07 |
jari |
370 |
} |
2 |
26 Feb 07 |
jari |
371 |
|
2 |
26 Feb 07 |
jari |
372 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
373 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
374 |
} |
2 |
26 Feb 07 |
jari |
375 |
|
2 |
26 Feb 07 |
jari |
376 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
377 |
if (!e.isPopupTrigger() || getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
378 |
return; |
2 |
26 Feb 07 |
jari |
379 |
} |
2 |
26 Feb 07 |
jari |
380 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
381 |
} |
2 |
26 Feb 07 |
jari |
382 |
} |
2 |
26 Feb 07 |
jari |
383 |
|
2 |
26 Feb 07 |
jari |
384 |
} |