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 |
* ScriptRunner.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
* Created on March 15, 2004, 3:27 PM |
2 |
26 Feb 07 |
jari |
9 |
*/ |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
package org.tigr.microarray.mev.script.util; |
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
14 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
15 |
import java.util.Enumeration; |
2 |
26 Feb 07 |
jari |
16 |
import java.util.Hashtable; |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.Action; |
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.JFileChooser; |
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 |
import javax.swing.tree.DefaultTreeModel; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.tree.TreePath; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.ResultTree; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.TMEV; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.action.ActionManager; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.action.AnalysisAction; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.LeafInfo; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.script.Script; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptCentroidViewer; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptCentroidsViewer; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptClusterSelectionInfoViewer; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptExperimentCentroidViewer; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptExperimentCentroidsViewer; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptExperimentClusterViewer; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptExperimentViewer; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.script.scriptGUI.ScriptTreeViewer; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
/** ScriptRunner supports script execution activities as directed by the |
2 |
26 Feb 07 |
jari |
* <CODE>ScriptManager</CODE> |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
51 |
*/ |
2 |
26 Feb 07 |
jari |
52 |
public class ScriptRunner { |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
/** Script to run |
2 |
26 Feb 07 |
jari |
55 |
*/ |
2 |
26 Feb 07 |
jari |
56 |
private Script script; |
2 |
26 Feb 07 |
jari |
/** ScriptTree containing objects for execution |
2 |
26 Feb 07 |
jari |
58 |
*/ |
2 |
26 Feb 07 |
jari |
59 |
private ScriptTree scriptTree; |
2 |
26 Feb 07 |
jari |
/** parent's frame |
2 |
26 Feb 07 |
jari |
61 |
*/ |
2 |
26 Feb 07 |
jari |
62 |
private Frame parentFrame; |
2 |
26 Feb 07 |
jari |
/** action manager to provide MeV algorithm access. |
2 |
26 Feb 07 |
jari |
64 |
*/ |
2 |
26 Feb 07 |
jari |
65 |
private ActionManager actionManager; |
2 |
26 Feb 07 |
jari |
/** framework object |
2 |
26 Feb 07 |
jari |
67 |
*/ |
2 |
26 Feb 07 |
jari |
68 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
/** hashtable of available algorithm classes |
2 |
26 Feb 07 |
jari |
70 |
*/ |
2 |
26 Feb 07 |
jari |
71 |
private Hashtable classHash; |
2 |
26 Feb 07 |
jari |
/** algorithm set collection to execute |
2 |
26 Feb 07 |
jari |
73 |
*/ |
2 |
26 Feb 07 |
jari |
74 |
private AlgorithmSet [] algSets; |
2 |
26 Feb 07 |
jari |
75 |
/** |
2 |
26 Feb 07 |
jari |
* Three output modes: internal (0), file (1), external (2) |
2 |
26 Feb 07 |
jari |
* see <code>ScriptConstants</code> document for constant names. |
2 |
26 Feb 07 |
jari |
78 |
*/ |
2 |
26 Feb 07 |
jari |
79 |
private int mode; |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of ScriptRunner |
2 |
26 Feb 07 |
jari |
* @param script Script to execute |
2 |
26 Feb 07 |
jari |
* @param actionManager action manager provides algorithms |
2 |
26 Feb 07 |
jari |
* @param framework |
2 |
26 Feb 07 |
jari |
85 |
*/ |
2 |
26 Feb 07 |
jari |
86 |
public ScriptRunner(Script script, ActionManager actionManager, IFramework framework) { |
2 |
26 Feb 07 |
jari |
87 |
this.script = script; |
2 |
26 Feb 07 |
jari |
88 |
scriptTree = script.getScriptTree(); |
2 |
26 Feb 07 |
jari |
89 |
this.actionManager = actionManager; |
2 |
26 Feb 07 |
jari |
90 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
91 |
mode = ScriptConstants.SCRIPT_OUTPUT_MODE_INTERNAL_OUTPUT; |
2 |
26 Feb 07 |
jari |
92 |
parentFrame = framework.getFrame(); |
2 |
26 Feb 07 |
jari |
93 |
classHash = getClassNames(); |
2 |
26 Feb 07 |
jari |
94 |
} |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
/** Sets the output mode (file or internal) |
2 |
26 Feb 07 |
jari |
* @param outputMode */ |
2 |
26 Feb 07 |
jari |
98 |
public void setOutputMode(int outputMode) { |
2 |
26 Feb 07 |
jari |
99 |
mode = outputMode; |
2 |
26 Feb 07 |
jari |
100 |
} |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
/** Triggers script execution |
2 |
26 Feb 07 |
jari |
* @param outputMode output mode |
2 |
26 Feb 07 |
jari |
104 |
*/ |
2 |
26 Feb 07 |
jari |
105 |
public void execute(int outputMode) { |
2 |
26 Feb 07 |
jari |
106 |
mode = outputMode; |
2 |
26 Feb 07 |
jari |
107 |
Thread thread = new Thread(new Runner()); |
2 |
26 Feb 07 |
jari |
108 |
thread.start(); |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
/** Triggers script execution to interal MeV result tree. |
2 |
26 Feb 07 |
jari |
112 |
*/ |
2 |
26 Feb 07 |
jari |
113 |
public void execute() { |
2 |
26 Feb 07 |
jari |
114 |
Thread thread = new Thread(new Runner()); |
2 |
26 Feb 07 |
jari |
115 |
thread.start(); |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
|
2 |
26 Feb 07 |
jari |
/** Executes a delivered <CODE>AlgorithmSet</CODE> |
2 |
26 Feb 07 |
jari |
* @param set set of algorithms and data |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
121 |
*/ |
2 |
26 Feb 07 |
jari |
122 |
private DefaultMutableTreeNode execute(AlgorithmSet set) { |
2 |
26 Feb 07 |
jari |
123 |
Experiment experiment = set.getExperiment(); |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
if(experiment == null) { |
2 |
26 Feb 07 |
jari |
126 |
DefaultMutableTreeNode emptyNode = new DefaultMutableTreeNode("No Result (empty input data node)"); |
2 |
26 Feb 07 |
jari |
127 |
return emptyNode; |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
int algCount = set.getAlgorithmCount(); |
2 |
26 Feb 07 |
jari |
131 |
File outputFile; |
2 |
26 Feb 07 |
jari |
132 |
AlgorithmNode algNode; |
2 |
26 Feb 07 |
jari |
133 |
AlgorithmData data; |
2 |
26 Feb 07 |
jari |
134 |
String algName, algType; |
2 |
26 Feb 07 |
jari |
135 |
|
2 |
26 Feb 07 |
jari |
136 |
DefaultMutableTreeNode currNode = null, outputNode = null; |
2 |
26 Feb 07 |
jari |
137 |
|
2 |
26 Feb 07 |
jari |
138 |
if(mode == ScriptConstants.SCRIPT_OUTPUT_MODE_FILE_OUTPUT) { |
2 |
26 Feb 07 |
jari |
139 |
JFileChooser chooser = new JFileChooser(TMEV.getFile("data/")); |
2 |
26 Feb 07 |
jari |
140 |
if(chooser.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) { |
2 |
26 Feb 07 |
jari |
141 |
outputFile = chooser.getSelectedFile(); |
2 |
26 Feb 07 |
jari |
142 |
} else { |
2 |
26 Feb 07 |
jari |
143 |
return null; |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
if(algCount > 0) { |
2 |
26 Feb 07 |
jari |
//create a node for the alg set and a data info node; |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
|
2 |
26 Feb 07 |
jari |
151 |
for(int i = 0; i < algCount; i++) { |
2 |
26 Feb 07 |
jari |
152 |
algNode = set.getAlgorithmNodeAt(i); |
2 |
26 Feb 07 |
jari |
153 |
data = algNode.getAlgorithmData(); |
2 |
26 Feb 07 |
jari |
154 |
algName = algNode.getAlgorithmName(); |
2 |
26 Feb 07 |
jari |
155 |
algType = algNode.getAlgorithmType(); |
2 |
26 Feb 07 |
jari |
// int actionIndex = getActionIndex(algName); |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
// Action action = actionManager.getAction(actionManager.ANALYSIS_ACTION+String.valueOf(actionIndex)); |
2 |
26 Feb 07 |
jari |
159 |
if(algType.equals(ScriptConstants.ALGORITHM_TYPE_CLUSTER) || algType.equals(ScriptConstants.ALGORITHM_TYPE_CLUSTER_GENES) |
2 |
26 Feb 07 |
jari |
160 |
|| algType.equals(ScriptConstants.ALGORITHM_TYPE_CLUSTER_EXPERIMENTS) || algType.equals(ScriptConstants.ALGORITHM_TYPE_VISUALIZATION)) { |
2 |
26 Feb 07 |
jari |
161 |
|
2 |
26 Feb 07 |
jari |
162 |
String className = (String)(this.classHash.get(algName)); |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
try { |
2 |
26 Feb 07 |
jari |
165 |
Class clazz = Class.forName(className); |
2 |
26 Feb 07 |
jari |
166 |
IScriptGUI gui = (IScriptGUI)clazz.newInstance(); |
2 |
26 Feb 07 |
jari |
167 |
currNode = gui.executeScript(framework, data, experiment); |
2 |
26 Feb 07 |
jari |
168 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
169 |
JOptionPane.showMessageDialog(parentFrame, "Can't execute script "+algName+ " algorithm", "Script Parameter Error", JOptionPane.WARNING_MESSAGE); |
2 |
26 Feb 07 |
jari |
170 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
171 |
} |
2 |
26 Feb 07 |
jari |
172 |
|
2 |
26 Feb 07 |
jari |
173 |
if(currNode != null) { |
2 |
26 Feb 07 |
jari |
174 |
if(outputNode == null) { |
2 |
26 Feb 07 |
jari |
175 |
outputNode = new DefaultMutableTreeNode("Results"); |
2 |
26 Feb 07 |
jari |
176 |
} |
2 |
26 Feb 07 |
jari |
177 |
outputNode.add(currNode); |
2 |
26 Feb 07 |
jari |
178 |
|
2 |
26 Feb 07 |
jari |
179 |
attachResultToChildAlgorithmSets(algNode, experiment, extractClusters(currNode)); |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
} else if(algType.equals(ScriptConstants.ALGORITHM_TYPE_ADJUSTMENT)){ |
2 |
26 Feb 07 |
jari |
//Handle adjustments here |
2 |
26 Feb 07 |
jari |
183 |
data.addParam("name", algName); |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
ScriptDataTransformer adjuster = new ScriptDataTransformer(experiment, framework); |
2 |
26 Feb 07 |
jari |
186 |
Experiment resultExperiment = adjuster.transformData(data); |
2 |
26 Feb 07 |
jari |
187 |
|
2 |
26 Feb 07 |
jari |
//Associate result experiment and indices with the output node's result set if it exists. |
2 |
26 Feb 07 |
jari |
189 |
int [][] clusters = new int[1][]; |
2 |
26 Feb 07 |
jari |
190 |
clusters[0] = getDefaultGeneIndices(resultExperiment.getNumberOfGenes()); |
2 |
26 Feb 07 |
jari |
191 |
attachResultToChildAlgorithmSets(algNode, resultExperiment, clusters); |
2 |
26 Feb 07 |
jari |
192 |
|
2 |
26 Feb 07 |
jari |
193 |
if(outputNode == null) { |
2 |
26 Feb 07 |
jari |
194 |
outputNode = new DefaultMutableTreeNode("Results"); |
2 |
26 Feb 07 |
jari |
195 |
} |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
DefaultMutableTreeNode resultNode = getViewerNodes(resultExperiment); |
2 |
26 Feb 07 |
jari |
198 |
resultNode.setUserObject("Data Adjustment: "+algName); |
2 |
26 Feb 07 |
jari |
199 |
outputNode.add(resultNode); |
2 |
26 Feb 07 |
jari |
200 |
} else if(algType.equals(ScriptConstants.ALGORITHM_TYPE_CLUSTER_SELECTION)) { |
2 |
26 Feb 07 |
jari |
//handle cluster selection |
2 |
26 Feb 07 |
jari |
202 |
data.addParam("name", algName); |
2 |
26 Feb 07 |
jari |
203 |
|
2 |
26 Feb 07 |
jari |
//DataNode node = (DataNode)(algNode.getParent()); |
2 |
26 Feb 07 |
jari |
205 |
ScriptDataTransformer selector = new ScriptDataTransformer(experiment, framework); |
2 |
26 Feb 07 |
jari |
206 |
int [][] selectedClusters = selector.selectClusters(data, set.getClusters()); |
2 |
26 Feb 07 |
jari |
207 |
|
2 |
26 Feb 07 |
jari |
208 |
attachResultToChildAlgorithmSets(algNode, experiment, selectedClusters); |
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
210 |
boolean areGeneClusters =data.getParams().getBoolean("process-gene-clusters"); |
2 |
26 Feb 07 |
jari |
211 |
DefaultMutableTreeNode node = getSelectedClusterViewers(data, experiment, selectedClusters, areGeneClusters); |
2 |
26 Feb 07 |
jari |
212 |
|
2 |
26 Feb 07 |
jari |
213 |
if(outputNode == null) { |
2 |
26 Feb 07 |
jari |
214 |
outputNode = new DefaultMutableTreeNode("Results"); |
2 |
26 Feb 07 |
jari |
215 |
} |
2 |
26 Feb 07 |
jari |
216 |
|
2 |
26 Feb 07 |
jari |
217 |
outputNode.add(node); |
2 |
26 Feb 07 |
jari |
218 |
} |
2 |
26 Feb 07 |
jari |
219 |
} |
2 |
26 Feb 07 |
jari |
220 |
return outputNode; |
2 |
26 Feb 07 |
jari |
221 |
} |
2 |
26 Feb 07 |
jari |
222 |
|
2 |
26 Feb 07 |
jari |
/** Thread runner for execution |
2 |
26 Feb 07 |
jari |
224 |
*/ |
2 |
26 Feb 07 |
jari |
225 |
private class Runner implements Runnable { |
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
/** run method to kick of execution |
2 |
26 Feb 07 |
jari |
228 |
*/ |
2 |
26 Feb 07 |
jari |
229 |
public void run() { |
2 |
26 Feb 07 |
jari |
230 |
algSets = scriptTree.getAlgorithmSets(); |
2 |
26 Feb 07 |
jari |
231 |
DefaultMutableTreeNode currNode, setNode, algSetViewerNode, dataNode, resultNode, scriptNode; |
2 |
26 Feb 07 |
jari |
232 |
AlgorithmSet set; |
2 |
26 Feb 07 |
jari |
233 |
Experiment experiment; |
2 |
26 Feb 07 |
jari |
234 |
boolean haveResult = false; |
2 |
26 Feb 07 |
jari |
235 |
DataNode inputNode; |
2 |
26 Feb 07 |
jari |
236 |
AlgorithmNode inputAlgNode; |
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
DefaultMutableTreeNode scriptResultNode = new DefaultMutableTreeNode("Script Result"); |
2 |
26 Feb 07 |
jari |
239 |
|
2 |
26 Feb 07 |
jari |
240 |
if(algSets.length > 0) { |
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
} |
2 |
26 Feb 07 |
jari |
243 |
|
2 |
26 Feb 07 |
jari |
244 |
for(int i = 0; i < algSets.length; i++) { |
2 |
26 Feb 07 |
jari |
245 |
set = algSets[i]; |
2 |
26 Feb 07 |
jari |
246 |
if(set.getAlgorithmCount() > 0) { |
2 |
26 Feb 07 |
jari |
247 |
|
2 |
26 Feb 07 |
jari |
248 |
resultNode = execute(set); |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
if(resultNode != null) { |
2 |
26 Feb 07 |
jari |
251 |
experiment = set.getExperiment(); |
2 |
26 Feb 07 |
jari |
252 |
|
2 |
26 Feb 07 |
jari |
253 |
haveResult = true; |
2 |
26 Feb 07 |
jari |
254 |
setNode = new DefaultMutableTreeNode("Algorithm Set"); |
2 |
26 Feb 07 |
jari |
255 |
dataNode = new DefaultMutableTreeNode("Input Data"); |
2 |
26 Feb 07 |
jari |
256 |
ScriptTree copyTree = new ScriptTree(scriptTree); |
2 |
26 Feb 07 |
jari |
257 |
algSetViewerNode = new DefaultMutableTreeNode(new LeafInfo("Script Tree", new ScriptTreeViewer(copyTree, scriptTree.getScriptManager(), set.getDataNode()))); |
2 |
26 Feb 07 |
jari |
258 |
|
2 |
26 Feb 07 |
jari |
259 |
inputNode = set.getDataNode(); |
2 |
26 Feb 07 |
jari |
260 |
inputAlgNode = (AlgorithmNode)(inputNode.getParent()); |
2 |
26 Feb 07 |
jari |
261 |
|
2 |
26 Feb 07 |
jari |
262 |
if(inputAlgNode != null) { |
2 |
26 Feb 07 |
jari |
263 |
currNode = new DefaultMutableTreeNode("Algorithm Source: "+ inputAlgNode.getAlgorithmName() + |
2 |
26 Feb 07 |
jari |
264 |
" ["+inputAlgNode.getDataNodeRef()+","+inputAlgNode.getID()+"] "); |
2 |
26 Feb 07 |
jari |
265 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
currNode = new DefaultMutableTreeNode("Input Data Node: "+inputNode.toString()); |
2 |
26 Feb 07 |
jari |
269 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
270 |
if(experiment != null) { |
2 |
26 Feb 07 |
jari |
271 |
currNode = new DefaultMutableTreeNode("Number of Experiments: "+experiment.getNumberOfSamples()); |
2 |
26 Feb 07 |
jari |
272 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
273 |
currNode = new DefaultMutableTreeNode("Number of Genes: "+experiment.getNumberOfGenes()); |
2 |
26 Feb 07 |
jari |
274 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
275 |
|
2 |
26 Feb 07 |
jari |
276 |
currNode = getViewerNodes(set.getExperiment()); |
2 |
26 Feb 07 |
jari |
277 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
278 |
} else { |
2 |
26 Feb 07 |
jari |
279 |
currNode = new DefaultMutableTreeNode("Number of Experiments: 0, null input data"); |
2 |
26 Feb 07 |
jari |
280 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
281 |
currNode = new DefaultMutableTreeNode("Number of Genes: 0, null input data"); |
2 |
26 Feb 07 |
jari |
282 |
dataNode.add(currNode); |
2 |
26 Feb 07 |
jari |
283 |
} |
2 |
26 Feb 07 |
jari |
284 |
setNode.add(algSetViewerNode); |
2 |
26 Feb 07 |
jari |
285 |
setNode.add(dataNode); |
2 |
26 Feb 07 |
jari |
286 |
setNode.add(resultNode); |
2 |
26 Feb 07 |
jari |
287 |
scriptResultNode.add(setNode); |
2 |
26 Feb 07 |
jari |
288 |
} |
2 |
26 Feb 07 |
jari |
289 |
} |
2 |
26 Feb 07 |
jari |
290 |
} |
2 |
26 Feb 07 |
jari |
291 |
|
2 |
26 Feb 07 |
jari |
292 |
ResultTree tree = framework.getResultTree(); |
2 |
26 Feb 07 |
jari |
//framework.addNode(tree.getAnalysisNode(), scriptResultNode); |
2 |
26 Feb 07 |
jari |
294 |
framework.addAnalysisResult(scriptResultNode); |
2 |
26 Feb 07 |
jari |
295 |
tree.scrollPathToVisible(new TreePath(((DefaultTreeModel)(tree.getModel())).getPathToRoot(scriptResultNode))); |
2 |
26 Feb 07 |
jari |
296 |
} |
2 |
26 Feb 07 |
jari |
297 |
} |
2 |
26 Feb 07 |
jari |
298 |
|
2 |
26 Feb 07 |
jari |
/** Constructs viewer nodes for input display |
2 |
26 Feb 07 |
jari |
* @param experiment |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
302 |
*/ |
2 |
26 Feb 07 |
jari |
303 |
private DefaultMutableTreeNode getViewerNodes(Experiment experiment) { |
2 |
26 Feb 07 |
jari |
304 |
DefaultMutableTreeNode viewerNode = new DefaultMutableTreeNode("Input Data Viewers"); |
2 |
26 Feb 07 |
jari |
305 |
int [][] cluster = new int [1][]; |
2 |
26 Feb 07 |
jari |
306 |
|
2 |
26 Feb 07 |
jari |
//since it's a single set, contains all indices in experiment. |
2 |
26 Feb 07 |
jari |
308 |
cluster[0] = getDefaultGeneIndices(experiment.getNumberOfGenes()); |
2 |
26 Feb 07 |
jari |
309 |
|
2 |
26 Feb 07 |
jari |
//Will need to deal with var. exp nums perhaps use exp cluster viewers |
2 |
26 Feb 07 |
jari |
311 |
|
2 |
26 Feb 07 |
jari |
312 |
DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(new LeafInfo("Expression Image", new ScriptExperimentViewer(experiment, cluster))); |
2 |
26 Feb 07 |
jari |
313 |
viewerNode.add(currNode); |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
316 |
FloatMatrix means = getMeans(matrix, cluster); |
2 |
26 Feb 07 |
jari |
317 |
FloatMatrix vars = getVariances(matrix, means, cluster); |
2 |
26 Feb 07 |
jari |
318 |
|
2 |
26 Feb 07 |
jari |
319 |
ScriptCentroidViewer viewer = new ScriptCentroidViewer(experiment, cluster); |
2 |
26 Feb 07 |
jari |
320 |
viewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
321 |
viewer.setVariances(vars.A); |
2 |
26 Feb 07 |
jari |
322 |
currNode = new DefaultMutableTreeNode(new LeafInfo("Centroid Graph", viewer, new CentroidUserObject(0,CentroidUserObject.VARIANCES_MODE))); |
2 |
26 Feb 07 |
jari |
323 |
viewerNode.add(currNode); |
2 |
26 Feb 07 |
jari |
324 |
currNode = new DefaultMutableTreeNode(new LeafInfo("Expression Graph", viewer, new CentroidUserObject(0,CentroidUserObject.VALUES_MODE))); |
2 |
26 Feb 07 |
jari |
325 |
viewerNode.add(currNode); |
2 |
26 Feb 07 |
jari |
326 |
|
2 |
26 Feb 07 |
jari |
327 |
return viewerNode; |
2 |
26 Feb 07 |
jari |
328 |
} |
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
/** Returns algorithm class names hash |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
332 |
*/ |
2 |
26 Feb 07 |
jari |
333 |
private Hashtable getClassNames() { |
2 |
26 Feb 07 |
jari |
334 |
Hashtable hash = new Hashtable(); |
2 |
26 Feb 07 |
jari |
335 |
int algCnt = 0; |
2 |
26 Feb 07 |
jari |
336 |
String algName, className; |
2 |
26 Feb 07 |
jari |
337 |
|
2 |
26 Feb 07 |
jari |
338 |
AnalysisAction action; |
2 |
26 Feb 07 |
jari |
339 |
|
2 |
26 Feb 07 |
jari |
340 |
while ((action = (AnalysisAction)(actionManager.getAction(ActionManager.ANALYSIS_ACTION+String.valueOf(algCnt))))!=null){ |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
//Name or Short Description?? |
2 |
26 Feb 07 |
jari |
343 |
|
2 |
26 Feb 07 |
jari |
344 |
algName = (String)(action.getValue(Action.NAME)); |
2 |
26 Feb 07 |
jari |
345 |
className = (String)(action.getValue(ActionManager.PARAMETER)); |
2 |
26 Feb 07 |
jari |
346 |
|
2 |
26 Feb 07 |
jari |
347 |
hash.put(algName, className); |
2 |
26 Feb 07 |
jari |
348 |
algCnt++; |
2 |
26 Feb 07 |
jari |
349 |
} |
2 |
26 Feb 07 |
jari |
350 |
return hash; |
2 |
26 Feb 07 |
jari |
351 |
} |
2 |
26 Feb 07 |
jari |
352 |
|
2 |
26 Feb 07 |
jari |
353 |
|
2 |
26 Feb 07 |
jari |
354 |
/** |
2 |
26 Feb 07 |
jari |
* Calculates means for the clusters |
2 |
26 Feb 07 |
jari |
356 |
*/ |
2 |
26 Feb 07 |
jari |
357 |
private FloatMatrix getMeans(FloatMatrix data, int [][] clusters){ |
2 |
26 Feb 07 |
jari |
358 |
FloatMatrix means = new FloatMatrix(clusters.length, data.getColumnDimension()); |
2 |
26 Feb 07 |
jari |
359 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
360 |
means.A[i] = getMeans(data, clusters[i]); |
2 |
26 Feb 07 |
jari |
361 |
} |
2 |
26 Feb 07 |
jari |
362 |
return means; |
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 |
* Returns a set of means for an element |
2 |
26 Feb 07 |
jari |
368 |
*/ |
2 |
26 Feb 07 |
jari |
369 |
private float [] getMeans(FloatMatrix data, int [] indices){ |
2 |
26 Feb 07 |
jari |
370 |
int nSamples = data.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
371 |
float [] means = new float[nSamples]; |
2 |
26 Feb 07 |
jari |
372 |
float sum = 0; |
2 |
26 Feb 07 |
jari |
373 |
float n = 0; |
2 |
26 Feb 07 |
jari |
374 |
float value; |
2 |
26 Feb 07 |
jari |
375 |
for(int i = 0; i < nSamples; i++){ |
2 |
26 Feb 07 |
jari |
376 |
n = 0; |
2 |
26 Feb 07 |
jari |
377 |
sum = 0; |
2 |
26 Feb 07 |
jari |
378 |
for(int j = 0; j < indices.length; j++){ |
2 |
26 Feb 07 |
jari |
379 |
value = data.get(indices[j],i); |
2 |
26 Feb 07 |
jari |
380 |
if(!Float.isNaN(value)){ |
2 |
26 Feb 07 |
jari |
381 |
sum += value; |
2 |
26 Feb 07 |
jari |
382 |
n++; |
2 |
26 Feb 07 |
jari |
383 |
} |
2 |
26 Feb 07 |
jari |
384 |
} |
2 |
26 Feb 07 |
jari |
385 |
if(n > 0) |
2 |
26 Feb 07 |
jari |
386 |
means[i] = sum/n; |
2 |
26 Feb 07 |
jari |
387 |
else |
2 |
26 Feb 07 |
jari |
388 |
means[i] = Float.NaN; |
2 |
26 Feb 07 |
jari |
389 |
} |
2 |
26 Feb 07 |
jari |
390 |
return means; |
2 |
26 Feb 07 |
jari |
391 |
} |
2 |
26 Feb 07 |
jari |
392 |
|
2 |
26 Feb 07 |
jari |
393 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a matrix of standard deviations grouped by cluster and element |
2 |
26 Feb 07 |
jari |
395 |
*/ |
2 |
26 Feb 07 |
jari |
396 |
private FloatMatrix getVariances(FloatMatrix data, FloatMatrix means, int [][] clusters){ |
2 |
26 Feb 07 |
jari |
397 |
int nSamples = data.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
398 |
FloatMatrix variances = new FloatMatrix(clusters.length, nSamples); |
2 |
26 Feb 07 |
jari |
399 |
for(int i = 0; i < clusters.length; i++){ |
2 |
26 Feb 07 |
jari |
400 |
variances.A[i] = getVariances(data, means, clusters[i], i); |
2 |
26 Feb 07 |
jari |
401 |
} |
2 |
26 Feb 07 |
jari |
402 |
return variances; |
2 |
26 Feb 07 |
jari |
403 |
} |
2 |
26 Feb 07 |
jari |
404 |
|
2 |
26 Feb 07 |
jari |
/** returns variances |
2 |
26 Feb 07 |
jari |
406 |
*/ |
2 |
26 Feb 07 |
jari |
407 |
private float [] getVariances(FloatMatrix data, FloatMatrix means, int [] indices, int clusterIndex){ |
2 |
26 Feb 07 |
jari |
408 |
int nSamples = data.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
409 |
float [] variances = new float[nSamples]; |
2 |
26 Feb 07 |
jari |
410 |
float sse = 0; |
2 |
26 Feb 07 |
jari |
411 |
float mean; |
2 |
26 Feb 07 |
jari |
412 |
float value; |
2 |
26 Feb 07 |
jari |
413 |
int n = 0; |
2 |
26 Feb 07 |
jari |
414 |
for(int i = 0; i < nSamples; i++){ |
2 |
26 Feb 07 |
jari |
415 |
mean = means.get(clusterIndex, i); |
2 |
26 Feb 07 |
jari |
416 |
n = 0; |
2 |
26 Feb 07 |
jari |
417 |
sse = 0; |
2 |
26 Feb 07 |
jari |
418 |
for(int j = 0; j < indices.length; j++){ |
2 |
26 Feb 07 |
jari |
419 |
value = data.get(indices[j], i); |
2 |
26 Feb 07 |
jari |
420 |
if(!Float.isNaN(value)){ |
2 |
26 Feb 07 |
jari |
421 |
sse += (float)Math.pow((value - mean),2); |
2 |
26 Feb 07 |
jari |
422 |
n++; |
2 |
26 Feb 07 |
jari |
423 |
} |
2 |
26 Feb 07 |
jari |
424 |
} |
2 |
26 Feb 07 |
jari |
425 |
if(n > 1) |
2 |
26 Feb 07 |
jari |
426 |
variances[i] = (float)Math.sqrt(sse/(n-1)); |
2 |
26 Feb 07 |
jari |
427 |
else |
2 |
26 Feb 07 |
jari |
428 |
variances[i] = 0.0f; |
2 |
26 Feb 07 |
jari |
429 |
} |
2 |
26 Feb 07 |
jari |
430 |
return variances; |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
432 |
|
2 |
26 Feb 07 |
jari |
/** Returns a set of dfault indices |
2 |
26 Feb 07 |
jari |
434 |
*/ |
2 |
26 Feb 07 |
jari |
435 |
private int [] getDefaultGeneIndices(int length) { |
2 |
26 Feb 07 |
jari |
436 |
int [] indices = new int[length]; |
2 |
26 Feb 07 |
jari |
437 |
for(int i = 0; i < indices.length; i++) |
2 |
26 Feb 07 |
jari |
438 |
indices[i] = i; |
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
440 |
return indices; |
2 |
26 Feb 07 |
jari |
441 |
} |
2 |
26 Feb 07 |
jari |
442 |
|
2 |
26 Feb 07 |
jari |
443 |
private void attachResultToChildAlgorithmSets(AlgorithmNode algNode, Experiment experiment, int [][] clusters) { |
2 |
26 Feb 07 |
jari |
//get data ouput nodes |
2 |
26 Feb 07 |
jari |
445 |
int outputCount = algNode.getChildCount(); |
2 |
26 Feb 07 |
jari |
446 |
DataNode dataNode; |
2 |
26 Feb 07 |
jari |
447 |
for(int i = 0; i < outputCount; i++) { |
2 |
26 Feb 07 |
jari |
448 |
dataNode = ((DataNode)algNode.getChildAt(i)); |
2 |
26 Feb 07 |
jari |
449 |
for( int j = 0; j < algSets.length; j++) { |
2 |
26 Feb 07 |
jari |
450 |
if(dataNode == algSets[j].getDataNode()) { |
2 |
26 Feb 07 |
jari |
//if it's not multicluster ouput then append the propper experiment |
2 |
26 Feb 07 |
jari |
452 |
|
2 |
26 Feb 07 |
jari |
453 |
if(!dataNode.getDataOutputClass().equals(ScriptConstants.OUTPUT_DATA_CLASS_MULTICLUSTER_OUTPUT) |
2 |
26 Feb 07 |
jari |
454 |
&& !dataNode.getDataOutputClass().equals(ScriptConstants.OUTPUT_DATA_CLASS_GENE_MULTICLUSTER_OUTPUT) |
2 |
26 Feb 07 |
jari |
455 |
&& !dataNode.getDataOutputClass().equals(ScriptConstants.OUTPUT_DATA_CLASS_EXPERIMENT_MULTICLUSTER_OUTPUT)) { |
2 |
26 Feb 07 |
jari |
456 |
if( i < clusters.length ) { |
2 |
26 Feb 07 |
jari |
457 |
if(algNode.getAlgorithmType().equals(ScriptConstants.ALGORITHM_TYPE_CLUSTER_EXPERIMENTS)) |
2 |
26 Feb 07 |
jari |
458 |
setExperiment(algSets[j], experiment, clusters[i], false); |
2 |
26 Feb 07 |
jari |
459 |
else |
2 |
26 Feb 07 |
jari |
460 |
setExperiment(algSets[j], experiment, clusters[i], true); |
2 |
26 Feb 07 |
jari |
461 |
} |
2 |
26 Feb 07 |
jari |
462 |
} |
2 |
26 Feb 07 |
jari |
463 |
|
2 |
26 Feb 07 |
jari |
//if it IS multicluster output then the next algorithm must be for |
2 |
26 Feb 07 |
jari |
//cluster selection. This algorithm will require clusters[][] for selection process |
2 |
26 Feb 07 |
jari |
466 |
else { |
2 |
26 Feb 07 |
jari |
467 |
setExperimentAndClusters(algSets[j], experiment, clusters, algNode); |
2 |
26 Feb 07 |
jari |
468 |
} |
2 |
26 Feb 07 |
jari |
469 |
|
2 |
26 Feb 07 |
jari |
470 |
} |
2 |
26 Feb 07 |
jari |
471 |
} |
2 |
26 Feb 07 |
jari |
472 |
} |
2 |
26 Feb 07 |
jari |
473 |
} |
2 |
26 Feb 07 |
jari |
474 |
|
2 |
26 Feb 07 |
jari |
/** Sets the Experiment into the output nodes |
2 |
26 Feb 07 |
jari |
476 |
*/ |
2 |
26 Feb 07 |
jari |
477 |
private void setExperiment(AlgorithmSet algSet, Experiment experiment, int [] indices, boolean geneReduction) { |
2 |
26 Feb 07 |
jari |
478 |
ScriptDataTransformer transformer = new ScriptDataTransformer(experiment, framework); |
2 |
26 Feb 07 |
jari |
479 |
Experiment trimmedExperiment = transformer.getTrimmedExperiment(indices, geneReduction); |
2 |
26 Feb 07 |
jari |
480 |
algSet.setExperiment(trimmedExperiment); |
2 |
26 Feb 07 |
jari |
481 |
} |
2 |
26 Feb 07 |
jari |
482 |
|
2 |
26 Feb 07 |
jari |
483 |
|
2 |
26 Feb 07 |
jari |
/** Sets Experiment and cluster indicies. |
2 |
26 Feb 07 |
jari |
485 |
*/ |
2 |
26 Feb 07 |
jari |
486 |
private void setExperimentAndClusters(AlgorithmSet algSet, Experiment experiment, int [][] clusters, AlgorithmNode algNode) { |
2 |
26 Feb 07 |
jari |
487 |
algSet.setExperiment(experiment); |
2 |
26 Feb 07 |
jari |
488 |
algSet.setClusters(clusters); |
2 |
26 Feb 07 |
jari |
489 |
if(algNode.getAlgorithmType().equals(ScriptConstants.ALGORITHM_TYPE_CLUSTER_GENES)) |
2 |
26 Feb 07 |
jari |
490 |
algSet.setClusterType(ScriptConstants.CLUSTER_TYPE_GENE); |
2 |
26 Feb 07 |
jari |
491 |
else |
2 |
26 Feb 07 |
jari |
492 |
algSet.setClusterType(ScriptConstants.CLUSTER_TYPE_EXPERIMENT); |
2 |
26 Feb 07 |
jari |
493 |
} |
2 |
26 Feb 07 |
jari |
494 |
|
2 |
26 Feb 07 |
jari |
/** Extracts cluster results from tree nodes |
2 |
26 Feb 07 |
jari |
496 |
*/ |
2 |
26 Feb 07 |
jari |
497 |
private int [][] extractClusters(DefaultMutableTreeNode analysisNode) { |
2 |
26 Feb 07 |
jari |
498 |
|
2 |
26 Feb 07 |
jari |
499 |
int [][] clusters; |
2 |
26 Feb 07 |
jari |
500 |
Enumeration _enum = analysisNode.depthFirstEnumeration(); |
2 |
26 Feb 07 |
jari |
501 |
DefaultMutableTreeNode currentNode; |
2 |
26 Feb 07 |
jari |
502 |
IViewer viewer; |
2 |
26 Feb 07 |
jari |
503 |
Experiment exp; |
2 |
26 Feb 07 |
jari |
504 |
|
2 |
26 Feb 07 |
jari |
505 |
while (_enum.hasMoreElements()){ |
2 |
26 Feb 07 |
jari |
506 |
currentNode = (DefaultMutableTreeNode)_enum.nextElement(); |
2 |
26 Feb 07 |
jari |
507 |
if(currentNode.getUserObject() instanceof LeafInfo){ |
2 |
26 Feb 07 |
jari |
508 |
viewer = ((LeafInfo)currentNode.getUserObject()).getViewer(); |
2 |
26 Feb 07 |
jari |
509 |
if(viewer != null) { |
2 |
26 Feb 07 |
jari |
510 |
exp = viewer.getExperiment(); |
2 |
26 Feb 07 |
jari |
511 |
clusters = viewer.getClusters(); |
2 |
26 Feb 07 |
jari |
512 |
if(exp != null && clusters != null) { |
2 |
26 Feb 07 |
jari |
513 |
return clusters; |
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 |
518 |
return null; |
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
/** Constructs cluster viewer for clusters selected |
2 |
26 Feb 07 |
jari |
* by cluster selection algorithms |
2 |
26 Feb 07 |
jari |
522 |
*/ |
2 |
26 Feb 07 |
jari |
523 |
private DefaultMutableTreeNode getSelectedClusterViewers(AlgorithmData data, Experiment experiment, int [][] clusters, boolean areGeneClusters) { |
2 |
26 Feb 07 |
jari |
524 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Selection Results"); |
2 |
26 Feb 07 |
jari |
525 |
addExpressionImages(node, experiment, clusters, areGeneClusters); |
2 |
26 Feb 07 |
jari |
526 |
addCentroidViews(node, experiment, clusters, areGeneClusters); |
2 |
26 Feb 07 |
jari |
527 |
addSelectionInfoViewer(node, data); |
2 |
26 Feb 07 |
jari |
528 |
return node; |
2 |
26 Feb 07 |
jari |
529 |
} |
2 |
26 Feb 07 |
jari |
530 |
|
2 |
26 Feb 07 |
jari |
531 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display clusters data. |
2 |
26 Feb 07 |
jari |
533 |
*/ |
2 |
26 Feb 07 |
jari |
534 |
private void addExpressionImages(DefaultMutableTreeNode root, Experiment experiment, int [][] clusters, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
535 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images"); |
2 |
26 Feb 07 |
jari |
536 |
IViewer expViewer; |
2 |
26 Feb 07 |
jari |
537 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
538 |
expViewer = new ScriptExperimentViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
539 |
else |
2 |
26 Feb 07 |
jari |
540 |
expViewer = new ScriptExperimentClusterViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
541 |
|
2 |
26 Feb 07 |
jari |
542 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
543 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
544 |
} |
2 |
26 Feb 07 |
jari |
545 |
root.add(node); |
2 |
26 Feb 07 |
jari |
546 |
} |
2 |
26 Feb 07 |
jari |
547 |
|
2 |
26 Feb 07 |
jari |
548 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display centroid charts. |
2 |
26 Feb 07 |
jari |
550 |
*/ |
2 |
26 Feb 07 |
jari |
551 |
private void addCentroidViews(DefaultMutableTreeNode root, Experiment experiment, int [][] clusters, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
552 |
DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs"); |
2 |
26 Feb 07 |
jari |
553 |
DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs"); |
2 |
26 Feb 07 |
jari |
554 |
|
2 |
26 Feb 07 |
jari |
555 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
556 |
if(!clusterGenes) |
2 |
26 Feb 07 |
jari |
557 |
matrix = matrix.transpose(); |
2 |
26 Feb 07 |
jari |
558 |
|
2 |
26 Feb 07 |
jari |
559 |
FloatMatrix means = getMeans(matrix, clusters); |
2 |
26 Feb 07 |
jari |
560 |
FloatMatrix variances = getVariances(matrix, means, clusters); |
2 |
26 Feb 07 |
jari |
561 |
|
2 |
26 Feb 07 |
jari |
//if ! genes then transpose it back |
2 |
26 Feb 07 |
jari |
563 |
if(!clusterGenes) |
2 |
26 Feb 07 |
jari |
564 |
matrix = matrix.transpose(); |
2 |
26 Feb 07 |
jari |
565 |
|
2 |
26 Feb 07 |
jari |
566 |
|
2 |
26 Feb 07 |
jari |
567 |
ScriptCentroidViewer centroidViewer; |
2 |
26 Feb 07 |
jari |
568 |
ScriptExperimentCentroidViewer expCentroidViewer; |
2 |
26 Feb 07 |
jari |
569 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
570 |
centroidViewer = new ScriptCentroidViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
571 |
centroidViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
572 |
centroidViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
573 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
574 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
575 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
576 |
} |
2 |
26 Feb 07 |
jari |
577 |
|
2 |
26 Feb 07 |
jari |
578 |
ScriptCentroidsViewer centroidsViewer = new ScriptCentroidsViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
579 |
centroidsViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
580 |
centroidsViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
581 |
|
2 |
26 Feb 07 |
jari |
582 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
583 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
584 |
|
2 |
26 Feb 07 |
jari |
585 |
} |
2 |
26 Feb 07 |
jari |
586 |
else{ |
2 |
26 Feb 07 |
jari |
587 |
expCentroidViewer = new ScriptExperimentCentroidViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
588 |
|
2 |
26 Feb 07 |
jari |
589 |
expCentroidViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
590 |
expCentroidViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
591 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
592 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
593 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Cluster "+String.valueOf(i+1), expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
594 |
} |
2 |
26 Feb 07 |
jari |
595 |
ScriptExperimentCentroidsViewer expCentroidsViewer = new ScriptExperimentCentroidsViewer(experiment, clusters); |
2 |
26 Feb 07 |
jari |
596 |
expCentroidsViewer.setMeans(means.A); |
2 |
26 Feb 07 |
jari |
597 |
expCentroidsViewer.setVariances(variances.A); |
2 |
26 Feb 07 |
jari |
598 |
|
2 |
26 Feb 07 |
jari |
599 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
600 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
601 |
} |
2 |
26 Feb 07 |
jari |
602 |
root.add(centroidNode); |
2 |
26 Feb 07 |
jari |
603 |
root.add(expressionNode); |
2 |
26 Feb 07 |
jari |
604 |
} |
2 |
26 Feb 07 |
jari |
605 |
|
2 |
26 Feb 07 |
jari |
/** Creates a viewer for cluster selection results |
2 |
26 Feb 07 |
jari |
607 |
*/ |
2 |
26 Feb 07 |
jari |
608 |
private void addSelectionInfoViewer(DefaultMutableTreeNode root, AlgorithmData data) { |
2 |
26 Feb 07 |
jari |
609 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new LeafInfo("Selection Information", new ScriptClusterSelectionInfoViewer(data))); |
2 |
26 Feb 07 |
jari |
610 |
root.add(node); |
2 |
26 Feb 07 |
jari |
611 |
} |
2 |
26 Feb 07 |
jari |
612 |
} |