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: SOTADiversityViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.7 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/03/24 15:51:44 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
/* |
2 |
26 Feb 07 |
jari |
*Class provides a graphical representation of the overall tree |
2 |
26 Feb 07 |
jari |
*diversity during construction of a sot. |
2 |
26 Feb 07 |
jari |
15 |
*/ |
2 |
26 Feb 07 |
jari |
16 |
package org.tigr.microarray.mev.cluster.gui.impl.sota; |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
21 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
25 |
|
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.graph.GC; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.graph.GraphPoint; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.graph.GraphTick; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.graph.GraphViewer; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
public class SOTADiversityViewer extends GraphViewer implements IViewer { |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
private int numPoints; |
2 |
26 Feb 07 |
jari |
// private int maxValue; |
2 |
26 Feb 07 |
jari |
41 |
private float initValue; |
2 |
26 Feb 07 |
jari |
42 |
private FloatMatrix values; |
2 |
26 Feb 07 |
jari |
43 |
public SOTADiversityViewer(FloatMatrix values){ |
2 |
26 Feb 07 |
jari |
/* public GraphViewer(JFrame frame, int startx, int stopx, int starty, int stopy, |
2 |
26 Feb 07 |
jari |
double graphstartx, double graphstopx, double graphstarty, double graphstopy, |
2 |
26 Feb 07 |
jari |
int preXSpacing, int postXSpacing, int preYSpacing, int postYSpacing, |
2 |
26 Feb 07 |
jari |
String title, String xLabel, String yLabel) |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
*/ |
2 |
26 Feb 07 |
jari |
50 |
|
2 |
26 Feb 07 |
jari |
51 |
super(new JFrame(), 0, values.getRowDimension() , 0, (int)(values.get(0,0)), 0, values.getRowDimension(), 0, values.get(0,0), |
2 |
26 Feb 07 |
jari |
52 |
75, 75, 75, 75, "SOTA Tree Diversity History", |
2 |
26 Feb 07 |
jari |
53 |
"Cycle Number", "Diversity (% of Initial)"); |
2 |
26 Feb 07 |
jari |
//Stored only so that this class can be re-created using a PersistenceDelegate |
2 |
26 Feb 07 |
jari |
//See IViewerPersistenceDelegate |
2 |
26 Feb 07 |
jari |
56 |
this.values = values; |
2 |
26 Feb 07 |
jari |
57 |
numPoints = values.getRowDimension(); |
2 |
26 Feb 07 |
jari |
// maxValue = maxYVal(values,0); |
2 |
26 Feb 07 |
jari |
59 |
initValue = values.get(0,0); |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
this.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
62 |
|
2 |
26 Feb 07 |
jari |
63 |
referenceLinesOn = false; |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
65 |
for(int i = 0; i < numPoints; i++){ |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
addGraphElement( new GraphPoint(i,(double)values.get(i,0), Color.black, 4)); |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
//xTicks |
2 |
26 Feb 07 |
jari |
70 |
if(i%5 == 0){ |
2 |
26 Feb 07 |
jari |
71 |
addGraphElement( new GraphTick((double)i, 10, Color.black, GC.HORIZONTAL, GC.S, String.valueOf(i), Color.black)); |
2 |
26 Feb 07 |
jari |
72 |
} |
2 |
26 Feb 07 |
jari |
73 |
else{ |
2 |
26 Feb 07 |
jari |
74 |
addGraphElement( new GraphTick(i, 5, Color.black, GC.HORIZONTAL, GC.S, "", Color.black)); |
2 |
26 Feb 07 |
jari |
75 |
} |
2 |
26 Feb 07 |
jari |
76 |
} |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
double yTickIncrement = initValue/10.0; |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
for(int i = 0; i <= 10; i++){ |
2 |
26 Feb 07 |
jari |
82 |
addGraphElement( new GraphTick(i*yTickIncrement, 10, Color.black, GC.VERTICAL, GC.W, String.valueOf(i*10), Color.black)); |
2 |
26 Feb 07 |
jari |
83 |
} |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
86 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
87 |
new Object[]{values}); |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
//These methods are only here to satisfy the IViewer interface |
2 |
26 Feb 07 |
jari |
91 |
public void setExperiment (Experiment e){} |
2 |
26 Feb 07 |
jari |
92 |
public int getExperimentID(){return 0;} |
2 |
26 Feb 07 |
jari |
93 |
public void setExperimentID(int i){} |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
//Over write super's method to rotatate text |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
public void drawVerticalTick(Graphics2D g, double x, int length, int alignment, Color color, String label, Color tickColor) { |
2 |
26 Feb 07 |
jari |
98 |
drawVerticalTick(g, x, length, alignment, color); |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
if (false) { //Rotate labels |
2 |
26 Feb 07 |
jari |
// g.rotate(- Math.PI / 2); |
2 |
26 Feb 07 |
jari |
//canvas.drawString(g, label, postYSpacing - length - (label.length() * tickFontWidth), convertX(x), labelColor, tickFont); |
2 |
26 Feb 07 |
jari |
//canvas.drawString(g, label, 750, convertX(x) + canvas.getSize().width, tickColor, tickFont); |
2 |
26 Feb 07 |
jari |
104 |
canvas.drawString(g, label, - canvas.getSize().height + postYSpacing - (label.length() * tickFontWidth) - length, |
2 |
26 Feb 07 |
jari |
105 |
convertX(x) + (tickFontHeight / 2), tickColor, tickFont); |
2 |
26 Feb 07 |
jari |
// g.rotate(Math.PI / 2); |
2 |
26 Feb 07 |
jari |
107 |
} else { |
2 |
26 Feb 07 |
jari |
108 |
canvas.drawString(g, label, convertX(x) - (label.length() * tickFontWidth / 2), |
2 |
26 Feb 07 |
jari |
109 |
canvas.getSize().height - postYSpacing + length + 10, tickColor, tickFont); |
2 |
26 Feb 07 |
jari |
110 |
} |
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 |
public void drawVerticalTick(Graphics2D g, double x, int length, int alignment, Color color, String label, Color tickColor) |
2 |
26 Feb 07 |
jari |
116 |
{ |
2 |
26 Feb 07 |
jari |
drawVerticalTick(g, x, length, alignment, color); |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
if (true) { //Rotate labels |
2 |
26 Feb 07 |
jari |
g.rotate(- Math.PI / 2); |
2 |
26 Feb 07 |
jari |
//canvas.drawString(g, label, postYSpacing - length - (label.length() * tickFontWidth), convertX(x), labelColor, tickFont); |
2 |
26 Feb 07 |
jari |
//canvas.drawString(g, label, 750, convertX(x) + canvas.getSize().width, tickColor, tickFont); |
2 |
26 Feb 07 |
jari |
canvas.drawString(g, label, - canvas.getSize().height + postYSpacing - (label.length() * tickFontWidth) - length, |
2 |
26 Feb 07 |
jari |
convertX(x) + (tickFontHeight / 2), tickColor, tickFont); |
2 |
26 Feb 07 |
jari |
g.rotate(Math.PI / 2); |
2 |
26 Feb 07 |
jari |
} else { |
2 |
26 Feb 07 |
jari |
canvas.drawString(g, label, convertX(x) - (label.length() * tickFontWidth / 2), |
2 |
26 Feb 07 |
jari |
canvas.getSize().height - postYSpacing + length + 10, tickColor, tickFont); |
2 |
26 Feb 07 |
jari |
129 |
} |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
*/ |
2 |
26 Feb 07 |
jari |
132 |
|
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
|
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
float maxYVal(FloatMatrix data, int col){ |
2 |
26 Feb 07 |
jari |
138 |
float max = Float.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
139 |
|
2 |
26 Feb 07 |
jari |
140 |
for(int i = 0; i < numPoints; i++){ |
2 |
26 Feb 07 |
jari |
141 |
if(data.get(i,col) > max) |
2 |
26 Feb 07 |
jari |
142 |
max = data.get(i,col); |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
return max; |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer was deselected. |
2 |
26 Feb 07 |
jari |
150 |
*/ |
2 |
26 Feb 07 |
jari |
151 |
public void onDeselected() { |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer is selected. |
2 |
26 Feb 07 |
jari |
156 |
*/ |
2 |
26 Feb 07 |
jari |
157 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
158 |
} |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when display menu is changed, |
2 |
26 Feb 07 |
jari |
* if this viewer is selected. |
2 |
26 Feb 07 |
jari |
* @see IDisplayMenu |
2 |
26 Feb 07 |
jari |
164 |
*/ |
2 |
26 Feb 07 |
jari |
165 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when data is changed, |
2 |
26 Feb 07 |
jari |
* if this viewer is selected. |
2 |
26 Feb 07 |
jari |
* @see IData |
2 |
26 Feb 07 |
jari |
172 |
*/ |
2 |
26 Feb 07 |
jari |
173 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked when the framework is going to be closed. |
2 |
26 Feb 07 |
jari |
178 |
*/ |
2 |
26 Feb 07 |
jari |
179 |
public void onClosed() { |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
|
2 |
26 Feb 07 |
jari |
182 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane view port. |
2 |
26 Feb 07 |
jari |
184 |
*/ |
2 |
26 Feb 07 |
jari |
185 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
186 |
return this; |
2 |
26 Feb 07 |
jari |
187 |
} |
2 |
26 Feb 07 |
jari |
188 |
|
2 |
26 Feb 07 |
jari |
189 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework to save or to print viewer image. |
2 |
26 Feb 07 |
jari |
191 |
*/ |
2 |
26 Feb 07 |
jari |
192 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
193 |
return null; |
2 |
26 Feb 07 |
jari |
194 |
} |
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane header. |
2 |
26 Feb 07 |
jari |
198 |
*/ |
2 |
26 Feb 07 |
jari |
199 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
200 |
return null; |
2 |
26 Feb 07 |
jari |
201 |
} |
2 |
26 Feb 07 |
jari |
202 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
204 |
*/ |
2 |
26 Feb 07 |
jari |
205 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
206 |
return null; |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
|
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 |
211 |
*/ |
2 |
26 Feb 07 |
jari |
212 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
213 |
return null; |
2 |
26 Feb 07 |
jari |
214 |
} |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's clusters or null |
2 |
26 Feb 07 |
jari |
217 |
*/ |
2 |
26 Feb 07 |
jari |
218 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
219 |
return null; |
2 |
26 Feb 07 |
jari |
220 |
} |
2 |
26 Feb 07 |
jari |
221 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's experiment or null |
2 |
26 Feb 07 |
jari |
223 |
*/ |
2 |
26 Feb 07 |
jari |
224 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
225 |
return null; |
2 |
26 Feb 07 |
jari |
226 |
} |
2 |
26 Feb 07 |
jari |
227 |
|
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 |
230 |
*/ |
2 |
26 Feb 07 |
jari |
231 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
232 |
return -1; |
2 |
26 Feb 07 |
jari |
233 |
} |
2 |
26 Feb 07 |
jari |
234 |
|
2 |
26 Feb 07 |
jari |
235 |
} |
2 |
26 Feb 07 |
jari |
236 |
|
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
|
2 |
26 Feb 07 |
jari |
239 |
|