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