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: PTMCentroidViewer.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.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.ExperimentUtil; |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
public class PTMCentroidViewer extends CentroidViewer { |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
39 |
private Vector templateVector; |
2 |
26 Feb 07 |
jari |
40 |
private String[] auxTitles; |
2 |
26 Feb 07 |
jari |
41 |
private Object[][] auxData; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
/** |
2 |
26 Feb 07 |
jari |
* Construct a <code>PTMCentroidViewer</code> with specified experiment |
2 |
26 Feb 07 |
jari |
* and clusters. |
2 |
26 Feb 07 |
jari |
46 |
*/ |
2 |
26 Feb 07 |
jari |
47 |
public PTMCentroidViewer(Experiment experiment, int[][] clusters, Vector templateVector, String[] auxTitles, Object[][] auxData) { |
2 |
26 Feb 07 |
jari |
48 |
super(experiment, clusters); |
2 |
26 Feb 07 |
jari |
49 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
50 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
51 |
this.templateVector = templateVector; |
2 |
26 Feb 07 |
jari |
52 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
53 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
54 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
55 |
} |
2 |
26 Feb 07 |
jari |
56 |
/** |
2 |
26 Feb 07 |
jari |
* @inheritDoc |
2 |
26 Feb 07 |
jari |
58 |
*/ |
2 |
26 Feb 07 |
jari |
59 |
public PTMCentroidViewer(Experiment e, int[][] clusters, float[][] variances, float[][] means, float[][] codes, Vector templateVector, String[] auxTitles, Object[][] auxData) { |
2 |
26 Feb 07 |
jari |
60 |
super(e, clusters, variances, means, codes); |
2 |
26 Feb 07 |
jari |
61 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
62 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
63 |
this.templateVector = templateVector; |
2 |
26 Feb 07 |
jari |
64 |
} |
2 |
26 Feb 07 |
jari |
65 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
66 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
67 |
new Object[]{this.experiment, this.clusters, this.variances, this.means, this.codes, this.templateVector, this.auxTitles, this.auxData}); |
2 |
26 Feb 07 |
jari |
68 |
} |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
72 |
*/ |
2 |
26 Feb 07 |
jari |
73 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
74 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
75 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
76 |
return popup; |
2 |
26 Feb 07 |
jari |
77 |
} |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
/** |
2 |
26 Feb 07 |
jari |
* Saves all clusters. |
2 |
26 Feb 07 |
jari |
81 |
*/ |
2 |
26 Feb 07 |
jari |
82 |
private void onSaveClusters() { |
2 |
26 Feb 07 |
jari |
83 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
84 |
try { |
2 |
26 Feb 07 |
jari |
85 |
ExperimentUtil.saveAllGeneClustersWithAux(frame, getExperiment(), getData(), getClusters(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
86 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
87 |
JOptionPane.showMessageDialog(frame, "Can not save clusters!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
88 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
89 |
} |
2 |
26 Feb 07 |
jari |
90 |
} |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
92 |
/** |
2 |
26 Feb 07 |
jari |
* Save the viewer cluster. |
2 |
26 Feb 07 |
jari |
94 |
*/ |
2 |
26 Feb 07 |
jari |
95 |
private void onSaveCluster() { |
2 |
26 Feb 07 |
jari |
96 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
97 |
try { |
2 |
26 Feb 07 |
jari |
98 |
ExperimentUtil.saveGeneClusterWithAux(frame, getExperiment(), getData(), getCluster(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
99 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
100 |
JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
101 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
102 |
} |
2 |
26 Feb 07 |
jari |
103 |
} |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a public color. |
2 |
26 Feb 07 |
jari |
107 |
*/ |
2 |
26 Feb 07 |
jari |
108 |
private void onSetColor() { |
2 |
26 Feb 07 |
jari |
109 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
110 |
Color newColor = JColorChooser.showDialog(frame, "Choose color", DEF_CLUSTER_COLOR); |
2 |
26 Feb 07 |
jari |
111 |
if (newColor != null) { |
2 |
26 Feb 07 |
jari |
112 |
setClusterColor(newColor); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
/** |
2 |
26 Feb 07 |
jari |
* Removes a public color. |
2 |
26 Feb 07 |
jari |
118 |
*/ |
2 |
26 Feb 07 |
jari |
119 |
private void onSetDefaultColor() { |
2 |
26 Feb 07 |
jari |
120 |
setClusterColor(null); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
/** |
2 |
26 Feb 07 |
jari |
* Paints chart into specified graphics. |
2 |
26 Feb 07 |
jari |
125 |
*/ |
2 |
26 Feb 07 |
jari |
126 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
127 |
FontMetrics metrics = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
128 |
Rectangle rect = new Rectangle(40, 20, getWidth()-80, getHeight() - 40 - getNamesWidth(metrics)); |
2 |
26 Feb 07 |
jari |
129 |
paint((Graphics2D)g, rect, true); |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
/** |
2 |
26 Feb 07 |
jari |
* Paints chart into specified graphics and with specified bounds. |
2 |
26 Feb 07 |
jari |
134 |
*/ |
2 |
26 Feb 07 |
jari |
135 |
public void paint(Graphics2D g, Rectangle rect, boolean drawMarks) { |
2 |
26 Feb 07 |
jari |
136 |
super.subPaint(g, rect, drawMarks); |
2 |
26 Feb 07 |
jari |
137 |
|
2 |
26 Feb 07 |
jari |
138 |
if (isAntiAliasing) { |
2 |
26 Feb 07 |
jari |
139 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
140 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
141 |
} |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
final int left = rect.x; |
2 |
26 Feb 07 |
jari |
144 |
final int top = rect.y; |
2 |
26 Feb 07 |
jari |
145 |
final int width = rect.width; |
2 |
26 Feb 07 |
jari |
146 |
final int height = rect.height; |
2 |
26 Feb 07 |
jari |
147 |
if (width < 5 || height < 5) { |
2 |
26 Feb 07 |
jari |
148 |
return; |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
|
2 |
26 Feb 07 |
jari |
151 |
final int zeroValue = top + (int)Math.round(height/2f); |
2 |
26 Feb 07 |
jari |
152 |
final int numberOfSamples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("maxYValue = " + maxYValue); |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
if(yRangeOption == CentroidViewer.USE_EXPERIMENT_MAX) |
2 |
26 Feb 07 |
jari |
157 |
maxYValue = maxExperimentValue; |
2 |
26 Feb 07 |
jari |
158 |
else if(this.yRangeOption == CentroidViewer.USE_CLUSTER_MAX) |
2 |
26 Feb 07 |
jari |
159 |
maxYValue = maxClusterValue; |
2 |
26 Feb 07 |
jari |
160 |
|
2 |
26 Feb 07 |
jari |
161 |
if (maxYValue == 0) { |
2 |
26 Feb 07 |
jari |
162 |
maxYValue = 1; |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
final float factor = height/(2f*maxYValue); |
2 |
26 Feb 07 |
jari |
166 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("factor = " + factor); |
2 |
26 Feb 07 |
jari |
168 |
final float stepX = width/(float)(numberOfSamples-1); |
2 |
26 Feb 07 |
jari |
169 |
final int stepsY = (int)maxYValue+1; |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
if (this.drawVariances /*&& clusters[clusterIndex].length > 0*/) { |
2 |
26 Feb 07 |
jari |
// draw variances |
2 |
26 Feb 07 |
jari |
173 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
174 |
for (int i=0; i<numberOfSamples; i++) { |
2 |
26 Feb 07 |
jari |
//System.out.println("(this.means[this.clusterIndex][" + i + "] = " + this.means[this.clusterIndex][i]); |
2 |
26 Feb 07 |
jari |
//System.out.println("this.variances[this.clusterIndex][" + i + "] = " + this.variances[this.clusterIndex][i]); |
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
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 |
179 |
continue; |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
|
2 |
26 Feb 07 |
jari |
182 |
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 |
183 |
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 |
184 |
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 |
185 |
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 |
186 |
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 |
187 |
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 |
188 |
} |
2 |
26 Feb 07 |
jari |
189 |
} |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: After if(drawVariances)"); |
2 |
26 Feb 07 |
jari |
192 |
|
2 |
26 Feb 07 |
jari |
193 |
if (this.drawValues /*&& clusters[clusterIndex].length > 0*/) { |
2 |
26 Feb 07 |
jari |
// draw values |
2 |
26 Feb 07 |
jari |
195 |
float fValue, sValue; |
2 |
26 Feb 07 |
jari |
196 |
Color color; |
2 |
26 Feb 07 |
jari |
197 |
for (int sample=0; sample<numberOfSamples-1; sample++) { |
2 |
26 Feb 07 |
jari |
198 |
for (int probe=0; probe<getCluster().length; probe++) { |
2 |
26 Feb 07 |
jari |
199 |
fValue = this.experiment.get(getProbe(probe), sample); |
2 |
26 Feb 07 |
jari |
200 |
sValue = this.experiment.get(getProbe(probe), sample+1); |
2 |
26 Feb 07 |
jari |
201 |
if (Float.isNaN(fValue) || Float.isNaN(sValue)) { |
2 |
26 Feb 07 |
jari |
202 |
continue; |
2 |
26 Feb 07 |
jari |
203 |
} |
2 |
26 Feb 07 |
jari |
204 |
color = this.data.getProbeColor(this.experiment.getGeneIndexMappedToData(getProbe(probe))); |
2 |
26 Feb 07 |
jari |
205 |
color = color == null ? DEF_CLUSTER_COLOR : color; |
2 |
26 Feb 07 |
jari |
206 |
g.setColor(color); |
2 |
26 Feb 07 |
jari |
207 |
g.drawLine(left+(int)Math.round(sample*stepX) , zeroValue - (int)Math.round(fValue*factor), |
2 |
26 Feb 07 |
jari |
208 |
left+(int)Math.round((sample+1)*stepX), zeroValue - (int)Math.round(sValue*factor)); |
2 |
26 Feb 07 |
jari |
209 |
} |
2 |
26 Feb 07 |
jari |
210 |
} |
2 |
26 Feb 07 |
jari |
211 |
} |
2 |
26 Feb 07 |
jari |
212 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after if(drawValues)"); |
2 |
26 Feb 07 |
jari |
214 |
|
2 |
26 Feb 07 |
jari |
215 |
if (this.drawCodes && this.codes != null && clusters[clusterIndex].length > 0) { |
2 |
26 Feb 07 |
jari |
216 |
g.setColor(Color.gray); |
2 |
26 Feb 07 |
jari |
217 |
for (int i=0; i<numberOfSamples-1; i++) { |
2 |
26 Feb 07 |
jari |
218 |
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 |
219 |
} |
2 |
26 Feb 07 |
jari |
220 |
} |
2 |
26 Feb 07 |
jari |
221 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after if(drawCodes)"); |
2 |
26 Feb 07 |
jari |
223 |
|
2 |
26 Feb 07 |
jari |
// draw zero line |
2 |
26 Feb 07 |
jari |
225 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
226 |
g.drawLine(left, zeroValue, left+width, zeroValue); |
2 |
26 Feb 07 |
jari |
227 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw zero line"); |
2 |
26 Feb 07 |
jari |
229 |
|
2 |
26 Feb 07 |
jari |
// draw magenta line |
2 |
26 Feb 07 |
jari |
231 |
if (getCluster() != null && getCluster().length > 0 /*&& clusters[clusterIndex].length > 0*/) { |
2 |
26 Feb 07 |
jari |
232 |
g.setColor(Color.magenta); |
2 |
26 Feb 07 |
jari |
233 |
for (int i=0; i<numberOfSamples-1; i++) { |
2 |
26 Feb 07 |
jari |
234 |
|
2 |
26 Feb 07 |
jari |
235 |
if(Float.isNaN(this.means[this.clusterIndex][i]) || Float.isNaN(this.means[this.clusterIndex][i+1])) { |
2 |
26 Feb 07 |
jari |
236 |
continue; |
2 |
26 Feb 07 |
jari |
237 |
} |
2 |
26 Feb 07 |
jari |
238 |
|
2 |
26 Feb 07 |
jari |
239 |
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 |
240 |
} |
2 |
26 Feb 07 |
jari |
241 |
} |
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw magenta line"); |
2 |
26 Feb 07 |
jari |
//draw template |
2 |
26 Feb 07 |
jari |
245 |
float[] templateArray = new float[templateVector.size()]; |
2 |
26 Feb 07 |
jari |
//System.out.println("templateVector.size()" + templateVector.size()); |
2 |
26 Feb 07 |
jari |
247 |
|
2 |
26 Feb 07 |
jari |
248 |
for (int i = 0; i < templateArray.length; i++) { |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
templateArray[i] = ((Float)(templateVector.get(i))).floatValue(); |
2 |
26 Feb 07 |
jari |
//System.out.println("templateArray[" + i + "] = " + templateArray[i]); |
2 |
26 Feb 07 |
jari |
252 |
} |
2 |
26 Feb 07 |
jari |
253 |
|
2 |
26 Feb 07 |
jari |
254 |
for (int i = 0; i < templateArray.length; i++) { |
2 |
26 Feb 07 |
jari |
255 |
templateArray[i] = templateArray[i] - 0.5f; |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("before drawing template, after creating templateArray"); |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
260 |
for (int i = 0; i < numberOfSamples - 1; i++) { |
2 |
26 Feb 07 |
jari |
261 |
g.setColor(Color.red); |
2 |
26 Feb 07 |
jari |
//System.out.println("drawing template point " + i); |
2 |
26 Feb 07 |
jari |
//System.out.println("templateArray[" + i + "] = " + templateArray[i]); |
2 |
26 Feb 07 |
jari |
//System.out.println("templateArray[" + (i + 1) + "] = " + templateArray[i +1]); |
2 |
26 Feb 07 |
jari |
265 |
if (!Float.isNaN(templateArray[i])) { |
2 |
26 Feb 07 |
jari |
266 |
g.fillOval(left+(int)Math.round(i*stepX) - 2, zeroValue-(int)Math.round(templateArray[i]*factor) - 2, 5, 5); |
2 |
26 Feb 07 |
jari |
267 |
} |
2 |
26 Feb 07 |
jari |
268 |
if (!Float.isNaN(templateArray[i+1])) { |
2 |
26 Feb 07 |
jari |
269 |
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 |
270 |
} |
2 |
26 Feb 07 |
jari |
271 |
if (Float.isNaN(templateArray[i]) || Float.isNaN(templateArray[i+1])) { |
2 |
26 Feb 07 |
jari |
272 |
continue; |
2 |
26 Feb 07 |
jari |
273 |
} |
2 |
26 Feb 07 |
jari |
274 |
g.setColor(Color.blue); |
2 |
26 Feb 07 |
jari |
275 |
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 |
276 |
} |
2 |
26 Feb 07 |
jari |
277 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw template"); |
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
// draw rectangle |
2 |
26 Feb 07 |
jari |
281 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
282 |
g.drawRect(left, top, width, height); |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw rectangle"); |
2 |
26 Feb 07 |
jari |
285 |
|
2 |
26 Feb 07 |
jari |
// draw X items |
2 |
26 Feb 07 |
jari |
287 |
for (int i=1; i<numberOfSamples-1; i++) { |
2 |
26 Feb 07 |
jari |
288 |
g.drawLine(left+(int)Math.round(i*stepX), top+height-5, left+(int)Math.round(i*stepX), top+height); |
2 |
26 Feb 07 |
jari |
289 |
} |
2 |
26 Feb 07 |
jari |
290 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw X items"); |
2 |
26 Feb 07 |
jari |
292 |
|
2 |
26 Feb 07 |
jari |
//draw Y items |
2 |
26 Feb 07 |
jari |
294 |
for (int i=1; i<stepsY; i++) { |
2 |
26 Feb 07 |
jari |
295 |
g.drawLine(left, zeroValue-(int)Math.round(i*factor), left+5, zeroValue-(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
296 |
g.drawLine(left, zeroValue+(int)Math.round(i*factor), left+5, zeroValue+(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
297 |
} |
2 |
26 Feb 07 |
jari |
298 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw Y Items"); |
2 |
26 Feb 07 |
jari |
300 |
if(this.showRefLine && this.drawReferenceBlock){ |
2 |
26 Feb 07 |
jari |
301 |
java.awt.Composite initComposite = g.getComposite(); |
2 |
26 Feb 07 |
jari |
302 |
g.setComposite(java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.3f)); |
2 |
26 Feb 07 |
jari |
303 |
g.setColor(Color.yellow); |
2 |
26 Feb 07 |
jari |
304 |
g.fillRect(xref-3, 20, 7, height); |
2 |
26 Feb 07 |
jari |
305 |
g.setComposite(initComposite); |
2 |
26 Feb 07 |
jari |
306 |
g.setColor(Color.blue); |
2 |
26 Feb 07 |
jari |
307 |
g.drawLine(xref, 20, xref, height+20); |
2 |
26 Feb 07 |
jari |
308 |
framework.setStatusText("Sample = "+data.getSampleName(experiment.getSampleIndex(currExpRefLine))+", mean = "+ this.means[this.clusterIndex][currExpRefLine]+", sd = "+ this.variances[this.clusterIndex][currExpRefLine]); |
2 |
26 Feb 07 |
jari |
309 |
} |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
// draw genes info |
2 |
26 Feb 07 |
jari |
312 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
313 |
if (drawMarks) { |
2 |
26 Feb 07 |
jari |
314 |
FontMetrics metrics = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
315 |
String str; |
2 |
26 Feb 07 |
jari |
316 |
int strWidth; |
2 |
26 Feb 07 |
jari |
//draw Y digits |
2 |
26 Feb 07 |
jari |
318 |
for (int i=1; i<stepsY; i++) { |
2 |
26 Feb 07 |
jari |
319 |
str = String.valueOf(i); |
2 |
26 Feb 07 |
jari |
320 |
strWidth = metrics.stringWidth(str); |
2 |
26 Feb 07 |
jari |
321 |
g.drawString(str, left-10-strWidth, zeroValue+5-(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
322 |
str = String.valueOf(-i); |
2 |
26 Feb 07 |
jari |
323 |
strWidth = metrics.stringWidth(str); |
2 |
26 Feb 07 |
jari |
324 |
g.drawString(str, left-10-strWidth, zeroValue+5+(int)Math.round(i*factor)); |
2 |
26 Feb 07 |
jari |
325 |
} |
2 |
26 Feb 07 |
jari |
// draw X samples names |
2 |
26 Feb 07 |
jari |
327 |
g.rotate(-Math.PI/2.0); |
2 |
26 Feb 07 |
jari |
328 |
final int max_name_width = getNamesWidth(metrics); |
2 |
26 Feb 07 |
jari |
329 |
for (int i=0; i<numberOfSamples; i++) { |
2 |
26 Feb 07 |
jari |
330 |
g.drawString(data.getSampleName(experiment.getSampleIndex(i)), -height-top-10-max_name_width, left+(int)Math.round(i*stepX)+3); |
2 |
26 Feb 07 |
jari |
331 |
} |
2 |
26 Feb 07 |
jari |
332 |
g.rotate(Math.PI/2.0); |
2 |
26 Feb 07 |
jari |
333 |
} |
2 |
26 Feb 07 |
jari |
334 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after if(drawMarks)"); |
2 |
26 Feb 07 |
jari |
336 |
|
2 |
26 Feb 07 |
jari |
337 |
if (getCluster() != null && getCluster().length > 0 && this.drawVariances /*&& clusters[clusterIndex].length > 0*/) { |
2 |
26 Feb 07 |
jari |
// draw points |
2 |
26 Feb 07 |
jari |
339 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
340 |
for (int i=0; i<numberOfSamples; i++) { |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
342 |
if (Float.isNaN(this.means[this.clusterIndex][i])) { |
2 |
26 Feb 07 |
jari |
343 |
continue; |
2 |
26 Feb 07 |
jari |
344 |
} |
2 |
26 Feb 07 |
jari |
345 |
|
2 |
26 Feb 07 |
jari |
346 |
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 |
347 |
} |
2 |
26 Feb 07 |
jari |
348 |
} |
2 |
26 Feb 07 |
jari |
349 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("PTMCentroidViewer: after draw points"); |
2 |
26 Feb 07 |
jari |
351 |
|
2 |
26 Feb 07 |
jari |
352 |
g.setColor(bColor); |
2 |
26 Feb 07 |
jari |
353 |
if (getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
354 |
g.drawString("No Genes", left+10, top+20); |
2 |
26 Feb 07 |
jari |
355 |
} else { |
2 |
26 Feb 07 |
jari |
356 |
g.drawString(getCluster().length+" Genes", left+10, top+20); |
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 |
* The class to listen to mouse and action events. |
2 |
26 Feb 07 |
jari |
362 |
*/ |
2 |
26 Feb 07 |
jari |
363 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
364 |
|
2 |
26 Feb 07 |
jari |
365 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
366 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
367 |
if (command.equals(SAVE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
368 |
onSaveCluster(); |
2 |
26 Feb 07 |
jari |
369 |
} else if (command.equals(SAVE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
370 |
onSaveClusters(); |
2 |
26 Feb 07 |
jari |
371 |
} else if (command.equals(SET_DEF_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
372 |
onSetDefaultColor(); |
2 |
26 Feb 07 |
jari |
373 |
} else if(command.equals(SET_Y_TO_EXPERIMENT_MAX_CMD)){ |
2 |
26 Feb 07 |
jari |
374 |
yRangeOption = CentroidViewer.USE_EXPERIMENT_MAX; |
2 |
26 Feb 07 |
jari |
375 |
setClusterMaxMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
376 |
setOverallMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
377 |
repaint(); |
2 |
26 Feb 07 |
jari |
378 |
} else if(command.equals(SET_Y_TO_CLUSTER_MAX_CMD)){ |
2 |
26 Feb 07 |
jari |
379 |
yRangeOption = CentroidViewer.USE_CLUSTER_MAX; |
2 |
26 Feb 07 |
jari |
380 |
setClusterMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
381 |
setOverallMaxMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
382 |
repaint(); |
2 |
26 Feb 07 |
jari |
383 |
} else if (command.equals(STORE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
384 |
storeCluster(); |
2 |
26 Feb 07 |
jari |
385 |
} else if(command.equals(LAUNCH_NEW_SESSION_CMD)){ |
2 |
26 Feb 07 |
jari |
386 |
launchNewSession(); |
2 |
26 Feb 07 |
jari |
387 |
} else if(command.equals(TOGGLE_REF_LINE_CMD)){ |
2 |
26 Feb 07 |
jari |
388 |
showRefLine = !showRefLine; |
2 |
26 Feb 07 |
jari |
389 |
repaint(); |
2 |
26 Feb 07 |
jari |
390 |
} |
2 |
26 Feb 07 |
jari |
391 |
} |
2 |
26 Feb 07 |
jari |
392 |
|
2 |
26 Feb 07 |
jari |
393 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
394 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
395 |
} |
2 |
26 Feb 07 |
jari |
396 |
|
2 |
26 Feb 07 |
jari |
397 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
398 |
if (!e.isPopupTrigger() || getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
399 |
return; |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
402 |
} |
2 |
26 Feb 07 |
jari |
403 |
} |
2 |
26 Feb 07 |
jari |
404 |
|
2 |
26 Feb 07 |
jari |
405 |
} |