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: RNGUI.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.7 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 20:39:04 $ |
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.rn; |
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 |
|
2 |
26 Feb 07 |
jari |
17 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.tree.DefaultMutableTreeNode; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
import org.tigr.microarray.mev.cluster.Cluster; |
2 |
26 Feb 07 |
jari |
21 |
import org.tigr.microarray.mev.cluster.NodeList; |
2 |
26 Feb 07 |
jari |
22 |
import org.tigr.microarray.mev.cluster.algorithm.Algorithm; |
2 |
26 Feb 07 |
jari |
23 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData; |
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent; |
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmListener; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.gui.IClusterGUI; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.gui.IDistanceMenu; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.LeafInfo; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.helpers.ClusterTableViewer; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterCentroidViewer; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterTableViewer; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.Progress; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.impl.util.IntSorter; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
44 |
|
2 |
26 Feb 07 |
jari |
45 |
public class RNGUI implements IClusterGUI, IScriptGUI { |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
private Algorithm algorithm; |
2 |
26 Feb 07 |
jari |
48 |
private Progress progress; |
2 |
26 Feb 07 |
jari |
49 |
private FloatMatrix means; |
2 |
26 Feb 07 |
jari |
50 |
private FloatMatrix variances; |
2 |
26 Feb 07 |
jari |
51 |
private IData data; |
2 |
26 Feb 07 |
jari |
52 |
/** |
2 |
26 Feb 07 |
jari |
* Initialize the algorithm's parameters and execute it. |
2 |
26 Feb 07 |
jari |
54 |
*/ |
2 |
26 Feb 07 |
jari |
55 |
public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
RelNetInitDialog dlg = new RelNetInitDialog(framework.getFrame()); |
2 |
26 Feb 07 |
jari |
58 |
if (dlg.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
59 |
return null; |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
boolean use_permutation = dlg.usePermutation(); |
2 |
26 Feb 07 |
jari |
63 |
float min_threshold = dlg.getMinThreshold(); |
2 |
26 Feb 07 |
jari |
64 |
float max_threshold = dlg.getMaxThreshold(); |
2 |
26 Feb 07 |
jari |
65 |
boolean use_entropy = dlg.useEntropy(); |
2 |
26 Feb 07 |
jari |
66 |
float entropy = use_entropy ? dlg.getEntropy() : 100f; |
2 |
26 Feb 07 |
jari |
67 |
boolean clusterGenes = dlg.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
68 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
71 |
try { |
2 |
26 Feb 07 |
jari |
72 |
this.algorithm = framework.getAlgorithmFactory().getAlgorithm("RN"); |
2 |
26 Feb 07 |
jari |
73 |
this.algorithm.addAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
this.progress = new Progress(framework.getFrame(), "Calculating Relevance Network", listener); |
2 |
26 Feb 07 |
jari |
76 |
this.progress.show(); |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
79 |
Experiment experiment = framework.getData().getExperiment(); |
2 |
26 Feb 07 |
jari |
80 |
data.addMatrix("experiment", clusterGenes ? experiment.getMatrix() : experiment.getMatrix().transpose()); |
2 |
26 Feb 07 |
jari |
81 |
data.addParam("distance-factor", String.valueOf(1.0f)); |
2 |
26 Feb 07 |
jari |
82 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
83 |
data.addParam("distance-absolute", String.valueOf(true)); // is always absolute |
2 |
26 Feb 07 |
jari |
84 |
int function = Algorithm.PEARSON; // is always pearson |
2 |
26 Feb 07 |
jari |
85 |
data.addParam("distance-function", String.valueOf(function)); |
2 |
26 Feb 07 |
jari |
86 |
data.addParam("use-permutation", String.valueOf(use_permutation)); |
2 |
26 Feb 07 |
jari |
87 |
data.addParam("min-threshold", String.valueOf(min_threshold)); |
2 |
26 Feb 07 |
jari |
88 |
data.addParam("max-threshold", String.valueOf(max_threshold)); |
2 |
26 Feb 07 |
jari |
89 |
data.addParam("filter-by-entropy", String.valueOf(use_entropy)); |
2 |
26 Feb 07 |
jari |
90 |
data.addParam("top-n-percent", String.valueOf(entropy)); |
2 |
26 Feb 07 |
jari |
// stub: to test PVM version |
2 |
26 Feb 07 |
jari |
92 |
data.addParam("threshold", String.valueOf(min_threshold)); |
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
94 |
long start = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
95 |
AlgorithmData result = this.algorithm.execute(data); |
2 |
26 Feb 07 |
jari |
96 |
long time = System.currentTimeMillis() - start; |
2 |
26 Feb 07 |
jari |
97 |
int[][] clusters = convert2int(result.getCluster("cluster")); |
2 |
26 Feb 07 |
jari |
98 |
float[][] weights = convert2float(result.getCluster("weights")); |
2 |
26 Feb 07 |
jari |
99 |
this.means = result.getMatrix("means"); |
2 |
26 Feb 07 |
jari |
100 |
this.variances = result.getMatrix("variances"); |
2 |
26 Feb 07 |
jari |
101 |
AlgorithmParameters params = result.getParams(); |
2 |
26 Feb 07 |
jari |
102 |
result = null; //gc |
2 |
26 Feb 07 |
jari |
103 |
int[] indices = getSortedIndices(clusters); |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
GeneralInfo info = new GeneralInfo(); |
2 |
26 Feb 07 |
jari |
106 |
info.time = time; |
2 |
26 Feb 07 |
jari |
107 |
info.links = params.getInt("links", 0); |
2 |
26 Feb 07 |
jari |
108 |
info.min_threshold = params.getFloat("min_threshold"); |
2 |
26 Feb 07 |
jari |
109 |
info.max_threshold = max_threshold; |
2 |
26 Feb 07 |
jari |
110 |
info.entropy = entropy; |
2 |
26 Feb 07 |
jari |
111 |
info.function = menu.getFunctionName(function); |
2 |
26 Feb 07 |
jari |
112 |
info.absolute = true; |
2 |
26 Feb 07 |
jari |
113 |
return createResultTree(experiment, clusters, weights, indices, info, clusterGenes); |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
} finally { |
2 |
26 Feb 07 |
jari |
116 |
if (algorithm != null) { |
2 |
26 Feb 07 |
jari |
117 |
algorithm.removeAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
if (progress != null) { |
2 |
26 Feb 07 |
jari |
120 |
progress.dispose(); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
} |
2 |
26 Feb 07 |
jari |
123 |
} |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
|
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
127 |
public AlgorithmData getScriptParameters(IFramework framework) { |
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
RelNetInitDialog dlg = new RelNetInitDialog(framework.getFrame()); |
2 |
26 Feb 07 |
jari |
130 |
if (dlg.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
131 |
return null; |
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
boolean use_permutation = dlg.usePermutation(); |
2 |
26 Feb 07 |
jari |
135 |
float min_threshold = dlg.getMinThreshold(); |
2 |
26 Feb 07 |
jari |
136 |
float max_threshold = dlg.getMaxThreshold(); |
2 |
26 Feb 07 |
jari |
137 |
boolean use_entropy = dlg.useEntropy(); |
2 |
26 Feb 07 |
jari |
138 |
float entropy = use_entropy ? dlg.getEntropy() : 100f; |
2 |
26 Feb 07 |
jari |
139 |
boolean clusterGenes = dlg.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
140 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
143 |
Experiment experiment = framework.getData().getExperiment(); |
2 |
26 Feb 07 |
jari |
144 |
data.addParam("rn-cluster-genes", String.valueOf(clusterGenes)); |
2 |
26 Feb 07 |
jari |
145 |
data.addParam("distance-factor", String.valueOf(1.0f)); |
2 |
26 Feb 07 |
jari |
146 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
147 |
data.addParam("distance-absolute", String.valueOf(true)); // is always absolute |
2 |
26 Feb 07 |
jari |
148 |
int function = Algorithm.PEARSON; // is always pearson |
2 |
26 Feb 07 |
jari |
149 |
data.addParam("distance-function", String.valueOf(function)); |
2 |
26 Feb 07 |
jari |
150 |
data.addParam("use-permutation", String.valueOf(use_permutation)); |
2 |
26 Feb 07 |
jari |
151 |
data.addParam("min-threshold", String.valueOf(min_threshold)); |
2 |
26 Feb 07 |
jari |
152 |
data.addParam("max-threshold", String.valueOf(max_threshold)); |
2 |
26 Feb 07 |
jari |
153 |
data.addParam("filter-by-entropy", String.valueOf(use_entropy)); |
2 |
26 Feb 07 |
jari |
154 |
data.addParam("top-n-percent", String.valueOf(entropy)); |
2 |
26 Feb 07 |
jari |
// stub: to test PVM version |
2 |
26 Feb 07 |
jari |
156 |
data.addParam("threshold", String.valueOf(min_threshold)); |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
//script control parameters |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
// alg name |
2 |
26 Feb 07 |
jari |
161 |
data.addParam("name", "RN"); |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
// alg type |
2 |
26 Feb 07 |
jari |
164 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
165 |
data.addParam("alg-type", "cluster-genes"); |
2 |
26 Feb 07 |
jari |
166 |
else |
2 |
26 Feb 07 |
jari |
167 |
data.addParam("alg-type", "cluster-experiments"); |
2 |
26 Feb 07 |
jari |
168 |
|
2 |
26 Feb 07 |
jari |
// output class |
2 |
26 Feb 07 |
jari |
170 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
171 |
data.addParam("output-class", "multi-gene-cluster-output"); |
2 |
26 Feb 07 |
jari |
172 |
else |
2 |
26 Feb 07 |
jari |
173 |
data.addParam("output-class", "multi-experiment-cluster-output"); |
2 |
26 Feb 07 |
jari |
174 |
|
2 |
26 Feb 07 |
jari |
//output nodes |
2 |
26 Feb 07 |
jari |
176 |
String [] outputNodes = new String[1]; |
2 |
26 Feb 07 |
jari |
177 |
outputNodes[0] = "Multi-cluster"; |
2 |
26 Feb 07 |
jari |
178 |
data.addStringArray("output-nodes", outputNodes); |
2 |
26 Feb 07 |
jari |
179 |
|
2 |
26 Feb 07 |
jari |
180 |
return data; |
2 |
26 Feb 07 |
jari |
181 |
} |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
public DefaultMutableTreeNode executeScript(IFramework framework, AlgorithmData algData, Experiment experiment) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
boolean clusterGenes = algData.getParams().getBoolean("rn-cluster-genes"); |
2 |
26 Feb 07 |
jari |
186 |
System.out.println("cluster genes = "+clusterGenes); |
2 |
26 Feb 07 |
jari |
187 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
188 |
|
2 |
26 Feb 07 |
jari |
189 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
try { |
2 |
26 Feb 07 |
jari |
192 |
this.algorithm = framework.getAlgorithmFactory().getAlgorithm("RN"); |
2 |
26 Feb 07 |
jari |
193 |
this.algorithm.addAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
this.progress = new Progress(framework.getFrame(), "Calculating Relevance Network", listener); |
2 |
26 Feb 07 |
jari |
196 |
this.progress.show(); |
2 |
26 Feb 07 |
jari |
197 |
|
2 |
26 Feb 07 |
jari |
198 |
algData.addMatrix("experiment", clusterGenes ? experiment.getMatrix() : experiment.getMatrix().transpose()); |
2 |
26 Feb 07 |
jari |
199 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
200 |
int function = Algorithm.PEARSON; // is always pearson |
2 |
26 Feb 07 |
jari |
201 |
|
2 |
26 Feb 07 |
jari |
202 |
|
2 |
26 Feb 07 |
jari |
203 |
long start = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
204 |
AlgorithmData result = this.algorithm.execute(algData); |
2 |
26 Feb 07 |
jari |
205 |
long time = System.currentTimeMillis() - start; |
2 |
26 Feb 07 |
jari |
206 |
int[][] clusters = convert2int(result.getCluster("cluster")); |
2 |
26 Feb 07 |
jari |
207 |
float[][] weights = convert2float(result.getCluster("weights")); |
2 |
26 Feb 07 |
jari |
208 |
this.means = result.getMatrix("means"); |
2 |
26 Feb 07 |
jari |
209 |
this.variances = result.getMatrix("variances"); |
2 |
26 Feb 07 |
jari |
210 |
AlgorithmParameters params = result.getParams(); |
2 |
26 Feb 07 |
jari |
211 |
result = null; //gc |
2 |
26 Feb 07 |
jari |
212 |
int[] indices = getSortedIndices(clusters); |
2 |
26 Feb 07 |
jari |
213 |
|
2 |
26 Feb 07 |
jari |
214 |
System.out.println("cluster length ="+clusters.length); |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
AlgorithmParameters algDataParams = algData.getParams(); |
2 |
26 Feb 07 |
jari |
217 |
function = algDataParams.getInt("distance-function"); |
2 |
26 Feb 07 |
jari |
218 |
|
2 |
26 Feb 07 |
jari |
219 |
GeneralInfo info = new GeneralInfo(); |
2 |
26 Feb 07 |
jari |
220 |
info.time = time; |
2 |
26 Feb 07 |
jari |
221 |
info.links = params.getInt("links", 0); |
2 |
26 Feb 07 |
jari |
222 |
info.min_threshold = algDataParams.getFloat("min-threshold"); |
2 |
26 Feb 07 |
jari |
223 |
info.max_threshold = algDataParams.getFloat("max-threshold"); |
2 |
26 Feb 07 |
jari |
224 |
info.entropy = algDataParams.getFloat("top-n-percent"); |
2 |
26 Feb 07 |
jari |
225 |
info.function = menu.getFunctionName(function); |
2 |
26 Feb 07 |
jari |
226 |
info.absolute = true; |
2 |
26 Feb 07 |
jari |
227 |
return createResultTree(experiment, clusters, weights, indices, info, clusterGenes); |
2 |
26 Feb 07 |
jari |
228 |
|
2 |
26 Feb 07 |
jari |
229 |
} finally { |
2 |
26 Feb 07 |
jari |
230 |
if (algorithm != null) { |
2 |
26 Feb 07 |
jari |
231 |
algorithm.removeAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
232 |
} |
2 |
26 Feb 07 |
jari |
233 |
if (progress != null) { |
2 |
26 Feb 07 |
jari |
234 |
progress.dispose(); |
2 |
26 Feb 07 |
jari |
235 |
} |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
} |
2 |
26 Feb 07 |
jari |
238 |
|
2 |
26 Feb 07 |
jari |
239 |
|
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
/** |
2 |
26 Feb 07 |
jari |
* Converts a passed cluster into a two dimensional int array. |
2 |
26 Feb 07 |
jari |
245 |
*/ |
2 |
26 Feb 07 |
jari |
246 |
private int[][] convert2int(Cluster cluster) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
247 |
NodeList nodeList = cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
248 |
final int nodeListSize = nodeList.getSize(); |
2 |
26 Feb 07 |
jari |
249 |
int[][] result = new int[nodeListSize][]; |
2 |
26 Feb 07 |
jari |
250 |
for (int i=0; i<nodeListSize; i++) { |
2 |
26 Feb 07 |
jari |
251 |
result[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
252 |
if (result[i] == null) { |
2 |
26 Feb 07 |
jari |
253 |
throw new AlgorithmException("Cluster "+i+" does not contain indices."); |
2 |
26 Feb 07 |
jari |
254 |
} |
2 |
26 Feb 07 |
jari |
255 |
} |
2 |
26 Feb 07 |
jari |
256 |
return result; |
2 |
26 Feb 07 |
jari |
257 |
} |
2 |
26 Feb 07 |
jari |
258 |
|
2 |
26 Feb 07 |
jari |
259 |
private static float[] int2float(int[] ints) { |
2 |
26 Feb 07 |
jari |
260 |
if (ints == null) |
2 |
26 Feb 07 |
jari |
261 |
return null; |
2 |
26 Feb 07 |
jari |
262 |
float[] floats = new float[ints.length]; |
2 |
26 Feb 07 |
jari |
263 |
for (int i=0; i<floats.length; i++) |
2 |
26 Feb 07 |
jari |
264 |
floats[i] = Float.intBitsToFloat(ints[i]); |
2 |
26 Feb 07 |
jari |
265 |
return floats; |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
/** |
2 |
26 Feb 07 |
jari |
* Converts a passed cluster into a two dimensional float array |
2 |
26 Feb 07 |
jari |
270 |
*/ |
2 |
26 Feb 07 |
jari |
271 |
private float[][] convert2float(Cluster cluster) { |
2 |
26 Feb 07 |
jari |
272 |
if (cluster == null) { |
2 |
26 Feb 07 |
jari |
273 |
return null; |
2 |
26 Feb 07 |
jari |
274 |
} |
2 |
26 Feb 07 |
jari |
275 |
NodeList nodeList = cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
276 |
float[][] result = new float[nodeList.getSize()][]; |
2 |
26 Feb 07 |
jari |
277 |
for (int i=0; i<nodeList.getSize(); i++) |
2 |
26 Feb 07 |
jari |
278 |
result[i] = int2float(nodeList.getNode(i).getFeaturesIndexes()); |
2 |
26 Feb 07 |
jari |
279 |
return result; |
2 |
26 Feb 07 |
jari |
280 |
} |
2 |
26 Feb 07 |
jari |
281 |
|
2 |
26 Feb 07 |
jari |
282 |
/** |
2 |
26 Feb 07 |
jari |
* Sort the order of specified clusters. |
2 |
26 Feb 07 |
jari |
* @return array of sorted indices. |
2 |
26 Feb 07 |
jari |
285 |
*/ |
2 |
26 Feb 07 |
jari |
286 |
private int[] getSortedIndices(int[][] clusters) { |
2 |
26 Feb 07 |
jari |
287 |
int[] indices = new int[clusters.length]; |
2 |
26 Feb 07 |
jari |
288 |
for (int i = indices.length; --i >= 0;) { |
2 |
26 Feb 07 |
jari |
289 |
indices[i] = i; |
2 |
26 Feb 07 |
jari |
290 |
} |
2 |
26 Feb 07 |
jari |
291 |
IntSorter.sort(indices, new RelNetComparator(clusters)); |
2 |
26 Feb 07 |
jari |
292 |
|
2 |
26 Feb 07 |
jari |
293 |
return indices; |
2 |
26 Feb 07 |
jari |
294 |
} |
2 |
26 Feb 07 |
jari |
295 |
|
2 |
26 Feb 07 |
jari |
296 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the relnet analysis result tree. |
2 |
26 Feb 07 |
jari |
298 |
*/ |
2 |
26 Feb 07 |
jari |
299 |
private DefaultMutableTreeNode createResultTree(Experiment experiment, int[][] clusters, float[][] weights, int[] indices, GeneralInfo info, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
300 |
DefaultMutableTreeNode root; |
2 |
26 Feb 07 |
jari |
301 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
302 |
root = new DefaultMutableTreeNode("RelNet - genes"); |
2 |
26 Feb 07 |
jari |
303 |
else |
2 |
26 Feb 07 |
jari |
304 |
root = new DefaultMutableTreeNode("RelNet - samples"); |
2 |
26 Feb 07 |
jari |
305 |
|
2 |
26 Feb 07 |
jari |
306 |
addResultNodes(root, experiment, clusters, weights, indices, info, clusterGenes); |
2 |
26 Feb 07 |
jari |
307 |
return root; |
2 |
26 Feb 07 |
jari |
308 |
} |
2 |
26 Feb 07 |
jari |
309 |
|
2 |
26 Feb 07 |
jari |
310 |
/** |
2 |
26 Feb 07 |
jari |
* Adds a result nodes. |
2 |
26 Feb 07 |
jari |
312 |
*/ |
2 |
26 Feb 07 |
jari |
313 |
private void addResultNodes(DefaultMutableTreeNode root, Experiment experiment, int[][] clusters, float[][] weights, int[] indices, GeneralInfo info, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
DefaultMutableTreeNode elementClusterNode = new DefaultMutableTreeNode("Element Seed Clusters"); |
2 |
26 Feb 07 |
jari |
316 |
addExpressionImages(elementClusterNode, experiment, clusters, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
317 |
addCentroidViews(elementClusterNode, experiment, clusters, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
318 |
addTableViews(elementClusterNode, experiment, clusters, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
319 |
addElementClusterInfo(elementClusterNode, experiment, clusters, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
320 |
|
2 |
26 Feb 07 |
jari |
321 |
DefaultMutableTreeNode subnetNode = new DefaultMutableTreeNode("Subnets"); |
2 |
26 Feb 07 |
jari |
322 |
addSubnets(subnetNode, experiment, clusters, clusterGenes); //adds expression images AND graphs |
2 |
26 Feb 07 |
jari |
323 |
|
2 |
26 Feb 07 |
jari |
324 |
addRelevanceNetworkViewer(root, experiment, clusters, weights, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
325 |
root.add(elementClusterNode); |
2 |
26 Feb 07 |
jari |
326 |
root.add(subnetNode); |
2 |
26 Feb 07 |
jari |
327 |
addGeneralInfo(root, info); |
2 |
26 Feb 07 |
jari |
328 |
} |
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
330 |
private void addElementClusterInfo(DefaultMutableTreeNode root, Experiment experiment, int [][] clusters, int [] orderedIndices, boolean clusterGenes){ |
2 |
26 Feb 07 |
jari |
331 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information"); |
2 |
26 Feb 07 |
jari |
332 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
333 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Genes in Clusters (#,%)", new RNElementSeedInfoViewer(clusters, experiment, orderedIndices, experiment.getNumberOfGenes(), true)))); |
2 |
26 Feb 07 |
jari |
334 |
else |
2 |
26 Feb 07 |
jari |
335 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Samples in Clusters (#,%)", new RNElementSeedInfoViewer(clusters, experiment, orderedIndices, experiment.getNumberOfSamples(), false)))); |
2 |
26 Feb 07 |
jari |
336 |
root.add(node); |
2 |
26 Feb 07 |
jari |
337 |
} |
2 |
26 Feb 07 |
jari |
338 |
|
2 |
26 Feb 07 |
jari |
339 |
private void addSubnetClusterInfo(DefaultMutableTreeNode root, Experiment experiment, int [][] clusters, int orderedIndices [], boolean clusterGenes){ |
2 |
26 Feb 07 |
jari |
340 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information"); |
2 |
26 Feb 07 |
jari |
341 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
342 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Genes in Subnets (#,%)", new RNSubnetInfoViewer(clusters, orderedIndices, experiment.getNumberOfGenes(), true)))); |
2 |
26 Feb 07 |
jari |
343 |
else |
2 |
26 Feb 07 |
jari |
344 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Samples in Subnets (#,%)", new RNSubnetInfoViewer(clusters, orderedIndices, experiment.getNumberOfSamples(), false)))); |
2 |
26 Feb 07 |
jari |
345 |
root.add(node); |
2 |
26 Feb 07 |
jari |
346 |
} |
2 |
26 Feb 07 |
jari |
347 |
|
2 |
26 Feb 07 |
jari |
348 |
|
2 |
26 Feb 07 |
jari |
349 |
private void addTableViews(DefaultMutableTreeNode root, Experiment experiment, int[][] clusters, int[] indices, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
350 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Table views"); |
2 |
26 Feb 07 |
jari |
351 |
IViewer viewer; |
2 |
26 Feb 07 |
jari |
352 |
if (clusterGenes) |
2 |
26 Feb 07 |
jari |
353 |
viewer = new ClusterTableViewer(experiment, clusters, this.data); |
2 |
26 Feb 07 |
jari |
354 |
else |
2 |
26 Feb 07 |
jari |
355 |
viewer = new ExperimentClusterTableViewer(experiment, clusters, this.data); |
2 |
26 Feb 07 |
jari |
//return; //placeholder for ExptClusterTableViewer |
2 |
26 Feb 07 |
jari |
//viewer = new RelNetExperimentClusterViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
358 |
for (int i=0; i<clusters.length; i++) |
2 |
26 Feb 07 |
jari |
359 |
if (clusters[indices[i]].length > 1) |
2 |
26 Feb 07 |
jari |
360 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Element index "+String.valueOf(experiment.getGeneIndexMappedToData(clusters[i][0])+1)+" ("+clusters[indices[i]].length+")", viewer, new Integer(indices[i])))); |
2 |
26 Feb 07 |
jari |
361 |
root.add(node); |
2 |
26 Feb 07 |
jari |
362 |
} |
2 |
26 Feb 07 |
jari |
363 |
|
2 |
26 Feb 07 |
jari |
364 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display expression images. |
2 |
26 Feb 07 |
jari |
366 |
*/ |
2 |
26 Feb 07 |
jari |
367 |
private void addExpressionImages(DefaultMutableTreeNode root, Experiment experiment, int[][] clusters, int[] indices, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
368 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images"); |
2 |
26 Feb 07 |
jari |
369 |
IViewer viewer; |
2 |
26 Feb 07 |
jari |
370 |
if (clusterGenes) |
2 |
26 Feb 07 |
jari |
371 |
viewer = new RelNetExperimentViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
372 |
else |
2 |
26 Feb 07 |
jari |
373 |
viewer = new RelNetExperimentClusterViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
374 |
for (int i=0; i<clusters.length; i++) |
2 |
26 Feb 07 |
jari |
375 |
if (clusters[indices[i]].length > 1) |
2 |
26 Feb 07 |
jari |
376 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Element index "+String.valueOf(experiment.getGeneIndexMappedToData(clusters[i][0])+1)+" ("+clusters[indices[i]].length+")", viewer, new Integer(indices[i])))); |
2 |
26 Feb 07 |
jari |
377 |
root.add(node); |
2 |
26 Feb 07 |
jari |
378 |
} |
2 |
26 Feb 07 |
jari |
379 |
|
2 |
26 Feb 07 |
jari |
380 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display centroid charts. |
2 |
26 Feb 07 |
jari |
382 |
*/ |
2 |
26 Feb 07 |
jari |
383 |
private void addCentroidViews(DefaultMutableTreeNode root, Experiment experiment, int [][] clusters, int [] indices, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
384 |
DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs"); |
2 |
26 Feb 07 |
jari |
385 |
DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs"); |
2 |
26 Feb 07 |
jari |
386 |
|
2 |
26 Feb 07 |
jari |
387 |
RNCentroidViewer centroidViewer; |
2 |
26 Feb 07 |
jari |
388 |
ExperimentClusterCentroidViewer expCentroidViewer; |
2 |
26 Feb 07 |
jari |
389 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
390 |
centroidViewer = new RNCentroidViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
391 |
centroidViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
392 |
centroidViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
393 |
for (int i=0; i< clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
394 |
if (clusters[indices[i]].length > 1){ |
2 |
26 Feb 07 |
jari |
395 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Element index "+String.valueOf(experiment.getGeneIndexMappedToData(clusters[i][0])+1)+" ("+clusters[indices[i]].length+")", centroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
396 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Element index "+String.valueOf(experiment.getGeneIndexMappedToData(clusters[i][0])+1)+" ("+clusters[indices[i]].length+")", centroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
397 |
} |
2 |
26 Feb 07 |
jari |
398 |
} |
2 |
26 Feb 07 |
jari |
399 |
|
2 |
26 Feb 07 |
jari |
// RNCentroidsViewer centroidsViewer = new RNCentroidsViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
// centroidsViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
// centroidsViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
403 |
|
2 |
26 Feb 07 |
jari |
// centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
// expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
406 |
|
2 |
26 Feb 07 |
jari |
407 |
} |
2 |
26 Feb 07 |
jari |
408 |
else{ |
2 |
26 Feb 07 |
jari |
409 |
expCentroidViewer = new RNExperimentCentroidViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
410 |
|
2 |
26 Feb 07 |
jari |
411 |
expCentroidViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
412 |
expCentroidViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
413 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
414 |
if (clusters[indices[i]].length > 1){ |
2 |
26 Feb 07 |
jari |
415 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Element index "+String.valueOf(indices[i]+1)+" ("+clusters[indices[i]].length+")", expCentroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
416 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Element index "+String.valueOf(indices[i]+1)+" ("+clusters[indices[i]].length+")", expCentroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
417 |
} |
2 |
26 Feb 07 |
jari |
418 |
} |
2 |
26 Feb 07 |
jari |
419 |
|
2 |
26 Feb 07 |
jari |
420 |
RNExperimentCentroidsViewer expCentroidsViewer = new RNExperimentCentroidsViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
421 |
expCentroidsViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
422 |
expCentroidsViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
423 |
|
2 |
26 Feb 07 |
jari |
424 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
425 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
426 |
} |
2 |
26 Feb 07 |
jari |
427 |
root.add(centroidNode); |
2 |
26 Feb 07 |
jari |
428 |
root.add(expressionNode); |
2 |
26 Feb 07 |
jari |
429 |
} |
2 |
26 Feb 07 |
jari |
430 |
|
2 |
26 Feb 07 |
jari |
431 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display relevance subnets. |
2 |
26 Feb 07 |
jari |
433 |
*/ |
2 |
26 Feb 07 |
jari |
434 |
private void addSubnets(DefaultMutableTreeNode root, Experiment experiment, int[][] clusters, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
435 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images"); |
2 |
26 Feb 07 |
jari |
436 |
RelevanceNetworkLayout layout = new RelevanceNetworkLayout(); |
2 |
26 Feb 07 |
jari |
437 |
int[][] subnets = layout.formRelevanceNetworks(clusters); |
2 |
26 Feb 07 |
jari |
438 |
int[] indices = getSortedIndices(subnets); |
2 |
26 Feb 07 |
jari |
439 |
IViewer viewer; |
2 |
26 Feb 07 |
jari |
440 |
if (clusterGenes) |
2 |
26 Feb 07 |
jari |
441 |
viewer = new RelNetExperimentViewer(experiment, subnets); |
2 |
26 Feb 07 |
jari |
442 |
else |
2 |
26 Feb 07 |
jari |
443 |
viewer = new RelNetExperimentClusterViewer(experiment, subnets); |
2 |
26 Feb 07 |
jari |
444 |
|
2 |
26 Feb 07 |
jari |
445 |
for (int i=0; i<subnets.length; i++) |
2 |
26 Feb 07 |
jari |
446 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Subnet "+String.valueOf(i+1)+" ("+subnets[indices[i]].length+")", viewer, new Integer(indices[i])))); |
2 |
26 Feb 07 |
jari |
447 |
root.add(node); |
2 |
26 Feb 07 |
jari |
448 |
addSubnetCentroidViews(root, experiment, subnets, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
449 |
addSubnetTableViews(root, experiment, subnets, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
450 |
addSubnetClusterInfo(root, experiment, subnets, indices, clusterGenes); |
2 |
26 Feb 07 |
jari |
451 |
} |
2 |
26 Feb 07 |
jari |
452 |
|
2 |
26 Feb 07 |
jari |
453 |
private void addSubnetTableViews(DefaultMutableTreeNode root, Experiment experiment, int [][] subnets, int [] indices, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
454 |
DefaultMutableTreeNode tabNode = new DefaultMutableTreeNode("Table Views"); |
2 |
26 Feb 07 |
jari |
455 |
IViewer viewer; |
2 |
26 Feb 07 |
jari |
456 |
if (clusterGenes) |
2 |
26 Feb 07 |
jari |
457 |
viewer = new ClusterTableViewer(experiment, subnets, this.data); |
2 |
26 Feb 07 |
jari |
458 |
else |
2 |
26 Feb 07 |
jari |
// viewer = new ExperimentClusterTableViewer(experiment, subnets, this.data); |
2 |
26 Feb 07 |
jari |
460 |
return; //placeholder for ExptClusterTableViewer |
2 |
26 Feb 07 |
jari |
461 |
for (int i=0; i<subnets.length; i++) |
2 |
26 Feb 07 |
jari |
462 |
tabNode.add(new DefaultMutableTreeNode(new LeafInfo("Subnet "+String.valueOf(i+1)+" ("+subnets[indices[i]].length+")", viewer, new Integer(indices[i])))); |
2 |
26 Feb 07 |
jari |
463 |
root.add(tabNode); |
2 |
26 Feb 07 |
jari |
464 |
} |
2 |
26 Feb 07 |
jari |
465 |
|
2 |
26 Feb 07 |
jari |
466 |
private void addSubnetCentroidViews(DefaultMutableTreeNode root, Experiment experiment, int [][] subnets, int [] indices, boolean clusterGenes){ |
2 |
26 Feb 07 |
jari |
467 |
DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs"); |
2 |
26 Feb 07 |
jari |
468 |
DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs"); |
2 |
26 Feb 07 |
jari |
469 |
|
2 |
26 Feb 07 |
jari |
470 |
RNCentroidViewer centroidViewer; |
2 |
26 Feb 07 |
jari |
471 |
ExperimentClusterCentroidViewer expCentroidViewer; |
2 |
26 Feb 07 |
jari |
472 |
FloatMatrix subnetMeans = getMeans(subnets, experiment, clusterGenes); |
2 |
26 Feb 07 |
jari |
473 |
FloatMatrix subnetVars = getVariances(subnetMeans, experiment, subnets, clusterGenes); |
2 |
26 Feb 07 |
jari |
474 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
475 |
centroidViewer = new RNCentroidViewer(experiment, subnets); |
2 |
26 Feb 07 |
jari |
476 |
centroidViewer.setMeans(subnetMeans.A); |
2 |
26 Feb 07 |
jari |
477 |
centroidViewer.setVariances(subnetVars.A); |
2 |
26 Feb 07 |
jari |
478 |
for (int i=0; i< subnets.length; i++) { |
2 |
26 Feb 07 |
jari |
479 |
|
2 |
26 Feb 07 |
jari |
480 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Subnet "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
481 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Subnet "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
482 |
|
2 |
26 Feb 07 |
jari |
483 |
} |
2 |
26 Feb 07 |
jari |
484 |
|
2 |
26 Feb 07 |
jari |
485 |
RNCentroidsViewer centroidsViewer = new RNCentroidsViewer(experiment, subnets); |
2 |
26 Feb 07 |
jari |
486 |
centroidsViewer.setMeans(subnetMeans.A); |
2 |
26 Feb 07 |
jari |
487 |
centroidsViewer.setVariances(subnetVars.A); |
2 |
26 Feb 07 |
jari |
488 |
|
2 |
26 Feb 07 |
jari |
489 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
490 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
491 |
|
2 |
26 Feb 07 |
jari |
492 |
} |
2 |
26 Feb 07 |
jari |
493 |
else{ |
2 |
26 Feb 07 |
jari |
494 |
expCentroidViewer = new RNExperimentCentroidViewer(experiment, subnets); |
2 |
26 Feb 07 |
jari |
495 |
|
2 |
26 Feb 07 |
jari |
496 |
expCentroidViewer.setMeans(subnetMeans.A); |
2 |
26 Feb 07 |
jari |
497 |
expCentroidViewer.setVariances(subnetVars.A); |
2 |
26 Feb 07 |
jari |
498 |
for (int i=0; i<subnets.length; i++) { |
2 |
26 Feb 07 |
jari |
499 |
|
2 |
26 Feb 07 |
jari |
500 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Subnet "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
501 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Subnet "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(indices[i], CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
502 |
|
2 |
26 Feb 07 |
jari |
503 |
} |
2 |
26 Feb 07 |
jari |
504 |
|
2 |
26 Feb 07 |
jari |
505 |
RNExperimentCentroidsViewer expCentroidsViewer = new RNExperimentCentroidsViewer(experiment, subnets); |
2 |
26 Feb 07 |
jari |
506 |
expCentroidsViewer.setMeans(subnetMeans.A); |
2 |
26 Feb 07 |
jari |
507 |
expCentroidsViewer.setVariances(subnetVars.A); |
2 |
26 Feb 07 |
jari |
508 |
|
2 |
26 Feb 07 |
jari |
509 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
510 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
511 |
} |
2 |
26 Feb 07 |
jari |
512 |
root.add(centroidNode); |
2 |
26 Feb 07 |
jari |
513 |
root.add(expressionNode); |
2 |
26 Feb 07 |
jari |
514 |
} |
2 |
26 Feb 07 |
jari |
515 |
|
2 |
26 Feb 07 |
jari |
516 |
|
2 |
26 Feb 07 |
jari |
517 |
/** |
2 |
26 Feb 07 |
jari |
* Retuns means values for each column within positives and negatives |
2 |
26 Feb 07 |
jari |
519 |
*/ |
2 |
26 Feb 07 |
jari |
520 |
private FloatMatrix getMeans(int [][] subnets, Experiment experiment, boolean classifyGenes){ |
2 |
26 Feb 07 |
jari |
521 |
FloatMatrix expMatrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
522 |
|
2 |
26 Feb 07 |
jari |
523 |
if(!classifyGenes) |
2 |
26 Feb 07 |
jari |
524 |
expMatrix = expMatrix.transpose(); |
2 |
26 Feb 07 |
jari |
525 |
|
2 |
26 Feb 07 |
jari |
526 |
int numSamples = expMatrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
527 |
int numGenes = expMatrix.getRowDimension(); |
2 |
26 Feb 07 |
jari |
528 |
|
2 |
26 Feb 07 |
jari |
529 |
FloatMatrix means = new FloatMatrix(subnets.length, numSamples); |
2 |
26 Feb 07 |
jari |
530 |
|
2 |
26 Feb 07 |
jari |
531 |
float value; |
2 |
26 Feb 07 |
jari |
532 |
float cumVal = 0; |
2 |
26 Feb 07 |
jari |
533 |
int n = 0; |
2 |
26 Feb 07 |
jari |
534 |
int index = 0; |
2 |
26 Feb 07 |
jari |
535 |
float [] currMeans; |
2 |
26 Feb 07 |
jari |
536 |
for(int i = 0; i < subnets.length; i++){ |
2 |
26 Feb 07 |
jari |
537 |
currMeans = new float[numSamples]; |
2 |
26 Feb 07 |
jari |
538 |
for(int j = 0; j < numSamples; j++){ |
2 |
26 Feb 07 |
jari |
539 |
for(int k = 0; k < subnets[i].length; k++){ |
2 |
26 Feb 07 |
jari |
540 |
index = subnets[i][k]; |
2 |
26 Feb 07 |
jari |
541 |
value = expMatrix.get(index, j); |
2 |
26 Feb 07 |
jari |
542 |
if(!Float.isNaN(value)){ |
2 |
26 Feb 07 |
jari |
543 |
n++; |
2 |
26 Feb 07 |
jari |
544 |
cumVal += value; |
2 |
26 Feb 07 |
jari |
545 |
} |
2 |
26 Feb 07 |
jari |
546 |
} |
2 |
26 Feb 07 |
jari |
547 |
if(n > 0){ |
2 |
26 Feb 07 |
jari |
548 |
currMeans[j] = cumVal/n; |
2 |
26 Feb 07 |
jari |
549 |
} else { |
2 |
26 Feb 07 |
jari |
550 |
currMeans[j] = 0; |
2 |
26 Feb 07 |
jari |
551 |
} |
2 |
26 Feb 07 |
jari |
552 |
n = 0; |
2 |
26 Feb 07 |
jari |
553 |
cumVal = 0; |
2 |
26 Feb 07 |
jari |
554 |
} |
2 |
26 Feb 07 |
jari |
555 |
means.A[i] = currMeans; |
2 |
26 Feb 07 |
jari |
556 |
} |
2 |
26 Feb 07 |
jari |
557 |
return means; |
2 |
26 Feb 07 |
jari |
558 |
} |
2 |
26 Feb 07 |
jari |
559 |
|
2 |
26 Feb 07 |
jari |
560 |
private FloatMatrix getVariances(FloatMatrix means, Experiment experiment, int [][] subnets, boolean clusterGenes){ |
2 |
26 Feb 07 |
jari |
561 |
FloatMatrix expMatrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
562 |
|
2 |
26 Feb 07 |
jari |
563 |
if(!clusterGenes) |
2 |
26 Feb 07 |
jari |
564 |
expMatrix = expMatrix.transpose(); |
2 |
26 Feb 07 |
jari |
565 |
|
2 |
26 Feb 07 |
jari |
566 |
int numSamples = expMatrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
567 |
int numGenes = expMatrix.getRowDimension(); |
2 |
26 Feb 07 |
jari |
568 |
|
2 |
26 Feb 07 |
jari |
569 |
FloatMatrix vars = new FloatMatrix(subnets.length, numSamples); |
2 |
26 Feb 07 |
jari |
570 |
|
2 |
26 Feb 07 |
jari |
571 |
float mean = 0; |
2 |
26 Feb 07 |
jari |
572 |
float value; |
2 |
26 Feb 07 |
jari |
573 |
float cumVal = 0; |
2 |
26 Feb 07 |
jari |
574 |
int n = 0; |
2 |
26 Feb 07 |
jari |
575 |
int index = 0; |
2 |
26 Feb 07 |
jari |
576 |
float [] currVars; |
2 |
26 Feb 07 |
jari |
577 |
for(int i = 0; i < subnets.length; i++){ |
2 |
26 Feb 07 |
jari |
578 |
currVars = new float[numSamples]; |
2 |
26 Feb 07 |
jari |
579 |
for(int j = 0; j < numSamples; j++){ |
2 |
26 Feb 07 |
jari |
580 |
for(int k = 0; k < subnets[i].length; k++){ |
2 |
26 Feb 07 |
jari |
581 |
index = subnets[i][k]; |
2 |
26 Feb 07 |
jari |
582 |
value = expMatrix.get(index, j); |
2 |
26 Feb 07 |
jari |
583 |
if(!Float.isNaN(value)){ |
2 |
26 Feb 07 |
jari |
584 |
n++; |
2 |
26 Feb 07 |
jari |
585 |
cumVal += Math.pow((value-means.get(i,j)), 2.0); |
2 |
26 Feb 07 |
jari |
586 |
} |
2 |
26 Feb 07 |
jari |
587 |
} |
2 |
26 Feb 07 |
jari |
588 |
if(n > 1) |
2 |
26 Feb 07 |
jari |
589 |
currVars[j] = (float) Math.sqrt(cumVal/(n-1)); |
2 |
26 Feb 07 |
jari |
590 |
else |
2 |
26 Feb 07 |
jari |
591 |
currVars[j] = 0; |
2 |
26 Feb 07 |
jari |
592 |
n = 0; |
2 |
26 Feb 07 |
jari |
593 |
cumVal = 0; |
2 |
26 Feb 07 |
jari |
594 |
} |
2 |
26 Feb 07 |
jari |
595 |
vars.A[i] = currVars; |
2 |
26 Feb 07 |
jari |
596 |
} |
2 |
26 Feb 07 |
jari |
597 |
return vars; |
2 |
26 Feb 07 |
jari |
598 |
} |
2 |
26 Feb 07 |
jari |
599 |
|
2 |
26 Feb 07 |
jari |
600 |
|
2 |
26 Feb 07 |
jari |
601 |
/** |
2 |
26 Feb 07 |
jari |
* Adds the node with a <code>RelevanceNetworkViewer</code>. |
2 |
26 Feb 07 |
jari |
603 |
*/ |
2 |
26 Feb 07 |
jari |
604 |
private void addRelevanceNetworkViewer(DefaultMutableTreeNode root, Experiment experiment, int[][] clusters, float[][] weights, int[] indices, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
605 |
root.add(new DefaultMutableTreeNode(new LeafInfo("Network", new RelevanceNetworkViewer(clusterGenes, experiment, clusters, weights, indices)))); |
2 |
26 Feb 07 |
jari |
606 |
} |
2 |
26 Feb 07 |
jari |
607 |
|
2 |
26 Feb 07 |
jari |
608 |
/** |
2 |
26 Feb 07 |
jari |
* Adds the node with a general info. |
2 |
26 Feb 07 |
jari |
610 |
*/ |
2 |
26 Feb 07 |
jari |
611 |
private void addGeneralInfo(DefaultMutableTreeNode root, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
612 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("General Information"); |
2 |
26 Feb 07 |
jari |
613 |
node.add(new DefaultMutableTreeNode("Links: "+String.valueOf(info.links))); |
2 |
26 Feb 07 |
jari |
614 |
node.add(new DefaultMutableTreeNode("Time: "+String.valueOf(info.time)+" ms")); |
2 |
26 Feb 07 |
jari |
615 |
node.add(new DefaultMutableTreeNode("Min Threshold: "+String.valueOf(info.min_threshold))); |
2 |
26 Feb 07 |
jari |
616 |
node.add(new DefaultMutableTreeNode("Max Threshold: "+String.valueOf(info.max_threshold))); |
2 |
26 Feb 07 |
jari |
617 |
node.add(new DefaultMutableTreeNode("Highest Entropy Filter: "+String.valueOf(info.entropy)+" %")); |
2 |
26 Feb 07 |
jari |
618 |
node.add(new DefaultMutableTreeNode(info.function)); |
2 |
26 Feb 07 |
jari |
619 |
node.add(new DefaultMutableTreeNode("Absolute: "+String.valueOf(info.absolute))); |
2 |
26 Feb 07 |
jari |
620 |
root.add(node); |
2 |
26 Feb 07 |
jari |
621 |
} |
2 |
26 Feb 07 |
jari |
622 |
|
2 |
26 Feb 07 |
jari |
623 |
|
2 |
26 Feb 07 |
jari |
624 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to progress and algorithms events. |
2 |
26 Feb 07 |
jari |
626 |
*/ |
2 |
26 Feb 07 |
jari |
627 |
private class Listener extends DialogListener implements AlgorithmListener { |
2 |
26 Feb 07 |
jari |
628 |
|
2 |
26 Feb 07 |
jari |
629 |
public void valueChanged(AlgorithmEvent event) { |
2 |
26 Feb 07 |
jari |
630 |
switch (event.getId()) { |
2 |
26 Feb 07 |
jari |
631 |
case AlgorithmEvent.SET_UNITS: |
2 |
26 Feb 07 |
jari |
632 |
progress.setUnits(event.getIntValue()); |
2 |
26 Feb 07 |
jari |
633 |
progress.setDescription(event.getDescription()); |
2 |
26 Feb 07 |
jari |
634 |
break; |
2 |
26 Feb 07 |
jari |
635 |
case AlgorithmEvent.PROGRESS_VALUE: |
2 |
26 Feb 07 |
jari |
636 |
progress.setValue(event.getIntValue()); |
2 |
26 Feb 07 |
jari |
637 |
progress.setDescription(event.getDescription()); |
2 |
26 Feb 07 |
jari |
638 |
break; |
2 |
26 Feb 07 |
jari |
639 |
} |
2 |
26 Feb 07 |
jari |
640 |
} |
2 |
26 Feb 07 |
jari |
641 |
|
2 |
26 Feb 07 |
jari |
642 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
643 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
644 |
if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
645 |
algorithm.abort(); |
2 |
26 Feb 07 |
jari |
646 |
progress.dispose(); |
2 |
26 Feb 07 |
jari |
647 |
} |
2 |
26 Feb 07 |
jari |
648 |
} |
2 |
26 Feb 07 |
jari |
649 |
|
2 |
26 Feb 07 |
jari |
650 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
651 |
algorithm.abort(); |
2 |
26 Feb 07 |
jari |
652 |
progress.dispose(); |
2 |
26 Feb 07 |
jari |
653 |
} |
2 |
26 Feb 07 |
jari |
654 |
} |
2 |
26 Feb 07 |
jari |
655 |
|
2 |
26 Feb 07 |
jari |
656 |
/** |
2 |
26 Feb 07 |
jari |
* The general info structure. |
2 |
26 Feb 07 |
jari |
658 |
*/ |
2 |
26 Feb 07 |
jari |
659 |
private class GeneralInfo { |
2 |
26 Feb 07 |
jari |
660 |
private long time; |
2 |
26 Feb 07 |
jari |
661 |
private int links; |
2 |
26 Feb 07 |
jari |
662 |
private float min_threshold; |
2 |
26 Feb 07 |
jari |
663 |
private float max_threshold; |
2 |
26 Feb 07 |
jari |
664 |
private float entropy; |
2 |
26 Feb 07 |
jari |
665 |
private String function; |
2 |
26 Feb 07 |
jari |
666 |
private boolean absolute; |
2 |
26 Feb 07 |
jari |
667 |
} |
2 |
26 Feb 07 |
jari |
668 |
} |