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: ScriptClusterSelectionInfoViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.5 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:58 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.script.scriptGUI; |
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.Dimension; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JTextPane; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.cluster.gui.impl.ViewerAdapter; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
/** The ScriptClusterSelectionInfoViewer presents the results of cluster selection algorithms |
2 |
26 Feb 07 |
jari |
* and the criteria upon which the selections were made. |
2 |
26 Feb 07 |
jari |
30 |
*/ |
2 |
26 Feb 07 |
jari |
31 |
public class ScriptClusterSelectionInfoViewer extends ViewerAdapter implements java.io.Serializable { |
2 |
26 Feb 07 |
jari |
32 |
public static final long serialVersionUID = 1000102010301020001L; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
35 |
private JTextPane content; |
2 |
26 Feb 07 |
jari |
36 |
private boolean clusterGenes; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
/** Constructs a <code>ScriptClusterSelectionInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
* @param algData |
2 |
26 Feb 07 |
jari |
41 |
*/ |
2 |
26 Feb 07 |
jari |
42 |
public ScriptClusterSelectionInfoViewer(AlgorithmData algData) { |
2 |
26 Feb 07 |
jari |
43 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
44 |
this.clusterGenes = algData.getParams().getBoolean("process-gene-clusters"); |
2 |
26 Feb 07 |
jari |
45 |
content = createContent(algData); |
2 |
26 Feb 07 |
jari |
46 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
47 |
} |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException { |
2 |
26 Feb 07 |
jari |
51 |
oos.writeBoolean(this.clusterGenes); |
2 |
26 Feb 07 |
jari |
52 |
oos.writeObject(this.content.getText()); |
2 |
26 Feb 07 |
jari |
53 |
} |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, ClassNotFoundException { |
2 |
26 Feb 07 |
jari |
58 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
59 |
this.clusterGenes = ois.readBoolean(); |
2 |
26 Feb 07 |
jari |
60 |
String contentString = (String)ois.readObject(); |
2 |
26 Feb 07 |
jari |
61 |
this.content = new JTextPane(); |
2 |
26 Feb 07 |
jari |
62 |
this.content.setContentType("text/html"); |
2 |
26 Feb 07 |
jari |
63 |
this.content.setEditable(false); |
2 |
26 Feb 07 |
jari |
64 |
this.content.setMargin(new Insets(0, 10, 0, 0)); |
2 |
26 Feb 07 |
jari |
65 |
this.content.setText(contentString); |
2 |
26 Feb 07 |
jari |
66 |
this.content.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
67 |
} |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
/** |
2 |
26 Feb 07 |
jari |
* Returns component to be inserted into the framework scroll pane. |
2 |
26 Feb 07 |
jari |
71 |
*/ |
2 |
26 Feb 07 |
jari |
72 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
73 |
return content; |
2 |
26 Feb 07 |
jari |
74 |
} |
2 |
26 Feb 07 |
jari |
75 |
|
2 |
26 Feb 07 |
jari |
76 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer header. |
2 |
26 Feb 07 |
jari |
78 |
*/ |
2 |
26 Feb 07 |
jari |
79 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
80 |
return header; |
2 |
26 Feb 07 |
jari |
81 |
} |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer header. |
2 |
26 Feb 07 |
jari |
85 |
*/ |
2 |
26 Feb 07 |
jari |
86 |
private JComponent createHeader() { |
2 |
26 Feb 07 |
jari |
87 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
88 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
89 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
90 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
91 |
gbc.insets = new Insets(10, 0, 10, 0); |
2 |
26 Feb 07 |
jari |
92 |
panel.add(new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Cluster Selection Information</b></font></body></html>"), gbc); |
2 |
26 Feb 07 |
jari |
93 |
return panel; |
2 |
26 Feb 07 |
jari |
94 |
} |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer content component. |
2 |
26 Feb 07 |
jari |
98 |
*/ |
2 |
26 Feb 07 |
jari |
99 |
private JTextPane createContent(AlgorithmData algData) { |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
String algName = algData.getParams().getString("name"); |
2 |
26 Feb 07 |
jari |
102 |
int numOfDesiredClusters = algData.getParams().getInt("desired-cluster-count"); |
2 |
26 Feb 07 |
jari |
103 |
String [] div = algData.getStringArray("diversity-value-array"); |
2 |
26 Feb 07 |
jari |
104 |
String [] pop = algData.getStringArray("cluster-population-array"); |
2 |
26 Feb 07 |
jari |
105 |
int popLimit = algData.getParams().getInt("minimum-cluster-size"); |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
JTextPane area = new JTextPane(); |
2 |
26 Feb 07 |
jari |
108 |
area.setContentType("text/html"); |
2 |
26 Feb 07 |
jari |
109 |
area.setEditable(false); |
2 |
26 Feb 07 |
jari |
110 |
area.setMargin(new Insets(0, 10, 0, 0)); |
2 |
26 Feb 07 |
jari |
111 |
|
2 |
26 Feb 07 |
jari |
112 |
String text; |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
int population; |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
if(algName.equals("Diversity Ranking Cluster Selection")) { |
2 |
26 Feb 07 |
jari |
117 |
boolean useCentroid = algData.getParams().getBoolean("use-centroid-based-variability"); |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
text = "<html><body bgcolor='#FFFFFF'><font face='serif' size='5'>"; |
2 |
26 Feb 07 |
jari |
120 |
text += "<br>Number of Desired Clusters: "+numOfDesiredClusters+"<br>"; |
2 |
26 Feb 07 |
jari |
121 |
text += "Minimum Cluster Size (population): "+popLimit+"<br>"; |
2 |
26 Feb 07 |
jari |
122 |
if(useCentroid) |
2 |
26 Feb 07 |
jari |
123 |
text += "Diversity Measurement: Centroid Based Diversity (mean gene-to-centroid dist.)<br>"; |
2 |
26 Feb 07 |
jari |
124 |
else |
2 |
26 Feb 07 |
jari |
125 |
text += "Diversity Measurement: Intra-gene Based Diversity (mean gene-to-gene dist.)<br>"; |
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
127 |
text += "<br><br>Note: Clusters are sorted by diversity. Selected clusters are in <b>bold</b> type.<br>"; |
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
text += "<table cellpadding=10><th><u>Div. Rank</u></th><th><u>Diversity</u></th><th><u>Population</u></td>"; |
2 |
26 Feb 07 |
jari |
131 |
int clusterCount = 0; |
2 |
26 Feb 07 |
jari |
132 |
for(int i = 0; i < div.length; i++) { |
2 |
26 Feb 07 |
jari |
133 |
population = Integer.parseInt(pop[i]); |
2 |
26 Feb 07 |
jari |
134 |
if(population >= popLimit && clusterCount < numOfDesiredClusters) { |
2 |
26 Feb 07 |
jari |
135 |
text += "<tr align=center><td><b>"+(i+1)+"</b></td><td><b>"+div[i]+"</b></td><td><b>"+pop[i]+"</b></td></tr>"; |
2 |
26 Feb 07 |
jari |
136 |
clusterCount++; |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
else |
2 |
26 Feb 07 |
jari |
139 |
text += "<tr align=center><td>"+(i+1)+"</td><td>"+div[i]+"</td><td>"+pop[i]+"</td></tr>"; |
2 |
26 Feb 07 |
jari |
140 |
} |
2 |
26 Feb 07 |
jari |
141 |
text += "</table></body></html>"; |
2 |
26 Feb 07 |
jari |
142 |
} else { |
2 |
26 Feb 07 |
jari |
143 |
boolean useVariance = algData.getParams().getBoolean("use-centroid-variance"); |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
text = "<html><body bgcolor='#FFFFFF'><font face='serif' size='5'>"; |
2 |
26 Feb 07 |
jari |
146 |
text += "<br>Number of Desired Clusters: "+numOfDesiredClusters+"<br>"; |
2 |
26 Feb 07 |
jari |
147 |
text += "Minimum Cluster Size (population): "+popLimit+"<br>"; |
2 |
26 Feb 07 |
jari |
148 |
if(useVariance) { |
2 |
26 Feb 07 |
jari |
149 |
text += "Selection Criteria: Centroid Variance<br>"; |
2 |
26 Feb 07 |
jari |
150 |
text += "<br><br>Note: Clusters are sorted by decreasing variance. Selected clusters are in <b>bold</b> type.<br>"; |
2 |
26 Feb 07 |
jari |
151 |
text += "<table cellpadding=10><th><u>Var. Rank</u></th><th><u>Variance</u></th><th><u>Population</u></td>"; |
2 |
26 Feb 07 |
jari |
152 |
} else { |
2 |
26 Feb 07 |
jari |
153 |
text += "Selection Criteria: Centroid Entropy<br>"; |
2 |
26 Feb 07 |
jari |
154 |
text += "<br><br>Note: Clusters are sorted by decreasing entropy. Selected clusters are in <b>bold</b> type.<br>"; |
2 |
26 Feb 07 |
jari |
155 |
text += "<table cellpadding=10><th><u>Entropy Rank</u></th><th><u>Entropy</u></th><th><u>Population</u></td>"; |
2 |
26 Feb 07 |
jari |
156 |
} |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
int clusterCount = 0; |
2 |
26 Feb 07 |
jari |
159 |
for(int i = 0; i < div.length; i++) { |
2 |
26 Feb 07 |
jari |
160 |
population = Integer.parseInt(pop[i]); |
2 |
26 Feb 07 |
jari |
161 |
if(population >= popLimit && clusterCount < numOfDesiredClusters) { |
2 |
26 Feb 07 |
jari |
162 |
text += "<tr align=center><td><b>"+(i+1)+"</b></td><td><b>"+div[i]+"</b></td><td><b>"+pop[i]+"</b></td></tr>"; |
2 |
26 Feb 07 |
jari |
163 |
clusterCount++; |
2 |
26 Feb 07 |
jari |
164 |
} |
2 |
26 Feb 07 |
jari |
165 |
else |
2 |
26 Feb 07 |
jari |
166 |
text += "<tr align=center><td>"+(i+1)+"</td><td>"+div[i]+"</td><td>"+pop[i]+"</td></tr>"; |
2 |
26 Feb 07 |
jari |
167 |
} |
2 |
26 Feb 07 |
jari |
168 |
text += "</table></body></html>"; |
2 |
26 Feb 07 |
jari |
169 |
} |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
area.setText(text); |
2 |
26 Feb 07 |
jari |
172 |
area.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
173 |
return area; |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize content and header sizes. |
2 |
26 Feb 07 |
jari |
178 |
*/ |
2 |
26 Feb 07 |
jari |
179 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
180 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
181 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
182 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
183 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
184 |
} else { |
2 |
26 Feb 07 |
jari |
185 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
186 |
} |
2 |
26 Feb 07 |
jari |
187 |
} |
2 |
26 Feb 07 |
jari |
188 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
190 |
*/ |
2 |
26 Feb 07 |
jari |
191 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
192 |
return null; |
2 |
26 Feb 07 |
jari |
193 |
} |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
} |