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: CASTGUI.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.8 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 20:30:31 $ |
2 |
26 Feb 07 |
jari |
* $Author: braistedj $ |
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.cast; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
|
2 |
26 Feb 07 |
jari |
15 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
17 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.tree.DefaultMutableTreeNode; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
import org.tigr.microarray.mev.cluster.Cluster; |
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.mev.cluster.Node; |
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.NodeList; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.cluster.NodeValueList; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.algorithm.Algorithm; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmListener; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.IClusterGUI; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.IDistanceMenu; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.cluster.gui.LeafInfo; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.helpers.ClusterTableViewer; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterTableViewer; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLGUI; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLInitDialog; |
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLViewer; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
50 |
|
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
public class CASTGUI implements IClusterGUI, IScriptGUI { |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
private Algorithm algorithm; |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
57 |
private IData data; |
2 |
26 Feb 07 |
jari |
58 |
private int[][] clusters; |
2 |
26 Feb 07 |
jari |
59 |
private FloatMatrix means; |
2 |
26 Feb 07 |
jari |
60 |
private FloatMatrix variances; |
2 |
26 Feb 07 |
jari |
61 |
private boolean clusterGenes; |
2 |
26 Feb 07 |
jari |
62 |
private int k; |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
/** |
2 |
26 Feb 07 |
jari |
* Default constructor. |
2 |
26 Feb 07 |
jari |
66 |
*/ |
2 |
26 Feb 07 |
jari |
67 |
public CASTGUI() { |
2 |
26 Feb 07 |
jari |
68 |
} |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
/** |
2 |
26 Feb 07 |
jari |
* Initialize the algorithm's parameters and execute it. |
2 |
26 Feb 07 |
jari |
72 |
*/ |
2 |
26 Feb 07 |
jari |
73 |
public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
74 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
// the default values |
2 |
26 Feb 07 |
jari |
76 |
float threshold = 0.5f; |
2 |
26 Feb 07 |
jari |
77 |
boolean modal = true; //I SET MODAL TO TRUE TO CALL THE HJC DIALOG BOX, HOPE THIS IS OK |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
int function = menu.getDistanceFunction(); |
2 |
26 Feb 07 |
jari |
82 |
int usedFunction = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
if (function == Algorithm.DEFAULT) { |
2 |
26 Feb 07 |
jari |
85 |
function = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
86 |
} |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
CASTInitDialog cast_dialog = new CASTInitDialog((JFrame) framework.getFrame(), modal, menu.getFunctionName(function), menu.isAbsoluteDistance()); |
2 |
26 Feb 07 |
jari |
89 |
cast_dialog.setVisible(true); |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
if (! cast_dialog.isOkPressed()) return null; |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
clusterGenes = cast_dialog.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
94 |
threshold = Float.parseFloat(cast_dialog.thresholdTextField.getText()); |
2 |
26 Feb 07 |
jari |
95 |
boolean isHierarchicalTree = cast_dialog.isHCLSelected(); |
2 |
26 Feb 07 |
jari |
// hcl init |
2 |
26 Feb 07 |
jari |
97 |
int hcl_method = 0; |
2 |
26 Feb 07 |
jari |
98 |
boolean hcl_samples = false; |
2 |
26 Feb 07 |
jari |
99 |
boolean hcl_genes = false; |
2 |
26 Feb 07 |
jari |
100 |
int hcl_function = 4; |
2 |
26 Feb 07 |
jari |
101 |
boolean hcl_absolute = false; |
2 |
26 Feb 07 |
jari |
102 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
HCLInitDialog hcl_dialog = new HCLInitDialog(framework.getFrame(), menu.getFunctionName(cast_dialog.getDistanceMetric()), cast_dialog.isAbsoluteDistance(), true); |
2 |
26 Feb 07 |
jari |
105 |
if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
106 |
return null; |
2 |
26 Feb 07 |
jari |
107 |
} |
2 |
26 Feb 07 |
jari |
108 |
hcl_method = hcl_dialog.getMethod(); |
2 |
26 Feb 07 |
jari |
109 |
hcl_samples = hcl_dialog.isClusterExperiments(); |
2 |
26 Feb 07 |
jari |
110 |
hcl_genes = hcl_dialog.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
111 |
hcl_function = hcl_dialog.getDistanceMetric(); |
2 |
26 Feb 07 |
jari |
112 |
hcl_absolute = hcl_dialog.getAbsoluteSelection(); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
this.experiment = framework.getData().getExperiment(); |
2 |
26 Feb 07 |
jari |
117 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
118 |
try { |
2 |
26 Feb 07 |
jari |
119 |
algorithm = framework.getAlgorithmFactory().getAlgorithm("CAST"); |
2 |
26 Feb 07 |
jari |
120 |
algorithm.addAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
int genes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
125 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
127 |
if(!clusterGenes) |
2 |
26 Feb 07 |
jari |
128 |
matrix = matrix.transpose(); |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
data.addMatrix("experiment", matrix); |
2 |
26 Feb 07 |
jari |
131 |
data.addParam("cast-cluster-genes", String.valueOf(clusterGenes)); |
2 |
26 Feb 07 |
jari |
132 |
data.addParam("distance-factor", String.valueOf(1.0f)); |
2 |
26 Feb 07 |
jari |
133 |
data.addParam("threshold", String.valueOf(threshold)); |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
function = cast_dialog.getDistanceMetric(); |
2 |
26 Feb 07 |
jari |
136 |
data.addParam("distance-absolute", String.valueOf(cast_dialog.isAbsoluteDistance())); |
2 |
26 Feb 07 |
jari |
137 |
data.addParam("distance-function", String.valueOf(function)); |
2 |
26 Feb 07 |
jari |
// hcl parameters |
2 |
26 Feb 07 |
jari |
139 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
140 |
data.addParam("hierarchical-tree", String.valueOf(true)); |
2 |
26 Feb 07 |
jari |
141 |
data.addParam("method-linkage", String.valueOf(hcl_method)); |
2 |
26 Feb 07 |
jari |
142 |
data.addParam("calculate-genes", String.valueOf(hcl_genes)); |
2 |
26 Feb 07 |
jari |
143 |
data.addParam("calculate-experiments", String.valueOf(hcl_samples)); |
2 |
26 Feb 07 |
jari |
144 |
data.addParam("hcl-distance-function", String.valueOf(hcl_function)); |
2 |
26 Feb 07 |
jari |
145 |
data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute)); |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
long start = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
149 |
AlgorithmData result = algorithm.execute(data); |
2 |
26 Feb 07 |
jari |
150 |
long time = System.currentTimeMillis() - start; |
2 |
26 Feb 07 |
jari |
// getting the results |
2 |
26 Feb 07 |
jari |
152 |
Cluster result_cluster = result.getCluster("cluster"); |
2 |
26 Feb 07 |
jari |
153 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
155 |
AlgorithmParameters resultMap = result.getParams(); |
2 |
26 Feb 07 |
jari |
156 |
k = resultMap.getInt("number-of-clusters"); // I USED THIS TO GET THE VALUE OF NUMBER-OF-CLUSTERS |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
this.clusters = new int[k][]; |
2 |
26 Feb 07 |
jari |
159 |
for (int i=0; i<k; i++) { |
2 |
26 Feb 07 |
jari |
160 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
161 |
} |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
163 |
this.means = result.getMatrix("clusters_means"); |
2 |
26 Feb 07 |
jari |
164 |
this.variances = result.getMatrix("clusters_variances"); |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
GeneralInfo info = new GeneralInfo(); |
2 |
26 Feb 07 |
jari |
167 |
info.clusters = k; |
2 |
26 Feb 07 |
jari |
168 |
info.time = time; |
2 |
26 Feb 07 |
jari |
169 |
info.threshold = threshold; |
2 |
26 Feb 07 |
jari |
170 |
info.isAbsolute = menu.isAbsoluteDistance(); |
2 |
26 Feb 07 |
jari |
171 |
|
2 |
26 Feb 07 |
jari |
172 |
|
2 |
26 Feb 07 |
jari |
173 |
if((function == Algorithm.DEFAULT)||(function == Algorithm.COSINE) |
2 |
26 Feb 07 |
jari |
174 |
||(function == Algorithm.COVARIANCE)||(function == Algorithm.EUCLIDEAN) |
2 |
26 Feb 07 |
jari |
175 |
||(function == Algorithm.DOTPRODUCT)||(function == Algorithm.MANHATTAN) |
2 |
26 Feb 07 |
jari |
176 |
||(function == Algorithm.SPEARMANRANK)||(function == Algorithm.KENDALLSTAU) |
2 |
26 Feb 07 |
jari |
177 |
||(function == Algorithm.MUTUALINFORMATION)){ |
2 |
26 Feb 07 |
jari |
// ONLY EUCLIDEAN OR PEARSON IS USED IN THE CALCULATION!!!! |
2 |
26 Feb 07 |
jari |
179 |
usedFunction = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
else if((function == Algorithm.PEARSON)||(function == Algorithm.PEARSONUNCENTERED) |
2 |
26 Feb 07 |
jari |
182 |
||(function == Algorithm.PEARSONSQARED)) { |
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
usedFunction = Algorithm.PEARSON; |
2 |
26 Feb 07 |
jari |
185 |
|
2 |
26 Feb 07 |
jari |
186 |
} |
2 |
26 Feb 07 |
jari |
187 |
info.function = menu.getFunctionName(usedFunction); |
2 |
26 Feb 07 |
jari |
188 |
info.hcl = isHierarchicalTree; |
2 |
26 Feb 07 |
jari |
189 |
info.hcl_genes = hcl_genes; |
2 |
26 Feb 07 |
jari |
190 |
info.hcl_samples = hcl_samples; |
2 |
26 Feb 07 |
jari |
191 |
info.hcl_method = hcl_method; |
2 |
26 Feb 07 |
jari |
192 |
return createResultTree(result_cluster, info); |
2 |
26 Feb 07 |
jari |
193 |
|
2 |
26 Feb 07 |
jari |
194 |
} finally { |
2 |
26 Feb 07 |
jari |
195 |
if (algorithm != null) { |
2 |
26 Feb 07 |
jari |
196 |
algorithm.removeAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
197 |
} |
2 |
26 Feb 07 |
jari |
198 |
|
2 |
26 Feb 07 |
jari |
199 |
|
2 |
26 Feb 07 |
jari |
200 |
} |
2 |
26 Feb 07 |
jari |
201 |
} |
2 |
26 Feb 07 |
jari |
202 |
|
2 |
26 Feb 07 |
jari |
203 |
|
2 |
26 Feb 07 |
jari |
204 |
/* |
2 |
26 Feb 07 |
jari |
* Scripting methods |
2 |
26 Feb 07 |
jari |
206 |
*/ |
2 |
26 Feb 07 |
jari |
207 |
|
2 |
26 Feb 07 |
jari |
208 |
public AlgorithmData getScriptParameters(IFramework framework) { |
2 |
26 Feb 07 |
jari |
209 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
// the default values |
2 |
26 Feb 07 |
jari |
211 |
float threshold = 0.5f; |
2 |
26 Feb 07 |
jari |
212 |
boolean modal = true; //I SET MODAL TO TRUE TO CALL THE HJC DIALOG BOX, HOPE THIS IS OK |
2 |
26 Feb 07 |
jari |
213 |
|
2 |
26 Feb 07 |
jari |
214 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
int function = menu.getDistanceFunction(); |
2 |
26 Feb 07 |
jari |
217 |
int usedFunction = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
218 |
|
2 |
26 Feb 07 |
jari |
219 |
if (function == Algorithm.DEFAULT) { |
2 |
26 Feb 07 |
jari |
220 |
function = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
221 |
} |
2 |
26 Feb 07 |
jari |
222 |
|
2 |
26 Feb 07 |
jari |
223 |
CASTInitDialog cast_dialog = new CASTInitDialog((JFrame) framework.getFrame(), modal, menu.getFunctionName(function), menu.isAbsoluteDistance()); |
2 |
26 Feb 07 |
jari |
224 |
|
2 |
26 Feb 07 |
jari |
225 |
cast_dialog.setVisible(true); |
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
227 |
if (! cast_dialog.isOkPressed()) return null; |
2 |
26 Feb 07 |
jari |
228 |
|
2 |
26 Feb 07 |
jari |
229 |
clusterGenes = cast_dialog.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
230 |
threshold = Float.parseFloat(cast_dialog.thresholdTextField.getText()); |
2 |
26 Feb 07 |
jari |
231 |
boolean isHierarchicalTree = cast_dialog.isHCLSelected(); |
2 |
26 Feb 07 |
jari |
// hcl init |
2 |
26 Feb 07 |
jari |
233 |
int hcl_method = 0; |
2 |
26 Feb 07 |
jari |
234 |
boolean hcl_samples = false; |
2 |
26 Feb 07 |
jari |
235 |
boolean hcl_genes = false; |
2 |
26 Feb 07 |
jari |
236 |
int hcl_function = 4; |
2 |
26 Feb 07 |
jari |
237 |
boolean hcl_absolute = false; |
2 |
26 Feb 07 |
jari |
238 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
239 |
|
2 |
26 Feb 07 |
jari |
240 |
HCLInitDialog hcl_dialog = new HCLInitDialog(framework.getFrame(), menu.getFunctionName(cast_dialog.getDistanceMetric()), cast_dialog.isAbsoluteDistance(), true); |
2 |
26 Feb 07 |
jari |
241 |
if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
242 |
return null; |
2 |
26 Feb 07 |
jari |
243 |
} |
2 |
26 Feb 07 |
jari |
244 |
hcl_method = hcl_dialog.getMethod(); |
2 |
26 Feb 07 |
jari |
245 |
hcl_samples = hcl_dialog.isClusterExperiments(); |
2 |
26 Feb 07 |
jari |
246 |
hcl_genes = hcl_dialog.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
247 |
hcl_function = hcl_dialog.getDistanceMetric(); |
2 |
26 Feb 07 |
jari |
248 |
hcl_absolute = hcl_dialog.getAbsoluteSelection(); |
2 |
26 Feb 07 |
jari |
249 |
} |
2 |
26 Feb 07 |
jari |
250 |
|
2 |
26 Feb 07 |
jari |
251 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
252 |
data.addParam("cast-cluster-genes", String.valueOf(clusterGenes)); |
2 |
26 Feb 07 |
jari |
253 |
data.addParam("distance-factor", String.valueOf(1.0f)); |
2 |
26 Feb 07 |
jari |
254 |
data.addParam("threshold", String.valueOf(threshold)); |
2 |
26 Feb 07 |
jari |
255 |
|
2 |
26 Feb 07 |
jari |
256 |
function = cast_dialog.getDistanceMetric(); |
2 |
26 Feb 07 |
jari |
257 |
data.addParam("distance-absolute", String.valueOf(cast_dialog.isAbsoluteDistance())); |
2 |
26 Feb 07 |
jari |
258 |
data.addParam("distance-function", String.valueOf(function)); |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
// hcl parameters |
2 |
26 Feb 07 |
jari |
261 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
262 |
data.addParam("hierarchical-tree", String.valueOf(true)); |
2 |
26 Feb 07 |
jari |
263 |
data.addParam("method-linkage", String.valueOf(hcl_method)); |
2 |
26 Feb 07 |
jari |
264 |
data.addParam("calculate-genes", String.valueOf(hcl_genes)); |
2 |
26 Feb 07 |
jari |
265 |
data.addParam("calculate-experiments", String.valueOf(hcl_samples)); |
2 |
26 Feb 07 |
jari |
266 |
data.addParam("hcl-distance-function", String.valueOf(hcl_function)); |
2 |
26 Feb 07 |
jari |
267 |
data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute)); |
2 |
26 Feb 07 |
jari |
268 |
} |
2 |
26 Feb 07 |
jari |
//script control parameters |
2 |
26 Feb 07 |
jari |
270 |
|
2 |
26 Feb 07 |
jari |
// alg name |
2 |
26 Feb 07 |
jari |
272 |
data.addParam("name", "CAST"); |
2 |
26 Feb 07 |
jari |
273 |
|
2 |
26 Feb 07 |
jari |
// alg type |
2 |
26 Feb 07 |
jari |
275 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
276 |
data.addParam("alg-type", "cluster-genes"); |
2 |
26 Feb 07 |
jari |
277 |
else |
2 |
26 Feb 07 |
jari |
278 |
data.addParam("alg-type", "cluster-experiments"); |
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
// output class |
2 |
26 Feb 07 |
jari |
281 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
282 |
data.addParam("output-class", "multi-gene-cluster-output"); |
2 |
26 Feb 07 |
jari |
283 |
else |
2 |
26 Feb 07 |
jari |
284 |
data.addParam("output-class", "multi-experiment-cluster-output"); |
2 |
26 Feb 07 |
jari |
285 |
|
2 |
26 Feb 07 |
jari |
//output nodes |
2 |
26 Feb 07 |
jari |
287 |
String [] outputNodes = new String[1]; |
2 |
26 Feb 07 |
jari |
288 |
outputNodes[0] = "Multi-cluster"; |
2 |
26 Feb 07 |
jari |
289 |
data.addStringArray("output-nodes", outputNodes); |
2 |
26 Feb 07 |
jari |
290 |
|
2 |
26 Feb 07 |
jari |
291 |
return data; |
2 |
26 Feb 07 |
jari |
292 |
} |
2 |
26 Feb 07 |
jari |
293 |
|
2 |
26 Feb 07 |
jari |
294 |
|
2 |
26 Feb 07 |
jari |
295 |
public DefaultMutableTreeNode executeScript(IFramework framework, AlgorithmData algData, Experiment experiment) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
296 |
|
2 |
26 Feb 07 |
jari |
297 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
298 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
299 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
300 |
try { |
2 |
26 Feb 07 |
jari |
301 |
algorithm = framework.getAlgorithmFactory().getAlgorithm("CAST"); |
2 |
26 Feb 07 |
jari |
302 |
algorithm.addAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
303 |
|
2 |
26 Feb 07 |
jari |
304 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
305 |
|
2 |
26 Feb 07 |
jari |
306 |
if(!algData.getParams().getBoolean("cast-cluster-genes")) { |
2 |
26 Feb 07 |
jari |
307 |
this.clusterGenes = false; |
2 |
26 Feb 07 |
jari |
308 |
matrix = matrix.transpose(); |
2 |
26 Feb 07 |
jari |
309 |
} else { |
2 |
26 Feb 07 |
jari |
310 |
this.clusterGenes = true; |
2 |
26 Feb 07 |
jari |
311 |
} |
2 |
26 Feb 07 |
jari |
312 |
|
2 |
26 Feb 07 |
jari |
313 |
algData.addMatrix("experiment", matrix); |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
long start = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
316 |
AlgorithmData result = algorithm.execute(algData); |
2 |
26 Feb 07 |
jari |
317 |
long time = System.currentTimeMillis() - start; |
2 |
26 Feb 07 |
jari |
// getting the results |
2 |
26 Feb 07 |
jari |
319 |
Cluster result_cluster = result.getCluster("cluster"); |
2 |
26 Feb 07 |
jari |
320 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
321 |
|
2 |
26 Feb 07 |
jari |
322 |
AlgorithmParameters resultMap = result.getParams(); |
2 |
26 Feb 07 |
jari |
323 |
k = resultMap.getInt("number-of-clusters"); // I USED THIS TO GET THE VALUE OF NUMBER-OF-CLUSTERS |
2 |
26 Feb 07 |
jari |
324 |
|
2 |
26 Feb 07 |
jari |
325 |
this.clusters = new int[k][]; |
2 |
26 Feb 07 |
jari |
326 |
for (int i=0; i<k; i++) { |
2 |
26 Feb 07 |
jari |
327 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
328 |
} |
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
330 |
this.means = result.getMatrix("clusters_means"); |
2 |
26 Feb 07 |
jari |
331 |
this.variances = result.getMatrix("clusters_variances"); |
2 |
26 Feb 07 |
jari |
332 |
|
2 |
26 Feb 07 |
jari |
333 |
AlgorithmParameters params = algData.getParams(); |
2 |
26 Feb 07 |
jari |
334 |
int function = params.getInt("distance-function"); |
2 |
26 Feb 07 |
jari |
335 |
|
2 |
26 Feb 07 |
jari |
336 |
GeneralInfo info = new GeneralInfo(); |
2 |
26 Feb 07 |
jari |
337 |
info.clusters = k; |
2 |
26 Feb 07 |
jari |
338 |
info.time = time; |
2 |
26 Feb 07 |
jari |
339 |
info.threshold = params.getFloat("threshold"); |
2 |
26 Feb 07 |
jari |
340 |
info.isAbsolute = params.getBoolean("distance-absolute"); |
2 |
26 Feb 07 |
jari |
341 |
int usedFunction = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
342 |
if((function == Algorithm.DEFAULT)||(function == Algorithm.COSINE) |
2 |
26 Feb 07 |
jari |
343 |
||(function == Algorithm.COVARIANCE)||(function == Algorithm.EUCLIDEAN) |
2 |
26 Feb 07 |
jari |
344 |
||(function == Algorithm.DOTPRODUCT)||(function == Algorithm.MANHATTAN) |
2 |
26 Feb 07 |
jari |
345 |
||(function == Algorithm.SPEARMANRANK)||(function == Algorithm.KENDALLSTAU) |
2 |
26 Feb 07 |
jari |
346 |
||(function == Algorithm.MUTUALINFORMATION)){ |
2 |
26 Feb 07 |
jari |
// ONLY EUCLIDEAN OR PEARSON IS USED IN THE CALCULATION!!!! |
2 |
26 Feb 07 |
jari |
348 |
usedFunction = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
349 |
} |
2 |
26 Feb 07 |
jari |
350 |
else if((function == Algorithm.PEARSON)||(function == Algorithm.PEARSONUNCENTERED) |
2 |
26 Feb 07 |
jari |
351 |
||(function == Algorithm.PEARSONSQARED)) { |
2 |
26 Feb 07 |
jari |
352 |
|
2 |
26 Feb 07 |
jari |
353 |
usedFunction = Algorithm.PEARSON; |
2 |
26 Feb 07 |
jari |
354 |
} |
2 |
26 Feb 07 |
jari |
355 |
|
2 |
26 Feb 07 |
jari |
356 |
info.function = framework.getDistanceMenu().getFunctionName(usedFunction); |
2 |
26 Feb 07 |
jari |
357 |
|
2 |
26 Feb 07 |
jari |
358 |
info.hcl = params.getBoolean("hierarchical-tree"); |
2 |
26 Feb 07 |
jari |
359 |
info.hcl_genes = params.getBoolean("calculate-genes"); |
2 |
26 Feb 07 |
jari |
360 |
info.hcl_samples = params.getBoolean("calculate-samples"); |
2 |
26 Feb 07 |
jari |
361 |
if(info.hcl) |
2 |
26 Feb 07 |
jari |
362 |
info.hcl_method = params.getInt("method-linkage"); |
2 |
26 Feb 07 |
jari |
363 |
else |
2 |
26 Feb 07 |
jari |
364 |
info.hcl_method = 0; |
2 |
26 Feb 07 |
jari |
365 |
|
2 |
26 Feb 07 |
jari |
366 |
return createResultTree(result_cluster, info); |
2 |
26 Feb 07 |
jari |
367 |
|
2 |
26 Feb 07 |
jari |
368 |
} finally { |
2 |
26 Feb 07 |
jari |
369 |
if (algorithm != null) { |
2 |
26 Feb 07 |
jari |
370 |
algorithm.removeAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
371 |
} |
2 |
26 Feb 07 |
jari |
372 |
} |
2 |
26 Feb 07 |
jari |
373 |
} |
2 |
26 Feb 07 |
jari |
374 |
|
2 |
26 Feb 07 |
jari |
375 |
|
2 |
26 Feb 07 |
jari |
376 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a hcl tree data from the specified cluster node. |
2 |
26 Feb 07 |
jari |
378 |
*/ |
2 |
26 Feb 07 |
jari |
379 |
private HCLTreeData getResult(Node clusterNode, int pos) { |
2 |
26 Feb 07 |
jari |
380 |
HCLTreeData data = new HCLTreeData(); |
2 |
26 Feb 07 |
jari |
381 |
NodeValueList valueList = clusterNode.getValues(); |
2 |
26 Feb 07 |
jari |
382 |
data.child_1_array = (int[])valueList.getNodeValue(pos).value; |
2 |
26 Feb 07 |
jari |
383 |
data.child_2_array = (int[])valueList.getNodeValue(pos+1).value; |
2 |
26 Feb 07 |
jari |
384 |
data.node_order = (int[])valueList.getNodeValue(pos+2).value; |
2 |
26 Feb 07 |
jari |
385 |
data.height = (float[])valueList.getNodeValue(pos+3).value; |
2 |
26 Feb 07 |
jari |
386 |
return data; |
2 |
26 Feb 07 |
jari |
387 |
} |
2 |
26 Feb 07 |
jari |
388 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a result tree to be inserted into the framework analysis node. |
2 |
26 Feb 07 |
jari |
390 |
*/ |
2 |
26 Feb 07 |
jari |
391 |
private DefaultMutableTreeNode createResultTree(Cluster result_cluster, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
392 |
DefaultMutableTreeNode root; |
2 |
26 Feb 07 |
jari |
393 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
394 |
root = new DefaultMutableTreeNode("CAST - genes"); |
2 |
26 Feb 07 |
jari |
395 |
else |
2 |
26 Feb 07 |
jari |
396 |
root = new DefaultMutableTreeNode("CAST - samples"); |
2 |
26 Feb 07 |
jari |
397 |
addResultNodes(root, result_cluster, info); |
2 |
26 Feb 07 |
jari |
398 |
return root; |
2 |
26 Feb 07 |
jari |
399 |
} |
2 |
26 Feb 07 |
jari |
400 |
|
2 |
26 Feb 07 |
jari |
401 |
/** |
2 |
26 Feb 07 |
jari |
* Adds result nodes into the tree root. |
2 |
26 Feb 07 |
jari |
403 |
*/ |
2 |
26 Feb 07 |
jari |
404 |
private void addResultNodes(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
405 |
addExpressionImages(root); |
2 |
26 Feb 07 |
jari |
406 |
addHierarchicalTrees(root, result_cluster, info); |
2 |
26 Feb 07 |
jari |
407 |
addCentroidViews(root); |
2 |
26 Feb 07 |
jari |
408 |
addTableViews(root); |
2 |
26 Feb 07 |
jari |
409 |
addClusterInfo(root); |
2 |
26 Feb 07 |
jari |
410 |
addGeneralInfo(root, info); |
2 |
26 Feb 07 |
jari |
411 |
} |
2 |
26 Feb 07 |
jari |
412 |
|
2 |
26 Feb 07 |
jari |
413 |
private void addTableViews(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
414 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Table views"); |
2 |
26 Feb 07 |
jari |
415 |
IViewer tabViewer; |
2 |
26 Feb 07 |
jari |
416 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
417 |
tabViewer= new ClusterTableViewer(this.experiment, this.clusters, this.data); |
2 |
26 Feb 07 |
jari |
418 |
else |
2 |
26 Feb 07 |
jari |
419 |
tabViewer= new ExperimentClusterTableViewer(this.experiment, this.clusters, this.data); |
2 |
26 Feb 07 |
jari |
//return; // placeholder for ExptClusterTableViewer |
2 |
26 Feb 07 |
jari |
//expViewer = new CASTExperimentClusterViewer(this.experiment, this.clusters); |
2 |
26 Feb 07 |
jari |
422 |
|
2 |
26 Feb 07 |
jari |
423 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
424 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), tabViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
425 |
} |
2 |
26 Feb 07 |
jari |
426 |
root.add(node); |
2 |
26 Feb 07 |
jari |
427 |
} |
2 |
26 Feb 07 |
jari |
428 |
|
2 |
26 Feb 07 |
jari |
429 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display clusters data. |
2 |
26 Feb 07 |
jari |
431 |
*/ |
2 |
26 Feb 07 |
jari |
432 |
private void addExpressionImages(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
433 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images"); |
2 |
26 Feb 07 |
jari |
434 |
IViewer expViewer; |
2 |
26 Feb 07 |
jari |
435 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
436 |
expViewer= new CASTExperimentViewer(this.experiment, this.clusters); |
2 |
26 Feb 07 |
jari |
437 |
else |
2 |
26 Feb 07 |
jari |
438 |
expViewer = new CASTExperimentClusterViewer(this.experiment, this.clusters); |
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
440 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
441 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
442 |
} |
2 |
26 Feb 07 |
jari |
443 |
root.add(node); |
2 |
26 Feb 07 |
jari |
444 |
} |
2 |
26 Feb 07 |
jari |
445 |
|
2 |
26 Feb 07 |
jari |
446 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display hierarchical trees. |
2 |
26 Feb 07 |
jari |
448 |
*/ |
2 |
26 Feb 07 |
jari |
449 |
private void addHierarchicalTrees(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
450 |
if (!info.hcl) { |
2 |
26 Feb 07 |
jari |
451 |
return; |
2 |
26 Feb 07 |
jari |
452 |
} |
2 |
26 Feb 07 |
jari |
453 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Hierarchical Trees"); |
2 |
26 Feb 07 |
jari |
454 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
455 |
int [][] clusters = null; |
2 |
26 Feb 07 |
jari |
456 |
|
2 |
26 Feb 07 |
jari |
457 |
if(!this.clusterGenes){ |
2 |
26 Feb 07 |
jari |
458 |
clusters = new int[k][]; |
2 |
26 Feb 07 |
jari |
459 |
for (int i=0; i<k; i++) { |
2 |
26 Feb 07 |
jari |
460 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
461 |
} |
2 |
26 Feb 07 |
jari |
462 |
if(info.hcl_samples) |
2 |
26 Feb 07 |
jari |
463 |
clusters = getOrderedIndices(nodeList, clusters, info.hcl_genes); |
2 |
26 Feb 07 |
jari |
464 |
} |
2 |
26 Feb 07 |
jari |
465 |
for (int i=0; i<nodeList.getSize(); i++) { |
2 |
26 Feb 07 |
jari |
466 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
467 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), createHCLViewer(nodeList.getNode(i), info, null)))); |
2 |
26 Feb 07 |
jari |
468 |
else |
2 |
26 Feb 07 |
jari |
469 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), createHCLViewer(nodeList.getNode(i), info, clusters), new Integer(i)))); |
2 |
26 Feb 07 |
jari |
470 |
} |
2 |
26 Feb 07 |
jari |
471 |
root.add(node); |
2 |
26 Feb 07 |
jari |
472 |
} |
2 |
26 Feb 07 |
jari |
473 |
|
2 |
26 Feb 07 |
jari |
474 |
|
2 |
26 Feb 07 |
jari |
475 |
/** |
2 |
26 Feb 07 |
jari |
* Creates an <code>HCLViewer</code>. |
2 |
26 Feb 07 |
jari |
477 |
*/ |
2 |
26 Feb 07 |
jari |
478 |
private IViewer createHCLViewer(Node clusterNode, GeneralInfo info, int [][] sampleClusters) { |
2 |
26 Feb 07 |
jari |
479 |
HCLTreeData genes_result = info.hcl_genes ? getResult(clusterNode, 0) : null; |
2 |
26 Feb 07 |
jari |
480 |
HCLTreeData samples_result = info.hcl_samples ? getResult(clusterNode, info.hcl_genes ? 4 : 0) : null; |
2 |
26 Feb 07 |
jari |
481 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
482 |
return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result); |
2 |
26 Feb 07 |
jari |
483 |
else |
2 |
26 Feb 07 |
jari |
484 |
return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result, sampleClusters, true); |
2 |
26 Feb 07 |
jari |
485 |
} |
2 |
26 Feb 07 |
jari |
486 |
|
2 |
26 Feb 07 |
jari |
487 |
/** |
2 |
26 Feb 07 |
jari |
* Adds node with cluster information. |
2 |
26 Feb 07 |
jari |
489 |
*/ |
2 |
26 Feb 07 |
jari |
490 |
private void addClusterInfo(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
491 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information"); |
2 |
26 Feb 07 |
jari |
492 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
493 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Genes in Clusters (#,%)", new CASTInfoViewer(this.clusters, this.experiment.getNumberOfGenes())))); |
2 |
26 Feb 07 |
jari |
494 |
else |
2 |
26 Feb 07 |
jari |
495 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Samples in Clusters (#,%)", new CASTInfoViewer(this.clusters, this.experiment.getNumberOfSamples(), false)))); |
2 |
26 Feb 07 |
jari |
496 |
root.add(node); |
2 |
26 Feb 07 |
jari |
497 |
} |
2 |
26 Feb 07 |
jari |
498 |
|
2 |
26 Feb 07 |
jari |
499 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display centroid charts. |
2 |
26 Feb 07 |
jari |
501 |
*/ |
2 |
26 Feb 07 |
jari |
502 |
private void addCentroidViews(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
503 |
DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs"); |
2 |
26 Feb 07 |
jari |
504 |
DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs"); |
2 |
26 Feb 07 |
jari |
505 |
|
2 |
26 Feb 07 |
jari |
506 |
CASTCentroidViewer centroidViewer; |
2 |
26 Feb 07 |
jari |
507 |
CASTExperimentCentroidViewer expCentroidViewer; |
2 |
26 Feb 07 |
jari |
508 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
509 |
centroidViewer = new CASTCentroidViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
510 |
centroidViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
511 |
centroidViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
512 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
513 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
514 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
515 |
} |
2 |
26 Feb 07 |
jari |
516 |
|
2 |
26 Feb 07 |
jari |
517 |
CASTCentroidsViewer centroidsViewer = new CASTCentroidsViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
518 |
centroidsViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
519 |
centroidsViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
520 |
|
2 |
26 Feb 07 |
jari |
521 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
522 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
523 |
|
2 |
26 Feb 07 |
jari |
524 |
} |
2 |
26 Feb 07 |
jari |
525 |
else{ |
2 |
26 Feb 07 |
jari |
526 |
expCentroidViewer = new CASTExperimentCentroidViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
527 |
|
2 |
26 Feb 07 |
jari |
528 |
expCentroidViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
529 |
expCentroidViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
530 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
531 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
532 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
533 |
} |
2 |
26 Feb 07 |
jari |
534 |
CASTExperimentCentroidsViewer expCentroidsViewer = new CASTExperimentCentroidsViewer(this.experiment, clusters); |
2 |
26 Feb 07 |
jari |
535 |
expCentroidsViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
536 |
expCentroidsViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
537 |
|
2 |
26 Feb 07 |
jari |
538 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
539 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
540 |
|
2 |
26 Feb 07 |
jari |
541 |
|
2 |
26 Feb 07 |
jari |
542 |
} |
2 |
26 Feb 07 |
jari |
543 |
root.add(centroidNode); |
2 |
26 Feb 07 |
jari |
544 |
root.add(expressionNode); |
2 |
26 Feb 07 |
jari |
545 |
} |
2 |
26 Feb 07 |
jari |
546 |
|
2 |
26 Feb 07 |
jari |
547 |
|
2 |
26 Feb 07 |
jari |
548 |
/** |
2 |
26 Feb 07 |
jari |
* Adds node with general iformation. |
2 |
26 Feb 07 |
jari |
550 |
*/ |
2 |
26 Feb 07 |
jari |
551 |
private void addGeneralInfo(DefaultMutableTreeNode root, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
552 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("General Information"); |
2 |
26 Feb 07 |
jari |
553 |
node.add(new DefaultMutableTreeNode("Clusters: "+String.valueOf(info.clusters))); |
2 |
26 Feb 07 |
jari |
554 |
node.add(new DefaultMutableTreeNode("Threshold: "+String.valueOf(info.threshold))); |
2 |
26 Feb 07 |
jari |
555 |
node.add(new DefaultMutableTreeNode("Absolute distance: "+String.valueOf(info.isAbsolute))); |
2 |
26 Feb 07 |
jari |
556 |
node.add(new DefaultMutableTreeNode("HCL: "+info.getMethodName())); |
2 |
26 Feb 07 |
jari |
557 |
node.add(new DefaultMutableTreeNode("Time: "+String.valueOf(info.time)+" ms")); |
2 |
26 Feb 07 |
jari |
558 |
node.add(new DefaultMutableTreeNode(info.function)); |
2 |
26 Feb 07 |
jari |
559 |
root.add(node); |
2 |
26 Feb 07 |
jari |
560 |
} |
2 |
26 Feb 07 |
jari |
561 |
|
2 |
26 Feb 07 |
jari |
562 |
/*************************************************************************************** |
2 |
26 Feb 07 |
jari |
* Code to order sample clustering results based on HCL runs. sampleClusters contain an array |
2 |
26 Feb 07 |
jari |
* of sample indices for each experiment cluster. Note that these indicies are ordered in |
2 |
26 Feb 07 |
jari |
* an order which matches HCL input matrix sample order so that HCL results (node-order) can |
2 |
26 Feb 07 |
jari |
* be used to order leaf indices to match HCL samples results |
2 |
26 Feb 07 |
jari |
567 |
*/ |
2 |
26 Feb 07 |
jari |
568 |
private int [][] getOrderedIndices(NodeList nodeList, int [][] sampleClusters, boolean calcGeneHCL){ |
2 |
26 Feb 07 |
jari |
569 |
HCLTreeData result; |
2 |
26 Feb 07 |
jari |
570 |
for(int i = 0; i < sampleClusters.length ; i++){ |
2 |
26 Feb 07 |
jari |
571 |
if(sampleClusters[i].length > 0){ |
2 |
26 Feb 07 |
jari |
572 |
result = getResult(nodeList.getNode(i), calcGeneHCL ? 4 : 0); //get sample Result |
2 |
26 Feb 07 |
jari |
573 |
sampleClusters[i] = getSampleOrder(result, sampleClusters[i]); |
2 |
26 Feb 07 |
jari |
574 |
} |
2 |
26 Feb 07 |
jari |
575 |
} |
2 |
26 Feb 07 |
jari |
576 |
return sampleClusters; |
2 |
26 Feb 07 |
jari |
577 |
} |
2 |
26 Feb 07 |
jari |
578 |
|
2 |
26 Feb 07 |
jari |
579 |
private int[] getSampleOrder(HCLTreeData result, int[] indices) { |
2 |
26 Feb 07 |
jari |
580 |
return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices); |
2 |
26 Feb 07 |
jari |
581 |
} |
2 |
26 Feb 07 |
jari |
582 |
|
2 |
26 Feb 07 |
jari |
583 |
private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) { |
2 |
26 Feb 07 |
jari |
584 |
int[] leafOrder = new int[nodeOrder.length]; |
2 |
26 Feb 07 |
jari |
585 |
Arrays.fill(leafOrder, -1); |
2 |
26 Feb 07 |
jari |
586 |
fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices); |
2 |
26 Feb 07 |
jari |
587 |
return leafOrder; |
2 |
26 Feb 07 |
jari |
588 |
} |
2 |
26 Feb 07 |
jari |
589 |
|
2 |
26 Feb 07 |
jari |
590 |
private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) { |
2 |
26 Feb 07 |
jari |
591 |
if (child1[index] != -1) { |
2 |
26 Feb 07 |
jari |
592 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices); |
2 |
26 Feb 07 |
jari |
593 |
} |
2 |
26 Feb 07 |
jari |
594 |
if (child2[index] != -1) { |
2 |
26 Feb 07 |
jari |
595 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices); |
2 |
26 Feb 07 |
jari |
596 |
} else { |
2 |
26 Feb 07 |
jari |
597 |
leafOrder[pos] = indices == null ? index : indices[index]; |
2 |
26 Feb 07 |
jari |
598 |
pos++; |
2 |
26 Feb 07 |
jari |
599 |
} |
2 |
26 Feb 07 |
jari |
600 |
return pos; |
2 |
26 Feb 07 |
jari |
601 |
} |
2 |
26 Feb 07 |
jari |
602 |
|
2 |
26 Feb 07 |
jari |
603 |
/**************************************************************************************** |
2 |
26 Feb 07 |
jari |
* End of Sample Cluster index ordering code |
2 |
26 Feb 07 |
jari |
605 |
*/ |
2 |
26 Feb 07 |
jari |
606 |
|
2 |
26 Feb 07 |
jari |
607 |
|
2 |
26 Feb 07 |
jari |
608 |
|
2 |
26 Feb 07 |
jari |
609 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to progress, monitor and algorithms events. |
2 |
26 Feb 07 |
jari |
611 |
*/ |
2 |
26 Feb 07 |
jari |
612 |
private class Listener extends DialogListener implements AlgorithmListener { |
2 |
26 Feb 07 |
jari |
613 |
|
2 |
26 Feb 07 |
jari |
614 |
public void valueChanged(AlgorithmEvent event) { |
2 |
26 Feb 07 |
jari |
615 |
|
2 |
26 Feb 07 |
jari |
616 |
} |
2 |
26 Feb 07 |
jari |
617 |
|
2 |
26 Feb 07 |
jari |
618 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
619 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
620 |
if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
621 |
algorithm.abort(); |
2 |
26 Feb 07 |
jari |
622 |
cleanUp(); |
2 |
26 Feb 07 |
jari |
623 |
} |
2 |
26 Feb 07 |
jari |
624 |
} |
2 |
26 Feb 07 |
jari |
625 |
|
2 |
26 Feb 07 |
jari |
626 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
627 |
algorithm.abort(); |
2 |
26 Feb 07 |
jari |
628 |
cleanUp(); |
2 |
26 Feb 07 |
jari |
629 |
} |
2 |
26 Feb 07 |
jari |
630 |
|
2 |
26 Feb 07 |
jari |
631 |
public void cleanUp() { |
2 |
26 Feb 07 |
jari |
632 |
} |
2 |
26 Feb 07 |
jari |
633 |
} |
2 |
26 Feb 07 |
jari |
634 |
|
2 |
26 Feb 07 |
jari |
// the general info structure |
2 |
26 Feb 07 |
jari |
636 |
private class GeneralInfo { |
2 |
26 Feb 07 |
jari |
637 |
public int clusters; |
2 |
26 Feb 07 |
jari |
//public boolean converged; |
2 |
26 Feb 07 |
jari |
//public int iterations; |
2 |
26 Feb 07 |
jari |
640 |
public long time; |
2 |
26 Feb 07 |
jari |
641 |
public float threshold; |
2 |
26 Feb 07 |
jari |
642 |
public boolean isAbsolute; |
2 |
26 Feb 07 |
jari |
643 |
public String function; |
2 |
26 Feb 07 |
jari |
644 |
|
2 |
26 Feb 07 |
jari |
645 |
private boolean hcl; |
2 |
26 Feb 07 |
jari |
646 |
private int hcl_method; |
2 |
26 Feb 07 |
jari |
647 |
private boolean hcl_genes; |
2 |
26 Feb 07 |
jari |
648 |
private boolean hcl_samples; |
2 |
26 Feb 07 |
jari |
649 |
|
2 |
26 Feb 07 |
jari |
650 |
public String getMethodName() { |
2 |
26 Feb 07 |
jari |
651 |
return hcl ? HCLGUI.GeneralInfo.getMethodName(hcl_method) : "no linkage"; |
2 |
26 Feb 07 |
jari |
652 |
} |
2 |
26 Feb 07 |
jari |
653 |
|
2 |
26 Feb 07 |
jari |
654 |
} |
2 |
26 Feb 07 |
jari |
655 |
} |