2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2006, 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: PTMGUI.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.11 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/14 15:31:10 $ |
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.ptm; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
17 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
18 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.tree.DefaultMutableTreeNode; |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.mev.cluster.Cluster; |
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.Node; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.cluster.NodeList; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.NodeValueList; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.algorithm.Algorithm; |
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.algorithm.AlgorithmEvent; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmListener; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.clusterUtil.ClusterList; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.clusterUtil.ClusterRepository; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.IClusterGUI; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.cluster.gui.IDistanceMenu; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.cluster.gui.LeafInfo; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidUserObject; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.cluster.gui.helpers.ClusterTableViewer; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterTableViewer; |
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLGUI; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLInitDialog; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData; |
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLViewer; |
2 |
26 Feb 07 |
jari |
51 |
import org.tigr.microarray.mev.script.scriptGUI.IScriptGUI; |
2 |
26 Feb 07 |
jari |
52 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
public class PTMGUI implements IClusterGUI, IScriptGUI { |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
private Algorithm algorithm; |
2 |
26 Feb 07 |
jari |
58 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
59 |
private int[][] clusters; |
2 |
26 Feb 07 |
jari |
60 |
private FloatMatrix means; |
2 |
26 Feb 07 |
jari |
61 |
private FloatMatrix variances; |
2 |
26 Feb 07 |
jari |
62 |
private IData data; |
2 |
26 Feb 07 |
jari |
63 |
Vector templateVector; |
2 |
26 Feb 07 |
jari |
64 |
private float[] pValues, rValues; |
2 |
26 Feb 07 |
jari |
65 |
private boolean clusterGenes = false; |
2 |
26 Feb 07 |
jari |
66 |
private Object[][] auxData; |
2 |
26 Feb 07 |
jari |
67 |
private String[] auxTitles; |
2 |
26 Feb 07 |
jari |
68 |
private boolean drawSigTreesOnly; |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
/** |
2 |
26 Feb 07 |
jari |
* Default constructor. |
2 |
26 Feb 07 |
jari |
72 |
*/ |
2 |
26 Feb 07 |
jari |
73 |
public PTMGUI() { |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
} |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
/** |
2 |
26 Feb 07 |
jari |
* Initialize the algorithm's parameters and execute it. |
2 |
26 Feb 07 |
jari |
81 |
*/ |
2 |
26 Feb 07 |
jari |
82 |
public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
83 |
int k = 2; //number of clusters |
2 |
26 Feb 07 |
jari |
84 |
boolean modality = true; // HOPE THIS IS OK; DID THIS TO CALL UP THE DIALOG BOX |
2 |
26 Feb 07 |
jari |
85 |
boolean useAbsolute = false; |
2 |
26 Feb 07 |
jari |
86 |
boolean useR = false; |
2 |
26 Feb 07 |
jari |
87 |
FloatMatrix templateMatrix; |
2 |
26 Feb 07 |
jari |
88 |
float threshold = 0.8f; |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
this.experiment = framework.getData().getExperiment(); |
2 |
26 Feb 07 |
jari |
91 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
92 |
Vector sampleNamesVector = new Vector(); |
2 |
26 Feb 07 |
jari |
93 |
int number_of_samples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
94 |
int number_of_genes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
for (int i = 0; i < number_of_samples; i++) { |
2 |
26 Feb 07 |
jari |
97 |
sampleNamesVector.add(framework.getData().getFullSampleName(experiment.getSampleIndex(i))); |
2 |
26 Feb 07 |
jari |
98 |
} |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
Vector uniqueIDs = new Vector(); |
2 |
26 Feb 07 |
jari |
101 |
int labelIndex = framework.getDisplayMenu().getLabelIndex(); |
2 |
26 Feb 07 |
jari |
102 |
for (int i = 0; i < number_of_genes; i++) { |
2 |
26 Feb 07 |
jari |
103 |
uniqueIDs.add(framework.getData().getElementAttribute(experiment.getGeneIndexMappedToData(i), labelIndex)); |
2 |
26 Feb 07 |
jari |
//uniqueIDs.add(framework.getData().getUniqueId(experiment.getGeneIndexMappedToData(i))); |
2 |
26 Feb 07 |
jari |
105 |
} |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
Vector clusterVector = new Vector(); |
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
109 |
Color clusterColors[] = framework.getData().getColors(); |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
boolean assignedToACluster[] = new boolean[number_of_genes]; |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
for (int i = 0; i < number_of_genes; i++) { |
2 |
26 Feb 07 |
jari |
114 |
assignedToACluster[i] = false; |
2 |
26 Feb 07 |
jari |
115 |
} |
2 |
26 Feb 07 |
jari |
116 |
|
2 |
26 Feb 07 |
jari |
//for (int i = 0; i < clusterColors.length; i++) { |
2 |
26 Feb 07 |
jari |
// Vector currentCluster = new Vector(); |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
/* |
2 |
26 Feb 07 |
jari |
for (int j = 0; j < number_of_genes; j++) { |
2 |
26 Feb 07 |
jari |
if (!assignedToACluster[j]) { |
2 |
26 Feb 07 |
jari |
if (clusterColors[i].equals(framework.getData().getProbeColor(experiment.getGeneIndexMappedToData(j)))) { |
2 |
26 Feb 07 |
jari |
currentCluster.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
assignedToACluster[j] = true; |
2 |
26 Feb 07 |
jari |
126 |
} |
2 |
26 Feb 07 |
jari |
127 |
} |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
*/ |
2 |
26 Feb 07 |
jari |
130 |
|
2 |
26 Feb 07 |
jari |
//can't assume that a null cluster color means that a gene is not in a cluster. |
2 |
26 Feb 07 |
jari |
132 |
ClusterRepository geneClusterRepository = framework.getClusterRepository(org.tigr.microarray.mev.cluster.clusterUtil.Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
//need to get total cluster count |
2 |
26 Feb 07 |
jari |
135 |
int numClusters = 0; |
2 |
26 Feb 07 |
jari |
136 |
for(int i = 0; i < geneClusterRepository.size(); i++) { |
2 |
26 Feb 07 |
jari |
137 |
numClusters += geneClusterRepository.getClusterList(i).size(); |
2 |
26 Feb 07 |
jari |
138 |
} |
2 |
26 Feb 07 |
jari |
139 |
|
2 |
26 Feb 07 |
jari |
140 |
clusterColors = new Color[numClusters]; |
2 |
26 Feb 07 |
jari |
141 |
int clusterIndex = 0; |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
for(int i = 0; i < geneClusterRepository.size(); i++) { |
2 |
26 Feb 07 |
jari |
144 |
ClusterList list = geneClusterRepository.getClusterList(i); |
2 |
26 Feb 07 |
jari |
145 |
Vector currentCluster; |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
//clusterColors = new Color[list.size()]; |
2 |
26 Feb 07 |
jari |
148 |
|
2 |
26 Feb 07 |
jari |
149 |
for(int j = 0; j < list.size(); j++) { |
2 |
26 Feb 07 |
jari |
//make a vector |
2 |
26 Feb 07 |
jari |
151 |
currentCluster = new Vector(); |
2 |
26 Feb 07 |
jari |
152 |
|
2 |
26 Feb 07 |
jari |
//get cluster |
2 |
26 Feb 07 |
jari |
154 |
org.tigr.microarray.mev.cluster.clusterUtil.Cluster mevCluster = list.getClusterAt(j); |
2 |
26 Feb 07 |
jari |
155 |
clusterColors[clusterIndex] = mevCluster.getClusterColor(); |
2 |
26 Feb 07 |
jari |
156 |
clusterIndex++; |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
//check genes for membership and add to cluster vector |
2 |
26 Feb 07 |
jari |
159 |
for(int m = 0 ; m < number_of_genes; m++) { |
2 |
26 Feb 07 |
jari |
160 |
if(mevCluster.isMember(experiment.getGeneIndexMappedToData(m))) |
2 |
26 Feb 07 |
jari |
161 |
currentCluster.add(new Integer(m)); |
2 |
26 Feb 07 |
jari |
162 |
assignedToACluster[m] = true; |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
clusterVector.add(currentCluster); |
2 |
26 Feb 07 |
jari |
166 |
|
2 |
26 Feb 07 |
jari |
167 |
} |
2 |
26 Feb 07 |
jari |
168 |
} |
2 |
26 Feb 07 |
jari |
169 |
|
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
//Experiment clustering |
2 |
26 Feb 07 |
jari |
172 |
Vector expClusterVector = new Vector(); |
2 |
26 Feb 07 |
jari |
173 |
Color expClusterColors[] = framework.getData().getExperimentColors(); |
2 |
26 Feb 07 |
jari |
174 |
boolean expAssignedToACluster[] = new boolean[number_of_samples]; |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
for(int i = 0; i < number_of_samples; i++) { |
2 |
26 Feb 07 |
jari |
177 |
expAssignedToACluster[i] = false; |
2 |
26 Feb 07 |
jari |
178 |
} |
2 |
26 Feb 07 |
jari |
179 |
|
2 |
26 Feb 07 |
jari |
//11.04.2005 JCB, bug fix, GENE_CLUSTER->EXPERIMENT_CLUSTER |
2 |
26 Feb 07 |
jari |
181 |
ClusterRepository expClusterRepository = framework.getClusterRepository(org.tigr.microarray.mev.cluster.clusterUtil.Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
//need to get total cluster count |
2 |
26 Feb 07 |
jari |
184 |
numClusters = 0; |
2 |
26 Feb 07 |
jari |
185 |
for(int i = 0; i < expClusterRepository.size(); i++) { |
2 |
26 Feb 07 |
jari |
186 |
numClusters += expClusterRepository.getClusterList(i).size(); |
2 |
26 Feb 07 |
jari |
187 |
} |
2 |
26 Feb 07 |
jari |
188 |
|
2 |
26 Feb 07 |
jari |
189 |
expClusterColors = new Color[numClusters]; |
2 |
26 Feb 07 |
jari |
190 |
clusterIndex = 0; |
2 |
26 Feb 07 |
jari |
191 |
|
2 |
26 Feb 07 |
jari |
192 |
for(int i = 0; i < expClusterRepository.size(); i++) { |
2 |
26 Feb 07 |
jari |
193 |
ClusterList list = expClusterRepository.getClusterList(i); |
2 |
26 Feb 07 |
jari |
194 |
Vector currentCluster; |
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
for(int j = 0; j < list.size(); j++) { |
2 |
26 Feb 07 |
jari |
//make a vector |
2 |
26 Feb 07 |
jari |
198 |
currentCluster = new Vector(); |
2 |
26 Feb 07 |
jari |
199 |
|
2 |
26 Feb 07 |
jari |
//get cluster |
2 |
26 Feb 07 |
jari |
201 |
org.tigr.microarray.mev.cluster.clusterUtil.Cluster mevCluster = list.getClusterAt(j); |
2 |
26 Feb 07 |
jari |
202 |
expClusterColors[clusterIndex] = mevCluster.getClusterColor(); |
2 |
26 Feb 07 |
jari |
203 |
clusterIndex++; |
2 |
26 Feb 07 |
jari |
204 |
|
2 |
26 Feb 07 |
jari |
//check genes for membership and add to cluster vector |
2 |
26 Feb 07 |
jari |
206 |
for(int m = 0 ; m < number_of_samples; m++) { |
2 |
26 Feb 07 |
jari |
207 |
if(mevCluster.isMember(experiment.getSampleIndex(m))) |
2 |
26 Feb 07 |
jari |
208 |
currentCluster.add(new Integer(m)); |
2 |
26 Feb 07 |
jari |
209 |
expAssignedToACluster[m] = true; |
2 |
26 Feb 07 |
jari |
210 |
} |
2 |
26 Feb 07 |
jari |
211 |
|
2 |
26 Feb 07 |
jari |
212 |
expClusterVector.add(currentCluster); |
2 |
26 Feb 07 |
jari |
213 |
} |
2 |
26 Feb 07 |
jari |
214 |
} |
2 |
26 Feb 07 |
jari |
/* for (int i = 0; i < expClusterColors.length; i++) { |
2 |
26 Feb 07 |
jari |
Vector currentCluster = new Vector(); |
2 |
26 Feb 07 |
jari |
217 |
|
2 |
26 Feb 07 |
jari |
for (int j = 0; j < number_of_samples; j++) { |
2 |
26 Feb 07 |
jari |
if (!expAssignedToACluster[j]) { |
2 |
26 Feb 07 |
jari |
if (expClusterColors[i].equals(framework.getData().getExperimentColor(experiment.getSampleIndex(j)))) { |
2 |
26 Feb 07 |
jari |
currentCluster.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
expAssignedToACluster[j] = true; |
2 |
26 Feb 07 |
jari |
223 |
} |
2 |
26 Feb 07 |
jari |
224 |
} |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
expClusterVector.add(currentCluster); |
2 |
26 Feb 07 |
jari |
227 |
} |
2 |
26 Feb 07 |
jari |
228 |
*/ |
2 |
26 Feb 07 |
jari |
229 |
|
2 |
26 Feb 07 |
jari |
230 |
|
2 |
26 Feb 07 |
jari |
231 |
PTMInitDialog ptmInitBox = new PTMInitDialog((JFrame)framework.getFrame(), modality, experiment.getMatrix(), uniqueIDs, sampleNamesVector, clusterVector, expClusterVector, clusterColors, expClusterColors); |
2 |
26 Feb 07 |
jari |
232 |
|
2 |
26 Feb 07 |
jari |
233 |
boolean isHierarchicalTree; |
2 |
26 Feb 07 |
jari |
// hcl init |
2 |
26 Feb 07 |
jari |
235 |
int hcl_method = 0; |
2 |
26 Feb 07 |
jari |
236 |
boolean hcl_samples = false; |
2 |
26 Feb 07 |
jari |
237 |
boolean hcl_genes = false; |
2 |
26 Feb 07 |
jari |
238 |
|
2 |
26 Feb 07 |
jari |
239 |
ptmInitBox.setVisible(true); |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
if (! ptmInitBox.isOkPressed()){ |
2 |
26 Feb 07 |
jari |
243 |
return null; |
2 |
26 Feb 07 |
jari |
244 |
} |
2 |
26 Feb 07 |
jari |
245 |
clusterGenes = ptmInitBox.isGeneTemplate(); |
2 |
26 Feb 07 |
jari |
246 |
|
2 |
26 Feb 07 |
jari |
247 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
248 |
templateMatrix = ptmInitBox.convertTemplateVectorToFloatMatrix(); |
2 |
26 Feb 07 |
jari |
249 |
templateVector = ptmInitBox.getTemplate(); |
2 |
26 Feb 07 |
jari |
250 |
useAbsolute = ptmInitBox.isUseAbsolute(); |
2 |
26 Feb 07 |
jari |
251 |
useR = ptmInitBox.isUseR(); |
2 |
26 Feb 07 |
jari |
252 |
threshold = (float) ptmInitBox.getThresholdR(); |
2 |
26 Feb 07 |
jari |
253 |
isHierarchicalTree = ptmInitBox.isDrawTrees(); |
2 |
26 Feb 07 |
jari |
254 |
} |
2 |
26 Feb 07 |
jari |
255 |
else{ |
2 |
26 Feb 07 |
jari |
256 |
templateMatrix = ptmInitBox.convertTemplateVectorToFloatMatrix(); |
2 |
26 Feb 07 |
jari |
257 |
templateVector = ptmInitBox.getTemplate(); |
2 |
26 Feb 07 |
jari |
258 |
useAbsolute = ptmInitBox.isUseAbsolute(); |
2 |
26 Feb 07 |
jari |
259 |
useR = ptmInitBox.isUseR(); |
2 |
26 Feb 07 |
jari |
260 |
threshold = (float) ptmInitBox.getThresholdR(); |
2 |
26 Feb 07 |
jari |
261 |
isHierarchicalTree = ptmInitBox.isDrawTrees(); |
2 |
26 Feb 07 |
jari |
262 |
} |
2 |
26 Feb 07 |
jari |
263 |
|
2 |
26 Feb 07 |
jari |
264 |
drawSigTreesOnly = true; |
2 |
26 Feb 07 |
jari |
265 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
266 |
drawSigTreesOnly = ptmInitBox.drawSigTreesOnly(); |
2 |
26 Feb 07 |
jari |
267 |
} |
2 |
26 Feb 07 |
jari |
268 |
|
2 |
26 Feb 07 |
jari |
269 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
270 |
int function = menu.getDistanceFunction(); |
2 |
26 Feb 07 |
jari |
271 |
if (function == Algorithm.DEFAULT) { |
2 |
26 Feb 07 |
jari |
272 |
function = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
273 |
} |
2 |
26 Feb 07 |
jari |
274 |
|
2 |
26 Feb 07 |
jari |
275 |
int hcl_function = 4; |
2 |
26 Feb 07 |
jari |
276 |
boolean hcl_absolute = false; |
2 |
26 Feb 07 |
jari |
277 |
|
2 |
26 Feb 07 |
jari |
278 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
279 |
HCLInitDialog hcl_dialog = new HCLInitDialog(new JFrame(), menu.getFunctionName(function), menu.isAbsoluteDistance(), true); |
2 |
26 Feb 07 |
jari |
280 |
if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
281 |
return null; |
2 |
26 Feb 07 |
jari |
282 |
} |
2 |
26 Feb 07 |
jari |
283 |
hcl_method = hcl_dialog.getMethod(); |
2 |
26 Feb 07 |
jari |
284 |
hcl_samples = hcl_dialog.isClusterExperiments(); |
2 |
26 Feb 07 |
jari |
285 |
hcl_genes = hcl_dialog.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
286 |
hcl_function = hcl_dialog.getDistanceMetric(); |
2 |
26 Feb 07 |
jari |
287 |
hcl_absolute = hcl_dialog.getAbsoluteSelection(); |
2 |
26 Feb 07 |
jari |
288 |
} |
2 |
26 Feb 07 |
jari |
289 |
|
2 |
26 Feb 07 |
jari |
290 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
291 |
|
2 |
26 Feb 07 |
jari |
292 |
try { |
2 |
26 Feb 07 |
jari |
293 |
algorithm = framework.getAlgorithmFactory().getAlgorithm("PTM"); |
2 |
26 Feb 07 |
jari |
294 |
algorithm.addAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
295 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
296 |
int genes; |
2 |
26 Feb 07 |
jari |
297 |
if(!clusterGenes){ |
2 |
26 Feb 07 |
jari |
298 |
matrix = matrix.transpose(); |
2 |
26 Feb 07 |
jari |
299 |
genes = matrix.getRowDimension(); |
2 |
26 Feb 07 |
jari |
300 |
} |
2 |
26 Feb 07 |
jari |
301 |
genes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
303 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
304 |
|
2 |
26 Feb 07 |
jari |
305 |
data.addMatrix("experiment", matrix); |
2 |
26 Feb 07 |
jari |
306 |
data.addParam("ptm-cluster-genes", String.valueOf(clusterGenes)); |
2 |
26 Feb 07 |
jari |
307 |
data.addMatrix("templateVectorMatrix", templateMatrix); |
2 |
26 Feb 07 |
jari |
308 |
data.addParam("distance-factor", String.valueOf(1.0f)); |
2 |
26 Feb 07 |
jari |
309 |
|
2 |
26 Feb 07 |
jari |
310 |
data.addParam("use-absolute", String.valueOf(useAbsolute)); |
2 |
26 Feb 07 |
jari |
311 |
data.addParam("useR", String.valueOf(useR)); |
2 |
26 Feb 07 |
jari |
312 |
data.addParam("threshold", String.valueOf(threshold)); |
2 |
26 Feb 07 |
jari |
313 |
|
2 |
26 Feb 07 |
jari |
//function = Algorithm.PEARSON; |
2 |
26 Feb 07 |
jari |
315 |
data.addParam("distance-function", String.valueOf(function)); |
2 |
26 Feb 07 |
jari |
316 |
|
2 |
26 Feb 07 |
jari |
// hcl parameters |
2 |
26 Feb 07 |
jari |
318 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
319 |
data.addParam("hierarchical-tree", String.valueOf(true)); |
2 |
26 Feb 07 |
jari |
320 |
data.addParam("draw-sig-trees-only", String.valueOf(drawSigTreesOnly)); |
2 |
26 Feb 07 |
jari |
321 |
data.addParam("method-linkage", String.valueOf(hcl_method)); |
2 |
26 Feb 07 |
jari |
322 |
data.addParam("calculate-genes", String.valueOf(hcl_genes)); |
2 |
26 Feb 07 |
jari |
323 |
data.addParam("calculate-experiments", String.valueOf(hcl_samples)); |
2 |
26 Feb 07 |
jari |
324 |
data.addParam("hcl-distance-function", String.valueOf(hcl_function)); |
2 |
26 Feb 07 |
jari |
325 |
data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute)); |
2 |
26 Feb 07 |
jari |
326 |
} |
2 |
26 Feb 07 |
jari |
327 |
|
2 |
26 Feb 07 |
jari |
328 |
long start = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
329 |
AlgorithmData result = algorithm.execute(data); |
2 |
26 Feb 07 |
jari |
330 |
long time = System.currentTimeMillis() - start; |
2 |
26 Feb 07 |
jari |
// getting the results |
2 |
26 Feb 07 |
jari |
332 |
Cluster result_cluster = result.getCluster("cluster"); |
2 |
26 Feb 07 |
jari |
333 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
334 |
|
2 |
26 Feb 07 |
jari |
335 |
this.clusters = new int[k][]; |
2 |
26 Feb 07 |
jari |
336 |
for (int i=0; i<k; i++) { |
2 |
26 Feb 07 |
jari |
337 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
338 |
} |
2 |
26 Feb 07 |
jari |
339 |
|
2 |
26 Feb 07 |
jari |
340 |
this.means = result.getMatrix("clusters_means"); |
2 |
26 Feb 07 |
jari |
341 |
this.variances = result.getMatrix("clusters_variances"); |
2 |
26 Feb 07 |
jari |
342 |
|
2 |
26 Feb 07 |
jari |
343 |
FloatMatrix rValuesMatrix = result.getMatrix("rValuesMatrix"); |
2 |
26 Feb 07 |
jari |
344 |
FloatMatrix pValuesMatrix = result.getMatrix("pValuesMatrix"); |
2 |
26 Feb 07 |
jari |
345 |
|
2 |
26 Feb 07 |
jari |
346 |
pValues = new float[pValuesMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
347 |
rValues = new float[rValuesMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
348 |
|
2 |
26 Feb 07 |
jari |
349 |
for (int i = 0; i < pValues.length; i++) { |
2 |
26 Feb 07 |
jari |
350 |
pValues[i] = pValuesMatrix.A[i][0]; |
2 |
26 Feb 07 |
jari |
351 |
rValues[i] = rValuesMatrix.A[i][0]; |
2 |
26 Feb 07 |
jari |
352 |
} |
2 |
26 Feb 07 |
jari |
353 |
|
2 |
26 Feb 07 |
jari |
354 |
auxTitles = new String[2]; |
2 |
26 Feb 07 |
jari |
355 |
auxTitles[0] = "R values"; |
2 |
26 Feb 07 |
jari |
356 |
auxTitles[1] = "p Values"; |
2 |
26 Feb 07 |
jari |
357 |
|
2 |
26 Feb 07 |
jari |
358 |
auxData = new Object[pValues.length][2]; |
2 |
26 Feb 07 |
jari |
359 |
|
2 |
26 Feb 07 |
jari |
360 |
for (int i = 0; i < auxData.length; i++) { |
2 |
26 Feb 07 |
jari |
361 |
auxData[i][0] = new Float(rValues[i]); |
2 |
26 Feb 07 |
jari |
362 |
auxData[i][1] = new Float(pValues[i]); |
2 |
26 Feb 07 |
jari |
363 |
} |
2 |
26 Feb 07 |
jari |
364 |
|
2 |
26 Feb 07 |
jari |
365 |
GeneralInfo info = new GeneralInfo(); |
2 |
26 Feb 07 |
jari |
366 |
info.clusters = k; |
2 |
26 Feb 07 |
jari |
367 |
info.time = time; |
2 |
26 Feb 07 |
jari |
368 |
info.function = menu.getFunctionName(function); |
2 |
26 Feb 07 |
jari |
369 |
info.isR = useR; |
2 |
26 Feb 07 |
jari |
370 |
info.isAbsolute = useAbsolute; |
2 |
26 Feb 07 |
jari |
371 |
info.threshold = threshold; |
2 |
26 Feb 07 |
jari |
372 |
info.hcl = isHierarchicalTree; |
2 |
26 Feb 07 |
jari |
373 |
info.hcl_genes = hcl_genes; |
2 |
26 Feb 07 |
jari |
374 |
info.hcl_samples = hcl_samples; |
2 |
26 Feb 07 |
jari |
375 |
info.hcl_method = hcl_method; |
2 |
26 Feb 07 |
jari |
376 |
|
2 |
26 Feb 07 |
jari |
377 |
return createResultTree(result_cluster, info); |
2 |
26 Feb 07 |
jari |
378 |
|
2 |
26 Feb 07 |
jari |
379 |
} finally { |
2 |
26 Feb 07 |
jari |
380 |
if (algorithm != null) { |
2 |
26 Feb 07 |
jari |
381 |
algorithm.removeAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
382 |
} |
2 |
26 Feb 07 |
jari |
383 |
} |
2 |
26 Feb 07 |
jari |
384 |
} |
2 |
26 Feb 07 |
jari |
385 |
|
2 |
26 Feb 07 |
jari |
386 |
|
2 |
26 Feb 07 |
jari |
387 |
|
2 |
26 Feb 07 |
jari |
388 |
|
2 |
26 Feb 07 |
jari |
389 |
|
2 |
26 Feb 07 |
jari |
390 |
public AlgorithmData getScriptParameters(IFramework framework) { |
2 |
26 Feb 07 |
jari |
391 |
int k = 2; //number of clusters |
2 |
26 Feb 07 |
jari |
392 |
boolean modality = true; // HOPE THIS IS OK; DID THIS TO CALL UP THE DIALOG BOX |
2 |
26 Feb 07 |
jari |
393 |
boolean useAbsolute = false; |
2 |
26 Feb 07 |
jari |
394 |
boolean useR = false; |
2 |
26 Feb 07 |
jari |
395 |
FloatMatrix templateMatrix; |
2 |
26 Feb 07 |
jari |
396 |
float threshold = 0.8f; |
2 |
26 Feb 07 |
jari |
397 |
|
2 |
26 Feb 07 |
jari |
398 |
this.experiment = framework.getData().getExperiment(); |
2 |
26 Feb 07 |
jari |
399 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
400 |
Vector sampleNamesVector = new Vector(); |
2 |
26 Feb 07 |
jari |
401 |
int number_of_samples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
402 |
int number_of_genes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
403 |
|
2 |
26 Feb 07 |
jari |
404 |
for (int i = 0; i < number_of_samples; i++) { |
2 |
26 Feb 07 |
jari |
405 |
sampleNamesVector.add(framework.getData().getFullSampleName(experiment.getSampleIndex(i))); |
2 |
26 Feb 07 |
jari |
406 |
} |
2 |
26 Feb 07 |
jari |
407 |
|
2 |
26 Feb 07 |
jari |
408 |
Vector uniqueIDs = new Vector(); |
2 |
26 Feb 07 |
jari |
409 |
int labelIndex = framework.getDisplayMenu().getLabelIndex(); |
2 |
26 Feb 07 |
jari |
410 |
for (int i = 0; i < number_of_genes; i++) { |
2 |
26 Feb 07 |
jari |
411 |
uniqueIDs.add(framework.getData().getElementAttribute(experiment.getGeneIndexMappedToData(i), labelIndex)); |
2 |
26 Feb 07 |
jari |
//uniqueIDs.add(framework.getData().getUniqueId(experiment.getGeneIndexMappedToData(i))); |
2 |
26 Feb 07 |
jari |
413 |
} |
2 |
26 Feb 07 |
jari |
414 |
|
2 |
26 Feb 07 |
jari |
415 |
Vector clusterVector = new Vector(); |
2 |
26 Feb 07 |
jari |
416 |
|
2 |
26 Feb 07 |
jari |
417 |
Color clusterColors[] = framework.getData().getColors(); |
2 |
26 Feb 07 |
jari |
418 |
boolean assignedToACluster[] = new boolean[number_of_genes]; |
2 |
26 Feb 07 |
jari |
419 |
|
2 |
26 Feb 07 |
jari |
420 |
for (int i = 0; i < number_of_genes; i++) { |
2 |
26 Feb 07 |
jari |
421 |
assignedToACluster[i] = false; |
2 |
26 Feb 07 |
jari |
422 |
} |
2 |
26 Feb 07 |
jari |
423 |
|
2 |
26 Feb 07 |
jari |
424 |
for (int i = 0; i < clusterColors.length; i++) { |
2 |
26 Feb 07 |
jari |
425 |
Vector currentCluster = new Vector(); |
2 |
26 Feb 07 |
jari |
426 |
|
2 |
26 Feb 07 |
jari |
427 |
for (int j = 0; j < number_of_genes; j++) { |
2 |
26 Feb 07 |
jari |
428 |
if (!assignedToACluster[j]) { |
2 |
26 Feb 07 |
jari |
429 |
if (clusterColors[i].equals(framework.getData().getProbeColor(experiment.getGeneIndexMappedToData(j)))) { |
2 |
26 Feb 07 |
jari |
430 |
currentCluster.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
431 |
assignedToACluster[j] = true; |
2 |
26 Feb 07 |
jari |
432 |
} |
2 |
26 Feb 07 |
jari |
433 |
} |
2 |
26 Feb 07 |
jari |
434 |
} |
2 |
26 Feb 07 |
jari |
435 |
|
2 |
26 Feb 07 |
jari |
436 |
clusterVector.add(currentCluster); |
2 |
26 Feb 07 |
jari |
437 |
} |
2 |
26 Feb 07 |
jari |
438 |
|
2 |
26 Feb 07 |
jari |
//Experiment clustering |
2 |
26 Feb 07 |
jari |
440 |
Vector expClusterVector = new Vector(); |
2 |
26 Feb 07 |
jari |
441 |
Color expClusterColors[] = framework.getData().getExperimentColors(); |
2 |
26 Feb 07 |
jari |
442 |
boolean expAssignedToACluster[] = new boolean[number_of_samples]; |
2 |
26 Feb 07 |
jari |
443 |
|
2 |
26 Feb 07 |
jari |
444 |
for (int i = 0; i < number_of_samples; i++) { |
2 |
26 Feb 07 |
jari |
445 |
expAssignedToACluster[i] = false; |
2 |
26 Feb 07 |
jari |
446 |
} |
2 |
26 Feb 07 |
jari |
447 |
|
2 |
26 Feb 07 |
jari |
448 |
for (int i = 0; i < expClusterColors.length; i++) { |
2 |
26 Feb 07 |
jari |
449 |
Vector currentCluster = new Vector(); |
2 |
26 Feb 07 |
jari |
450 |
|
2 |
26 Feb 07 |
jari |
451 |
for (int j = 0; j < number_of_samples; j++) { |
2 |
26 Feb 07 |
jari |
452 |
if (!expAssignedToACluster[j]) { |
2 |
26 Feb 07 |
jari |
453 |
if (expClusterColors[i].equals(framework.getData().getExperimentColor(experiment.getSampleIndex(j)))) { |
2 |
26 Feb 07 |
jari |
454 |
currentCluster.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
455 |
expAssignedToACluster[j] = true; |
2 |
26 Feb 07 |
jari |
456 |
} |
2 |
26 Feb 07 |
jari |
457 |
} |
2 |
26 Feb 07 |
jari |
458 |
} |
2 |
26 Feb 07 |
jari |
459 |
expClusterVector.add(currentCluster); |
2 |
26 Feb 07 |
jari |
460 |
} |
2 |
26 Feb 07 |
jari |
461 |
|
2 |
26 Feb 07 |
jari |
462 |
PTMInitDialog ptmInitBox = new PTMInitDialog((JFrame)framework.getFrame(), modality, experiment.getMatrix(), uniqueIDs, sampleNamesVector, clusterVector, expClusterVector, clusterColors, expClusterColors); |
2 |
26 Feb 07 |
jari |
463 |
|
2 |
26 Feb 07 |
jari |
464 |
boolean isHierarchicalTree; |
2 |
26 Feb 07 |
jari |
// hcl init |
2 |
26 Feb 07 |
jari |
466 |
int hcl_method = 0; |
2 |
26 Feb 07 |
jari |
467 |
boolean hcl_samples = false; |
2 |
26 Feb 07 |
jari |
468 |
boolean hcl_genes = false; |
2 |
26 Feb 07 |
jari |
469 |
|
2 |
26 Feb 07 |
jari |
470 |
ptmInitBox.setVisible(true); |
2 |
26 Feb 07 |
jari |
471 |
|
2 |
26 Feb 07 |
jari |
472 |
|
2 |
26 Feb 07 |
jari |
473 |
if (! ptmInitBox.isOkPressed()){ |
2 |
26 Feb 07 |
jari |
474 |
return null; |
2 |
26 Feb 07 |
jari |
475 |
} |
2 |
26 Feb 07 |
jari |
476 |
clusterGenes = ptmInitBox.isGeneTemplate(); |
2 |
26 Feb 07 |
jari |
477 |
|
2 |
26 Feb 07 |
jari |
478 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
479 |
templateMatrix = ptmInitBox.convertTemplateVectorToFloatMatrix(); |
2 |
26 Feb 07 |
jari |
480 |
templateVector = ptmInitBox.getTemplate(); |
2 |
26 Feb 07 |
jari |
481 |
useAbsolute = ptmInitBox.isUseAbsolute(); |
2 |
26 Feb 07 |
jari |
482 |
useR = ptmInitBox.isUseR(); |
2 |
26 Feb 07 |
jari |
483 |
threshold = (float) ptmInitBox.getThresholdR(); |
2 |
26 Feb 07 |
jari |
484 |
isHierarchicalTree = ptmInitBox.isDrawTrees(); |
2 |
26 Feb 07 |
jari |
485 |
} |
2 |
26 Feb 07 |
jari |
486 |
else{ |
2 |
26 Feb 07 |
jari |
487 |
templateMatrix = ptmInitBox.convertTemplateVectorToFloatMatrix(); |
2 |
26 Feb 07 |
jari |
488 |
templateVector = ptmInitBox.getTemplate(); |
2 |
26 Feb 07 |
jari |
489 |
useAbsolute = ptmInitBox.isUseAbsolute(); |
2 |
26 Feb 07 |
jari |
490 |
useR = ptmInitBox.isUseR(); |
2 |
26 Feb 07 |
jari |
491 |
threshold = (float) ptmInitBox.getThresholdR(); |
2 |
26 Feb 07 |
jari |
492 |
isHierarchicalTree = ptmInitBox.isDrawTrees(); |
2 |
26 Feb 07 |
jari |
493 |
} |
2 |
26 Feb 07 |
jari |
494 |
|
2 |
26 Feb 07 |
jari |
495 |
drawSigTreesOnly = true; |
2 |
26 Feb 07 |
jari |
496 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
497 |
drawSigTreesOnly = ptmInitBox.drawSigTreesOnly(); |
2 |
26 Feb 07 |
jari |
498 |
} |
2 |
26 Feb 07 |
jari |
499 |
|
2 |
26 Feb 07 |
jari |
500 |
IDistanceMenu menu = framework.getDistanceMenu(); |
2 |
26 Feb 07 |
jari |
501 |
int function = menu.getDistanceFunction(); |
2 |
26 Feb 07 |
jari |
502 |
if (function == Algorithm.DEFAULT) { |
2 |
26 Feb 07 |
jari |
503 |
function = Algorithm.EUCLIDEAN; |
2 |
26 Feb 07 |
jari |
504 |
} |
2 |
26 Feb 07 |
jari |
505 |
|
2 |
26 Feb 07 |
jari |
506 |
int hcl_function = 4; |
2 |
26 Feb 07 |
jari |
507 |
boolean hcl_absolute = false; |
2 |
26 Feb 07 |
jari |
508 |
|
2 |
26 Feb 07 |
jari |
509 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
510 |
HCLInitDialog hcl_dialog = new HCLInitDialog(new JFrame(), menu.getFunctionName(function), menu.isAbsoluteDistance(), true); |
2 |
26 Feb 07 |
jari |
511 |
if (hcl_dialog.showModal() != JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
512 |
return null; |
2 |
26 Feb 07 |
jari |
513 |
} |
2 |
26 Feb 07 |
jari |
514 |
hcl_method = hcl_dialog.getMethod(); |
2 |
26 Feb 07 |
jari |
515 |
hcl_samples = hcl_dialog.isClusterExperiments(); |
2 |
26 Feb 07 |
jari |
516 |
hcl_genes = hcl_dialog.isClusterGenes(); |
2 |
26 Feb 07 |
jari |
517 |
hcl_function = hcl_dialog.getDistanceMetric(); |
2 |
26 Feb 07 |
jari |
518 |
hcl_absolute = hcl_dialog.getAbsoluteSelection(); |
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
520 |
|
2 |
26 Feb 07 |
jari |
521 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
522 |
data.addParam("ptm-cluster-genes", String.valueOf(clusterGenes)); |
2 |
26 Feb 07 |
jari |
523 |
data.addMatrix("templateVectorMatrix", templateMatrix); |
2 |
26 Feb 07 |
jari |
524 |
data.addParam("distance-factor", String.valueOf(1.0f)); |
2 |
26 Feb 07 |
jari |
525 |
data.addParam("use-absolute", String.valueOf(useAbsolute)); |
2 |
26 Feb 07 |
jari |
526 |
data.addParam("useR", String.valueOf(useR)); |
2 |
26 Feb 07 |
jari |
527 |
data.addParam("threshold", String.valueOf(threshold)); |
2 |
26 Feb 07 |
jari |
528 |
|
2 |
26 Feb 07 |
jari |
//function = Algorithm.PEARSON; |
2 |
26 Feb 07 |
jari |
530 |
data.addParam("distance-function", String.valueOf(function)); |
2 |
26 Feb 07 |
jari |
531 |
|
2 |
26 Feb 07 |
jari |
// hcl parameters |
2 |
26 Feb 07 |
jari |
533 |
if (isHierarchicalTree) { |
2 |
26 Feb 07 |
jari |
534 |
data.addParam("hierarchical-tree", String.valueOf(true)); |
2 |
26 Feb 07 |
jari |
535 |
data.addParam("draw-sig-trees-only", String.valueOf(drawSigTreesOnly)); |
2 |
26 Feb 07 |
jari |
536 |
data.addParam("method-linkage", String.valueOf(hcl_method)); |
2 |
26 Feb 07 |
jari |
537 |
data.addParam("calculate-genes", String.valueOf(hcl_genes)); |
2 |
26 Feb 07 |
jari |
538 |
data.addParam("calculate-experiments", String.valueOf(hcl_samples)); |
2 |
26 Feb 07 |
jari |
539 |
data.addParam("hcl-distance-function", String.valueOf(hcl_function)); |
2 |
26 Feb 07 |
jari |
540 |
data.addParam("hcl-distance-absolute", String.valueOf(hcl_absolute)); |
2 |
26 Feb 07 |
jari |
541 |
} |
2 |
26 Feb 07 |
jari |
542 |
|
2 |
26 Feb 07 |
jari |
// alg name |
2 |
26 Feb 07 |
jari |
544 |
data.addParam("name", "PTM"); |
2 |
26 Feb 07 |
jari |
545 |
|
2 |
26 Feb 07 |
jari |
// alg type |
2 |
26 Feb 07 |
jari |
547 |
if(clusterGenes) |
2 |
26 Feb 07 |
jari |
548 |
data.addParam("alg-type", "cluster-genes"); |
2 |
26 Feb 07 |
jari |
549 |
else |
2 |
26 Feb 07 |
jari |
550 |
data.addParam("alg-type", "cluster-experiments"); |
2 |
26 Feb 07 |
jari |
551 |
|
2 |
26 Feb 07 |
jari |
// output class |
2 |
26 Feb 07 |
jari |
553 |
data.addParam("output-class", "partition-output"); |
2 |
26 Feb 07 |
jari |
554 |
|
2 |
26 Feb 07 |
jari |
//output nodes |
2 |
26 Feb 07 |
jari |
556 |
String [] outputNodes = new String[2]; |
2 |
26 Feb 07 |
jari |
557 |
outputNodes[0] = "Significant Genes"; |
2 |
26 Feb 07 |
jari |
558 |
outputNodes[1] = "Non-significant Genes"; |
2 |
26 Feb 07 |
jari |
559 |
|
2 |
26 Feb 07 |
jari |
560 |
data.addStringArray("output-nodes", outputNodes); |
2 |
26 Feb 07 |
jari |
561 |
|
2 |
26 Feb 07 |
jari |
562 |
return data; |
2 |
26 Feb 07 |
jari |
563 |
} |
2 |
26 Feb 07 |
jari |
564 |
|
2 |
26 Feb 07 |
jari |
565 |
public DefaultMutableTreeNode executeScript(IFramework framework, AlgorithmData algData, Experiment experiment) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
566 |
int k = 2; |
2 |
26 Feb 07 |
jari |
567 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
568 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
569 |
AlgorithmParameters params = algData.getParams(); |
2 |
26 Feb 07 |
jari |
570 |
this.drawSigTreesOnly = algData.getParams().getBoolean("draw-sig-trees-only"); |
2 |
26 Feb 07 |
jari |
571 |
this.clusterGenes = params.getBoolean("ptm-cluster-genes"); |
2 |
26 Feb 07 |
jari |
572 |
FloatMatrix templateMatrix = algData.getMatrix("templateVectorMatrix"); |
2 |
26 Feb 07 |
jari |
573 |
this.templateVector = new Vector(); |
2 |
26 Feb 07 |
jari |
574 |
int cols = templateMatrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
575 |
for(int i = 0; i < cols; i++) { |
2 |
26 Feb 07 |
jari |
576 |
templateVector.add(new Float(templateMatrix.A[0][i])); |
2 |
26 Feb 07 |
jari |
577 |
} |
2 |
26 Feb 07 |
jari |
578 |
|
2 |
26 Feb 07 |
jari |
579 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
580 |
|
2 |
26 Feb 07 |
jari |
581 |
try { |
2 |
26 Feb 07 |
jari |
582 |
algorithm = framework.getAlgorithmFactory().getAlgorithm("PTM"); |
2 |
26 Feb 07 |
jari |
583 |
algorithm.addAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
584 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
585 |
int genes; |
2 |
26 Feb 07 |
jari |
586 |
if(!clusterGenes){ |
2 |
26 Feb 07 |
jari |
587 |
matrix = matrix.transpose(); |
2 |
26 Feb 07 |
jari |
588 |
genes = matrix.getRowDimension(); |
2 |
26 Feb 07 |
jari |
589 |
} |
2 |
26 Feb 07 |
jari |
590 |
genes = experiment.getNumberOfGenes(); |
2 |
26 Feb 07 |
jari |
591 |
|
2 |
26 Feb 07 |
jari |
592 |
algData.addMatrix("experiment", matrix); |
2 |
26 Feb 07 |
jari |
593 |
|
2 |
26 Feb 07 |
jari |
594 |
long start = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
595 |
AlgorithmData result = algorithm.execute(algData); |
2 |
26 Feb 07 |
jari |
596 |
long time = System.currentTimeMillis() - start; |
2 |
26 Feb 07 |
jari |
// getting the results |
2 |
26 Feb 07 |
jari |
598 |
Cluster result_cluster = result.getCluster("cluster"); |
2 |
26 Feb 07 |
jari |
599 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
600 |
|
2 |
26 Feb 07 |
jari |
601 |
this.clusters = new int[k][]; |
2 |
26 Feb 07 |
jari |
602 |
for (int i=0; i<k; i++) { |
2 |
26 Feb 07 |
jari |
603 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
604 |
} |
2 |
26 Feb 07 |
jari |
605 |
|
2 |
26 Feb 07 |
jari |
606 |
this.means = result.getMatrix("clusters_means"); |
2 |
26 Feb 07 |
jari |
607 |
this.variances = result.getMatrix("clusters_variances"); |
2 |
26 Feb 07 |
jari |
608 |
|
2 |
26 Feb 07 |
jari |
609 |
FloatMatrix rValuesMatrix = result.getMatrix("rValuesMatrix"); |
2 |
26 Feb 07 |
jari |
610 |
FloatMatrix pValuesMatrix = result.getMatrix("pValuesMatrix"); |
2 |
26 Feb 07 |
jari |
611 |
|
2 |
26 Feb 07 |
jari |
612 |
pValues = new float[pValuesMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
613 |
rValues = new float[rValuesMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
614 |
|
2 |
26 Feb 07 |
jari |
615 |
for (int i = 0; i < pValues.length; i++) { |
2 |
26 Feb 07 |
jari |
616 |
pValues[i] = pValuesMatrix.A[i][0]; |
2 |
26 Feb 07 |
jari |
617 |
rValues[i] = rValuesMatrix.A[i][0]; |
2 |
26 Feb 07 |
jari |
618 |
} |
2 |
26 Feb 07 |
jari |
619 |
|
2 |
26 Feb 07 |
jari |
620 |
auxTitles = new String[2]; |
2 |
26 Feb 07 |
jari |
621 |
auxTitles[0] = "R values"; |
2 |
26 Feb 07 |
jari |
622 |
auxTitles[1] = "p Values"; |
2 |
26 Feb 07 |
jari |
623 |
|
2 |
26 Feb 07 |
jari |
624 |
auxData = new Object[pValues.length][2]; |
2 |
26 Feb 07 |
jari |
625 |
|
2 |
26 Feb 07 |
jari |
626 |
for (int i = 0; i < auxData.length; i++) { |
2 |
26 Feb 07 |
jari |
627 |
auxData[i][0] = new Float(rValues[i]); |
2 |
26 Feb 07 |
jari |
628 |
auxData[i][1] = new Float(pValues[i]); |
2 |
26 Feb 07 |
jari |
629 |
} |
2 |
26 Feb 07 |
jari |
630 |
|
2 |
26 Feb 07 |
jari |
631 |
GeneralInfo info = new GeneralInfo(); |
2 |
26 Feb 07 |
jari |
632 |
info.clusters = k; |
2 |
26 Feb 07 |
jari |
633 |
info.time = time; |
2 |
26 Feb 07 |
jari |
634 |
int function = params.getInt("distance-function"); |
2 |
26 Feb 07 |
jari |
635 |
info.function = framework.getDistanceMenu().getFunctionName(function); |
2 |
26 Feb 07 |
jari |
636 |
info.isR = params.getBoolean("useR"); |
2 |
26 Feb 07 |
jari |
637 |
info.isAbsolute = params.getBoolean("use-absolute"); |
2 |
26 Feb 07 |
jari |
638 |
info.threshold = params.getFloat("threshold"); |
2 |
26 Feb 07 |
jari |
639 |
info.hcl = params.getBoolean("hierarchical-tree"); |
2 |
26 Feb 07 |
jari |
640 |
info.hcl_genes = params.getBoolean("calculate-genes"); |
2 |
26 Feb 07 |
jari |
641 |
info.hcl_samples = params.getBoolean("calculate-experiments"); |
2 |
26 Feb 07 |
jari |
642 |
if(info.hcl) |
2 |
26 Feb 07 |
jari |
643 |
info.hcl_method = params.getInt("method-linkage") ; |
2 |
26 Feb 07 |
jari |
644 |
return createResultTree(result_cluster, info); |
2 |
26 Feb 07 |
jari |
645 |
|
2 |
26 Feb 07 |
jari |
646 |
} finally { |
2 |
26 Feb 07 |
jari |
647 |
if (algorithm != null) { |
2 |
26 Feb 07 |
jari |
648 |
algorithm.removeAlgorithmListener(listener); |
2 |
26 Feb 07 |
jari |
649 |
} |
2 |
26 Feb 07 |
jari |
650 |
} |
2 |
26 Feb 07 |
jari |
651 |
} |
2 |
26 Feb 07 |
jari |
652 |
|
2 |
26 Feb 07 |
jari |
653 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a hcl tree data from the specified cluster node. |
2 |
26 Feb 07 |
jari |
655 |
*/ |
2 |
26 Feb 07 |
jari |
656 |
private HCLTreeData getResult(Node clusterNode, int pos) { |
2 |
26 Feb 07 |
jari |
657 |
HCLTreeData data = new HCLTreeData(); |
2 |
26 Feb 07 |
jari |
658 |
NodeValueList valueList = clusterNode.getValues(); |
2 |
26 Feb 07 |
jari |
659 |
data.child_1_array = (int[])valueList.getNodeValue(pos).value; |
2 |
26 Feb 07 |
jari |
660 |
data.child_2_array = (int[])valueList.getNodeValue(pos+1).value; |
2 |
26 Feb 07 |
jari |
661 |
data.node_order = (int[])valueList.getNodeValue(pos+2).value; |
2 |
26 Feb 07 |
jari |
662 |
data.height = (float[])valueList.getNodeValue(pos+3).value; |
2 |
26 Feb 07 |
jari |
663 |
return data; |
2 |
26 Feb 07 |
jari |
664 |
} |
2 |
26 Feb 07 |
jari |
665 |
|
2 |
26 Feb 07 |
jari |
666 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a result tree to be inserted into the framework analysis node. |
2 |
26 Feb 07 |
jari |
668 |
*/ |
2 |
26 Feb 07 |
jari |
669 |
private DefaultMutableTreeNode createResultTree(Cluster result_cluster, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
670 |
DefaultMutableTreeNode root; |
2 |
26 Feb 07 |
jari |
671 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
672 |
root = new DefaultMutableTreeNode("PTM - genes"); |
2 |
26 Feb 07 |
jari |
673 |
else |
2 |
26 Feb 07 |
jari |
674 |
root = new DefaultMutableTreeNode("PTM - samples"); |
2 |
26 Feb 07 |
jari |
675 |
addResultNodes(root, result_cluster, info); |
2 |
26 Feb 07 |
jari |
676 |
return root; |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
|
2 |
26 Feb 07 |
jari |
679 |
/** |
2 |
26 Feb 07 |
jari |
* Adds result nodes into the tree root. |
2 |
26 Feb 07 |
jari |
681 |
*/ |
2 |
26 Feb 07 |
jari |
682 |
private void addResultNodes(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
683 |
addExpressionImages(root); |
2 |
26 Feb 07 |
jari |
684 |
addHierarchicalTrees(root, result_cluster, info); |
2 |
26 Feb 07 |
jari |
685 |
addCentroidViews(root); |
2 |
26 Feb 07 |
jari |
686 |
addStatsTables(root); |
2 |
26 Feb 07 |
jari |
687 |
addClusterInfo(root); |
2 |
26 Feb 07 |
jari |
688 |
addGeneralInfo(root, info); |
2 |
26 Feb 07 |
jari |
689 |
} |
2 |
26 Feb 07 |
jari |
690 |
|
2 |
26 Feb 07 |
jari |
691 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display clusters data. |
2 |
26 Feb 07 |
jari |
693 |
*/ |
2 |
26 Feb 07 |
jari |
694 |
private void addExpressionImages(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
695 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Expression Images"); |
2 |
26 Feb 07 |
jari |
696 |
IViewer expViewer; |
2 |
26 Feb 07 |
jari |
697 |
|
2 |
26 Feb 07 |
jari |
698 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
699 |
expViewer = new PTMExperimentViewer(this.experiment, this.clusters, this.templateVector, auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
700 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
701 |
if (i < this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
702 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes ", expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
703 |
} else if (i == this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
704 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Genes ", expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
705 |
} |
2 |
26 Feb 07 |
jari |
706 |
} |
2 |
26 Feb 07 |
jari |
707 |
} |
2 |
26 Feb 07 |
jari |
708 |
else { |
2 |
26 Feb 07 |
jari |
709 |
|
2 |
26 Feb 07 |
jari |
710 |
expViewer = new PTMExperimentClusterViewer(this.experiment, this.clusters, "Template", this.templateVector, auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
711 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
712 |
if (i < this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
713 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matched Experiments ", expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
714 |
} else if (i == this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
715 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Experiments ", expViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
716 |
} |
2 |
26 Feb 07 |
jari |
717 |
} |
2 |
26 Feb 07 |
jari |
718 |
} |
2 |
26 Feb 07 |
jari |
719 |
root.add(node); |
2 |
26 Feb 07 |
jari |
720 |
} |
2 |
26 Feb 07 |
jari |
721 |
|
2 |
26 Feb 07 |
jari |
722 |
|
2 |
26 Feb 07 |
jari |
723 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display hierarchical trees. |
2 |
26 Feb 07 |
jari |
725 |
*/ |
2 |
26 Feb 07 |
jari |
726 |
private void addHierarchicalTrees(DefaultMutableTreeNode root, Cluster result_cluster, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
727 |
if (!info.hcl) { |
2 |
26 Feb 07 |
jari |
728 |
return; |
2 |
26 Feb 07 |
jari |
729 |
} |
2 |
26 Feb 07 |
jari |
730 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Hierarchical Trees"); |
2 |
26 Feb 07 |
jari |
731 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
732 |
int n = nodeList.getSize(); |
2 |
26 Feb 07 |
jari |
733 |
int [][] clusters = null; |
2 |
26 Feb 07 |
jari |
734 |
|
2 |
26 Feb 07 |
jari |
735 |
if (!drawSigTreesOnly) { |
2 |
26 Feb 07 |
jari |
736 |
if(!this.clusterGenes){ |
2 |
26 Feb 07 |
jari |
737 |
clusters = new int[n][]; |
2 |
26 Feb 07 |
jari |
738 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
739 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
740 |
} |
2 |
26 Feb 07 |
jari |
741 |
if(info.hcl_samples) |
2 |
26 Feb 07 |
jari |
742 |
clusters = getOrderedIndices(nodeList, clusters, info.hcl_genes); |
2 |
26 Feb 07 |
jari |
743 |
} |
2 |
26 Feb 07 |
jari |
744 |
for (int i=0; i<n; i++) { |
2 |
26 Feb 07 |
jari |
745 |
if(this.clusterGenes){ |
2 |
26 Feb 07 |
jari |
746 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
747 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes", createHCLViewer(nodeList.getNode(i), info, null)))); |
2 |
26 Feb 07 |
jari |
748 |
else |
2 |
26 Feb 07 |
jari |
749 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Genes", createHCLViewer(nodeList.getNode(i), info, null)))); |
2 |
26 Feb 07 |
jari |
750 |
} |
2 |
26 Feb 07 |
jari |
751 |
else{ |
2 |
26 Feb 07 |
jari |
752 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
753 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matched Experiments", createHCLViewer(nodeList.getNode(i), info, clusters), new Integer(i)))); |
2 |
26 Feb 07 |
jari |
754 |
else |
2 |
26 Feb 07 |
jari |
755 |
node.add(new DefaultMutableTreeNode(new LeafInfo("UnMatched Experiments", createHCLViewer(nodeList.getNode(i), info, clusters), new Integer(i)))); |
2 |
26 Feb 07 |
jari |
756 |
} |
2 |
26 Feb 07 |
jari |
757 |
} |
2 |
26 Feb 07 |
jari |
758 |
|
2 |
26 Feb 07 |
jari |
759 |
} else { // if (drawSigTreesOnly) |
2 |
26 Feb 07 |
jari |
760 |
if(!this.clusterGenes){ |
2 |
26 Feb 07 |
jari |
//clusters = new int[n][]; |
2 |
26 Feb 07 |
jari |
762 |
clusters = new int[1][]; |
2 |
26 Feb 07 |
jari |
763 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
764 |
clusters[i] = nodeList.getNode(i).getFeaturesIndexes(); |
2 |
26 Feb 07 |
jari |
765 |
} |
2 |
26 Feb 07 |
jari |
766 |
if(info.hcl_samples) |
2 |
26 Feb 07 |
jari |
767 |
clusters = getOrderedIndices(nodeList, clusters, info.hcl_genes); |
2 |
26 Feb 07 |
jari |
768 |
} |
2 |
26 Feb 07 |
jari |
769 |
for (int i=0; i<n; i++) { |
2 |
26 Feb 07 |
jari |
770 |
if(this.clusterGenes){ |
2 |
26 Feb 07 |
jari |
771 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
772 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes", createHCLViewer(nodeList.getNode(i), info, null)))); |
2 |
26 Feb 07 |
jari |
773 |
} |
2 |
26 Feb 07 |
jari |
774 |
else{ |
2 |
26 Feb 07 |
jari |
775 |
if(i == 0) |
2 |
26 Feb 07 |
jari |
776 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matched Experiments", createHCLViewer(nodeList.getNode(i), info, clusters), new Integer(i)))); |
2 |
26 Feb 07 |
jari |
777 |
} |
2 |
26 Feb 07 |
jari |
778 |
} |
2 |
26 Feb 07 |
jari |
779 |
|
2 |
26 Feb 07 |
jari |
780 |
} |
2 |
26 Feb 07 |
jari |
781 |
|
2 |
26 Feb 07 |
jari |
782 |
root.add(node); |
2 |
26 Feb 07 |
jari |
783 |
} |
2 |
26 Feb 07 |
jari |
784 |
|
2 |
26 Feb 07 |
jari |
785 |
/** |
2 |
26 Feb 07 |
jari |
* Creates an <code>HCLViewer</code>. |
2 |
26 Feb 07 |
jari |
787 |
*/ |
2 |
26 Feb 07 |
jari |
788 |
private IViewer createHCLViewer(Node clusterNode, GeneralInfo info, int [][] sampleClusters) { |
2 |
26 Feb 07 |
jari |
789 |
HCLTreeData genes_result = info.hcl_genes ? getResult(clusterNode, 0) : null; |
2 |
26 Feb 07 |
jari |
790 |
HCLTreeData samples_result = info.hcl_samples ? getResult(clusterNode, info.hcl_genes ? 4 : 0) : null; |
2 |
26 Feb 07 |
jari |
791 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
792 |
return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result); |
2 |
26 Feb 07 |
jari |
793 |
else |
2 |
26 Feb 07 |
jari |
794 |
return new HCLViewer(this.experiment, clusterNode.getFeaturesIndexes(), genes_result, samples_result, sampleClusters, true); |
2 |
26 Feb 07 |
jari |
795 |
} |
2 |
26 Feb 07 |
jari |
796 |
|
2 |
26 Feb 07 |
jari |
797 |
|
2 |
26 Feb 07 |
jari |
798 |
/** |
2 |
26 Feb 07 |
jari |
* Adds node with cluster information. |
2 |
26 Feb 07 |
jari |
800 |
*/ |
2 |
26 Feb 07 |
jari |
801 |
private void addClusterInfo(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
802 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Cluster Information"); |
2 |
26 Feb 07 |
jari |
803 |
if(this.clusterGenes) |
2 |
26 Feb 07 |
jari |
804 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matching Results (#,%)", new PTMInfoViewer(this.clusters, this.experiment.getNumberOfGenes())))); |
2 |
26 Feb 07 |
jari |
805 |
else |
2 |
26 Feb 07 |
jari |
806 |
node.add(new DefaultMutableTreeNode(new LeafInfo("Matching Results (#,%)", new PTMInfoViewer(this.clusters, this.experiment.getNumberOfSamples(), this.clusterGenes)))); |
2 |
26 Feb 07 |
jari |
807 |
|
2 |
26 Feb 07 |
jari |
808 |
root.add(node); |
2 |
26 Feb 07 |
jari |
809 |
} |
2 |
26 Feb 07 |
jari |
810 |
|
2 |
26 Feb 07 |
jari |
811 |
|
2 |
26 Feb 07 |
jari |
812 |
/** |
2 |
26 Feb 07 |
jari |
* Adds nodes to display centroid charts. |
2 |
26 Feb 07 |
jari |
814 |
*/ |
2 |
26 Feb 07 |
jari |
815 |
private void addCentroidViews(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
816 |
DefaultMutableTreeNode centroidNode = new DefaultMutableTreeNode("Centroid Graphs"); |
2 |
26 Feb 07 |
jari |
817 |
DefaultMutableTreeNode expressionNode = new DefaultMutableTreeNode("Expression Graphs"); |
2 |
26 Feb 07 |
jari |
818 |
|
2 |
26 Feb 07 |
jari |
819 |
PTMCentroidViewer centroidViewer; |
2 |
26 Feb 07 |
jari |
820 |
PTMExperimentCentroidViewer expCentroidViewer; |
2 |
26 Feb 07 |
jari |
821 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
822 |
centroidViewer = new PTMCentroidViewer(this.experiment, clusters, templateVector, auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
823 |
centroidViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
824 |
centroidViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
825 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
826 |
if(i == 0){ |
2 |
26 Feb 07 |
jari |
827 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes ", centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
828 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes ", centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
829 |
} |
2 |
26 Feb 07 |
jari |
830 |
else{ |
2 |
26 Feb 07 |
jari |
831 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Genes ", centroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
832 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Genes ", centroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
833 |
|
2 |
26 Feb 07 |
jari |
834 |
} |
2 |
26 Feb 07 |
jari |
835 |
} |
2 |
26 Feb 07 |
jari |
836 |
|
2 |
26 Feb 07 |
jari |
837 |
PTMCentroidsViewer centroidsViewer = new PTMCentroidsViewer(this.experiment, clusters, templateVector, auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
838 |
centroidsViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
839 |
centroidsViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
840 |
|
2 |
26 Feb 07 |
jari |
841 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
842 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", centroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
843 |
} |
2 |
26 Feb 07 |
jari |
844 |
else{ |
2 |
26 Feb 07 |
jari |
845 |
expCentroidViewer = new PTMExperimentCentroidViewer(this.experiment, clusters, templateVector, auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
846 |
float [][] codes = getCodes(this.templateVector); |
2 |
26 Feb 07 |
jari |
847 |
expCentroidViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
848 |
expCentroidViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
// expCentroidViewer.setCodes(codes); |
2 |
26 Feb 07 |
jari |
// expCentroidViewer.setDrawCodes(true); |
2 |
26 Feb 07 |
jari |
851 |
|
2 |
26 Feb 07 |
jari |
852 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
853 |
if(i == 0){ |
2 |
26 Feb 07 |
jari |
854 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Experiments ", expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
855 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Experiments ", expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
856 |
} |
2 |
26 Feb 07 |
jari |
857 |
else { |
2 |
26 Feb 07 |
jari |
858 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Experiments ", expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
859 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Experiments ", expCentroidViewer, new CentroidUserObject(i, CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
860 |
} |
2 |
26 Feb 07 |
jari |
861 |
} |
2 |
26 Feb 07 |
jari |
862 |
PTMExperimentCentroidsViewer expCentroidsViewer = new PTMExperimentCentroidsViewer(this.experiment, clusters, templateVector, auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
863 |
expCentroidsViewer.setMeans(this.means.A); |
2 |
26 Feb 07 |
jari |
864 |
expCentroidsViewer.setVariances(this.variances.A); |
2 |
26 Feb 07 |
jari |
// expCentroidsViewer.setCodes(codes); |
2 |
26 Feb 07 |
jari |
// expCentroidsViewer.setDrawCodes(true); |
2 |
26 Feb 07 |
jari |
867 |
centroidNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VARIANCES_MODE)))); |
2 |
26 Feb 07 |
jari |
868 |
expressionNode.add(new DefaultMutableTreeNode(new LeafInfo("All Clusters", expCentroidsViewer, new Integer(CentroidUserObject.VALUES_MODE)))); |
2 |
26 Feb 07 |
jari |
869 |
} |
2 |
26 Feb 07 |
jari |
870 |
root.add(centroidNode); |
2 |
26 Feb 07 |
jari |
871 |
root.add(expressionNode); |
2 |
26 Feb 07 |
jari |
872 |
} |
2 |
26 Feb 07 |
jari |
873 |
|
2 |
26 Feb 07 |
jari |
874 |
private void addStatsTables(DefaultMutableTreeNode root) { |
2 |
26 Feb 07 |
jari |
875 |
DefaultMutableTreeNode tablesNode = new DefaultMutableTreeNode("Table views"); |
2 |
26 Feb 07 |
jari |
876 |
if (clusterGenes) { |
2 |
26 Feb 07 |
jari |
877 |
IViewer tabViewer = new ClusterTableViewer(this.experiment, this.clusters, this.data, this.auxTitles, this.auxData); |
2 |
26 Feb 07 |
jari |
878 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
879 |
if (i < this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
880 |
tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes ", tabViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
881 |
} else if (i == this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
882 |
tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Genes ", tabViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
883 |
} |
2 |
26 Feb 07 |
jari |
884 |
} |
2 |
26 Feb 07 |
jari |
//IViewer nonSigTableViewer = new PTMGeneStatsTableViewer(this.experiment, this.clusters, this.data, this.auxTitles, this.auxData, false); |
2 |
26 Feb 07 |
jari |
//tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Genes", sigTableViewer))); |
2 |
26 Feb 07 |
jari |
//tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Genes", nonSigTableViewer))); |
2 |
26 Feb 07 |
jari |
888 |
} else { |
2 |
26 Feb 07 |
jari |
889 |
IViewer tabViewer = new ExperimentClusterTableViewer(this.experiment, this.clusters, this.data, this.auxTitles, this.auxData); |
2 |
26 Feb 07 |
jari |
890 |
for (int i=0; i<this.clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
891 |
if (i < this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
892 |
tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched Experiments ", tabViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
893 |
} else if (i == this.clusters.length - 1) { |
2 |
26 Feb 07 |
jari |
894 |
tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched Experiments ", tabViewer, new Integer(i)))); |
2 |
26 Feb 07 |
jari |
895 |
} |
2 |
26 Feb 07 |
jari |
896 |
} |
2 |
26 Feb 07 |
jari |
897 |
} |
2 |
26 Feb 07 |
jari |
/*else { |
2 |
26 Feb 07 |
jari |
IViewer sigTableViewer = new PTMExpStatsTableViewer(this.experiment, this.clusters, this.data, this.auxTitles, this.auxData, true); |
2 |
26 Feb 07 |
jari |
IViewer nonSigTableViewer = new PTMExpStatsTableViewer(this.experiment, this.clusters, this.data, this.auxTitles, this.auxData, false); |
2 |
26 Feb 07 |
jari |
tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Matched experiments", sigTableViewer))); |
2 |
26 Feb 07 |
jari |
tablesNode.add(new DefaultMutableTreeNode(new LeafInfo("Unmatched experiments", nonSigTableViewer))); |
2 |
26 Feb 07 |
jari |
903 |
} |
2 |
26 Feb 07 |
jari |
904 |
*/ |
2 |
26 Feb 07 |
jari |
905 |
|
2 |
26 Feb 07 |
jari |
906 |
root.add(tablesNode); |
2 |
26 Feb 07 |
jari |
907 |
} |
2 |
26 Feb 07 |
jari |
908 |
|
2 |
26 Feb 07 |
jari |
909 |
/** |
2 |
26 Feb 07 |
jari |
* Gets template in form for viewer codes |
2 |
26 Feb 07 |
jari |
911 |
*/ |
2 |
26 Feb 07 |
jari |
912 |
public float[][] getCodes(Vector template){ |
2 |
26 Feb 07 |
jari |
913 |
int length = template.size(); |
2 |
26 Feb 07 |
jari |
914 |
float [][] codes = new float[2][length]; |
2 |
26 Feb 07 |
jari |
915 |
for(int i = 0; i < codes.length; i++){ |
2 |
26 Feb 07 |
jari |
916 |
for(int j = 0; j < codes[i].length; j++){ |
2 |
26 Feb 07 |
jari |
917 |
codes[i][j] = ((Float)(template.elementAt(i))).intValue(); |
2 |
26 Feb 07 |
jari |
918 |
} |
2 |
26 Feb 07 |
jari |
919 |
} |
2 |
26 Feb 07 |
jari |
920 |
return codes; |
2 |
26 Feb 07 |
jari |
921 |
} |
2 |
26 Feb 07 |
jari |
922 |
|
2 |
26 Feb 07 |
jari |
923 |
/** |
2 |
26 Feb 07 |
jari |
* Adds node with general iformation. |
2 |
26 Feb 07 |
jari |
925 |
*/ |
2 |
26 Feb 07 |
jari |
926 |
private void addGeneralInfo(DefaultMutableTreeNode root, GeneralInfo info) { |
2 |
26 Feb 07 |
jari |
927 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode("General Information"); |
2 |
26 Feb 07 |
jari |
// node.add(new DefaultMutableTreeNode("Clusters: "+String.valueOf(info.clusters))); |
2 |
26 Feb 07 |
jari |
929 |
node.add(new DefaultMutableTreeNode("Absolute: "+String.valueOf(info.isAbsolute))); |
2 |
26 Feb 07 |
jari |
930 |
if (info.isR) { |
2 |
26 Feb 07 |
jari |
931 |
node.add(new DefaultMutableTreeNode("Threshold Pearson R: "+String.valueOf(info.threshold))); |
2 |
26 Feb 07 |
jari |
932 |
} else { |
2 |
26 Feb 07 |
jari |
933 |
node.add(new DefaultMutableTreeNode("Threshold prob. of R: "+String.valueOf(info.threshold))); |
2 |
26 Feb 07 |
jari |
934 |
|
2 |
26 Feb 07 |
jari |
935 |
} |
2 |
26 Feb 07 |
jari |
// node.add(new DefaultMutableTreeNode("Converged: "+String.valueOf(info.converged))); |
2 |
26 Feb 07 |
jari |
// node.add(new DefaultMutableTreeNode("Iterations: "+String.valueOf(info.iterations))); |
2 |
26 Feb 07 |
jari |
938 |
node.add(new DefaultMutableTreeNode("HCL: "+info.getMethodName())); |
2 |
26 Feb 07 |
jari |
939 |
node.add(new DefaultMutableTreeNode("Time: "+String.valueOf(info.time)+" ms")); |
2 |
26 Feb 07 |
jari |
940 |
node.add(new DefaultMutableTreeNode(info.function)); |
2 |
26 Feb 07 |
jari |
941 |
root.add(node); |
2 |
26 Feb 07 |
jari |
942 |
} |
2 |
26 Feb 07 |
jari |
943 |
|
2 |
26 Feb 07 |
jari |
944 |
|
2 |
26 Feb 07 |
jari |
945 |
/*************************************************************************************** |
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 |
950 |
*/ |
2 |
26 Feb 07 |
jari |
951 |
private int [][] getOrderedIndices(NodeList nodeList, int [][] sampleClusters, boolean calcGeneHCL){ |
2 |
26 Feb 07 |
jari |
952 |
HCLTreeData result; |
2 |
26 Feb 07 |
jari |
953 |
for(int i = 0; i < sampleClusters.length ; i++){ |
2 |
26 Feb 07 |
jari |
954 |
if(sampleClusters[i].length > 0){ |
2 |
26 Feb 07 |
jari |
955 |
result = getResult(nodeList.getNode(i), calcGeneHCL ? 4 : 0); //get sample Result |
2 |
26 Feb 07 |
jari |
956 |
sampleClusters[i] = getSampleOrder(result, sampleClusters[i]); |
2 |
26 Feb 07 |
jari |
957 |
} |
2 |
26 Feb 07 |
jari |
958 |
} |
2 |
26 Feb 07 |
jari |
959 |
return sampleClusters; |
2 |
26 Feb 07 |
jari |
960 |
} |
2 |
26 Feb 07 |
jari |
961 |
|
2 |
26 Feb 07 |
jari |
962 |
private int[] getSampleOrder(HCLTreeData result, int[] indices) { |
2 |
26 Feb 07 |
jari |
963 |
return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices); |
2 |
26 Feb 07 |
jari |
964 |
} |
2 |
26 Feb 07 |
jari |
965 |
|
2 |
26 Feb 07 |
jari |
966 |
private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) { |
2 |
26 Feb 07 |
jari |
967 |
int[] leafOrder = new int[nodeOrder.length]; |
2 |
26 Feb 07 |
jari |
968 |
Arrays.fill(leafOrder, -1); |
2 |
26 Feb 07 |
jari |
969 |
fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices); |
2 |
26 Feb 07 |
jari |
970 |
return leafOrder; |
2 |
26 Feb 07 |
jari |
971 |
} |
2 |
26 Feb 07 |
jari |
972 |
|
2 |
26 Feb 07 |
jari |
973 |
private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) { |
2 |
26 Feb 07 |
jari |
974 |
if (child1[index] != -1) { |
2 |
26 Feb 07 |
jari |
975 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices); |
2 |
26 Feb 07 |
jari |
976 |
} |
2 |
26 Feb 07 |
jari |
977 |
if (child2[index] != -1) { |
2 |
26 Feb 07 |
jari |
978 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices); |
2 |
26 Feb 07 |
jari |
979 |
} else { |
2 |
26 Feb 07 |
jari |
980 |
leafOrder[pos] = indices == null ? index : indices[index]; |
2 |
26 Feb 07 |
jari |
981 |
pos++; |
2 |
26 Feb 07 |
jari |
982 |
} |
2 |
26 Feb 07 |
jari |
983 |
return pos; |
2 |
26 Feb 07 |
jari |
984 |
} |
2 |
26 Feb 07 |
jari |
985 |
|
2 |
26 Feb 07 |
jari |
986 |
|
2 |
26 Feb 07 |
jari |
987 |
|
2 |
26 Feb 07 |
jari |
988 |
/**************************************************************************************** |
2 |
26 Feb 07 |
jari |
* End of Sample Cluster index ordering code |
2 |
26 Feb 07 |
jari |
990 |
*/ |
2 |
26 Feb 07 |
jari |
991 |
|
2 |
26 Feb 07 |
jari |
992 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to progress, monitor and algorithms events. |
2 |
26 Feb 07 |
jari |
994 |
*/ |
2 |
26 Feb 07 |
jari |
995 |
private class Listener extends DialogListener implements AlgorithmListener { |
2 |
26 Feb 07 |
jari |
996 |
|
2 |
26 Feb 07 |
jari |
997 |
public void valueChanged(AlgorithmEvent event) { |
2 |
26 Feb 07 |
jari |
998 |
|
2 |
26 Feb 07 |
jari |
999 |
} |
2 |
26 Feb 07 |
jari |
1000 |
|
2 |
26 Feb 07 |
jari |
1001 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
1002 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
1003 |
if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
1004 |
algorithm.abort(); |
2 |
26 Feb 07 |
jari |
1005 |
cleanUp(); |
2 |
26 Feb 07 |
jari |
1006 |
} |
2 |
26 Feb 07 |
jari |
1007 |
} |
2 |
26 Feb 07 |
jari |
1008 |
|
2 |
26 Feb 07 |
jari |
1009 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
1010 |
algorithm.abort(); |
2 |
26 Feb 07 |
jari |
1011 |
cleanUp(); |
2 |
26 Feb 07 |
jari |
1012 |
} |
2 |
26 Feb 07 |
jari |
1013 |
|
2 |
26 Feb 07 |
jari |
1014 |
public void cleanUp() { |
2 |
26 Feb 07 |
jari |
1015 |
|
2 |
26 Feb 07 |
jari |
1016 |
} |
2 |
26 Feb 07 |
jari |
1017 |
} |
2 |
26 Feb 07 |
jari |
1018 |
|
2 |
26 Feb 07 |
jari |
// the general info structure |
2 |
26 Feb 07 |
jari |
1020 |
private class GeneralInfo { |
2 |
26 Feb 07 |
jari |
1021 |
public int clusters; |
2 |
26 Feb 07 |
jari |
1022 |
public long time; |
2 |
26 Feb 07 |
jari |
1023 |
public String function; |
2 |
26 Feb 07 |
jari |
1024 |
public boolean isAbsolute; |
2 |
26 Feb 07 |
jari |
1025 |
public boolean isR; |
2 |
26 Feb 07 |
jari |
1026 |
public float threshold; |
2 |
26 Feb 07 |
jari |
1027 |
|
2 |
26 Feb 07 |
jari |
1028 |
private boolean hcl; |
2 |
26 Feb 07 |
jari |
1029 |
private int hcl_method; |
2 |
26 Feb 07 |
jari |
1030 |
private boolean hcl_genes; |
2 |
26 Feb 07 |
jari |
1031 |
private boolean hcl_samples; |
2 |
26 Feb 07 |
jari |
1032 |
|
2 |
26 Feb 07 |
jari |
1033 |
public String getMethodName() { |
2 |
26 Feb 07 |
jari |
1034 |
return hcl ? HCLGUI.GeneralInfo.getMethodName(hcl_method) : "no linkage"; |
2 |
26 Feb 07 |
jari |
1035 |
} |
2 |
26 Feb 07 |
jari |
1036 |
|
2 |
26 Feb 07 |
jari |
1037 |
} |
2 |
26 Feb 07 |
jari |
1038 |
|
2 |
26 Feb 07 |
jari |
1039 |
} |