2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2005, 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 |
* DAMInfoViewer.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
8 |
*/ |
2 |
26 Feb 07 |
jari |
9 |
|
2 |
26 Feb 07 |
jari |
10 |
package org.tigr.microarray.mev.cluster.gui.impl.dam; |
2 |
26 Feb 07 |
jari |
11 |
|
2 |
26 Feb 07 |
jari |
12 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JTextArea; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
import org.tigr.microarray.mev.cluster.gui.impl.ViewerAdapter; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
public class DAMInfoViewer extends ViewerAdapter implements java.io.Serializable { |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
28 |
private JTextArea content; |
2 |
26 Feb 07 |
jari |
29 |
private boolean clusterGenes; |
2 |
26 Feb 07 |
jari |
30 |
private int numClasses; |
2 |
26 Feb 07 |
jari |
31 |
private int numUsedGenes; |
2 |
26 Feb 07 |
jari |
32 |
private int numUnUsedGenes; |
2 |
26 Feb 07 |
jari |
33 |
private double alpha; |
2 |
26 Feb 07 |
jari |
34 |
private int algorithmSelection; |
2 |
26 Feb 07 |
jari |
35 |
private boolean isPDA; |
2 |
26 Feb 07 |
jari |
36 |
private boolean preSelectGenes; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>KMCInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
41 |
*/ |
2 |
26 Feb 07 |
jari |
42 |
public DAMInfoViewer(int[][] clusters, int genes, int numClasses, int numUsedGenes, int numUnUsedGenes, double alpha, int algorithmSelection, boolean isPDA, boolean preSelectGenes) { |
2 |
26 Feb 07 |
jari |
43 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
44 |
this.clusterGenes = true; |
2 |
26 Feb 07 |
jari |
45 |
this.numClasses = numClasses; |
2 |
26 Feb 07 |
jari |
46 |
this.numUsedGenes = numUsedGenes; |
2 |
26 Feb 07 |
jari |
47 |
this.numUnUsedGenes = numUnUsedGenes; |
2 |
26 Feb 07 |
jari |
48 |
this.alpha = alpha; |
2 |
26 Feb 07 |
jari |
49 |
this.algorithmSelection = algorithmSelection; |
2 |
26 Feb 07 |
jari |
50 |
this.isPDA = isPDA; |
2 |
26 Feb 07 |
jari |
51 |
this.preSelectGenes = preSelectGenes; |
2 |
26 Feb 07 |
jari |
52 |
content = createContent(clusters, genes); |
2 |
26 Feb 07 |
jari |
53 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
54 |
} |
2 |
26 Feb 07 |
jari |
55 |
public DAMInfoViewer(JTextArea content, JComponent header){ |
2 |
26 Feb 07 |
jari |
56 |
this.content = content; |
2 |
26 Feb 07 |
jari |
57 |
this.header = header; |
2 |
26 Feb 07 |
jari |
58 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
59 |
} |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>KMCInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
64 |
*/ |
2 |
26 Feb 07 |
jari |
65 |
public DAMInfoViewer(int[][] clusters, int genes, boolean clusterGenes, int numClasses, int numUsedGenes, int numUnUsedGenes, double alpha, int algorithmSelection, boolean isPDA, boolean preSelectedGenes) { |
2 |
26 Feb 07 |
jari |
66 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
67 |
this.clusterGenes = clusterGenes; |
2 |
26 Feb 07 |
jari |
68 |
this.numClasses = numClasses; |
2 |
26 Feb 07 |
jari |
69 |
this.numUsedGenes = numUsedGenes; |
2 |
26 Feb 07 |
jari |
70 |
this.numUnUsedGenes = numUnUsedGenes; |
2 |
26 Feb 07 |
jari |
71 |
this.alpha = alpha; |
2 |
26 Feb 07 |
jari |
72 |
this.algorithmSelection = algorithmSelection; |
2 |
26 Feb 07 |
jari |
73 |
this.isPDA = isPDA; |
2 |
26 Feb 07 |
jari |
74 |
this.preSelectGenes = preSelectedGenes; |
2 |
26 Feb 07 |
jari |
75 |
content = createContent(clusters, genes); |
2 |
26 Feb 07 |
jari |
76 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
77 |
} |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
/** |
2 |
26 Feb 07 |
jari |
* Returns component to be inserted into the framework scroll pane. |
2 |
26 Feb 07 |
jari |
81 |
*/ |
2 |
26 Feb 07 |
jari |
82 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
83 |
return content; |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer header. |
2 |
26 Feb 07 |
jari |
88 |
*/ |
2 |
26 Feb 07 |
jari |
89 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
90 |
return header; |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer header. |
2 |
26 Feb 07 |
jari |
95 |
*/ |
2 |
26 Feb 07 |
jari |
96 |
private JComponent createHeader() { |
2 |
26 Feb 07 |
jari |
97 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
98 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
99 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
100 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
101 |
gbc.insets = new Insets(10, 0, 10, 0); |
2 |
26 Feb 07 |
jari |
102 |
panel.add(new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Cluster Information</b></font></body></html>"), gbc); |
2 |
26 Feb 07 |
jari |
103 |
return panel; |
2 |
26 Feb 07 |
jari |
104 |
} |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer content component. |
2 |
26 Feb 07 |
jari |
108 |
*/ |
2 |
26 Feb 07 |
jari |
109 |
private JTextArea createContent(int[][] clusters, int genes) { |
2 |
26 Feb 07 |
jari |
110 |
JTextArea area = new JTextArea(clusters.length*3, 20); |
2 |
26 Feb 07 |
jari |
111 |
area.setEditable(false); |
2 |
26 Feb 07 |
jari |
112 |
area.setMargin(new Insets(0, 10, 0, 0)); |
2 |
26 Feb 07 |
jari |
113 |
StringBuffer sb = new StringBuffer(clusters.length*3*10); |
2 |
26 Feb 07 |
jari |
114 |
int numberOfGenes = numUsedGenes + numUnUsedGenes; |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
117 |
for (int counter = 2*numClasses; counter < 3*numClasses; counter++) { |
2 |
26 Feb 07 |
jari |
118 |
sb.append("Class "+(counter+1 - 2*numClasses)); |
2 |
26 Feb 07 |
jari |
119 |
sb.append("\t"); |
2 |
26 Feb 07 |
jari |
120 |
sb.append("# of Genes in Class: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
121 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
122 |
sb.append("% of Genes in Class: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
123 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
124 |
} |
2 |
26 Feb 07 |
jari |
125 |
if (preSelectGenes) { |
2 |
26 Feb 07 |
jari |
126 |
sb.append("alpha value =" + alpha); |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
129 |
sb.append("# of Experiments: " + numberOfGenes); |
2 |
26 Feb 07 |
jari |
130 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
131 |
sb.append("# of Selected Experiments: " + numUsedGenes); |
2 |
26 Feb 07 |
jari |
132 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
133 |
sb.append("# of Experiments not Selected: " + numUnUsedGenes); |
2 |
26 Feb 07 |
jari |
134 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
135 |
} else { |
2 |
26 Feb 07 |
jari |
136 |
sb.append("No Experiment Screening Applied"); |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
|
2 |
26 Feb 07 |
jari |
139 |
} |
2 |
26 Feb 07 |
jari |
140 |
else{ |
2 |
26 Feb 07 |
jari |
141 |
for (int counter = 2*numClasses; counter < 3*numClasses; counter++) { |
2 |
26 Feb 07 |
jari |
142 |
sb.append("Class "+(counter+1 - 2*numClasses)); |
2 |
26 Feb 07 |
jari |
143 |
sb.append("\t"); |
2 |
26 Feb 07 |
jari |
144 |
sb.append("# of Experiments in Class: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
145 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
146 |
sb.append("% of Experiments in Class: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
147 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
if (preSelectGenes) { |
2 |
26 Feb 07 |
jari |
150 |
sb.append("alpha value =" + alpha); |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
153 |
sb.append("# of Genes: " + numberOfGenes); |
2 |
26 Feb 07 |
jari |
154 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
155 |
sb.append("# of Selected Genes: " + numUsedGenes); |
2 |
26 Feb 07 |
jari |
156 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
157 |
sb.append("# of Genes not Selected: " + numUnUsedGenes); |
2 |
26 Feb 07 |
jari |
158 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
159 |
} else { |
2 |
26 Feb 07 |
jari |
160 |
sb.append("No Gene Screening Applied"); |
2 |
26 Feb 07 |
jari |
161 |
} |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
switch (algorithmSelection) { |
2 |
26 Feb 07 |
jari |
167 |
case 0: |
2 |
26 Feb 07 |
jari |
168 |
sb.append("Classification Algorithm: A0"); |
2 |
26 Feb 07 |
jari |
169 |
break; |
2 |
26 Feb 07 |
jari |
170 |
case 1: |
2 |
26 Feb 07 |
jari |
171 |
sb.append("Classification Algorithm: A1"); |
2 |
26 Feb 07 |
jari |
172 |
break; |
2 |
26 Feb 07 |
jari |
173 |
case 2: |
2 |
26 Feb 07 |
jari |
174 |
sb.append("Classification Algorithm: A2"); |
2 |
26 Feb 07 |
jari |
175 |
break; |
2 |
26 Feb 07 |
jari |
176 |
case 3: |
2 |
26 Feb 07 |
jari |
177 |
sb.append("Classification Algorithm: Initial Classification"); |
2 |
26 Feb 07 |
jari |
178 |
break; |
2 |
26 Feb 07 |
jari |
179 |
default: |
2 |
26 Feb 07 |
jari |
180 |
break; |
2 |
26 Feb 07 |
jari |
181 |
} |
2 |
26 Feb 07 |
jari |
182 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
183 |
sb.append("\n"); |
2 |
26 Feb 07 |
jari |
184 |
if (isPDA) { |
2 |
26 Feb 07 |
jari |
185 |
sb.append("Classification Method: PDA"); |
2 |
26 Feb 07 |
jari |
186 |
} else { |
2 |
26 Feb 07 |
jari |
187 |
sb.append("Classification Method: QDA"); |
2 |
26 Feb 07 |
jari |
188 |
} |
2 |
26 Feb 07 |
jari |
189 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
190 |
area.setText(sb.toString()); |
2 |
26 Feb 07 |
jari |
191 |
area.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
192 |
return area; |
2 |
26 Feb 07 |
jari |
193 |
} |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize content and header sizes. |
2 |
26 Feb 07 |
jari |
197 |
*/ |
2 |
26 Feb 07 |
jari |
198 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
199 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
200 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
201 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
202 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
203 |
} else { |
2 |
26 Feb 07 |
jari |
204 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
} |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
|