2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: Ttest.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.7 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 15:45:19 $ |
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 |
|
2 |
26 Feb 07 |
jari |
13 |
package org.tigr.microarray.mev.cluster.algorithm.impl; |
2 |
26 Feb 07 |
jari |
14 |
|
2 |
26 Feb 07 |
jari |
15 |
|
2 |
26 Feb 07 |
jari |
16 |
import java.util.Random; |
2 |
26 Feb 07 |
jari |
17 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
import org.tigr.microarray.mev.cluster.Cluster; |
2 |
26 Feb 07 |
jari |
20 |
import org.tigr.microarray.mev.cluster.Node; |
2 |
26 Feb 07 |
jari |
21 |
import org.tigr.microarray.mev.cluster.NodeList; |
2 |
26 Feb 07 |
jari |
22 |
import org.tigr.microarray.mev.cluster.NodeValue; |
2 |
26 Feb 07 |
jari |
23 |
import org.tigr.microarray.mev.cluster.NodeValueList; |
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.mev.cluster.algorithm.AbortException; |
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.algorithm.AbstractAlgorithm; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmData; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmEvent; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.algorithm.AlgorithmParameters; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.util.Combinations; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.util.QSort; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
import JSci.maths.statistics.TDistribution; |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
public class Ttest extends AbstractAlgorithm { |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
public static final int GROUP_A = 1; |
2 |
26 Feb 07 |
jari |
39 |
public static final int GROUP_B = 2; |
2 |
26 Feb 07 |
jari |
40 |
public static final int NEITHER_GROUP = 3; |
2 |
26 Feb 07 |
jari |
41 |
public static final int JUST_ALPHA = 4; |
2 |
26 Feb 07 |
jari |
42 |
public static final int STD_BONFERRONI = 5; |
2 |
26 Feb 07 |
jari |
43 |
public static final int ADJ_BONFERRONI = 6; |
2 |
26 Feb 07 |
jari |
44 |
public static final int BETWEEN_SUBJECTS = 7; |
2 |
26 Feb 07 |
jari |
45 |
public static final int ONE_CLASS = 8; |
2 |
26 Feb 07 |
jari |
46 |
public static final int MAX_T = 9; |
2 |
26 Feb 07 |
jari |
47 |
public static final int MIN_P = 10; |
2 |
26 Feb 07 |
jari |
48 |
public static final int PAIRED = 11; |
2 |
26 Feb 07 |
jari |
49 |
public static final int FALSE_NUM = 12; |
2 |
26 Feb 07 |
jari |
50 |
public static final int FALSE_PROP = 13; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
private boolean stop = false; |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
private int function; |
2 |
26 Feb 07 |
jari |
55 |
private float factor; |
2 |
26 Feb 07 |
jari |
56 |
private boolean absolute; |
2 |
26 Feb 07 |
jari |
57 |
private FloatMatrix expMatrix; |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
boolean hierarchical_tree, drawSigTreesOnly; |
2 |
26 Feb 07 |
jari |
60 |
int method_linkage; |
2 |
26 Feb 07 |
jari |
61 |
boolean calculate_genes; |
2 |
26 Feb 07 |
jari |
62 |
boolean calculate_experiments; |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
private Vector[] clusters; |
2 |
26 Feb 07 |
jari |
65 |
private int k; // # of clusters |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
private int numGenes, numExps, falseNum; |
2 |
26 Feb 07 |
jari |
68 |
private float alpha, falseProp; |
2 |
26 Feb 07 |
jari |
69 |
private int significanceMethod; |
2 |
26 Feb 07 |
jari |
70 |
private boolean isPermut, useWelchDf, calculateAdjFDRPVals, useFastFDRApprox; |
2 |
26 Feb 07 |
jari |
71 |
private int[] groupAssignments, pairedGroupAExpts, pairedGroupBExpts; |
2 |
26 Feb 07 |
jari |
72 |
private int numCombs; |
2 |
26 Feb 07 |
jari |
73 |
boolean useAllCombs; |
2 |
26 Feb 07 |
jari |
74 |
int tTestDesign; |
2 |
26 Feb 07 |
jari |
75 |
float oneClassMean = 0.0f; |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
AlgorithmEvent event; |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
double[] tValues, oneClassMeans, groupAMeans, groupBMeans, oneClassSDs, groupASDs, groupBSDs, dfValues, origPVals, adjustedPVals; |
2 |
26 Feb 07 |
jari |
80 |
private boolean[] isSig; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
private int hcl_function; |
2 |
26 Feb 07 |
jari |
83 |
private boolean hcl_absolute; |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
/** This method should interrupt the calculation. |
2 |
26 Feb 07 |
jari |
86 |
*/ |
2 |
26 Feb 07 |
jari |
87 |
public void abort() { |
2 |
26 Feb 07 |
jari |
88 |
stop = true; |
2 |
26 Feb 07 |
jari |
89 |
} |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
/** This method execute calculation and return result, |
2 |
26 Feb 07 |
jari |
* stored in <code>AlgorithmData</code> class. |
2 |
26 Feb 07 |
jari |
93 |
* |
2 |
26 Feb 07 |
jari |
* @param data the data to be calculated. |
2 |
26 Feb 07 |
jari |
95 |
*/ |
2 |
26 Feb 07 |
jari |
96 |
public AlgorithmData execute(AlgorithmData data) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
97 |
/* |
2 |
26 Feb 07 |
jari |
if ((tTestDesign == ONE_CLASS) || (tTestDesign == BETWEEN_SUBJECTS)) { |
2 |
26 Feb 07 |
jari |
groupAssignments = data.getIntArray("group-assignments"); |
2 |
26 Feb 07 |
jari |
100 |
} |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
if (tTestDesign == PAIRED) { |
2 |
26 Feb 07 |
jari |
FloatMatrix pairedAExptsMatrix = data.getMatrix("pairedAExptsMatrix"); |
2 |
26 Feb 07 |
jari |
FloatMatrix pairedBExptsMatrix = data.getMatrix("pairedBExptsMatrix"); |
2 |
26 Feb 07 |
jari |
pairedGroupAExpts = new int[pairedAExptsMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
pairedGroupBExpts = new int[pairedBExptsMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < pairedAExptsMatrix.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
pairedGroupAExpts[i] = (int)(pairedAExptsMatrix.A[i][0]); |
2 |
26 Feb 07 |
jari |
pairedGroupBExpts[i] = (int)(pairedBExptsMatrix.A[i][0]); |
2 |
26 Feb 07 |
jari |
110 |
} |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
*/ |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
AlgorithmParameters map = data.getParams(); |
2 |
26 Feb 07 |
jari |
115 |
function = map.getInt("distance-function", EUCLIDEAN); |
2 |
26 Feb 07 |
jari |
116 |
factor = map.getFloat("distance-factor", 1.0f); |
2 |
26 Feb 07 |
jari |
117 |
absolute = map.getBoolean("distance-absolute", false); |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
hcl_function = map.getInt("hcl-distance-function", EUCLIDEAN); |
2 |
26 Feb 07 |
jari |
120 |
hcl_absolute = map.getBoolean("hcl-distance-absolute", false); |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
hierarchical_tree = map.getBoolean("hierarchical-tree", false); |
2 |
26 Feb 07 |
jari |
123 |
if (hierarchical_tree) { |
2 |
26 Feb 07 |
jari |
124 |
drawSigTreesOnly = map.getBoolean("draw-sig-trees-only"); |
2 |
26 Feb 07 |
jari |
125 |
} |
2 |
26 Feb 07 |
jari |
126 |
method_linkage = map.getInt("method-linkage", 0); |
2 |
26 Feb 07 |
jari |
127 |
calculate_genes = map.getBoolean("calculate-genes", false); |
2 |
26 Feb 07 |
jari |
128 |
calculate_experiments = map.getBoolean("calculate-experiments", false); |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
this.expMatrix = data.getMatrix("experiment"); |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
numGenes = this.expMatrix.getRowDimension(); |
2 |
26 Feb 07 |
jari |
133 |
numExps = this.expMatrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
134 |
tTestDesign = map.getInt("tTestDesign", BETWEEN_SUBJECTS); |
2 |
26 Feb 07 |
jari |
135 |
if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
136 |
oneClassMean = map.getFloat("oneClassMean", 0.0f); |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
alpha = map.getFloat("alpha", 0.01f); |
2 |
26 Feb 07 |
jari |
139 |
significanceMethod = map.getInt("significance-method", JUST_ALPHA); |
2 |
26 Feb 07 |
jari |
140 |
isPermut = map.getBoolean("is-permut", false); |
2 |
26 Feb 07 |
jari |
141 |
useWelchDf = map.getBoolean("useWelchDf", true); |
2 |
26 Feb 07 |
jari |
142 |
numCombs = map.getInt("num-combs", 100); |
2 |
26 Feb 07 |
jari |
143 |
useAllCombs = map.getBoolean("use-all-combs", false); |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
if ((significanceMethod == FALSE_NUM) || (significanceMethod == FALSE_PROP)) { |
2 |
26 Feb 07 |
jari |
146 |
calculateAdjFDRPVals = map.getBoolean("calculateAdjFDRPVals", false); |
2 |
26 Feb 07 |
jari |
147 |
useFastFDRApprox = map.getBoolean("useFastFDRApprox", true); |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
|
2 |
26 Feb 07 |
jari |
150 |
if (significanceMethod == FALSE_NUM) { |
2 |
26 Feb 07 |
jari |
151 |
falseNum = map.getInt("falseNum", 10); |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
if (significanceMethod == FALSE_PROP) { |
2 |
26 Feb 07 |
jari |
155 |
falseProp = map.getFloat("falseProp", 0.05f); |
2 |
26 Feb 07 |
jari |
156 |
} |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
if ((tTestDesign == ONE_CLASS) || (tTestDesign == BETWEEN_SUBJECTS)) { |
2 |
26 Feb 07 |
jari |
159 |
groupAssignments = data.getIntArray("group-assignments"); |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
|
2 |
26 Feb 07 |
jari |
162 |
if (tTestDesign == PAIRED) { |
2 |
26 Feb 07 |
jari |
163 |
FloatMatrix pairedAExptsMatrix = data.getMatrix("pairedAExptsMatrix"); |
2 |
26 Feb 07 |
jari |
164 |
FloatMatrix pairedBExptsMatrix = data.getMatrix("pairedBExptsMatrix"); |
2 |
26 Feb 07 |
jari |
165 |
pairedGroupAExpts = new int[pairedAExptsMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
166 |
pairedGroupBExpts = new int[pairedBExptsMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
167 |
for (int i = 0; i < pairedAExptsMatrix.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
168 |
pairedGroupAExpts[i] = (int)(pairedAExptsMatrix.A[i][0]); |
2 |
26 Feb 07 |
jari |
169 |
pairedGroupBExpts[i] = (int)(pairedBExptsMatrix.A[i][0]); |
2 |
26 Feb 07 |
jari |
170 |
} |
2 |
26 Feb 07 |
jari |
171 |
} |
2 |
26 Feb 07 |
jari |
172 |
|
2 |
26 Feb 07 |
jari |
173 |
if ((significanceMethod == FALSE_NUM) || (significanceMethod == FALSE_PROP)) { |
2 |
26 Feb 07 |
jari |
174 |
if (tTestDesign == BETWEEN_SUBJECTS) { |
2 |
26 Feb 07 |
jari |
175 |
computeBtnSubOrigVals(); |
2 |
26 Feb 07 |
jari |
176 |
} else if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
177 |
computeOneClassOrigVals(); |
2 |
26 Feb 07 |
jari |
178 |
} else if (tTestDesign == PAIRED) { |
2 |
26 Feb 07 |
jari |
179 |
computePairedOrigVals(); |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
origPVals = getRawPValsFromTDist(); |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
} else { |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
if (tTestDesign == BETWEEN_SUBJECTS) { |
2 |
26 Feb 07 |
jari |
186 |
computeBtnSubOrigVals(); |
2 |
26 Feb 07 |
jari |
187 |
if (!isPermut) { |
2 |
26 Feb 07 |
jari |
188 |
origPVals = getRawPValsFromTDist(); |
2 |
26 Feb 07 |
jari |
189 |
} else { |
2 |
26 Feb 07 |
jari |
190 |
origPVals = getTwoClassRawPValsFromPerms(); |
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
} else if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
193 |
computeOneClassOrigVals(); |
2 |
26 Feb 07 |
jari |
194 |
if (!isPermut) { |
2 |
26 Feb 07 |
jari |
195 |
origPVals = getRawPValsFromTDist(); |
2 |
26 Feb 07 |
jari |
196 |
} else { |
2 |
26 Feb 07 |
jari |
197 |
origPVals = getOneClassRawPValsFromPerms(); |
2 |
26 Feb 07 |
jari |
198 |
} |
2 |
26 Feb 07 |
jari |
199 |
} else if (tTestDesign == PAIRED) { |
2 |
26 Feb 07 |
jari |
200 |
computePairedOrigVals(); |
2 |
26 Feb 07 |
jari |
201 |
if (!isPermut) { |
2 |
26 Feb 07 |
jari |
202 |
origPVals = getRawPValsFromTDist(); |
2 |
26 Feb 07 |
jari |
203 |
} else { |
2 |
26 Feb 07 |
jari |
204 |
origPVals = getPairedRawPValsFromPerms(); |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
//return null; //for now |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
} |
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
210 |
Vector clusterVector = new Vector(); |
2 |
26 Feb 07 |
jari |
211 |
Vector sigGenes = new Vector(); |
2 |
26 Feb 07 |
jari |
212 |
Vector nonSigGenes = new Vector(); |
2 |
26 Feb 07 |
jari |
213 |
|
2 |
26 Feb 07 |
jari |
214 |
if ( (significanceMethod == Ttest.FALSE_NUM) || (significanceMethod == Ttest.FALSE_PROP) ) { |
2 |
26 Feb 07 |
jari |
215 |
boolean[] isGeneSig = new boolean[1]; |
2 |
26 Feb 07 |
jari |
216 |
if (significanceMethod == Ttest.FALSE_NUM) { |
2 |
26 Feb 07 |
jari |
217 |
isGeneSig = isGeneSigByFDRNum(); |
2 |
26 Feb 07 |
jari |
218 |
} else { |
2 |
26 Feb 07 |
jari |
219 |
isGeneSig = isGeneSigByFDRPropNew2(); |
2 |
26 Feb 07 |
jari |
220 |
} |
2 |
26 Feb 07 |
jari |
221 |
|
2 |
26 Feb 07 |
jari |
222 |
if (!calculateAdjFDRPVals) { |
2 |
26 Feb 07 |
jari |
223 |
adjustedPVals = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
224 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("isGeneSig.length = " + isGeneSig.length); |
2 |
26 Feb 07 |
jari |
226 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
227 |
if (isGeneSig[i]) { |
2 |
26 Feb 07 |
jari |
228 |
sigGenes.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
229 |
} else { |
2 |
26 Feb 07 |
jari |
230 |
nonSigGenes.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
231 |
} |
2 |
26 Feb 07 |
jari |
232 |
} |
2 |
26 Feb 07 |
jari |
233 |
|
2 |
26 Feb 07 |
jari |
234 |
} else { // if ! ((significanceMethod == this.FALSE_NUM) || (significanceMethod == this.FALSE_PROP)) |
2 |
26 Feb 07 |
jari |
235 |
|
2 |
26 Feb 07 |
jari |
236 |
adjustedPVals = getAdjPVals(origPVals, significanceMethod); |
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numGenes); |
2 |
26 Feb 07 |
jari |
239 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
240 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
243 |
if (stop) { |
2 |
26 Feb 07 |
jari |
244 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
245 |
} |
2 |
26 Feb 07 |
jari |
246 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
247 |
event.setDescription("Finding significant genes: Current gene = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
248 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
float currAdjP = (float)(adjustedPVals[i]); |
2 |
26 Feb 07 |
jari |
//System.out.println("currAdjP: gene" + i + " = " + currAdjP); |
2 |
26 Feb 07 |
jari |
252 |
if (significanceMethod == ADJ_BONFERRONI) {// because we have to break out of the loop if a non-sig value is encountered |
2 |
26 Feb 07 |
jari |
253 |
if (isSig[i]) { |
2 |
26 Feb 07 |
jari |
254 |
sigGenes.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
255 |
} else { |
2 |
26 Feb 07 |
jari |
256 |
nonSigGenes.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
257 |
} |
2 |
26 Feb 07 |
jari |
258 |
} else { |
2 |
26 Feb 07 |
jari |
259 |
if (currAdjP <= alpha) { |
2 |
26 Feb 07 |
jari |
260 |
sigGenes.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
261 |
} else { |
2 |
26 Feb 07 |
jari |
262 |
nonSigGenes.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
263 |
} |
2 |
26 Feb 07 |
jari |
264 |
} |
2 |
26 Feb 07 |
jari |
265 |
} |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
clusterVector.add(sigGenes); |
2 |
26 Feb 07 |
jari |
269 |
clusterVector.add(nonSigGenes); |
2 |
26 Feb 07 |
jari |
270 |
k = clusterVector.size(); |
2 |
26 Feb 07 |
jari |
271 |
|
2 |
26 Feb 07 |
jari |
272 |
FloatMatrix rawPValuesMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
273 |
FloatMatrix adjPValuesMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
274 |
FloatMatrix tValuesMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
275 |
FloatMatrix dfMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
276 |
FloatMatrix meansAMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
277 |
FloatMatrix meansBMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
278 |
FloatMatrix sdAMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
279 |
FloatMatrix sdBMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
280 |
FloatMatrix isSigMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
281 |
FloatMatrix oneClassMeansMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
282 |
FloatMatrix oneClassSDsMatrix = new FloatMatrix(numGenes, 1); |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
for (int i = 0; i < isSigMatrix.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
285 |
isSigMatrix.A[i][0] = 0.0f; |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
for (int i = 0 ; i < sigGenes.size(); i++) { |
2 |
26 Feb 07 |
jari |
289 |
int currentGene = ((Integer)(sigGenes.get(i))).intValue(); |
2 |
26 Feb 07 |
jari |
290 |
isSigMatrix.A[currentGene][0] = 1.0f; |
2 |
26 Feb 07 |
jari |
291 |
} |
2 |
26 Feb 07 |
jari |
292 |
|
2 |
26 Feb 07 |
jari |
293 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
294 |
rawPValuesMatrix.A[i][0] = (float)(origPVals[i]); |
2 |
26 Feb 07 |
jari |
295 |
adjPValuesMatrix.A[i][0] = (float)(adjustedPVals[i]); |
2 |
26 Feb 07 |
jari |
296 |
tValuesMatrix.A[i][0] = (float)(tValues[i]); |
2 |
26 Feb 07 |
jari |
297 |
dfMatrix.A[i][0] = (float)(dfValues[i]); |
2 |
26 Feb 07 |
jari |
298 |
if ((tTestDesign == BETWEEN_SUBJECTS) ||(tTestDesign == PAIRED)){ |
2 |
26 Feb 07 |
jari |
299 |
meansAMatrix.A[i][0] = (float)(groupAMeans[i]); |
2 |
26 Feb 07 |
jari |
300 |
meansBMatrix.A[i][0] = (float)(groupBMeans[i]); |
2 |
26 Feb 07 |
jari |
301 |
sdAMatrix.A[i][0] = (float)(groupASDs[i]); |
2 |
26 Feb 07 |
jari |
302 |
sdBMatrix.A[i][0] = (float)(groupBSDs[i]); |
2 |
26 Feb 07 |
jari |
303 |
} else if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
304 |
oneClassMeansMatrix.A[i][0] = (float)(oneClassMeans[i]); |
2 |
26 Feb 07 |
jari |
305 |
oneClassSDsMatrix.A[i][0] = (float)(oneClassSDs[i]); |
2 |
26 Feb 07 |
jari |
306 |
} |
2 |
26 Feb 07 |
jari |
307 |
} |
2 |
26 Feb 07 |
jari |
308 |
|
2 |
26 Feb 07 |
jari |
309 |
clusters = new Vector[k]; |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
311 |
for (int i = 0; i < k; i++) { |
2 |
26 Feb 07 |
jari |
312 |
clusters[i] = (Vector)(clusterVector.get(i)); |
2 |
26 Feb 07 |
jari |
313 |
} |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
FloatMatrix means = getMeans(clusters); |
2 |
26 Feb 07 |
jari |
316 |
FloatMatrix variances = getVariances(clusters, means); |
2 |
26 Feb 07 |
jari |
317 |
|
2 |
26 Feb 07 |
jari |
318 |
AlgorithmEvent event = null; |
2 |
26 Feb 07 |
jari |
319 |
if (hierarchical_tree) { |
2 |
26 Feb 07 |
jari |
320 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, clusters.length, "Calculate Hierarchical Trees"); |
2 |
26 Feb 07 |
jari |
321 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
322 |
event.setIntValue(0); |
2 |
26 Feb 07 |
jari |
323 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
324 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
325 |
} |
2 |
26 Feb 07 |
jari |
326 |
|
2 |
26 Feb 07 |
jari |
327 |
Cluster result_cluster = new Cluster(); |
2 |
26 Feb 07 |
jari |
328 |
NodeList nodeList = result_cluster.getNodeList(); |
2 |
26 Feb 07 |
jari |
329 |
int[] features; |
2 |
26 Feb 07 |
jari |
330 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
331 |
if (stop) { |
2 |
26 Feb 07 |
jari |
332 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
333 |
} |
2 |
26 Feb 07 |
jari |
334 |
features = convert2int(clusters[i]); |
2 |
26 Feb 07 |
jari |
335 |
Node node = new Node(features); |
2 |
26 Feb 07 |
jari |
336 |
nodeList.addNode(node); |
2 |
26 Feb 07 |
jari |
337 |
if (hierarchical_tree) { |
2 |
26 Feb 07 |
jari |
338 |
if (drawSigTreesOnly) { |
2 |
26 Feb 07 |
jari |
339 |
if (i == 0) { |
2 |
26 Feb 07 |
jari |
340 |
node.setValues(calculateHierarchicalTree(features, method_linkage, calculate_genes, calculate_experiments)); |
2 |
26 Feb 07 |
jari |
341 |
event.setIntValue(i+1); |
2 |
26 Feb 07 |
jari |
342 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
343 |
} |
2 |
26 Feb 07 |
jari |
344 |
} else { |
2 |
26 Feb 07 |
jari |
345 |
node.setValues(calculateHierarchicalTree(features, method_linkage, calculate_genes, calculate_experiments)); |
2 |
26 Feb 07 |
jari |
346 |
event.setIntValue(i+1); |
2 |
26 Feb 07 |
jari |
347 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
348 |
} |
2 |
26 Feb 07 |
jari |
349 |
} |
2 |
26 Feb 07 |
jari |
350 |
} |
2 |
26 Feb 07 |
jari |
351 |
|
2 |
26 Feb 07 |
jari |
// prepare the result |
2 |
26 Feb 07 |
jari |
353 |
AlgorithmData result = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
354 |
result.addCluster("cluster", result_cluster); |
2 |
26 Feb 07 |
jari |
355 |
result.addParam("number-of-clusters", String.valueOf(clusters.length)); |
2 |
26 Feb 07 |
jari |
//result.addParam("unassigned-genes-exist", String.valueOf(unassignedExists)); |
2 |
26 Feb 07 |
jari |
357 |
result.addMatrix("clusters_means", means); |
2 |
26 Feb 07 |
jari |
358 |
result.addMatrix("clusters_variances", variances); |
2 |
26 Feb 07 |
jari |
//result.addMatrix("sigPValues", sigPValuesMatrix); |
2 |
26 Feb 07 |
jari |
//result.addMatrix("sigTValues", sigTValuesMatrix); |
2 |
26 Feb 07 |
jari |
//result.addMatrix("nonSigPValues", nonSigPValuesMatrix); |
2 |
26 Feb 07 |
jari |
//result.addMatrix("nonSigTValues", nonSigTValuesMatrix); |
2 |
26 Feb 07 |
jari |
363 |
result.addMatrix("rawPValues", rawPValuesMatrix); |
2 |
26 Feb 07 |
jari |
364 |
result.addMatrix("adjPValues", adjPValuesMatrix); |
2 |
26 Feb 07 |
jari |
365 |
result.addMatrix("tValues", tValuesMatrix); |
2 |
26 Feb 07 |
jari |
366 |
result.addMatrix("dfValues", dfMatrix); |
2 |
26 Feb 07 |
jari |
367 |
result.addMatrix("meansAMatrix", meansAMatrix); |
2 |
26 Feb 07 |
jari |
368 |
result.addMatrix("meansBMatrix", meansBMatrix); |
2 |
26 Feb 07 |
jari |
369 |
result.addMatrix("sdAMatrix", sdAMatrix); |
2 |
26 Feb 07 |
jari |
370 |
result.addMatrix("sdBMatrix", sdBMatrix); |
2 |
26 Feb 07 |
jari |
371 |
result.addMatrix("isSigMatrix", isSigMatrix); |
2 |
26 Feb 07 |
jari |
372 |
result.addMatrix("oneClassMeansMatrix", oneClassMeansMatrix); |
2 |
26 Feb 07 |
jari |
373 |
result.addMatrix("oneClassSDsMatrix", oneClassSDsMatrix); |
2 |
26 Feb 07 |
jari |
374 |
return result; |
2 |
26 Feb 07 |
jari |
//return null; //for now |
2 |
26 Feb 07 |
jari |
376 |
} |
2 |
26 Feb 07 |
jari |
377 |
|
2 |
26 Feb 07 |
jari |
378 |
private NodeValueList calculateHierarchicalTree(int[] features, int method, boolean genes, boolean experiments) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
379 |
NodeValueList nodeList = new NodeValueList(); |
2 |
26 Feb 07 |
jari |
380 |
AlgorithmData data = new AlgorithmData(); |
2 |
26 Feb 07 |
jari |
381 |
FloatMatrix experiment = getSubExperiment(this.expMatrix, features); |
2 |
26 Feb 07 |
jari |
382 |
data.addMatrix("experiment", experiment); |
2 |
26 Feb 07 |
jari |
383 |
data.addParam("hcl-distance-function", String.valueOf(this.hcl_function)); |
2 |
26 Feb 07 |
jari |
384 |
data.addParam("hcl-distance-absolute", String.valueOf(this.hcl_absolute)); |
2 |
26 Feb 07 |
jari |
385 |
data.addParam("method-linkage", String.valueOf(method)); |
2 |
26 Feb 07 |
jari |
386 |
HCL hcl = new HCL(); |
2 |
26 Feb 07 |
jari |
387 |
AlgorithmData result; |
2 |
26 Feb 07 |
jari |
388 |
if (genes) { |
2 |
26 Feb 07 |
jari |
389 |
data.addParam("calculate-genes", String.valueOf(true)); |
2 |
26 Feb 07 |
jari |
390 |
result = hcl.execute(data); |
2 |
26 Feb 07 |
jari |
391 |
validate(result); |
2 |
26 Feb 07 |
jari |
392 |
addNodeValues(nodeList, result); |
2 |
26 Feb 07 |
jari |
393 |
} |
2 |
26 Feb 07 |
jari |
394 |
if (experiments) { |
2 |
26 Feb 07 |
jari |
395 |
data.addParam("calculate-genes", String.valueOf(false)); |
2 |
26 Feb 07 |
jari |
396 |
result = hcl.execute(data); |
2 |
26 Feb 07 |
jari |
397 |
validate(result); |
2 |
26 Feb 07 |
jari |
398 |
addNodeValues(nodeList, result); |
2 |
26 Feb 07 |
jari |
399 |
} |
2 |
26 Feb 07 |
jari |
400 |
return nodeList; |
2 |
26 Feb 07 |
jari |
401 |
} |
2 |
26 Feb 07 |
jari |
402 |
|
2 |
26 Feb 07 |
jari |
403 |
private void addNodeValues(NodeValueList target_list, AlgorithmData source_result) { |
2 |
26 Feb 07 |
jari |
404 |
target_list.addNodeValue(new NodeValue("child-1-array", source_result.getIntArray("child-1-array"))); |
2 |
26 Feb 07 |
jari |
405 |
target_list.addNodeValue(new NodeValue("child-2-array", source_result.getIntArray("child-2-array"))); |
2 |
26 Feb 07 |
jari |
406 |
target_list.addNodeValue(new NodeValue("node-order", source_result.getIntArray("node-order"))); |
2 |
26 Feb 07 |
jari |
407 |
target_list.addNodeValue(new NodeValue("height", source_result.getMatrix("height").getRowPackedCopy())); |
2 |
26 Feb 07 |
jari |
408 |
} |
2 |
26 Feb 07 |
jari |
409 |
|
2 |
26 Feb 07 |
jari |
410 |
private FloatMatrix getSubExperiment(FloatMatrix experiment, int[] features) { |
2 |
26 Feb 07 |
jari |
411 |
FloatMatrix subExperiment = new FloatMatrix(features.length, experiment.getColumnDimension()); |
2 |
26 Feb 07 |
jari |
412 |
for (int i=0; i<features.length; i++) { |
2 |
26 Feb 07 |
jari |
413 |
subExperiment.A[i] = experiment.A[features[i]]; |
2 |
26 Feb 07 |
jari |
414 |
} |
2 |
26 Feb 07 |
jari |
415 |
return subExperiment; |
2 |
26 Feb 07 |
jari |
416 |
} |
2 |
26 Feb 07 |
jari |
417 |
|
2 |
26 Feb 07 |
jari |
418 |
/** |
2 |
26 Feb 07 |
jari |
* Checking the result of hcl algorithm calculation. |
2 |
26 Feb 07 |
jari |
* @throws AlgorithmException, if the result is incorrect. |
2 |
26 Feb 07 |
jari |
421 |
*/ |
2 |
26 Feb 07 |
jari |
422 |
private void validate(AlgorithmData result) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
423 |
if (result.getIntArray("child-1-array") == null) { |
2 |
26 Feb 07 |
jari |
424 |
throw new AlgorithmException("parameter 'child-1-array' is null"); |
2 |
26 Feb 07 |
jari |
425 |
} |
2 |
26 Feb 07 |
jari |
426 |
if (result.getIntArray("child-2-array") == null) { |
2 |
26 Feb 07 |
jari |
427 |
throw new AlgorithmException("parameter 'child-2-array' is null"); |
2 |
26 Feb 07 |
jari |
428 |
} |
2 |
26 Feb 07 |
jari |
429 |
if (result.getIntArray("node-order") == null) { |
2 |
26 Feb 07 |
jari |
430 |
throw new AlgorithmException("parameter 'node-order' is null"); |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
432 |
if (result.getMatrix("height") == null) { |
2 |
26 Feb 07 |
jari |
433 |
throw new AlgorithmException("parameter 'height' is null"); |
2 |
26 Feb 07 |
jari |
434 |
} |
2 |
26 Feb 07 |
jari |
435 |
} |
2 |
26 Feb 07 |
jari |
436 |
|
2 |
26 Feb 07 |
jari |
437 |
private int[] convert2int(Vector source) { |
2 |
26 Feb 07 |
jari |
438 |
int[] int_matrix = new int[source.size()]; |
2 |
26 Feb 07 |
jari |
439 |
for (int i=0; i<int_matrix.length; i++) { |
2 |
26 Feb 07 |
jari |
440 |
int_matrix[i] = (int)((Integer)source.get(i)).intValue(); |
2 |
26 Feb 07 |
jari |
441 |
} |
2 |
26 Feb 07 |
jari |
442 |
return int_matrix; |
2 |
26 Feb 07 |
jari |
443 |
} |
2 |
26 Feb 07 |
jari |
444 |
|
2 |
26 Feb 07 |
jari |
445 |
private FloatMatrix getMeans(Vector[] clusters) { |
2 |
26 Feb 07 |
jari |
446 |
FloatMatrix means = new FloatMatrix(clusters.length, numExps); |
2 |
26 Feb 07 |
jari |
447 |
FloatMatrix mean; |
2 |
26 Feb 07 |
jari |
448 |
for (int i=0; i<clusters.length; i++) { |
2 |
26 Feb 07 |
jari |
449 |
mean = getMean(clusters[i]); |
2 |
26 Feb 07 |
jari |
450 |
means.A[i] = mean.A[0]; |
2 |
26 Feb 07 |
jari |
451 |
} |
2 |
26 Feb 07 |
jari |
452 |
return means; |
2 |
26 Feb 07 |
jari |
453 |
} |
2 |
26 Feb 07 |
jari |
454 |
|
2 |
26 Feb 07 |
jari |
455 |
private FloatMatrix getMean(Vector cluster) { |
2 |
26 Feb 07 |
jari |
456 |
FloatMatrix mean = new FloatMatrix(1, numExps); |
2 |
26 Feb 07 |
jari |
457 |
float currentMean; |
2 |
26 Feb 07 |
jari |
458 |
int n = cluster.size(); |
2 |
26 Feb 07 |
jari |
459 |
int denom = 0; |
2 |
26 Feb 07 |
jari |
460 |
float value; |
2 |
26 Feb 07 |
jari |
461 |
for (int i=0; i<numExps; i++) { |
2 |
26 Feb 07 |
jari |
462 |
currentMean = 0f; |
2 |
26 Feb 07 |
jari |
463 |
denom = 0; |
2 |
26 Feb 07 |
jari |
464 |
for (int j=0; j<n; j++) { |
2 |
26 Feb 07 |
jari |
465 |
value = expMatrix.get(((Integer) cluster.get(j)).intValue(), i); |
2 |
26 Feb 07 |
jari |
466 |
if (!Float.isNaN(value)) { |
2 |
26 Feb 07 |
jari |
467 |
currentMean += value; |
2 |
26 Feb 07 |
jari |
468 |
denom++; |
2 |
26 Feb 07 |
jari |
469 |
} |
2 |
26 Feb 07 |
jari |
470 |
} |
2 |
26 Feb 07 |
jari |
471 |
mean.set(0, i, currentMean/(float)denom); |
2 |
26 Feb 07 |
jari |
472 |
} |
2 |
26 Feb 07 |
jari |
473 |
|
2 |
26 Feb 07 |
jari |
474 |
return mean; |
2 |
26 Feb 07 |
jari |
475 |
} |
2 |
26 Feb 07 |
jari |
476 |
|
2 |
26 Feb 07 |
jari |
477 |
private FloatMatrix getVariances(Vector[] clusters, FloatMatrix means) { |
2 |
26 Feb 07 |
jari |
478 |
final int rows = means.getRowDimension(); |
2 |
26 Feb 07 |
jari |
479 |
final int columns = means.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
480 |
FloatMatrix variances = new FloatMatrix(rows, columns); |
2 |
26 Feb 07 |
jari |
481 |
for (int row=0; row<rows; row++) { |
2 |
26 Feb 07 |
jari |
482 |
for (int column=0; column<columns; column++) { |
2 |
26 Feb 07 |
jari |
483 |
variances.set(row, column, getSampleVariance(clusters[row], column, means.get(row, column))); |
2 |
26 Feb 07 |
jari |
484 |
} |
2 |
26 Feb 07 |
jari |
485 |
} |
2 |
26 Feb 07 |
jari |
486 |
return variances; |
2 |
26 Feb 07 |
jari |
487 |
} |
2 |
26 Feb 07 |
jari |
488 |
|
2 |
26 Feb 07 |
jari |
489 |
int validN; |
2 |
26 Feb 07 |
jari |
490 |
|
2 |
26 Feb 07 |
jari |
491 |
private float getSampleNormalizedSum(Vector cluster, int column, float mean) { |
2 |
26 Feb 07 |
jari |
492 |
final int size = cluster.size(); |
2 |
26 Feb 07 |
jari |
493 |
float sum = 0f; |
2 |
26 Feb 07 |
jari |
494 |
float value; |
2 |
26 Feb 07 |
jari |
495 |
validN = 0; |
2 |
26 Feb 07 |
jari |
496 |
for (int i=0; i<size; i++) { |
2 |
26 Feb 07 |
jari |
497 |
value = expMatrix.get(((Integer) cluster.get(i)).intValue(), column); |
2 |
26 Feb 07 |
jari |
498 |
if (!Float.isNaN(value)) { |
2 |
26 Feb 07 |
jari |
499 |
sum += Math.pow(value-mean, 2); |
2 |
26 Feb 07 |
jari |
500 |
validN++; |
2 |
26 Feb 07 |
jari |
501 |
} |
2 |
26 Feb 07 |
jari |
502 |
} |
2 |
26 Feb 07 |
jari |
503 |
return sum; |
2 |
26 Feb 07 |
jari |
504 |
} |
2 |
26 Feb 07 |
jari |
505 |
|
2 |
26 Feb 07 |
jari |
506 |
private float getSampleVariance(Vector cluster, int column, float mean) { |
2 |
26 Feb 07 |
jari |
507 |
return(float)Math.sqrt(getSampleNormalizedSum(cluster, column, mean)/(float)(validN-1)); |
2 |
26 Feb 07 |
jari |
508 |
|
2 |
26 Feb 07 |
jari |
509 |
} |
2 |
26 Feb 07 |
jari |
510 |
|
2 |
26 Feb 07 |
jari |
511 |
private boolean[] isGeneSigByFDRPropOld() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
512 |
double[] nonNanPVals = new double[origPVals.length]; |
2 |
26 Feb 07 |
jari |
513 |
for (int i = 0; i < origPVals.length; i++) { //gets rid of NaN's for sorting |
2 |
26 Feb 07 |
jari |
514 |
if (Double.isNaN(origPVals[i])) { |
2 |
26 Feb 07 |
jari |
515 |
nonNanPVals[i] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
516 |
} else { |
2 |
26 Feb 07 |
jari |
517 |
nonNanPVals[i] = origPVals[i]; |
2 |
26 Feb 07 |
jari |
518 |
} |
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
520 |
|
2 |
26 Feb 07 |
jari |
521 |
QSort sortOrigPVals = new QSort(nonNanPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
522 |
double[] sortedOrigPVals = sortOrigPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
523 |
int[] sortedIndices = sortOrigPVals.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
524 |
boolean[] isGeneSig = new boolean[numGenes]; |
2 |
26 Feb 07 |
jari |
525 |
for (int i = 0; i < isGeneSig.length; i++) { |
2 |
26 Feb 07 |
jari |
526 |
isGeneSig[i] = false; |
2 |
26 Feb 07 |
jari |
527 |
} |
2 |
26 Feb 07 |
jari |
528 |
|
2 |
26 Feb 07 |
jari |
529 |
double yKZero = getYConservative(alpha, 0); |
2 |
26 Feb 07 |
jari |
530 |
|
2 |
26 Feb 07 |
jari |
531 |
if (sortedOrigPVals[0] >= yKZero) { |
2 |
26 Feb 07 |
jari |
532 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
534 |
} else { |
2 |
26 Feb 07 |
jari |
535 |
isGeneSig[sortedIndices[0]] = true; |
2 |
26 Feb 07 |
jari |
536 |
if (useFastFDRApprox) { |
2 |
26 Feb 07 |
jari |
537 |
for (int i = 1; i < sortedOrigPVals.length; i++) { |
2 |
26 Feb 07 |
jari |
538 |
int rGamma = (int)(Math.floor((i+1)*falseProp)); |
2 |
26 Feb 07 |
jari |
539 |
int rMinusOneGamma = (int)(Math.floor(i*falseProp)); |
2 |
26 Feb 07 |
jari |
540 |
double yKRGamma = getYConservative(alpha, rGamma); |
2 |
26 Feb 07 |
jari |
541 |
System.out.println("rGamma = " + rGamma + ", (r - 1)Gamma = " + rMinusOneGamma + ", yKRGamma = " + yKRGamma); |
2 |
26 Feb 07 |
jari |
542 |
if ((rGamma > rMinusOneGamma) || (sortedOrigPVals[i] < yKRGamma)) { |
2 |
26 Feb 07 |
jari |
543 |
isGeneSig[sortedIndices[i]] = true; |
2 |
26 Feb 07 |
jari |
544 |
} else { |
2 |
26 Feb 07 |
jari |
545 |
break; |
2 |
26 Feb 07 |
jari |
546 |
} |
2 |
26 Feb 07 |
jari |
547 |
} |
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
549 |
} |
2 |
26 Feb 07 |
jari |
550 |
|
2 |
26 Feb 07 |
jari |
551 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
//return null; // for now |
2 |
26 Feb 07 |
jari |
553 |
} |
2 |
26 Feb 07 |
jari |
554 |
|
2 |
26 Feb 07 |
jari |
555 |
private boolean[] isGeneSigByFDRPropNew2() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
556 |
double[] nonNanPVals = new double[origPVals.length]; |
2 |
26 Feb 07 |
jari |
557 |
for (int i = 0; i < origPVals.length; i++) { //gets rid of NaN's for sorting |
2 |
26 Feb 07 |
jari |
558 |
if (Double.isNaN(origPVals[i])) { |
2 |
26 Feb 07 |
jari |
559 |
nonNanPVals[i] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
560 |
} else { |
2 |
26 Feb 07 |
jari |
561 |
nonNanPVals[i] = origPVals[i]; |
2 |
26 Feb 07 |
jari |
562 |
} |
2 |
26 Feb 07 |
jari |
563 |
} |
2 |
26 Feb 07 |
jari |
564 |
|
2 |
26 Feb 07 |
jari |
565 |
QSort sortOrigPVals = new QSort(nonNanPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
566 |
double[] sortedOrigPVals = sortOrigPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
567 |
int[] sortedIndices = sortOrigPVals.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
568 |
boolean[] isGeneSig = new boolean[numGenes]; |
2 |
26 Feb 07 |
jari |
569 |
for (int i = 0; i < isGeneSig.length; i++) { |
2 |
26 Feb 07 |
jari |
570 |
isGeneSig[i] = false; |
2 |
26 Feb 07 |
jari |
571 |
} |
2 |
26 Feb 07 |
jari |
572 |
|
2 |
26 Feb 07 |
jari |
573 |
double[] yKArray = getYKArray(); |
2 |
26 Feb 07 |
jari |
574 |
|
2 |
26 Feb 07 |
jari |
575 |
if (sortedOrigPVals[0] >= yKArray[0]) { |
2 |
26 Feb 07 |
jari |
576 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
577 |
|
2 |
26 Feb 07 |
jari |
578 |
} else { |
2 |
26 Feb 07 |
jari |
579 |
isGeneSig[sortedIndices[0]] = true; |
2 |
26 Feb 07 |
jari |
580 |
if (useFastFDRApprox) { |
2 |
26 Feb 07 |
jari |
581 |
|
2 |
26 Feb 07 |
jari |
582 |
for (int i = 1; i < sortedOrigPVals.length; i++) { |
2 |
26 Feb 07 |
jari |
583 |
int rGamma = (int)(Math.floor((i+1)*falseProp)); |
2 |
26 Feb 07 |
jari |
584 |
int rMinusOneGamma = (int)(Math.floor(i*falseProp)); |
2 |
26 Feb 07 |
jari |
585 |
double yKRGamma = yKArray[rGamma]; |
2 |
26 Feb 07 |
jari |
//System.out.println("rGamma = " + rGamma + ", (r - 1)Gamma = " + rMinusOneGamma + ", yKRGamma = " + yKRGamma); |
2 |
26 Feb 07 |
jari |
587 |
if ((rGamma > rMinusOneGamma) || (sortedOrigPVals[i] < yKRGamma)) { |
2 |
26 Feb 07 |
jari |
588 |
isGeneSig[sortedIndices[i]] = true; |
2 |
26 Feb 07 |
jari |
589 |
} else { |
2 |
26 Feb 07 |
jari |
590 |
break; |
2 |
26 Feb 07 |
jari |
591 |
} |
2 |
26 Feb 07 |
jari |
592 |
} |
2 |
26 Feb 07 |
jari |
593 |
|
2 |
26 Feb 07 |
jari |
594 |
} |
2 |
26 Feb 07 |
jari |
595 |
} |
2 |
26 Feb 07 |
jari |
596 |
|
2 |
26 Feb 07 |
jari |
597 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
598 |
} |
2 |
26 Feb 07 |
jari |
599 |
|
2 |
26 Feb 07 |
jari |
600 |
private boolean[] isGeneSigByFDRPropNew() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
601 |
double[] nonNanPVals = new double[origPVals.length]; |
2 |
26 Feb 07 |
jari |
602 |
for (int i = 0; i < origPVals.length; i++) { //gets rid of NaN's for sorting |
2 |
26 Feb 07 |
jari |
603 |
if (Double.isNaN(origPVals[i])) { |
2 |
26 Feb 07 |
jari |
604 |
nonNanPVals[i] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
605 |
} else { |
2 |
26 Feb 07 |
jari |
606 |
nonNanPVals[i] = origPVals[i]; |
2 |
26 Feb 07 |
jari |
607 |
} |
2 |
26 Feb 07 |
jari |
608 |
} |
2 |
26 Feb 07 |
jari |
609 |
|
2 |
26 Feb 07 |
jari |
610 |
QSort sortOrigPVals = new QSort(nonNanPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
611 |
double[] sortedOrigPVals = sortOrigPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
612 |
int[] sortedIndices = sortOrigPVals.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
613 |
boolean[] isGeneSig = new boolean[numGenes]; |
2 |
26 Feb 07 |
jari |
614 |
for (int i = 0; i < isGeneSig.length; i++) { |
2 |
26 Feb 07 |
jari |
615 |
isGeneSig[i] = false; |
2 |
26 Feb 07 |
jari |
616 |
} |
2 |
26 Feb 07 |
jari |
617 |
|
2 |
26 Feb 07 |
jari |
618 |
FloatMatrix sortedExpMatrix = new FloatMatrix(expMatrix.getRowDimension(), expMatrix.getColumnDimension()); |
2 |
26 Feb 07 |
jari |
619 |
for (int i = 0; i < expMatrix.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
620 |
for (int j = 0; j < expMatrix.getColumnDimension(); j++) { |
2 |
26 Feb 07 |
jari |
621 |
sortedExpMatrix.A[i][j] = expMatrix.A[sortedIndices[i]][j]; |
2 |
26 Feb 07 |
jari |
622 |
} |
2 |
26 Feb 07 |
jari |
623 |
} |
2 |
26 Feb 07 |
jari |
624 |
|
2 |
26 Feb 07 |
jari |
625 |
double yKZero = getYConservative(alpha, 0); |
2 |
26 Feb 07 |
jari |
626 |
|
2 |
26 Feb 07 |
jari |
627 |
if (sortedOrigPVals[0] >= yKZero) { |
2 |
26 Feb 07 |
jari |
628 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
629 |
|
2 |
26 Feb 07 |
jari |
630 |
} else { |
2 |
26 Feb 07 |
jari |
631 |
isGeneSig[sortedIndices[0]] = true; |
2 |
26 Feb 07 |
jari |
632 |
if (useFastFDRApprox) { |
2 |
26 Feb 07 |
jari |
633 |
int currMinGene = 1; |
2 |
26 Feb 07 |
jari |
634 |
int currMaxGene = 100; |
2 |
26 Feb 07 |
jari |
635 |
if (currMaxGene > (numGenes - 1)) currMaxGene = (numGenes - 1); |
2 |
26 Feb 07 |
jari |
636 |
int rGammaPrev = (int)(Math.floor(2*falseProp)); |
2 |
26 Feb 07 |
jari |
//double yKRGamma = getYKFromPMatrix(pValMatrix, rGammaPrev); |
2 |
26 Feb 07 |
jari |
638 |
|
2 |
26 Feb 07 |
jari |
639 |
boolean sig = true; |
2 |
26 Feb 07 |
jari |
640 |
while (sig) { |
2 |
26 Feb 07 |
jari |
641 |
System.out.println("Entering while, sig = " + sig); |
2 |
26 Feb 07 |
jari |
642 |
if (currMinGene > (numGenes - 1)) { |
2 |
26 Feb 07 |
jari |
643 |
break; |
2 |
26 Feb 07 |
jari |
644 |
} |
2 |
26 Feb 07 |
jari |
645 |
if (currMaxGene > (numGenes - 1)) { |
2 |
26 Feb 07 |
jari |
646 |
currMaxGene = (numGenes - 1); |
2 |
26 Feb 07 |
jari |
647 |
sig = false; |
2 |
26 Feb 07 |
jari |
648 |
} |
2 |
26 Feb 07 |
jari |
649 |
System.out.println("currMinGene = " + currMinGene + ", currMaxGene = " + currMaxGene); |
2 |
26 Feb 07 |
jari |
650 |
FloatMatrix smallMatrix = sortedExpMatrix.getMatrix(0, currMaxGene, 0, sortedExpMatrix.getColumnDimension() - 1); |
2 |
26 Feb 07 |
jari |
651 |
double[][] pValMatrix = getSortedPermPValMatrix(smallMatrix); |
2 |
26 Feb 07 |
jari |
652 |
double yKRGamma = getYKFromPMatrix(pValMatrix, rGammaPrev); |
2 |
26 Feb 07 |
jari |
653 |
for (int i = currMinGene; i <= currMaxGene; i++) { |
2 |
26 Feb 07 |
jari |
654 |
int rGamma = (int)(Math.floor((i+1)*falseProp)); |
2 |
26 Feb 07 |
jari |
655 |
int rMinusOneGamma = (int)(Math.floor(i*falseProp)); |
2 |
26 Feb 07 |
jari |
656 |
if (rGamma > currMaxGene) { |
2 |
26 Feb 07 |
jari |
//currMinGene = currMaxGene + 1; |
2 |
26 Feb 07 |
jari |
//currMaxGene = currMaxGene + 100; |
2 |
26 Feb 07 |
jari |
659 |
break; |
2 |
26 Feb 07 |
jari |
660 |
} else { |
2 |
26 Feb 07 |
jari |
661 |
System.out.println("i = " + i +", rGamma = " + rGamma + ", rMinusOneGamma = " + rMinusOneGamma + ", rGammaPrev = " + rGammaPrev); |
2 |
26 Feb 07 |
jari |
//FloatMatrix smallMatrix = expMatrix.getMatrix(0, currMaxGene, 0, expMatrix.getColumnDimension() - 1); |
2 |
26 Feb 07 |
jari |
//double[][] pValMatrix = getSortedPermPValMatrix(smallMatrix); |
2 |
26 Feb 07 |
jari |
664 |
if (rGamma != rGammaPrev) { |
2 |
26 Feb 07 |
jari |
665 |
yKRGamma = getYKFromPMatrix(pValMatrix, rGamma); |
2 |
26 Feb 07 |
jari |
666 |
rGammaPrev = rGamma; |
2 |
26 Feb 07 |
jari |
667 |
} |
2 |
26 Feb 07 |
jari |
668 |
System.out.println("yKRGamma = " + yKRGamma); |
2 |
26 Feb 07 |
jari |
//double yKRGamma = getYKFromPMatrix(pValMatrix, rGamma); |
2 |
26 Feb 07 |
jari |
670 |
if ((rGamma > rMinusOneGamma) || (sortedOrigPVals[i] < yKRGamma)) { |
2 |
26 Feb 07 |
jari |
671 |
isGeneSig[sortedIndices[i]] = true; |
2 |
26 Feb 07 |
jari |
672 |
System.out.println("true"); |
2 |
26 Feb 07 |
jari |
673 |
} else { |
2 |
26 Feb 07 |
jari |
674 |
sig = false; |
2 |
26 Feb 07 |
jari |
675 |
System.out.println("false"); |
2 |
26 Feb 07 |
jari |
676 |
break; |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
} |
2 |
26 Feb 07 |
jari |
679 |
|
2 |
26 Feb 07 |
jari |
680 |
currMinGene = currMaxGene + 1; |
2 |
26 Feb 07 |
jari |
681 |
currMaxGene = currMaxGene + 100; |
2 |
26 Feb 07 |
jari |
682 |
|
2 |
26 Feb 07 |
jari |
683 |
} |
2 |
26 Feb 07 |
jari |
684 |
} |
2 |
26 Feb 07 |
jari |
685 |
} |
2 |
26 Feb 07 |
jari |
686 |
} |
2 |
26 Feb 07 |
jari |
687 |
|
2 |
26 Feb 07 |
jari |
//return null; // for now |
2 |
26 Feb 07 |
jari |
689 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
690 |
} |
2 |
26 Feb 07 |
jari |
691 |
|
2 |
26 Feb 07 |
jari |
692 |
private double getYKFromPMatrix(double[][] pMatrix, int u) { |
2 |
26 Feb 07 |
jari |
693 |
double[] uPlusOnePValArray = new double[pMatrix[u].length]; |
2 |
26 Feb 07 |
jari |
694 |
for (int i = 0; i < pMatrix[u].length; i++) { |
2 |
26 Feb 07 |
jari |
695 |
uPlusOnePValArray[i] = pMatrix[u][i]; |
2 |
26 Feb 07 |
jari |
696 |
} |
2 |
26 Feb 07 |
jari |
697 |
|
2 |
26 Feb 07 |
jari |
698 |
QSort sortPValArray = new QSort(uPlusOnePValArray, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
699 |
double[] sortedPValArray = sortPValArray.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
700 |
int selectedIndex = (int)Math.floor(sortedPValArray.length*alpha) - 1; |
2 |
26 Feb 07 |
jari |
//System.out.println("Selected index (before setting to zero) = " + selectedIndex); |
2 |
26 Feb 07 |
jari |
702 |
if (selectedIndex < 0) selectedIndex = 0; |
2 |
26 Feb 07 |
jari |
703 |
|
2 |
26 Feb 07 |
jari |
704 |
return sortedPValArray[selectedIndex]; |
2 |
26 Feb 07 |
jari |
705 |
} |
2 |
26 Feb 07 |
jari |
706 |
|
2 |
26 Feb 07 |
jari |
707 |
private double[][] getSortedPermPValMatrix(FloatMatrix inputMatrix) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
708 |
AlgorithmEvent event2 = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
709 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
710 |
event2.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
711 |
double[][] pValMatrix = new double[inputMatrix.getRowDimension()][numCombs]; |
2 |
26 Feb 07 |
jari |
712 |
if (tTestDesign == Ttest.BETWEEN_SUBJECTS) { |
2 |
26 Feb 07 |
jari |
713 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
714 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
715 |
if (stop) { |
2 |
26 Feb 07 |
jari |
716 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
717 |
} |
2 |
26 Feb 07 |
jari |
718 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
719 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
720 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
721 |
|
2 |
26 Feb 07 |
jari |
722 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
723 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
724 |
|
2 |
26 Feb 07 |
jari |
725 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
726 |
if (groupAssignments[j] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
727 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
728 |
} |
2 |
26 Feb 07 |
jari |
729 |
} |
2 |
26 Feb 07 |
jari |
730 |
|
2 |
26 Feb 07 |
jari |
731 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
732 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
733 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
734 |
} |
2 |
26 Feb 07 |
jari |
735 |
|
2 |
26 Feb 07 |
jari |
736 |
permutedExpts = getPermutedValues(numExps, validArray); //returns an int array of size "numExps", with the valid values permuted |
2 |
26 Feb 07 |
jari |
737 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
738 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
739 |
int[] currPermDfValues = getTwoClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
740 |
|
2 |
26 Feb 07 |
jari |
741 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
742 |
|
2 |
26 Feb 07 |
jari |
743 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
744 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
746 |
} |
2 |
26 Feb 07 |
jari |
747 |
|
2 |
26 Feb 07 |
jari |
748 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
749 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
750 |
|
2 |
26 Feb 07 |
jari |
751 |
for (int j = 0; j < pValMatrix.length; j++) { |
2 |
26 Feb 07 |
jari |
752 |
pValMatrix[j][i] = sortedCurrPVals[i]; |
2 |
26 Feb 07 |
jari |
753 |
} |
2 |
26 Feb 07 |
jari |
754 |
|
2 |
26 Feb 07 |
jari |
755 |
} |
2 |
26 Feb 07 |
jari |
756 |
} |
2 |
26 Feb 07 |
jari |
757 |
} |
2 |
26 Feb 07 |
jari |
758 |
return pValMatrix; |
2 |
26 Feb 07 |
jari |
759 |
} |
2 |
26 Feb 07 |
jari |
760 |
|
2 |
26 Feb 07 |
jari |
761 |
private boolean[] isGeneSigByFDRNum() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
762 |
double[] nonNanPVals = new double[origPVals.length]; |
2 |
26 Feb 07 |
jari |
763 |
for (int i = 0; i < origPVals.length; i++) { //gets rid of NaN's for sorting |
2 |
26 Feb 07 |
jari |
764 |
if (Double.isNaN(origPVals[i])) { |
2 |
26 Feb 07 |
jari |
765 |
nonNanPVals[i] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
766 |
} else { |
2 |
26 Feb 07 |
jari |
767 |
nonNanPVals[i] = origPVals[i]; |
2 |
26 Feb 07 |
jari |
768 |
} |
2 |
26 Feb 07 |
jari |
769 |
} |
2 |
26 Feb 07 |
jari |
770 |
QSort sortOrigPVals = new QSort(nonNanPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
771 |
double[] sortedOrigPVals = sortOrigPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
772 |
int[] sortedIndices = sortOrigPVals.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
773 |
boolean[] isGeneSig = new boolean[numGenes]; |
2 |
26 Feb 07 |
jari |
774 |
for (int i = 0; i < isGeneSig.length; i++) { |
2 |
26 Feb 07 |
jari |
775 |
isGeneSig[i] = false; |
2 |
26 Feb 07 |
jari |
776 |
} |
2 |
26 Feb 07 |
jari |
777 |
for (int i = 0; i < falseNum; i++) { |
2 |
26 Feb 07 |
jari |
778 |
isGeneSig[sortedIndices[i]] = true; |
2 |
26 Feb 07 |
jari |
779 |
} |
2 |
26 Feb 07 |
jari |
780 |
if (useFastFDRApprox) { |
2 |
26 Feb 07 |
jari |
781 |
double yK = getYConservative(alpha, falseNum); |
2 |
26 Feb 07 |
jari |
//System.out.println("yK = " + yK); |
2 |
26 Feb 07 |
jari |
783 |
for (int i = falseNum; i < sortedOrigPVals.length; i++) { |
2 |
26 Feb 07 |
jari |
784 |
if (sortedOrigPVals[i] < yK) { |
2 |
26 Feb 07 |
jari |
785 |
isGeneSig[sortedIndices[i]] = true; |
2 |
26 Feb 07 |
jari |
786 |
} else { |
2 |
26 Feb 07 |
jari |
787 |
break; |
2 |
26 Feb 07 |
jari |
788 |
} |
2 |
26 Feb 07 |
jari |
789 |
} |
2 |
26 Feb 07 |
jari |
790 |
|
2 |
26 Feb 07 |
jari |
791 |
} else {// if (!useFastFDRAprpox) |
2 |
26 Feb 07 |
jari |
792 |
for (int i = falseNum; i < origPVals.length; i++) { |
2 |
26 Feb 07 |
jari |
793 |
|
2 |
26 Feb 07 |
jari |
794 |
} |
2 |
26 Feb 07 |
jari |
795 |
} |
2 |
26 Feb 07 |
jari |
//return null; //for now |
2 |
26 Feb 07 |
jari |
797 |
return isGeneSig; |
2 |
26 Feb 07 |
jari |
798 |
} |
2 |
26 Feb 07 |
jari |
799 |
|
2 |
26 Feb 07 |
jari |
800 |
/* |
2 |
26 Feb 07 |
jari |
private double getY(double alphaQuantile, double[] T, int u) { |
2 |
26 Feb 07 |
jari |
QSort sortT = new QSort(T); |
2 |
26 Feb 07 |
jari |
double[] sortedT = sortT.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
double[] smallT = new double[u + 1]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < smallT.length; i++) { |
2 |
26 Feb 07 |
jari |
smallT[i] = sortedT[i]; |
2 |
26 Feb 07 |
jari |
807 |
} |
2 |
26 Feb 07 |
jari |
int selectedIndex = (int)Math.floor(smallT.length*alphaQuantile) - 1; |
2 |
26 Feb 07 |
jari |
System.out.println("Selected index (before setting to zero) = " + selectedIndex); |
2 |
26 Feb 07 |
jari |
if (selectedIndex < 0) selectedIndex = 0; |
2 |
26 Feb 07 |
jari |
return smallT[selectedIndex]; |
2 |
26 Feb 07 |
jari |
812 |
} |
2 |
26 Feb 07 |
jari |
813 |
*/ |
2 |
26 Feb 07 |
jari |
814 |
|
2 |
26 Feb 07 |
jari |
815 |
private double[] getYKArray() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
816 |
AlgorithmEvent event2 = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
817 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
818 |
event2.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
819 |
int maxRGamma = (int)(Math.floor(numGenes*falseProp)); |
2 |
26 Feb 07 |
jari |
820 |
double[][] pValArray =new double[maxRGamma + 1][numCombs]; |
2 |
26 Feb 07 |
jari |
821 |
if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
822 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
823 |
boolean[] changeSign = new boolean[1]; |
2 |
26 Feb 07 |
jari |
824 |
|
2 |
26 Feb 07 |
jari |
825 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
826 |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
827 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
828 |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
829 |
} |
2 |
26 Feb 07 |
jari |
830 |
|
2 |
26 Feb 07 |
jari |
831 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
832 |
if (stop) { |
2 |
26 Feb 07 |
jari |
833 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
834 |
} |
2 |
26 Feb 07 |
jari |
835 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
836 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
837 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
838 |
|
2 |
26 Feb 07 |
jari |
839 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
840 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
841 |
|
2 |
26 Feb 07 |
jari |
842 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
843 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
844 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
845 |
} |
2 |
26 Feb 07 |
jari |
846 |
} |
2 |
26 Feb 07 |
jari |
847 |
|
2 |
26 Feb 07 |
jari |
848 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
849 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
850 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
851 |
} |
2 |
26 Feb 07 |
jari |
852 |
|
2 |
26 Feb 07 |
jari |
853 |
changeSign = getOneClassChangeSignArray(randomSeeds[i], validArray); |
2 |
26 Feb 07 |
jari |
854 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
855 |
|
2 |
26 Feb 07 |
jari |
856 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
857 |
int[] currPermDfValues = getOneClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
858 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
859 |
|
2 |
26 Feb 07 |
jari |
860 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
861 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
863 |
} |
2 |
26 Feb 07 |
jari |
864 |
|
2 |
26 Feb 07 |
jari |
865 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
866 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
//uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
868 |
for (int j = 0; j < pValArray.length; j++) { |
2 |
26 Feb 07 |
jari |
869 |
pValArray[j][i] = sortedCurrPVals[j]; |
2 |
26 Feb 07 |
jari |
870 |
} |
2 |
26 Feb 07 |
jari |
871 |
} |
2 |
26 Feb 07 |
jari |
872 |
} else {// if (useAllCombs) |
2 |
26 Feb 07 |
jari |
873 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
874 |
if (stop) { |
2 |
26 Feb 07 |
jari |
875 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
876 |
} |
2 |
26 Feb 07 |
jari |
877 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
878 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
879 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
880 |
|
2 |
26 Feb 07 |
jari |
881 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
882 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
883 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
884 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
885 |
} |
2 |
26 Feb 07 |
jari |
886 |
} |
2 |
26 Feb 07 |
jari |
887 |
|
2 |
26 Feb 07 |
jari |
888 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
889 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
890 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
891 |
} |
2 |
26 Feb 07 |
jari |
892 |
|
2 |
26 Feb 07 |
jari |
893 |
boolean[] changeSign = getOneClassChangeSignArrayAllUniquePerms(i, validArray); |
2 |
26 Feb 07 |
jari |
894 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
895 |
|
2 |
26 Feb 07 |
jari |
896 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
897 |
int[] currPermDfValues = getOneClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
898 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
899 |
|
2 |
26 Feb 07 |
jari |
900 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
901 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
903 |
} |
2 |
26 Feb 07 |
jari |
904 |
|
2 |
26 Feb 07 |
jari |
905 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
906 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
//uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
908 |
for (int j = 0; j < pValArray.length; j++) { |
2 |
26 Feb 07 |
jari |
909 |
pValArray[j][i] = sortedCurrPVals[j]; |
2 |
26 Feb 07 |
jari |
910 |
} |
2 |
26 Feb 07 |
jari |
911 |
} |
2 |
26 Feb 07 |
jari |
912 |
} |
2 |
26 Feb 07 |
jari |
913 |
|
2 |
26 Feb 07 |
jari |
914 |
} else if (tTestDesign == Ttest.BETWEEN_SUBJECTS) { |
2 |
26 Feb 07 |
jari |
915 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
916 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
917 |
if (stop) { |
2 |
26 Feb 07 |
jari |
918 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
919 |
} |
2 |
26 Feb 07 |
jari |
920 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
921 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
922 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
923 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
924 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
925 |
|
2 |
26 Feb 07 |
jari |
926 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
927 |
if (groupAssignments[j] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
928 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
929 |
} |
2 |
26 Feb 07 |
jari |
930 |
} |
2 |
26 Feb 07 |
jari |
931 |
|
2 |
26 Feb 07 |
jari |
932 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
933 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
934 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
935 |
} |
2 |
26 Feb 07 |
jari |
936 |
|
2 |
26 Feb 07 |
jari |
937 |
permutedExpts = getPermutedValues(numExps, validArray); //returns an int array of size "numExps", with the valid values permuted |
2 |
26 Feb 07 |
jari |
938 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
939 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
940 |
int[] currPermDfValues = getTwoClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
941 |
|
2 |
26 Feb 07 |
jari |
942 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
943 |
|
2 |
26 Feb 07 |
jari |
944 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
945 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
947 |
} |
2 |
26 Feb 07 |
jari |
948 |
|
2 |
26 Feb 07 |
jari |
949 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
950 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
951 |
for (int j = 0; j < pValArray.length; j++) { |
2 |
26 Feb 07 |
jari |
952 |
pValArray[j][i] = sortedCurrPVals[j]; |
2 |
26 Feb 07 |
jari |
953 |
} |
2 |
26 Feb 07 |
jari |
954 |
} |
2 |
26 Feb 07 |
jari |
955 |
} else { //if (useAllCombs) |
2 |
26 Feb 07 |
jari |
956 |
int[] permutedExpts = new int[numExps]; |
2 |
26 Feb 07 |
jari |
957 |
|
2 |
26 Feb 07 |
jari |
958 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
959 |
permutedExpts[i] = i; |
2 |
26 Feb 07 |
jari |
960 |
} |
2 |
26 Feb 07 |
jari |
961 |
|
2 |
26 Feb 07 |
jari |
962 |
Vector usedExptsVector = new Vector(); |
2 |
26 Feb 07 |
jari |
963 |
int numGroupAValues = 0; |
2 |
26 Feb 07 |
jari |
964 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
965 |
if (groupAssignments[i] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
966 |
usedExptsVector.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
967 |
} |
2 |
26 Feb 07 |
jari |
968 |
if (groupAssignments[i] == Ttest.GROUP_A) { |
2 |
26 Feb 07 |
jari |
969 |
numGroupAValues++; |
2 |
26 Feb 07 |
jari |
970 |
} |
2 |
26 Feb 07 |
jari |
971 |
} |
2 |
26 Feb 07 |
jari |
972 |
int[] usedExptsArray = new int[usedExptsVector.size()]; |
2 |
26 Feb 07 |
jari |
973 |
|
2 |
26 Feb 07 |
jari |
974 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
975 |
usedExptsArray[i] = ((Integer)(usedExptsVector.get(i))).intValue(); |
2 |
26 Feb 07 |
jari |
976 |
} |
2 |
26 Feb 07 |
jari |
977 |
|
2 |
26 Feb 07 |
jari |
978 |
int[] combArray = new int[numGroupAValues]; |
2 |
26 Feb 07 |
jari |
979 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
980 |
combArray[i] = -1; |
2 |
26 Feb 07 |
jari |
981 |
} |
2 |
26 Feb 07 |
jari |
982 |
|
2 |
26 Feb 07 |
jari |
983 |
int numGroupBValues = usedExptsArray.length - numGroupAValues; |
2 |
26 Feb 07 |
jari |
984 |
|
2 |
26 Feb 07 |
jari |
985 |
int permCounter = 0; |
2 |
26 Feb 07 |
jari |
986 |
|
2 |
26 Feb 07 |
jari |
987 |
while (Combinations.enumerateCombinations(usedExptsArray.length, numGroupAValues, combArray)) { |
2 |
26 Feb 07 |
jari |
988 |
if (stop) { |
2 |
26 Feb 07 |
jari |
989 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
990 |
} |
2 |
26 Feb 07 |
jari |
991 |
event2.setIntValue(permCounter); |
2 |
26 Feb 07 |
jari |
992 |
event2.setDescription("Permuting matrix: Current permutation = " + (permCounter+1)); |
2 |
26 Feb 07 |
jari |
993 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
994 |
|
2 |
26 Feb 07 |
jari |
995 |
int[] notInCombArray = new int[numGroupBValues]; |
2 |
26 Feb 07 |
jari |
996 |
int notCombCounter = 0; |
2 |
26 Feb 07 |
jari |
997 |
|
2 |
26 Feb 07 |
jari |
998 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
999 |
if(!belongsInArray(i, combArray)) { |
2 |
26 Feb 07 |
jari |
1000 |
notInCombArray[notCombCounter] = i; |
2 |
26 Feb 07 |
jari |
1001 |
notCombCounter++; |
2 |
26 Feb 07 |
jari |
1002 |
} |
2 |
26 Feb 07 |
jari |
1003 |
} |
2 |
26 Feb 07 |
jari |
1004 |
|
2 |
26 Feb 07 |
jari |
1005 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1006 |
permutedExpts[usedExptsArray[i]] = usedExptsArray[combArray[i]]; |
2 |
26 Feb 07 |
jari |
1007 |
} |
2 |
26 Feb 07 |
jari |
1008 |
for (int i = 0; i < notInCombArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1009 |
permutedExpts[usedExptsArray[combArray.length + i]] = usedExptsArray[notInCombArray[i]]; |
2 |
26 Feb 07 |
jari |
1010 |
} |
2 |
26 Feb 07 |
jari |
1011 |
|
2 |
26 Feb 07 |
jari |
1012 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1013 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1014 |
int[] currPermDfValues = getTwoClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1015 |
|
2 |
26 Feb 07 |
jari |
1016 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1017 |
|
2 |
26 Feb 07 |
jari |
1018 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1019 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1021 |
} |
2 |
26 Feb 07 |
jari |
1022 |
|
2 |
26 Feb 07 |
jari |
1023 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
//double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
//uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1026 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1027 |
for (int j = 0; j < pValArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1028 |
pValArray[j][permCounter] = sortedCurrPVals[j]; |
2 |
26 Feb 07 |
jari |
1029 |
} |
2 |
26 Feb 07 |
jari |
1030 |
permCounter++; |
2 |
26 Feb 07 |
jari |
1031 |
} |
2 |
26 Feb 07 |
jari |
1032 |
|
2 |
26 Feb 07 |
jari |
1033 |
} |
2 |
26 Feb 07 |
jari |
1034 |
} else if (tTestDesign == Ttest.PAIRED) { |
2 |
26 Feb 07 |
jari |
1035 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
1036 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
1037 |
/* |
2 |
26 Feb 07 |
jari |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1041 |
} |
2 |
26 Feb 07 |
jari |
1042 |
*/ |
2 |
26 Feb 07 |
jari |
1043 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1044 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1045 |
event2.setDescription("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1046 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1047 |
long randomSeed = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1048 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1049 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1050 |
} |
2 |
26 Feb 07 |
jari |
1051 |
int[] permutedExpts = permuteWithinPairs(randomSeed); //returns an int array with some paired experiment indices permuted |
2 |
26 Feb 07 |
jari |
1052 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1053 |
double[] currentPermTValues = getPairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1054 |
int[] currPermDfValues = getPairedDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1055 |
|
2 |
26 Feb 07 |
jari |
1056 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1057 |
|
2 |
26 Feb 07 |
jari |
1058 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1059 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1061 |
} |
2 |
26 Feb 07 |
jari |
1062 |
|
2 |
26 Feb 07 |
jari |
1063 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1064 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
//uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1066 |
for (int j = 0; j < pValArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1067 |
pValArray[j][i] = sortedCurrPVals[j]; |
2 |
26 Feb 07 |
jari |
1068 |
} |
2 |
26 Feb 07 |
jari |
1069 |
} |
2 |
26 Feb 07 |
jari |
1070 |
} else {//if (useAllCombs) |
2 |
26 Feb 07 |
jari |
1071 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1072 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1073 |
event2.setDescription("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1074 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1075 |
int[] permutedExpts = permuteWithinPairsAllPerms(i); |
2 |
26 Feb 07 |
jari |
1076 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1077 |
|
2 |
26 Feb 07 |
jari |
1078 |
double[] currentPermTValues = getPairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1079 |
int[] currPermDfValues = getPairedDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1080 |
|
2 |
26 Feb 07 |
jari |
1081 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1082 |
|
2 |
26 Feb 07 |
jari |
1083 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1084 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1086 |
} |
2 |
26 Feb 07 |
jari |
1087 |
|
2 |
26 Feb 07 |
jari |
1088 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1089 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
//uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1091 |
for (int j = 0; j < pValArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1092 |
pValArray[j][i] = sortedCurrPVals[j]; |
2 |
26 Feb 07 |
jari |
1093 |
} |
2 |
26 Feb 07 |
jari |
1094 |
} |
2 |
26 Feb 07 |
jari |
1095 |
} |
2 |
26 Feb 07 |
jari |
1096 |
} //end if (tTestDesign == this.PAIRED) |
2 |
26 Feb 07 |
jari |
1097 |
|
2 |
26 Feb 07 |
jari |
1098 |
double[] yKArray = new double[pValArray.length]; |
2 |
26 Feb 07 |
jari |
1099 |
|
2 |
26 Feb 07 |
jari |
1100 |
for (int i = 0; i < pValArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1101 |
double[] currRow = new double[pValArray[i].length]; |
2 |
26 Feb 07 |
jari |
1102 |
|
2 |
26 Feb 07 |
jari |
1103 |
for (int j = 0; j < currRow.length; j++) { |
2 |
26 Feb 07 |
jari |
1104 |
currRow[j] = pValArray[i][j]; |
2 |
26 Feb 07 |
jari |
1105 |
} |
2 |
26 Feb 07 |
jari |
1106 |
|
2 |
26 Feb 07 |
jari |
1107 |
for (int j = 0; j < currRow.length; j++) { |
2 |
26 Feb 07 |
jari |
1108 |
if (Double.isNaN(currRow[j])) currRow[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1110 |
} |
2 |
26 Feb 07 |
jari |
1111 |
|
2 |
26 Feb 07 |
jari |
1112 |
QSort sortCurrRow = new QSort(currRow, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1113 |
double[] sortedCurrRow = sortCurrRow.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1114 |
int selectedIndex = (int)Math.floor(sortedCurrRow.length*alpha) - 1; |
2 |
26 Feb 07 |
jari |
1115 |
if (selectedIndex < 0) selectedIndex = 0; |
2 |
26 Feb 07 |
jari |
1116 |
yKArray[i] = sortedCurrRow[selectedIndex]; |
2 |
26 Feb 07 |
jari |
//System.out.println("i= " + i + ", selectedIndex = " + selectedIndex + ", yKArray[i] = " + yKArray[i]); |
2 |
26 Feb 07 |
jari |
1118 |
} |
2 |
26 Feb 07 |
jari |
1119 |
|
2 |
26 Feb 07 |
jari |
1120 |
return yKArray; |
2 |
26 Feb 07 |
jari |
1121 |
} |
2 |
26 Feb 07 |
jari |
1122 |
|
2 |
26 Feb 07 |
jari |
1123 |
private double getYConservative(double alphaQuantile, int u) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
1124 |
AlgorithmEvent event2 = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
1125 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1126 |
event2.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
1127 |
Vector uPlusOneSmallestPVector = new Vector(); |
2 |
26 Feb 07 |
jari |
1128 |
|
2 |
26 Feb 07 |
jari |
1129 |
if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
1130 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
1131 |
boolean[] changeSign = new boolean[1]; |
2 |
26 Feb 07 |
jari |
1132 |
|
2 |
26 Feb 07 |
jari |
1133 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
1134 |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
1135 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1136 |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1137 |
} |
2 |
26 Feb 07 |
jari |
1138 |
|
2 |
26 Feb 07 |
jari |
1139 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1140 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1141 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1142 |
} |
2 |
26 Feb 07 |
jari |
1143 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1144 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
1145 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1146 |
|
2 |
26 Feb 07 |
jari |
1147 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
1148 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
1149 |
|
2 |
26 Feb 07 |
jari |
1150 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
1151 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
1152 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
1153 |
} |
2 |
26 Feb 07 |
jari |
1154 |
} |
2 |
26 Feb 07 |
jari |
1155 |
|
2 |
26 Feb 07 |
jari |
1156 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
1157 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1158 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
1159 |
} |
2 |
26 Feb 07 |
jari |
1160 |
|
2 |
26 Feb 07 |
jari |
1161 |
changeSign = getOneClassChangeSignArray(randomSeeds[i], validArray); |
2 |
26 Feb 07 |
jari |
1162 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
1163 |
|
2 |
26 Feb 07 |
jari |
1164 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1165 |
int[] currPermDfValues = getOneClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1166 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1167 |
|
2 |
26 Feb 07 |
jari |
1168 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1169 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1171 |
} |
2 |
26 Feb 07 |
jari |
1172 |
|
2 |
26 Feb 07 |
jari |
1173 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1174 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1175 |
uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1176 |
} |
2 |
26 Feb 07 |
jari |
1177 |
|
2 |
26 Feb 07 |
jari |
1178 |
} else { //if(useAllCombs) |
2 |
26 Feb 07 |
jari |
1179 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1180 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1181 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1182 |
} |
2 |
26 Feb 07 |
jari |
1183 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1184 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
1185 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1186 |
|
2 |
26 Feb 07 |
jari |
1187 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
1188 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
1189 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
1190 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
1191 |
} |
2 |
26 Feb 07 |
jari |
1192 |
} |
2 |
26 Feb 07 |
jari |
1193 |
|
2 |
26 Feb 07 |
jari |
1194 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
1195 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1196 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
1197 |
} |
2 |
26 Feb 07 |
jari |
1198 |
|
2 |
26 Feb 07 |
jari |
1199 |
boolean[] changeSign = getOneClassChangeSignArrayAllUniquePerms(i, validArray); |
2 |
26 Feb 07 |
jari |
1200 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
1201 |
|
2 |
26 Feb 07 |
jari |
1202 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1203 |
int[] currPermDfValues = getOneClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1204 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1205 |
|
2 |
26 Feb 07 |
jari |
1206 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1207 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1209 |
} |
2 |
26 Feb 07 |
jari |
1210 |
|
2 |
26 Feb 07 |
jari |
1211 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1212 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1213 |
uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1214 |
} |
2 |
26 Feb 07 |
jari |
1215 |
} |
2 |
26 Feb 07 |
jari |
1216 |
|
2 |
26 Feb 07 |
jari |
1217 |
} else if (tTestDesign == Ttest.BETWEEN_SUBJECTS) { |
2 |
26 Feb 07 |
jari |
1218 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
1219 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1220 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1221 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1222 |
} |
2 |
26 Feb 07 |
jari |
1223 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1224 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
1225 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1226 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
1227 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
1228 |
|
2 |
26 Feb 07 |
jari |
1229 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
1230 |
if (groupAssignments[j] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
1231 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
1232 |
} |
2 |
26 Feb 07 |
jari |
1233 |
} |
2 |
26 Feb 07 |
jari |
1234 |
|
2 |
26 Feb 07 |
jari |
1235 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
1236 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1237 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
1238 |
} |
2 |
26 Feb 07 |
jari |
1239 |
|
2 |
26 Feb 07 |
jari |
1240 |
permutedExpts = getPermutedValues(numExps, validArray); //returns an int array of size "numExps", with the valid values permuted |
2 |
26 Feb 07 |
jari |
1241 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1242 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1243 |
int[] currPermDfValues = getTwoClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1244 |
|
2 |
26 Feb 07 |
jari |
1245 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1246 |
|
2 |
26 Feb 07 |
jari |
1247 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1248 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1250 |
} |
2 |
26 Feb 07 |
jari |
1251 |
|
2 |
26 Feb 07 |
jari |
1252 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1253 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1254 |
uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1255 |
} |
2 |
26 Feb 07 |
jari |
1256 |
|
2 |
26 Feb 07 |
jari |
1257 |
} else {// if(useAllCombs) |
2 |
26 Feb 07 |
jari |
1258 |
int[] permutedExpts = new int[numExps]; |
2 |
26 Feb 07 |
jari |
1259 |
|
2 |
26 Feb 07 |
jari |
1260 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
1261 |
permutedExpts[i] = i; |
2 |
26 Feb 07 |
jari |
1262 |
} |
2 |
26 Feb 07 |
jari |
1263 |
|
2 |
26 Feb 07 |
jari |
1264 |
Vector usedExptsVector = new Vector(); |
2 |
26 Feb 07 |
jari |
1265 |
int numGroupAValues = 0; |
2 |
26 Feb 07 |
jari |
1266 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
1267 |
if (groupAssignments[i] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
1268 |
usedExptsVector.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
1269 |
} |
2 |
26 Feb 07 |
jari |
1270 |
if (groupAssignments[i] == Ttest.GROUP_A) { |
2 |
26 Feb 07 |
jari |
1271 |
numGroupAValues++; |
2 |
26 Feb 07 |
jari |
1272 |
} |
2 |
26 Feb 07 |
jari |
1273 |
} |
2 |
26 Feb 07 |
jari |
1274 |
int[] usedExptsArray = new int[usedExptsVector.size()]; |
2 |
26 Feb 07 |
jari |
1275 |
|
2 |
26 Feb 07 |
jari |
1276 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1277 |
usedExptsArray[i] = ((Integer)(usedExptsVector.get(i))).intValue(); |
2 |
26 Feb 07 |
jari |
1278 |
} |
2 |
26 Feb 07 |
jari |
1279 |
|
2 |
26 Feb 07 |
jari |
1280 |
int[] combArray = new int[numGroupAValues]; |
2 |
26 Feb 07 |
jari |
1281 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1282 |
combArray[i] = -1; |
2 |
26 Feb 07 |
jari |
1283 |
} |
2 |
26 Feb 07 |
jari |
1284 |
|
2 |
26 Feb 07 |
jari |
1285 |
int numGroupBValues = usedExptsArray.length - numGroupAValues; |
2 |
26 Feb 07 |
jari |
1286 |
|
2 |
26 Feb 07 |
jari |
1287 |
int permCounter = 0; |
2 |
26 Feb 07 |
jari |
1288 |
|
2 |
26 Feb 07 |
jari |
1289 |
while (Combinations.enumerateCombinations(usedExptsArray.length, numGroupAValues, combArray)) { |
2 |
26 Feb 07 |
jari |
1290 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1291 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1292 |
} |
2 |
26 Feb 07 |
jari |
1293 |
event2.setIntValue(permCounter); |
2 |
26 Feb 07 |
jari |
1294 |
event2.setDescription("Permuting matrix: Current permutation = " + (permCounter+1)); |
2 |
26 Feb 07 |
jari |
1295 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1296 |
|
2 |
26 Feb 07 |
jari |
1297 |
int[] notInCombArray = new int[numGroupBValues]; |
2 |
26 Feb 07 |
jari |
1298 |
int notCombCounter = 0; |
2 |
26 Feb 07 |
jari |
1299 |
|
2 |
26 Feb 07 |
jari |
1300 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1301 |
if(!belongsInArray(i, combArray)) { |
2 |
26 Feb 07 |
jari |
1302 |
notInCombArray[notCombCounter] = i; |
2 |
26 Feb 07 |
jari |
1303 |
notCombCounter++; |
2 |
26 Feb 07 |
jari |
1304 |
} |
2 |
26 Feb 07 |
jari |
1305 |
} |
2 |
26 Feb 07 |
jari |
1306 |
|
2 |
26 Feb 07 |
jari |
1307 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1308 |
permutedExpts[usedExptsArray[i]] = usedExptsArray[combArray[i]]; |
2 |
26 Feb 07 |
jari |
1309 |
} |
2 |
26 Feb 07 |
jari |
1310 |
for (int i = 0; i < notInCombArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1311 |
permutedExpts[usedExptsArray[combArray.length + i]] = usedExptsArray[notInCombArray[i]]; |
2 |
26 Feb 07 |
jari |
1312 |
} |
2 |
26 Feb 07 |
jari |
1313 |
|
2 |
26 Feb 07 |
jari |
1314 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1315 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1316 |
int[] currPermDfValues = getTwoClassDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1317 |
|
2 |
26 Feb 07 |
jari |
1318 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1319 |
|
2 |
26 Feb 07 |
jari |
1320 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1321 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1323 |
} |
2 |
26 Feb 07 |
jari |
1324 |
|
2 |
26 Feb 07 |
jari |
1325 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1326 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1327 |
uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1328 |
|
2 |
26 Feb 07 |
jari |
1329 |
permCounter++; |
2 |
26 Feb 07 |
jari |
1330 |
} |
2 |
26 Feb 07 |
jari |
1331 |
|
2 |
26 Feb 07 |
jari |
1332 |
} |
2 |
26 Feb 07 |
jari |
1333 |
|
2 |
26 Feb 07 |
jari |
1334 |
} else if (tTestDesign == Ttest.PAIRED) { |
2 |
26 Feb 07 |
jari |
1335 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
1336 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
1337 |
/* |
2 |
26 Feb 07 |
jari |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1341 |
} |
2 |
26 Feb 07 |
jari |
1342 |
*/ |
2 |
26 Feb 07 |
jari |
1343 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1344 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1345 |
event2.setDescription("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1346 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1347 |
long randomSeed = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1348 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1349 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1350 |
} |
2 |
26 Feb 07 |
jari |
1351 |
int[] permutedExpts = permuteWithinPairs(randomSeed); //returns an int array with some paired experiment indices permuted |
2 |
26 Feb 07 |
jari |
1352 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1353 |
double[] currentPermTValues = getPairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1354 |
int[] currPermDfValues = getPairedDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1355 |
|
2 |
26 Feb 07 |
jari |
1356 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1357 |
|
2 |
26 Feb 07 |
jari |
1358 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1359 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1361 |
} |
2 |
26 Feb 07 |
jari |
1362 |
|
2 |
26 Feb 07 |
jari |
1363 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1364 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1365 |
uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1366 |
} |
2 |
26 Feb 07 |
jari |
1367 |
|
2 |
26 Feb 07 |
jari |
1368 |
} else { // if (useAllCombs) |
2 |
26 Feb 07 |
jari |
1369 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1370 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1371 |
event2.setDescription("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1372 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
1373 |
int[] permutedExpts = permuteWithinPairsAllPerms(i); |
2 |
26 Feb 07 |
jari |
1374 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1375 |
|
2 |
26 Feb 07 |
jari |
1376 |
double[] currentPermTValues = getPairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1377 |
int[] currPermDfValues = getPairedDfs(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1378 |
|
2 |
26 Feb 07 |
jari |
1379 |
double[] currPermPVals = getParametricPVals(currentPermTValues, currPermDfValues); |
2 |
26 Feb 07 |
jari |
1380 |
|
2 |
26 Feb 07 |
jari |
1381 |
for (int j = 0; j < currPermPVals.length; j++) { |
2 |
26 Feb 07 |
jari |
1382 |
if (Double.isNaN(currPermPVals[j])) currPermPVals[j] = Double.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
// this is to push NaNs to the end of the sorted array, since otherwise they would mess up quantile calculations |
2 |
26 Feb 07 |
jari |
1384 |
} |
2 |
26 Feb 07 |
jari |
1385 |
|
2 |
26 Feb 07 |
jari |
1386 |
QSort sortCurrPVals = new QSort(currPermPVals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1387 |
double[] sortedCurrPVals = sortCurrPVals.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1388 |
uPlusOneSmallestPVector.add(new Double(sortedCurrPVals[u])); |
2 |
26 Feb 07 |
jari |
1389 |
} |
2 |
26 Feb 07 |
jari |
1390 |
} |
2 |
26 Feb 07 |
jari |
1391 |
}// end if (tTestDesign == this.PAIRED) |
2 |
26 Feb 07 |
jari |
1392 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("uPlusOneSmallestPVector.size() = " + uPlusOneSmallestPVector.size()); |
2 |
26 Feb 07 |
jari |
1394 |
double[] uPlusOneSmallestArray = new double[uPlusOneSmallestPVector.size()]; |
2 |
26 Feb 07 |
jari |
1395 |
for(int i = 0; i < uPlusOneSmallestPVector.size(); i++) { |
2 |
26 Feb 07 |
jari |
1396 |
uPlusOneSmallestArray[i] = ((Double)(uPlusOneSmallestPVector.get(i))).doubleValue(); |
2 |
26 Feb 07 |
jari |
1397 |
} |
2 |
26 Feb 07 |
jari |
1398 |
|
2 |
26 Feb 07 |
jari |
1399 |
QSort sortUPlusOneArray = new QSort(uPlusOneSmallestArray, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
1400 |
double[] sortedUPlusOneArray = sortUPlusOneArray.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
1401 |
|
2 |
26 Feb 07 |
jari |
1402 |
int selectedIndex = (int)Math.floor(sortedUPlusOneArray.length*alphaQuantile) - 1; |
2 |
26 Feb 07 |
jari |
//System.out.println("Selected index (before setting to zero) = " + selectedIndex); |
2 |
26 Feb 07 |
jari |
1404 |
if (selectedIndex < 0) selectedIndex = 0; |
2 |
26 Feb 07 |
jari |
1405 |
|
2 |
26 Feb 07 |
jari |
1406 |
return sortedUPlusOneArray[selectedIndex]; |
2 |
26 Feb 07 |
jari |
//return null; //for now |
2 |
26 Feb 07 |
jari |
1408 |
} |
2 |
26 Feb 07 |
jari |
1409 |
|
2 |
26 Feb 07 |
jari |
1410 |
private double getMinY(double alphaQuantile, int r, int u) {//this is for exhaustive sampling for false significant number calculation |
2 |
26 Feb 07 |
jari |
1411 |
|
2 |
26 Feb 07 |
jari |
1412 |
return 0.0d; // for now |
2 |
26 Feb 07 |
jari |
1413 |
} |
2 |
26 Feb 07 |
jari |
1414 |
|
2 |
26 Feb 07 |
jari |
1415 |
private double[] getOneClassRawPValsFromPerms() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
1416 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
1417 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
1418 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
1419 |
double[] rawPVals = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
1420 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
1421 |
if (Double.isNaN(tValues[i])) { |
2 |
26 Feb 07 |
jari |
1422 |
rawPVals[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
1423 |
} else { |
2 |
26 Feb 07 |
jari |
1424 |
rawPVals[i] = 0d; |
2 |
26 Feb 07 |
jari |
1425 |
} |
2 |
26 Feb 07 |
jari |
1426 |
} |
2 |
26 Feb 07 |
jari |
1427 |
|
2 |
26 Feb 07 |
jari |
1428 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
1429 |
boolean[] changeSign = new boolean[1]; |
2 |
26 Feb 07 |
jari |
1430 |
|
2 |
26 Feb 07 |
jari |
1431 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
1432 |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
1433 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1434 |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1435 |
} |
2 |
26 Feb 07 |
jari |
1436 |
|
2 |
26 Feb 07 |
jari |
1437 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1438 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1439 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1440 |
} |
2 |
26 Feb 07 |
jari |
1441 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1442 |
event.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
1443 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
1444 |
|
2 |
26 Feb 07 |
jari |
1445 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
1446 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
1447 |
|
2 |
26 Feb 07 |
jari |
1448 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
1449 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
1450 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
1451 |
} |
2 |
26 Feb 07 |
jari |
1452 |
} |
2 |
26 Feb 07 |
jari |
1453 |
|
2 |
26 Feb 07 |
jari |
1454 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
1455 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1456 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
1457 |
} |
2 |
26 Feb 07 |
jari |
1458 |
|
2 |
26 Feb 07 |
jari |
1459 |
changeSign = getOneClassChangeSignArray(randomSeeds[i], validArray); |
2 |
26 Feb 07 |
jari |
1460 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
1461 |
|
2 |
26 Feb 07 |
jari |
1462 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1463 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
1464 |
if (tValues[gene] < currentPermTValues[gene]) { |
2 |
26 Feb 07 |
jari |
1465 |
rawPVals[gene] = rawPVals[gene] + 1d; |
2 |
26 Feb 07 |
jari |
1466 |
} |
2 |
26 Feb 07 |
jari |
1467 |
} |
2 |
26 Feb 07 |
jari |
1468 |
} |
2 |
26 Feb 07 |
jari |
1469 |
|
2 |
26 Feb 07 |
jari |
1470 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
1471 |
rawPVals[i] = rawPVals[i]/(double)numCombs; |
2 |
26 Feb 07 |
jari |
1472 |
} |
2 |
26 Feb 07 |
jari |
1473 |
|
2 |
26 Feb 07 |
jari |
1474 |
} else { //if (useAllCombs) |
2 |
26 Feb 07 |
jari |
1475 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1476 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1477 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1478 |
} |
2 |
26 Feb 07 |
jari |
1479 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1480 |
event.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
1481 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
1482 |
|
2 |
26 Feb 07 |
jari |
1483 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
1484 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
1485 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
1486 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
1487 |
} |
2 |
26 Feb 07 |
jari |
1488 |
} |
2 |
26 Feb 07 |
jari |
1489 |
|
2 |
26 Feb 07 |
jari |
1490 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
1491 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
1492 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
1493 |
} |
2 |
26 Feb 07 |
jari |
1494 |
|
2 |
26 Feb 07 |
jari |
1495 |
boolean[] changeSign = getOneClassChangeSignArrayAllUniquePerms(i, validArray); |
2 |
26 Feb 07 |
jari |
1496 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
1497 |
|
2 |
26 Feb 07 |
jari |
1498 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
1499 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
1500 |
if (tValues[gene] < currentPermTValues[gene]) { |
2 |
26 Feb 07 |
jari |
1501 |
rawPVals[gene] = rawPVals[gene] + 1d; |
2 |
26 Feb 07 |
jari |
1502 |
} |
2 |
26 Feb 07 |
jari |
1503 |
} |
2 |
26 Feb 07 |
jari |
1504 |
} |
2 |
26 Feb 07 |
jari |
1505 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
1506 |
rawPVals[i] = rawPVals[i]/(double)numCombs; |
2 |
26 Feb 07 |
jari |
1507 |
} |
2 |
26 Feb 07 |
jari |
1508 |
} |
2 |
26 Feb 07 |
jari |
1509 |
/* |
2 |
26 Feb 07 |
jari |
if (useAllCombs) { |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
if (stop) { |
2 |
26 Feb 07 |
jari |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1514 |
} |
2 |
26 Feb 07 |
jari |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
event.setDescription("Calculating raw p values: gene = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
rawPVals[i] = (double)(getAllCombsOneClassProb(i)); |
2 |
26 Feb 07 |
jari |
1519 |
} |
2 |
26 Feb 07 |
jari |
1520 |
|
2 |
26 Feb 07 |
jari |
} else {// if (!useAllCombs) |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
if (stop) { |
2 |
26 Feb 07 |
jari |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1525 |
} |
2 |
26 Feb 07 |
jari |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
event.setDescription("Calculating raw p values: gene = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
rawPVals[i] = getSomeCombsOneClassProb(i); |
2 |
26 Feb 07 |
jari |
1530 |
} |
2 |
26 Feb 07 |
jari |
1531 |
} |
2 |
26 Feb 07 |
jari |
1532 |
*/ |
2 |
26 Feb 07 |
jari |
1533 |
return rawPVals; |
2 |
26 Feb 07 |
jari |
1534 |
} |
2 |
26 Feb 07 |
jari |
1535 |
|
2 |
26 Feb 07 |
jari |
1536 |
private float getAllCombsOneClassProb(int gene) { |
2 |
26 Feb 07 |
jari |
1537 |
|
2 |
26 Feb 07 |
jari |
1538 |
int validNumExps = getNumValidOneClassExpts(); |
2 |
26 Feb 07 |
jari |
1539 |
int numAllPossOneClassPerms = (int)(Math.pow(2, validNumExps)); |
2 |
26 Feb 07 |
jari |
1540 |
float[] currentGene = expMatrix.A[gene]; |
2 |
26 Feb 07 |
jari |
1541 |
float[] origGeneValues = getOneClassGeneValues(gene); |
2 |
26 Feb 07 |
jari |
1542 |
float origOneClassT = (float)Math.abs(getOneClassTValue(origGeneValues)); |
2 |
26 Feb 07 |
jari |
1543 |
if (Float.isNaN(origOneClassT)) { |
2 |
26 Feb 07 |
jari |
1544 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
1545 |
} |
2 |
26 Feb 07 |
jari |
1546 |
int exceedCount = 0; |
2 |
26 Feb 07 |
jari |
1547 |
|
2 |
26 Feb 07 |
jari |
1548 |
for (int j = 0; j < numAllPossOneClassPerms; j++) { |
2 |
26 Feb 07 |
jari |
1549 |
boolean[] changeSign = getOneClassPermutArray(j); |
2 |
26 Feb 07 |
jari |
1550 |
float[] randomizedGene = new float[currentGene.length]; |
2 |
26 Feb 07 |
jari |
1551 |
|
2 |
26 Feb 07 |
jari |
1552 |
for (int l = 0; l < changeSign.length; l++) { |
2 |
26 Feb 07 |
jari |
1553 |
if (changeSign[l]) { |
2 |
26 Feb 07 |
jari |
1554 |
randomizedGene[l] = (float)(currentGene[l] - 2.0f*(currentGene[l] - oneClassMean)); |
2 |
26 Feb 07 |
jari |
1555 |
} else { |
2 |
26 Feb 07 |
jari |
1556 |
randomizedGene[l] = currentGene[l]; |
2 |
26 Feb 07 |
jari |
1557 |
} |
2 |
26 Feb 07 |
jari |
1558 |
} |
2 |
26 Feb 07 |
jari |
1559 |
|
2 |
26 Feb 07 |
jari |
1560 |
float[] reducedRandGene = new float[validNumExps]; |
2 |
26 Feb 07 |
jari |
1561 |
int count = 0; |
2 |
26 Feb 07 |
jari |
1562 |
for (int l = 0; l < groupAssignments.length; l++) { |
2 |
26 Feb 07 |
jari |
1563 |
if (groupAssignments[l] == 1) { |
2 |
26 Feb 07 |
jari |
1564 |
reducedRandGene[count] = randomizedGene[l]; |
2 |
26 Feb 07 |
jari |
1565 |
count++; |
2 |
26 Feb 07 |
jari |
1566 |
} |
2 |
26 Feb 07 |
jari |
1567 |
} |
2 |
26 Feb 07 |
jari |
1568 |
|
2 |
26 Feb 07 |
jari |
1569 |
double randTValue = Math.abs(getOneClassTValue(reducedRandGene)); |
2 |
26 Feb 07 |
jari |
1570 |
if (randTValue > origOneClassT) { |
2 |
26 Feb 07 |
jari |
1571 |
exceedCount++; |
2 |
26 Feb 07 |
jari |
1572 |
} |
2 |
26 Feb 07 |
jari |
1573 |
|
2 |
26 Feb 07 |
jari |
1574 |
} |
2 |
26 Feb 07 |
jari |
1575 |
|
2 |
26 Feb 07 |
jari |
//System.out.println(); |
2 |
26 Feb 07 |
jari |
1577 |
double prob = (double)exceedCount / (double)numAllPossOneClassPerms; |
2 |
26 Feb 07 |
jari |
1578 |
|
2 |
26 Feb 07 |
jari |
1579 |
return (float)prob; |
2 |
26 Feb 07 |
jari |
1580 |
} |
2 |
26 Feb 07 |
jari |
1581 |
|
2 |
26 Feb 07 |
jari |
1582 |
private boolean[] getOneClassChangeSignArray(long seed, int[] validExpts) { |
2 |
26 Feb 07 |
jari |
1583 |
boolean[] changeSignArray = new boolean[numExps]; |
2 |
26 Feb 07 |
jari |
1584 |
for (int i = 0; i < changeSignArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1585 |
changeSignArray[i] = false; |
2 |
26 Feb 07 |
jari |
1586 |
} |
2 |
26 Feb 07 |
jari |
1587 |
|
2 |
26 Feb 07 |
jari |
1588 |
Random generator2 = new Random(seed); |
2 |
26 Feb 07 |
jari |
1589 |
for (int i = 0; i < validExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
1590 |
changeSignArray[validExpts[i]] = generator2.nextBoolean(); |
2 |
26 Feb 07 |
jari |
1591 |
} |
2 |
26 Feb 07 |
jari |
1592 |
|
2 |
26 Feb 07 |
jari |
1593 |
return changeSignArray; |
2 |
26 Feb 07 |
jari |
1594 |
} |
2 |
26 Feb 07 |
jari |
1595 |
|
2 |
26 Feb 07 |
jari |
1596 |
private FloatMatrix getOneClassPermMatrix(FloatMatrix inputMatrix, boolean[] changeSign) { |
2 |
26 Feb 07 |
jari |
1597 |
FloatMatrix permutedMatrix = new FloatMatrix(inputMatrix.getRowDimension(), inputMatrix.getColumnDimension()); |
2 |
26 Feb 07 |
jari |
1598 |
|
2 |
26 Feb 07 |
jari |
1599 |
for (int i = 0; i < inputMatrix.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
1600 |
for (int j = 0; j < inputMatrix.getColumnDimension(); j++) { |
2 |
26 Feb 07 |
jari |
1601 |
if (changeSign[j]) { |
2 |
26 Feb 07 |
jari |
1602 |
permutedMatrix.A[i][j] = (float)(inputMatrix.A[i][j] - 2.0f*(inputMatrix.A[i][j] - oneClassMean)); |
2 |
26 Feb 07 |
jari |
1603 |
} else { |
2 |
26 Feb 07 |
jari |
1604 |
permutedMatrix.A[i][j] = inputMatrix.A[i][j]; |
2 |
26 Feb 07 |
jari |
1605 |
} |
2 |
26 Feb 07 |
jari |
1606 |
} |
2 |
26 Feb 07 |
jari |
1607 |
} |
2 |
26 Feb 07 |
jari |
1608 |
|
2 |
26 Feb 07 |
jari |
1609 |
return permutedMatrix; |
2 |
26 Feb 07 |
jari |
1610 |
} |
2 |
26 Feb 07 |
jari |
1611 |
|
2 |
26 Feb 07 |
jari |
1612 |
private boolean[] getOneClassChangeSignArrayAllUniquePerms(int num, int[] validExpts) { |
2 |
26 Feb 07 |
jari |
1613 |
boolean[] changeSignArray = new boolean[numExps]; |
2 |
26 Feb 07 |
jari |
1614 |
for (int i = 0; i < changeSignArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1615 |
changeSignArray[i] = false; |
2 |
26 Feb 07 |
jari |
1616 |
} |
2 |
26 Feb 07 |
jari |
1617 |
|
2 |
26 Feb 07 |
jari |
//Random generator2 = new Random(seed); |
2 |
26 Feb 07 |
jari |
1619 |
int numValidExps = validExpts.length; |
2 |
26 Feb 07 |
jari |
1620 |
|
2 |
26 Feb 07 |
jari |
1621 |
String binaryString = Integer.toBinaryString(num); |
2 |
26 Feb 07 |
jari |
//System.out.println(binaryString); |
2 |
26 Feb 07 |
jari |
1623 |
char[] binArray = binaryString.toCharArray(); |
2 |
26 Feb 07 |
jari |
1624 |
if (binArray.length < numValidExps) { |
2 |
26 Feb 07 |
jari |
1625 |
Vector binVector = new Vector(); |
2 |
26 Feb 07 |
jari |
1626 |
for (int i = 0; i < (numValidExps - binArray.length); i++) { |
2 |
26 Feb 07 |
jari |
1627 |
binVector.add(new Character('0')); |
2 |
26 Feb 07 |
jari |
1628 |
} |
2 |
26 Feb 07 |
jari |
1629 |
|
2 |
26 Feb 07 |
jari |
1630 |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1631 |
binVector.add(new Character(binArray[i])); |
2 |
26 Feb 07 |
jari |
1632 |
} |
2 |
26 Feb 07 |
jari |
1633 |
binArray = new char[binVector.size()]; |
2 |
26 Feb 07 |
jari |
1634 |
|
2 |
26 Feb 07 |
jari |
1635 |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1636 |
binArray[i] = ((Character)(binVector.get(i))).charValue(); |
2 |
26 Feb 07 |
jari |
1637 |
} |
2 |
26 Feb 07 |
jari |
1638 |
} |
2 |
26 Feb 07 |
jari |
1639 |
|
2 |
26 Feb 07 |
jari |
1640 |
for (int i = 0; i < validExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
1641 |
if (binArray[i] == '1') { |
2 |
26 Feb 07 |
jari |
1642 |
changeSignArray[validExpts[i]] = true; |
2 |
26 Feb 07 |
jari |
1643 |
} else { |
2 |
26 Feb 07 |
jari |
1644 |
changeSignArray[validExpts[i]] = false; |
2 |
26 Feb 07 |
jari |
1645 |
} |
2 |
26 Feb 07 |
jari |
1646 |
} |
2 |
26 Feb 07 |
jari |
1647 |
|
2 |
26 Feb 07 |
jari |
1648 |
return changeSignArray; |
2 |
26 Feb 07 |
jari |
1649 |
} |
2 |
26 Feb 07 |
jari |
1650 |
|
2 |
26 Feb 07 |
jari |
1651 |
boolean[] getOneClassPermutArray(int num) { |
2 |
26 Feb 07 |
jari |
1652 |
boolean[] oneClassPermutArray = new boolean[numExps]; |
2 |
26 Feb 07 |
jari |
1653 |
|
2 |
26 Feb 07 |
jari |
1654 |
for (int i = 0; i < oneClassPermutArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1655 |
oneClassPermutArray[i] = false; |
2 |
26 Feb 07 |
jari |
1656 |
} |
2 |
26 Feb 07 |
jari |
1657 |
|
2 |
26 Feb 07 |
jari |
1658 |
int validNumExps = getNumValidOneClassExpts(); |
2 |
26 Feb 07 |
jari |
1659 |
|
2 |
26 Feb 07 |
jari |
1660 |
String binaryString = Integer.toBinaryString(num); |
2 |
26 Feb 07 |
jari |
//System.out.println(binaryString); |
2 |
26 Feb 07 |
jari |
1662 |
char[] binArray = binaryString.toCharArray(); |
2 |
26 Feb 07 |
jari |
1663 |
if (binArray.length < validNumExps) { |
2 |
26 Feb 07 |
jari |
1664 |
Vector binVector = new Vector(); |
2 |
26 Feb 07 |
jari |
1665 |
for (int i = 0; i < (validNumExps - binArray.length); i++) { |
2 |
26 Feb 07 |
jari |
1666 |
binVector.add(new Character('0')); |
2 |
26 Feb 07 |
jari |
1667 |
} |
2 |
26 Feb 07 |
jari |
1668 |
|
2 |
26 Feb 07 |
jari |
1669 |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1670 |
binVector.add(new Character(binArray[i])); |
2 |
26 Feb 07 |
jari |
1671 |
} |
2 |
26 Feb 07 |
jari |
1672 |
binArray = new char[binVector.size()]; |
2 |
26 Feb 07 |
jari |
1673 |
|
2 |
26 Feb 07 |
jari |
1674 |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1675 |
binArray[i] = ((Character)(binVector.get(i))).charValue(); |
2 |
26 Feb 07 |
jari |
1676 |
} |
2 |
26 Feb 07 |
jari |
1677 |
} |
2 |
26 Feb 07 |
jari |
1678 |
/* |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
System.out.print(binArray[i]); |
2 |
26 Feb 07 |
jari |
1681 |
} |
2 |
26 Feb 07 |
jari |
System.out.println(); |
2 |
26 Feb 07 |
jari |
1683 |
*/ |
2 |
26 Feb 07 |
jari |
1684 |
int counter = 0; |
2 |
26 Feb 07 |
jari |
1685 |
|
2 |
26 Feb 07 |
jari |
1686 |
for (int i = 0; i < oneClassPermutArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1687 |
if (groupAssignments[i] == 1) { |
2 |
26 Feb 07 |
jari |
1688 |
if (binArray[counter] == '1') { |
2 |
26 Feb 07 |
jari |
1689 |
oneClassPermutArray[i] = true; |
2 |
26 Feb 07 |
jari |
1690 |
} else { |
2 |
26 Feb 07 |
jari |
1691 |
oneClassPermutArray[i] = false; |
2 |
26 Feb 07 |
jari |
1692 |
} |
2 |
26 Feb 07 |
jari |
1693 |
counter++; |
2 |
26 Feb 07 |
jari |
1694 |
} |
2 |
26 Feb 07 |
jari |
1695 |
} |
2 |
26 Feb 07 |
jari |
1696 |
/* |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < oneClassPermutArray.length; i++) { |
2 |
26 Feb 07 |
jari |
System.out.print(oneClassPermutArray[i] + " "); |
2 |
26 Feb 07 |
jari |
1699 |
} |
2 |
26 Feb 07 |
jari |
System.out.println(); |
2 |
26 Feb 07 |
jari |
1701 |
*/ |
2 |
26 Feb 07 |
jari |
1702 |
return oneClassPermutArray; |
2 |
26 Feb 07 |
jari |
1703 |
} |
2 |
26 Feb 07 |
jari |
1704 |
|
2 |
26 Feb 07 |
jari |
1705 |
public int getNumValidOneClassExpts() { |
2 |
26 Feb 07 |
jari |
1706 |
int validNum = 0; |
2 |
26 Feb 07 |
jari |
1707 |
|
2 |
26 Feb 07 |
jari |
1708 |
for (int i =0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
1709 |
if (groupAssignments[i] == 1) { |
2 |
26 Feb 07 |
jari |
1710 |
validNum++; |
2 |
26 Feb 07 |
jari |
1711 |
} |
2 |
26 Feb 07 |
jari |
1712 |
} |
2 |
26 Feb 07 |
jari |
1713 |
|
2 |
26 Feb 07 |
jari |
1714 |
return validNum; |
2 |
26 Feb 07 |
jari |
1715 |
} |
2 |
26 Feb 07 |
jari |
1716 |
|
2 |
26 Feb 07 |
jari |
1717 |
private float[] getOneClassGeneValues(int gene) { |
2 |
26 Feb 07 |
jari |
1718 |
Vector currentGene = new Vector(); |
2 |
26 Feb 07 |
jari |
1719 |
|
2 |
26 Feb 07 |
jari |
1720 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
1721 |
if (groupAssignments[i] == 1) { |
2 |
26 Feb 07 |
jari |
1722 |
currentGene.add(new Float(expMatrix.A[gene][i])); |
2 |
26 Feb 07 |
jari |
1723 |
} |
2 |
26 Feb 07 |
jari |
1724 |
} |
2 |
26 Feb 07 |
jari |
1725 |
|
2 |
26 Feb 07 |
jari |
1726 |
float[] currGeneArray = new float[currentGene.size()]; |
2 |
26 Feb 07 |
jari |
1727 |
|
2 |
26 Feb 07 |
jari |
1728 |
for (int i = 0; i < currGeneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1729 |
currGeneArray[i] = ((Float)(currentGene.get(i))).floatValue(); |
2 |
26 Feb 07 |
jari |
1730 |
} |
2 |
26 Feb 07 |
jari |
1731 |
|
2 |
26 Feb 07 |
jari |
1732 |
return currGeneArray; |
2 |
26 Feb 07 |
jari |
1733 |
} |
2 |
26 Feb 07 |
jari |
1734 |
|
2 |
26 Feb 07 |
jari |
1735 |
private double getOneClassTValue(int gene, FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
1736 |
Vector currentGene = new Vector(); |
2 |
26 Feb 07 |
jari |
1737 |
|
2 |
26 Feb 07 |
jari |
1738 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
1739 |
if (groupAssignments[i] == 1) { |
2 |
26 Feb 07 |
jari |
1740 |
currentGene.add(new Float(inputMatrix.A[gene][i])); |
2 |
26 Feb 07 |
jari |
1741 |
} |
2 |
26 Feb 07 |
jari |
1742 |
} |
2 |
26 Feb 07 |
jari |
1743 |
|
2 |
26 Feb 07 |
jari |
1744 |
float[] currGeneArray = new float[currentGene.size()]; |
2 |
26 Feb 07 |
jari |
1745 |
|
2 |
26 Feb 07 |
jari |
1746 |
for (int i = 0; i < currGeneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1747 |
currGeneArray[i] = ((Float)(currentGene.get(i))).floatValue(); |
2 |
26 Feb 07 |
jari |
1748 |
} |
2 |
26 Feb 07 |
jari |
1749 |
|
2 |
26 Feb 07 |
jari |
1750 |
return getOneClassTValue(currGeneArray); |
2 |
26 Feb 07 |
jari |
1751 |
} |
2 |
26 Feb 07 |
jari |
1752 |
|
2 |
26 Feb 07 |
jari |
1753 |
private float getSomeCombsOneClassProb(int gene) { |
2 |
26 Feb 07 |
jari |
1754 |
|
2 |
26 Feb 07 |
jari |
1755 |
int validNumExps = getNumValidOneClassExpts(); |
2 |
26 Feb 07 |
jari |
//int numAllPossOneClassPerms = (int)(Math.pow(2, validNumExps)); |
2 |
26 Feb 07 |
jari |
1757 |
float[] currentGene = expMatrix.A[gene]; |
2 |
26 Feb 07 |
jari |
1758 |
float[] origGeneValues = getOneClassGeneValues(gene); |
2 |
26 Feb 07 |
jari |
1759 |
float origOneClassT = (float)Math.abs(getOneClassTValue(origGeneValues)); |
2 |
26 Feb 07 |
jari |
1760 |
if (Float.isNaN(origOneClassT)) { |
2 |
26 Feb 07 |
jari |
1761 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
1762 |
} |
2 |
26 Feb 07 |
jari |
1763 |
|
2 |
26 Feb 07 |
jari |
1764 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
1765 |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
1766 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1767 |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1768 |
} |
2 |
26 Feb 07 |
jari |
1769 |
|
2 |
26 Feb 07 |
jari |
1770 |
int exceedCount = 0; |
2 |
26 Feb 07 |
jari |
1771 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1772 |
boolean[] changeSign = getSomeCombsPermutArray(randomSeeds[i]); |
2 |
26 Feb 07 |
jari |
1773 |
float[] randomizedGene = new float[origGeneValues.length]; |
2 |
26 Feb 07 |
jari |
1774 |
|
2 |
26 Feb 07 |
jari |
1775 |
for (int l = 0; l < changeSign.length; l++) { |
2 |
26 Feb 07 |
jari |
1776 |
if (changeSign[l]) { |
2 |
26 Feb 07 |
jari |
1777 |
randomizedGene[l] = (float)(origGeneValues[l] - 2.0f*(origGeneValues[l] - oneClassMean)); |
2 |
26 Feb 07 |
jari |
1778 |
} else { |
2 |
26 Feb 07 |
jari |
1779 |
randomizedGene[l] = origGeneValues[l]; |
2 |
26 Feb 07 |
jari |
1780 |
} |
2 |
26 Feb 07 |
jari |
1781 |
} |
2 |
26 Feb 07 |
jari |
1782 |
|
2 |
26 Feb 07 |
jari |
1783 |
double randTValue = Math.abs(getOneClassTValue(randomizedGene)); |
2 |
26 Feb 07 |
jari |
1784 |
if (randTValue > origOneClassT) { |
2 |
26 Feb 07 |
jari |
1785 |
exceedCount++; |
2 |
26 Feb 07 |
jari |
1786 |
} |
2 |
26 Feb 07 |
jari |
1787 |
} |
2 |
26 Feb 07 |
jari |
1788 |
|
2 |
26 Feb 07 |
jari |
//System.out.println(); |
2 |
26 Feb 07 |
jari |
1790 |
|
2 |
26 Feb 07 |
jari |
1791 |
double prob = (double)exceedCount / (double)numCombs; |
2 |
26 Feb 07 |
jari |
1792 |
|
2 |
26 Feb 07 |
jari |
1793 |
return (float)prob; |
2 |
26 Feb 07 |
jari |
1794 |
} |
2 |
26 Feb 07 |
jari |
1795 |
|
2 |
26 Feb 07 |
jari |
1796 |
private boolean[] getSomeCombsPermutArray(long seed) { |
2 |
26 Feb 07 |
jari |
1797 |
boolean[] boolArray = new boolean[getNumValidOneClassExpts()]; |
2 |
26 Feb 07 |
jari |
1798 |
for (int i = 0; i < boolArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1799 |
boolArray[i] = false; |
2 |
26 Feb 07 |
jari |
1800 |
} |
2 |
26 Feb 07 |
jari |
1801 |
|
2 |
26 Feb 07 |
jari |
1802 |
Random generator2 =new Random(seed); |
2 |
26 Feb 07 |
jari |
1803 |
for (int i = 0; i < boolArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1804 |
|
2 |
26 Feb 07 |
jari |
1805 |
boolArray[i] = generator2.nextBoolean(); |
2 |
26 Feb 07 |
jari |
//System.out.print(boolArray[i] + " "); |
2 |
26 Feb 07 |
jari |
1807 |
/* |
2 |
26 Feb 07 |
jari |
try { |
2 |
26 Feb 07 |
jari |
Thread.sleep(10); |
2 |
26 Feb 07 |
jari |
} catch (Exception exc) { |
2 |
26 Feb 07 |
jari |
exc.printStackTrace(); |
2 |
26 Feb 07 |
jari |
1812 |
} |
2 |
26 Feb 07 |
jari |
1813 |
*/ |
2 |
26 Feb 07 |
jari |
1814 |
|
2 |
26 Feb 07 |
jari |
1815 |
} |
2 |
26 Feb 07 |
jari |
1816 |
|
2 |
26 Feb 07 |
jari |
//System.out.println(); |
2 |
26 Feb 07 |
jari |
1818 |
return boolArray; |
2 |
26 Feb 07 |
jari |
1819 |
} |
2 |
26 Feb 07 |
jari |
1820 |
|
2 |
26 Feb 07 |
jari |
1821 |
private double[] getPairedRawPValsFromPerms() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
1822 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
1823 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
1824 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
1825 |
double[] rawPVals = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
1826 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
1827 |
if (Double.isNaN(tValues[i])) { |
2 |
26 Feb 07 |
jari |
1828 |
rawPVals[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
1829 |
} else { |
2 |
26 Feb 07 |
jari |
1830 |
rawPVals[i] = 0d; |
2 |
26 Feb 07 |
jari |
1831 |
} |
2 |
26 Feb 07 |
jari |
1832 |
} |
2 |
26 Feb 07 |
jari |
1833 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
1834 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
1835 |
/* |
2 |
26 Feb 07 |
jari |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1839 |
} |
2 |
26 Feb 07 |
jari |
1840 |
*/ |
2 |
26 Feb 07 |
jari |
1841 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1842 |
long randomSeed = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1843 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1844 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1845 |
} |
2 |
26 Feb 07 |
jari |
1846 |
int[] permutedExpts = permuteWithinPairs(randomSeed); //returns an int array with some paired experiment indices permuted |
2 |
26 Feb 07 |
jari |
1847 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1848 |
|
2 |
26 Feb 07 |
jari |
1849 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1850 |
event.setDescription("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1851 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
//System.out.println("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1853 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
1854 |
double currT = getPairedTValue(gene, permutedMatrix); |
2 |
26 Feb 07 |
jari |
1855 |
if (tValues[gene] < currT) { |
2 |
26 Feb 07 |
jari |
1856 |
rawPVals[gene] = rawPVals[gene] + 1d; |
2 |
26 Feb 07 |
jari |
1857 |
} |
2 |
26 Feb 07 |
jari |
1858 |
} |
2 |
26 Feb 07 |
jari |
1859 |
} |
2 |
26 Feb 07 |
jari |
1860 |
} else { //if (useAllCombs) |
2 |
26 Feb 07 |
jari |
1861 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
1862 |
if (stop) { |
2 |
26 Feb 07 |
jari |
1863 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1864 |
} |
2 |
26 Feb 07 |
jari |
1865 |
int[] permutedExpts = permuteWithinPairsAllPerms(i); |
2 |
26 Feb 07 |
jari |
1866 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
1867 |
|
2 |
26 Feb 07 |
jari |
1868 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
1869 |
event.setDescription("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1870 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
//System.out.println("Calculating raw p values: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
1872 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
1873 |
double currT = getPairedTValue(gene, permutedMatrix); |
2 |
26 Feb 07 |
jari |
1874 |
if (tValues[gene] < currT) { |
2 |
26 Feb 07 |
jari |
1875 |
rawPVals[gene] = rawPVals[gene] + 1d; |
2 |
26 Feb 07 |
jari |
1876 |
} |
2 |
26 Feb 07 |
jari |
1877 |
} |
2 |
26 Feb 07 |
jari |
1878 |
} |
2 |
26 Feb 07 |
jari |
1879 |
} |
2 |
26 Feb 07 |
jari |
1880 |
|
2 |
26 Feb 07 |
jari |
1881 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
1882 |
rawPVals[i] = rawPVals[i]/(double)numCombs; |
2 |
26 Feb 07 |
jari |
1883 |
} |
2 |
26 Feb 07 |
jari |
1884 |
/* |
2 |
26 Feb 07 |
jari |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
//System.out.println("Current gene = " + gene); |
2 |
26 Feb 07 |
jari |
if (stop) { |
2 |
26 Feb 07 |
jari |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
1889 |
} |
2 |
26 Feb 07 |
jari |
event.setIntValue(gene); |
2 |
26 Feb 07 |
jari |
event.setDescription("Calculating raw p values: Current gene = " + (gene + 1)); |
2 |
26 Feb 07 |
jari |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
if (Double.isNaN(tValues[gene])) { |
2 |
26 Feb 07 |
jari |
rawPVals[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
} else { |
2 |
26 Feb 07 |
jari |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
1901 |
} |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
int[] permutedExpts = permuteWithinPairs(randomSeeds[i]); //returns an int array with some paired experiment indices permuted |
2 |
26 Feb 07 |
jari |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
//double[] permTValues |
2 |
26 Feb 07 |
jari |
1906 |
} |
2 |
26 Feb 07 |
jari |
1907 |
|
2 |
26 Feb 07 |
jari |
} else { // if (useAllCombs) |
2 |
26 Feb 07 |
jari |
1909 |
} |
2 |
26 Feb 07 |
jari |
1910 |
} |
2 |
26 Feb 07 |
jari |
1911 |
} |
2 |
26 Feb 07 |
jari |
1912 |
*/ |
2 |
26 Feb 07 |
jari |
1913 |
|
2 |
26 Feb 07 |
jari |
1914 |
return rawPVals; |
2 |
26 Feb 07 |
jari |
1915 |
} |
2 |
26 Feb 07 |
jari |
1916 |
|
2 |
26 Feb 07 |
jari |
1917 |
private int[] permuteWithinPairsAllPerms(int num) { |
2 |
26 Feb 07 |
jari |
1918 |
int[] permutedValues = new int[numExps]; |
2 |
26 Feb 07 |
jari |
1919 |
for (int i = 0; i < permutedValues.length; i++) { |
2 |
26 Feb 07 |
jari |
1920 |
permutedValues[i] = i; |
2 |
26 Feb 07 |
jari |
1921 |
} |
2 |
26 Feb 07 |
jari |
1922 |
|
2 |
26 Feb 07 |
jari |
1923 |
int temp; |
2 |
26 Feb 07 |
jari |
//Random generator2 =new Random(seed); |
2 |
26 Feb 07 |
jari |
1925 |
boolean[] changeSign = getChangeSignArrayForAllPairedPerms(num); |
2 |
26 Feb 07 |
jari |
1926 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
1927 |
|
2 |
26 Feb 07 |
jari |
1928 |
boolean swap = changeSign[i]; |
2 |
26 Feb 07 |
jari |
//System.out.print(swap + " "); |
2 |
26 Feb 07 |
jari |
1930 |
if (swap) { |
2 |
26 Feb 07 |
jari |
1931 |
temp = permutedValues[pairedGroupBExpts[i]]; |
2 |
26 Feb 07 |
jari |
1932 |
permutedValues[pairedGroupBExpts[i]] = permutedValues[pairedGroupAExpts[i]]; |
2 |
26 Feb 07 |
jari |
1933 |
permutedValues[pairedGroupAExpts[i]] = temp; |
2 |
26 Feb 07 |
jari |
1934 |
} |
2 |
26 Feb 07 |
jari |
1935 |
} |
2 |
26 Feb 07 |
jari |
1936 |
/* |
2 |
26 Feb 07 |
jari |
try { |
2 |
26 Feb 07 |
jari |
Thread.sleep(10); |
2 |
26 Feb 07 |
jari |
} catch (Exception exc) { |
2 |
26 Feb 07 |
jari |
exc.printStackTrace(); |
2 |
26 Feb 07 |
jari |
1941 |
} |
2 |
26 Feb 07 |
jari |
1942 |
*/ |
2 |
26 Feb 07 |
jari |
1943 |
|
2 |
26 Feb 07 |
jari |
1944 |
return permutedValues; |
2 |
26 Feb 07 |
jari |
1945 |
} |
2 |
26 Feb 07 |
jari |
1946 |
|
2 |
26 Feb 07 |
jari |
1947 |
boolean[] getChangeSignArrayForAllPairedPerms(int num) { |
2 |
26 Feb 07 |
jari |
1948 |
boolean[] permutArray = new boolean[pairedGroupAExpts.length]; |
2 |
26 Feb 07 |
jari |
1949 |
|
2 |
26 Feb 07 |
jari |
1950 |
for (int i = 0; i < permutArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1951 |
permutArray[i] = false; |
2 |
26 Feb 07 |
jari |
1952 |
} |
2 |
26 Feb 07 |
jari |
1953 |
|
2 |
26 Feb 07 |
jari |
1954 |
int numPairs = pairedGroupAExpts.length; |
2 |
26 Feb 07 |
jari |
1955 |
|
2 |
26 Feb 07 |
jari |
1956 |
String binaryString = Integer.toBinaryString(num); |
2 |
26 Feb 07 |
jari |
//System.out.println(binaryString); |
2 |
26 Feb 07 |
jari |
1958 |
char[] binArray = binaryString.toCharArray(); |
2 |
26 Feb 07 |
jari |
1959 |
if (binArray.length < numPairs) { |
2 |
26 Feb 07 |
jari |
1960 |
Vector binVector = new Vector(); |
2 |
26 Feb 07 |
jari |
1961 |
for (int i = 0; i < (numPairs - binArray.length); i++) { |
2 |
26 Feb 07 |
jari |
1962 |
binVector.add(new Character('0')); |
2 |
26 Feb 07 |
jari |
1963 |
} |
2 |
26 Feb 07 |
jari |
1964 |
|
2 |
26 Feb 07 |
jari |
1965 |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1966 |
binVector.add(new Character(binArray[i])); |
2 |
26 Feb 07 |
jari |
1967 |
} |
2 |
26 Feb 07 |
jari |
1968 |
binArray = new char[binVector.size()]; |
2 |
26 Feb 07 |
jari |
1969 |
|
2 |
26 Feb 07 |
jari |
1970 |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1971 |
binArray[i] = ((Character)(binVector.get(i))).charValue(); |
2 |
26 Feb 07 |
jari |
1972 |
} |
2 |
26 Feb 07 |
jari |
1973 |
} |
2 |
26 Feb 07 |
jari |
1974 |
/* |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < binArray.length; i++) { |
2 |
26 Feb 07 |
jari |
System.out.print(binArray[i]); |
2 |
26 Feb 07 |
jari |
1977 |
} |
2 |
26 Feb 07 |
jari |
System.out.println(); |
2 |
26 Feb 07 |
jari |
1979 |
*/ |
2 |
26 Feb 07 |
jari |
//int counter = 0; |
2 |
26 Feb 07 |
jari |
1981 |
|
2 |
26 Feb 07 |
jari |
1982 |
for (int i = 0; i < permutArray.length; i++) { |
2 |
26 Feb 07 |
jari |
1983 |
|
2 |
26 Feb 07 |
jari |
1984 |
if (binArray[i] == '1') { |
2 |
26 Feb 07 |
jari |
1985 |
permutArray[i] = true; |
2 |
26 Feb 07 |
jari |
1986 |
} else { |
2 |
26 Feb 07 |
jari |
1987 |
permutArray[i] = false; |
2 |
26 Feb 07 |
jari |
1988 |
} |
2 |
26 Feb 07 |
jari |
1989 |
|
2 |
26 Feb 07 |
jari |
1990 |
} |
2 |
26 Feb 07 |
jari |
1991 |
/* |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < oneClassPermutArray.length; i++) { |
2 |
26 Feb 07 |
jari |
System.out.print(oneClassPermutArray[i] + " "); |
2 |
26 Feb 07 |
jari |
1994 |
} |
2 |
26 Feb 07 |
jari |
System.out.println(); |
2 |
26 Feb 07 |
jari |
1996 |
*/ |
2 |
26 Feb 07 |
jari |
1997 |
return permutArray; |
2 |
26 Feb 07 |
jari |
1998 |
} |
2 |
26 Feb 07 |
jari |
1999 |
|
2 |
26 Feb 07 |
jari |
2000 |
private int[] permuteWithinPairs(long seed) { |
2 |
26 Feb 07 |
jari |
2001 |
int[] permutedValues = new int[numExps]; |
2 |
26 Feb 07 |
jari |
2002 |
for (int i = 0; i < permutedValues.length; i++) { |
2 |
26 Feb 07 |
jari |
2003 |
permutedValues[i] = i; |
2 |
26 Feb 07 |
jari |
2004 |
} |
2 |
26 Feb 07 |
jari |
2005 |
|
2 |
26 Feb 07 |
jari |
2006 |
int temp; |
2 |
26 Feb 07 |
jari |
2007 |
Random generator2 =new Random(seed); |
2 |
26 Feb 07 |
jari |
2008 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
2009 |
|
2 |
26 Feb 07 |
jari |
2010 |
boolean swap = generator2.nextBoolean(); |
2 |
26 Feb 07 |
jari |
//System.out.print(swap + " "); |
2 |
26 Feb 07 |
jari |
2012 |
if (swap) { |
2 |
26 Feb 07 |
jari |
2013 |
temp = permutedValues[pairedGroupBExpts[i]]; |
2 |
26 Feb 07 |
jari |
2014 |
permutedValues[pairedGroupBExpts[i]] = permutedValues[pairedGroupAExpts[i]]; |
2 |
26 Feb 07 |
jari |
2015 |
permutedValues[pairedGroupAExpts[i]] = temp; |
2 |
26 Feb 07 |
jari |
2016 |
} |
2 |
26 Feb 07 |
jari |
2017 |
} |
2 |
26 Feb 07 |
jari |
2018 |
|
2 |
26 Feb 07 |
jari |
2019 |
try { |
2 |
26 Feb 07 |
jari |
2020 |
Thread.sleep(10); |
2 |
26 Feb 07 |
jari |
2021 |
} catch (Exception exc) { |
2 |
26 Feb 07 |
jari |
2022 |
exc.printStackTrace(); |
2 |
26 Feb 07 |
jari |
2023 |
} |
2 |
26 Feb 07 |
jari |
2024 |
|
2 |
26 Feb 07 |
jari |
2025 |
return permutedValues; |
2 |
26 Feb 07 |
jari |
2026 |
} |
2 |
26 Feb 07 |
jari |
2027 |
|
2 |
26 Feb 07 |
jari |
2028 |
private double[] getTwoClassRawPValsFromPerms() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
2029 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
2030 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2031 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
2032 |
double[] rawPVals = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2033 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2034 |
if (Double.isNaN(tValues[i])) { |
2 |
26 Feb 07 |
jari |
2035 |
rawPVals[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
2036 |
} else { |
2 |
26 Feb 07 |
jari |
2037 |
rawPVals[i] = 0d; |
2 |
26 Feb 07 |
jari |
2038 |
} |
2 |
26 Feb 07 |
jari |
2039 |
} |
2 |
26 Feb 07 |
jari |
2040 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
2041 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2042 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2043 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2044 |
} |
2 |
26 Feb 07 |
jari |
2045 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2046 |
event.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
2047 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2048 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
2049 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
2050 |
|
2 |
26 Feb 07 |
jari |
2051 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
2052 |
if (groupAssignments[j] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
2053 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
2054 |
} |
2 |
26 Feb 07 |
jari |
2055 |
} |
2 |
26 Feb 07 |
jari |
2056 |
|
2 |
26 Feb 07 |
jari |
2057 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
2058 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
2059 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
2060 |
} |
2 |
26 Feb 07 |
jari |
2061 |
|
2 |
26 Feb 07 |
jari |
2062 |
permutedExpts = getPermutedValues(numExps, validArray); //returns an int array of size "numExps", with the valid values permuted |
2 |
26 Feb 07 |
jari |
2063 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
2064 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
2065 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
2066 |
if (tValues[gene] < currentPermTValues[gene]) { |
2 |
26 Feb 07 |
jari |
2067 |
rawPVals[gene] = rawPVals[gene] + 1d; |
2 |
26 Feb 07 |
jari |
2068 |
} |
2 |
26 Feb 07 |
jari |
2069 |
} |
2 |
26 Feb 07 |
jari |
2070 |
} |
2 |
26 Feb 07 |
jari |
2071 |
|
2 |
26 Feb 07 |
jari |
2072 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2073 |
rawPVals[i] = rawPVals[i]/(double)numCombs; |
2 |
26 Feb 07 |
jari |
2074 |
} |
2 |
26 Feb 07 |
jari |
2075 |
|
2 |
26 Feb 07 |
jari |
2076 |
} else { // if (useAllCombs) |
2 |
26 Feb 07 |
jari |
2077 |
int[] permutedExpts = new int[numExps]; |
2 |
26 Feb 07 |
jari |
2078 |
|
2 |
26 Feb 07 |
jari |
2079 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
2080 |
permutedExpts[i] = i; |
2 |
26 Feb 07 |
jari |
2081 |
} |
2 |
26 Feb 07 |
jari |
2082 |
|
2 |
26 Feb 07 |
jari |
2083 |
Vector usedExptsVector = new Vector(); |
2 |
26 Feb 07 |
jari |
2084 |
int numGroupAValues = 0; |
2 |
26 Feb 07 |
jari |
2085 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
2086 |
if (groupAssignments[i] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
2087 |
usedExptsVector.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
2088 |
} |
2 |
26 Feb 07 |
jari |
2089 |
if (groupAssignments[i] == Ttest.GROUP_A) { |
2 |
26 Feb 07 |
jari |
2090 |
numGroupAValues++; |
2 |
26 Feb 07 |
jari |
2091 |
} |
2 |
26 Feb 07 |
jari |
2092 |
} |
2 |
26 Feb 07 |
jari |
2093 |
int[] usedExptsArray = new int[usedExptsVector.size()]; |
2 |
26 Feb 07 |
jari |
2094 |
|
2 |
26 Feb 07 |
jari |
2095 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2096 |
usedExptsArray[i] = ((Integer)(usedExptsVector.get(i))).intValue(); |
2 |
26 Feb 07 |
jari |
2097 |
} |
2 |
26 Feb 07 |
jari |
2098 |
|
2 |
26 Feb 07 |
jari |
2099 |
int[] combArray = new int[numGroupAValues]; |
2 |
26 Feb 07 |
jari |
2100 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2101 |
combArray[i] = -1; |
2 |
26 Feb 07 |
jari |
2102 |
} |
2 |
26 Feb 07 |
jari |
2103 |
|
2 |
26 Feb 07 |
jari |
2104 |
int numGroupBValues = usedExptsArray.length - numGroupAValues; |
2 |
26 Feb 07 |
jari |
2105 |
|
2 |
26 Feb 07 |
jari |
2106 |
int permCounter = 0; |
2 |
26 Feb 07 |
jari |
2107 |
|
2 |
26 Feb 07 |
jari |
2108 |
while (Combinations.enumerateCombinations(usedExptsArray.length, numGroupAValues, combArray)) { |
2 |
26 Feb 07 |
jari |
2109 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2110 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2111 |
} |
2 |
26 Feb 07 |
jari |
2112 |
event.setIntValue(permCounter); |
2 |
26 Feb 07 |
jari |
2113 |
event.setDescription("Permuting matrix: Current permutation = " + (permCounter+1)); |
2 |
26 Feb 07 |
jari |
2114 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2115 |
|
2 |
26 Feb 07 |
jari |
2116 |
int[] notInCombArray = new int[numGroupBValues]; |
2 |
26 Feb 07 |
jari |
2117 |
int notCombCounter = 0; |
2 |
26 Feb 07 |
jari |
2118 |
|
2 |
26 Feb 07 |
jari |
2119 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2120 |
if(!belongsInArray(i, combArray)) { |
2 |
26 Feb 07 |
jari |
2121 |
notInCombArray[notCombCounter] = i; |
2 |
26 Feb 07 |
jari |
2122 |
notCombCounter++; |
2 |
26 Feb 07 |
jari |
2123 |
} |
2 |
26 Feb 07 |
jari |
2124 |
} |
2 |
26 Feb 07 |
jari |
2125 |
|
2 |
26 Feb 07 |
jari |
2126 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2127 |
permutedExpts[usedExptsArray[i]] = usedExptsArray[combArray[i]]; |
2 |
26 Feb 07 |
jari |
2128 |
} |
2 |
26 Feb 07 |
jari |
2129 |
for (int i = 0; i < notInCombArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2130 |
permutedExpts[usedExptsArray[combArray.length + i]] = usedExptsArray[notInCombArray[i]]; |
2 |
26 Feb 07 |
jari |
2131 |
} |
2 |
26 Feb 07 |
jari |
2132 |
|
2 |
26 Feb 07 |
jari |
2133 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
2134 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
2135 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
2136 |
if (tValues[gene] < currentPermTValues[gene]) { |
2 |
26 Feb 07 |
jari |
2137 |
rawPVals[gene] = rawPVals[gene] + 1d; |
2 |
26 Feb 07 |
jari |
2138 |
} |
2 |
26 Feb 07 |
jari |
2139 |
} |
2 |
26 Feb 07 |
jari |
2140 |
permCounter++; |
2 |
26 Feb 07 |
jari |
2141 |
} |
2 |
26 Feb 07 |
jari |
2142 |
|
2 |
26 Feb 07 |
jari |
2143 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2144 |
rawPVals[i] = rawPVals[i]/(double)permCounter; |
2 |
26 Feb 07 |
jari |
2145 |
} |
2 |
26 Feb 07 |
jari |
2146 |
} |
2 |
26 Feb 07 |
jari |
2147 |
/* |
2 |
26 Feb 07 |
jari |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
//System.out.println("Current gene = " + gene); |
2 |
26 Feb 07 |
jari |
if (stop) { |
2 |
26 Feb 07 |
jari |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2152 |
} |
2 |
26 Feb 07 |
jari |
event.setIntValue(gene); |
2 |
26 Feb 07 |
jari |
event.setDescription("Calculating raw p values: Current gene = " + (gene + 1)); |
2 |
26 Feb 07 |
jari |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
if (Double.isNaN(tValues[gene])) { |
2 |
26 Feb 07 |
jari |
rawPVals[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
} else { |
2 |
26 Feb 07 |
jari |
double origTValue = tValues[gene]; |
2 |
26 Feb 07 |
jari |
float[] geneValues = new float[numExps]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
geneValues[i] = expMatrix.A[gene][i]; |
2 |
26 Feb 07 |
jari |
2163 |
} |
2 |
26 Feb 07 |
jari |
2164 |
|
2 |
26 Feb 07 |
jari |
int groupACounter = 0; |
2 |
26 Feb 07 |
jari |
int groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
2167 |
|
2 |
26 Feb 07 |
jari |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
if (groupAssignments[i] == this.GROUP_A) { |
2 |
26 Feb 07 |
jari |
groupACounter++; |
2 |
26 Feb 07 |
jari |
} else if (groupAssignments[i] == this.GROUP_B) { |
2 |
26 Feb 07 |
jari |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
2173 |
} |
2 |
26 Feb 07 |
jari |
2174 |
} |
2 |
26 Feb 07 |
jari |
2175 |
|
2 |
26 Feb 07 |
jari |
float[] groupAValues = new float[groupACounter]; |
2 |
26 Feb 07 |
jari |
float[] groupBValues = new float[groupBCounter]; |
2 |
26 Feb 07 |
jari |
int[] groupedExpts = new int[(groupACounter + groupBCounter)]; |
2 |
26 Feb 07 |
jari |
2179 |
|
2 |
26 Feb 07 |
jari |
int numbValidValuesA = 0; |
2 |
26 Feb 07 |
jari |
int numbValidValuesB = 0; |
2 |
26 Feb 07 |
jari |
2182 |
|
2 |
26 Feb 07 |
jari |
groupACounter = 0; |
2 |
26 Feb 07 |
jari |
groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
int groupedExptsCounter = 0; |
2 |
26 Feb 07 |
jari |
2186 |
|
2 |
26 Feb 07 |
jari |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
if (groupAssignments[i] == GROUP_A) { |
2 |
26 Feb 07 |
jari |
groupAValues[groupACounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
if (!Float.isNaN(geneValues[i])) { |
2 |
26 Feb 07 |
jari |
numbValidValuesA++; |
2 |
26 Feb 07 |
jari |
2192 |
} |
2 |
26 Feb 07 |
jari |
groupACounter++; |
2 |
26 Feb 07 |
jari |
groupedExpts[groupedExptsCounter] = i; |
2 |
26 Feb 07 |
jari |
groupedExptsCounter++; |
2 |
26 Feb 07 |
jari |
} else if (groupAssignments[i] == GROUP_B) { |
2 |
26 Feb 07 |
jari |
groupBValues[groupBCounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
if (!Float.isNaN(geneValues[i])) { |
2 |
26 Feb 07 |
jari |
numbValidValuesB++; |
2 |
26 Feb 07 |
jari |
2200 |
} |
2 |
26 Feb 07 |
jari |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
groupedExpts[groupedExptsCounter] = i; |
2 |
26 Feb 07 |
jari |
groupedExptsCounter++; |
2 |
26 Feb 07 |
jari |
2204 |
} |
2 |
26 Feb 07 |
jari |
2205 |
} |
2 |
26 Feb 07 |
jari |
2206 |
|
2 |
26 Feb 07 |
jari |
if (useAllCombs) { |
2 |
26 Feb 07 |
jari |
double permutProb = 0d; |
2 |
26 Feb 07 |
jari |
int numCombsCounter = 0; |
2 |
26 Feb 07 |
jari |
int[] combArray = new int[groupAValues.length]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
combArray[i] = -1; |
2 |
26 Feb 07 |
jari |
2213 |
} |
2 |
26 Feb 07 |
jari |
while (Combinations.enumerateCombinations(groupedExpts.length, groupAValues.length, combArray)) { |
2 |
26 Feb 07 |
jari |
float[] resampGroupA = new float[groupAValues.length]; |
2 |
26 Feb 07 |
jari |
float[] resampGroupB = new float[groupBValues.length]; |
2 |
26 Feb 07 |
jari |
int[] notInCombArray = new int[groupBValues.length]; |
2 |
26 Feb 07 |
jari |
int notCombCounter = 0; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < groupedExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
if(!belongsInArray(i, combArray)) { |
2 |
26 Feb 07 |
jari |
notInCombArray[notCombCounter] = i; |
2 |
26 Feb 07 |
jari |
notCombCounter++; |
2 |
26 Feb 07 |
jari |
2223 |
} |
2 |
26 Feb 07 |
jari |
2224 |
} |
2 |
26 Feb 07 |
jari |
2225 |
|
2 |
26 Feb 07 |
jari |
for(int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
resampGroupA[i] = geneValues[groupedExpts[combArray[i]]]; |
2 |
26 Feb 07 |
jari |
2228 |
} |
2 |
26 Feb 07 |
jari |
2229 |
|
2 |
26 Feb 07 |
jari |
for(int i = 0; i < notInCombArray.length; i++) { |
2 |
26 Feb 07 |
jari |
resampGroupB[i] = geneValues[groupedExpts[notInCombArray[i]]]; |
2 |
26 Feb 07 |
jari |
2232 |
} |
2 |
26 Feb 07 |
jari |
2233 |
|
2 |
26 Feb 07 |
jari |
float resampTValue = Math.abs(calculateTValue(resampGroupA, resampGroupB)); |
2 |
26 Feb 07 |
jari |
//System.out.println("resampTValue = " + resampTValue); |
2 |
26 Feb 07 |
jari |
if (origTValue < (double)(resampTValue)) { |
2 |
26 Feb 07 |
jari |
permutProb++; |
2 |
26 Feb 07 |
jari |
2238 |
} |
2 |
26 Feb 07 |
jari |
numCombsCounter++; |
2 |
26 Feb 07 |
jari |
2240 |
} |
2 |
26 Feb 07 |
jari |
2241 |
|
2 |
26 Feb 07 |
jari |
permutProb = (double)(permutProb/(double)numCombsCounter); |
2 |
26 Feb 07 |
jari |
//System.out.println("permutProb = " + permutProb); |
2 |
26 Feb 07 |
jari |
rawPVals[gene] = permutProb; |
2 |
26 Feb 07 |
jari |
2245 |
|
2 |
26 Feb 07 |
jari |
} else { // if (!useAllCombs) |
2 |
26 Feb 07 |
jari |
double permutProb = 0d; |
2 |
26 Feb 07 |
jari |
int randomCounter = 0; |
2 |
26 Feb 07 |
jari |
//permutProb = 0; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
//int[] randomGroupA = new int[groupAValues.length]; |
2 |
26 Feb 07 |
jari |
//int[] randomGroupB = new int[groupBValues.length]; |
2 |
26 Feb 07 |
jari |
float[][] randomGroups = randomlyPermute(geneValues, groupedExpts, groupAValues.length, groupBValues.length); |
2 |
26 Feb 07 |
jari |
float randomizedTValue = Math.abs(calculateTValue(randomGroups[0], randomGroups[1])); |
2 |
26 Feb 07 |
jari |
if (origTValue < (double)(randomizedTValue)) { |
2 |
26 Feb 07 |
jari |
permutProb++; |
2 |
26 Feb 07 |
jari |
2257 |
} |
2 |
26 Feb 07 |
jari |
randomCounter++; |
2 |
26 Feb 07 |
jari |
2259 |
} |
2 |
26 Feb 07 |
jari |
2260 |
|
2 |
26 Feb 07 |
jari |
permutProb = (double)(permutProb/(double)randomCounter); |
2 |
26 Feb 07 |
jari |
rawPVals[gene] = permutProb; |
2 |
26 Feb 07 |
jari |
2263 |
} |
2 |
26 Feb 07 |
jari |
2264 |
} |
2 |
26 Feb 07 |
jari |
2265 |
} */ |
2 |
26 Feb 07 |
jari |
2266 |
|
2 |
26 Feb 07 |
jari |
2267 |
return rawPVals; |
2 |
26 Feb 07 |
jari |
2268 |
} |
2 |
26 Feb 07 |
jari |
2269 |
|
2 |
26 Feb 07 |
jari |
2270 |
private float[][] randomlyPermute(float[] gene, int[] groupedExpts, int groupALength, int groupBLength) { |
2 |
26 Feb 07 |
jari |
2271 |
float[][] groupedValues = new float[2][]; |
2 |
26 Feb 07 |
jari |
2272 |
groupedValues[0] = new float[groupALength]; |
2 |
26 Feb 07 |
jari |
2273 |
groupedValues[1] = new float[groupBLength]; |
2 |
26 Feb 07 |
jari |
2274 |
if (groupALength > groupBLength) { |
2 |
26 Feb 07 |
jari |
2275 |
groupedValues[0] = new float[groupBLength]; |
2 |
26 Feb 07 |
jari |
2276 |
groupedValues[1] = new float[groupALength]; |
2 |
26 Feb 07 |
jari |
2277 |
} |
2 |
26 Feb 07 |
jari |
2278 |
|
2 |
26 Feb 07 |
jari |
2279 |
Vector groupedExptsVector = new Vector(); |
2 |
26 Feb 07 |
jari |
2280 |
for (int i = 0; i < groupedExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
2281 |
groupedExptsVector.add(new Integer(groupedExpts[i])); |
2 |
26 Feb 07 |
jari |
2282 |
} |
2 |
26 Feb 07 |
jari |
2283 |
|
2 |
26 Feb 07 |
jari |
//System.out.print("In randomly permute: random expts groupA: "); |
2 |
26 Feb 07 |
jari |
2285 |
|
2 |
26 Feb 07 |
jari |
2286 |
for (int i = 0; i < groupedValues[0].length; i++) { |
2 |
26 Feb 07 |
jari |
//Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
//int randInt = (int)Math.round(rand.nextDouble()*(groupedExptsVector.size()-1)); |
2 |
26 Feb 07 |
jari |
2289 |
int randInt = (int)Math.round(Math.random()*(groupedExptsVector.size()-1)); |
2 |
26 Feb 07 |
jari |
2290 |
int randIndex = ((Integer)groupedExptsVector.remove(randInt)).intValue(); |
2 |
26 Feb 07 |
jari |
//System.out.print(" " + randIndex); |
2 |
26 Feb 07 |
jari |
2292 |
groupedValues[0][i] = gene[randIndex]; |
2 |
26 Feb 07 |
jari |
2293 |
} |
2 |
26 Feb 07 |
jari |
2294 |
|
2 |
26 Feb 07 |
jari |
//System.out.println(); |
2 |
26 Feb 07 |
jari |
2296 |
|
2 |
26 Feb 07 |
jari |
//System.out.print("In randomly permute: random expts groupB: "); |
2 |
26 Feb 07 |
jari |
2298 |
|
2 |
26 Feb 07 |
jari |
2299 |
for (int i = 0; i < groupedValues[1].length; i++) { |
2 |
26 Feb 07 |
jari |
2300 |
int index = ((Integer)groupedExptsVector.get(i)).intValue(); |
2 |
26 Feb 07 |
jari |
//System.out.print(" " + index); |
2 |
26 Feb 07 |
jari |
2302 |
groupedValues[1][i] = gene[index]; |
2 |
26 Feb 07 |
jari |
2303 |
} |
2 |
26 Feb 07 |
jari |
2304 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("\n"); |
2 |
26 Feb 07 |
jari |
2306 |
|
2 |
26 Feb 07 |
jari |
2307 |
return groupedValues; |
2 |
26 Feb 07 |
jari |
2308 |
|
2 |
26 Feb 07 |
jari |
2309 |
} |
2 |
26 Feb 07 |
jari |
2310 |
|
2 |
26 Feb 07 |
jari |
2311 |
private double[] getParametricPVals(double[] tVals, int dfs[]) { |
2 |
26 Feb 07 |
jari |
2312 |
double[] pVals = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2313 |
|
2 |
26 Feb 07 |
jari |
2314 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2315 |
if (Double.isNaN(tVals[i])) { |
2 |
26 Feb 07 |
jari |
2316 |
pVals[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
2317 |
} else { |
2 |
26 Feb 07 |
jari |
2318 |
TDistribution tDist = new TDistribution(dfs[i]); |
2 |
26 Feb 07 |
jari |
2319 |
double cumulP = tDist.cumulative(tVals[i]); |
2 |
26 Feb 07 |
jari |
2320 |
double prob = 2*(1 - cumulP); // two-tailed test |
2 |
26 Feb 07 |
jari |
2321 |
if (prob > 1) { |
2 |
26 Feb 07 |
jari |
2322 |
prob = 1; |
2 |
26 Feb 07 |
jari |
2323 |
} |
2 |
26 Feb 07 |
jari |
2324 |
pVals[i] = prob; |
2 |
26 Feb 07 |
jari |
2325 |
} |
2 |
26 Feb 07 |
jari |
2326 |
} |
2 |
26 Feb 07 |
jari |
2327 |
return pVals; |
2 |
26 Feb 07 |
jari |
2328 |
} |
2 |
26 Feb 07 |
jari |
2329 |
|
2 |
26 Feb 07 |
jari |
2330 |
private double[] getRawPValsFromTDist() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
2331 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numGenes); |
2 |
26 Feb 07 |
jari |
2332 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2333 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
2334 |
|
2 |
26 Feb 07 |
jari |
2335 |
double[] rawPVals = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2336 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2337 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2338 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2339 |
} |
2 |
26 Feb 07 |
jari |
2340 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2341 |
event.setDescription("Calculating raw p values: Current gene = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
2342 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2343 |
|
2 |
26 Feb 07 |
jari |
2344 |
if (Double.isNaN(tValues[i])) { |
2 |
26 Feb 07 |
jari |
2345 |
rawPVals[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
2346 |
} else { |
2 |
26 Feb 07 |
jari |
2347 |
TDistribution tDist = new TDistribution((int)(dfValues[i])); |
2 |
26 Feb 07 |
jari |
2348 |
double cumulP = tDist.cumulative(tValues[i]); |
2 |
26 Feb 07 |
jari |
2349 |
double prob = 2*(1 - cumulP); // two-tailed test |
2 |
26 Feb 07 |
jari |
2350 |
if (prob > 1) { |
2 |
26 Feb 07 |
jari |
2351 |
prob = 1; |
2 |
26 Feb 07 |
jari |
2352 |
} |
2 |
26 Feb 07 |
jari |
2353 |
rawPVals[i] = prob; |
2 |
26 Feb 07 |
jari |
2354 |
} |
2 |
26 Feb 07 |
jari |
2355 |
} |
2 |
26 Feb 07 |
jari |
2356 |
|
2 |
26 Feb 07 |
jari |
2357 |
return rawPVals; |
2 |
26 Feb 07 |
jari |
2358 |
} |
2 |
26 Feb 07 |
jari |
2359 |
|
2 |
26 Feb 07 |
jari |
2360 |
private double[] getAdjPVals(double[] rawPVals, int adjMethod) throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
2361 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numGenes); |
2 |
26 Feb 07 |
jari |
2362 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2363 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
2364 |
|
2 |
26 Feb 07 |
jari |
2365 |
double[] adjPVals = new double[rawPVals.length]; |
2 |
26 Feb 07 |
jari |
2366 |
if (adjMethod == Ttest.JUST_ALPHA) { |
2 |
26 Feb 07 |
jari |
2367 |
adjPVals = rawPVals; |
2 |
26 Feb 07 |
jari |
2368 |
} |
2 |
26 Feb 07 |
jari |
2369 |
if (adjMethod == Ttest.STD_BONFERRONI) { |
2 |
26 Feb 07 |
jari |
2370 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2371 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2372 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2373 |
} |
2 |
26 Feb 07 |
jari |
2374 |
event.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2375 |
event.setDescription("Computing adjusted p-values: Current gene = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
2376 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
2377 |
double currP = rawPVals[i]; |
2 |
26 Feb 07 |
jari |
2378 |
double currAdjP = (double)(currP*numGenes); |
2 |
26 Feb 07 |
jari |
2379 |
if (currAdjP > 1.0d) currAdjP = 1.0d; |
2 |
26 Feb 07 |
jari |
2380 |
adjPVals[i] = currAdjP; |
2 |
26 Feb 07 |
jari |
2381 |
} |
2 |
26 Feb 07 |
jari |
2382 |
} |
2 |
26 Feb 07 |
jari |
2383 |
if (adjMethod == Ttest.ADJ_BONFERRONI) { |
2 |
26 Feb 07 |
jari |
2384 |
adjPVals = getAdjBonfPVals(rawPVals); |
2 |
26 Feb 07 |
jari |
2385 |
} |
2 |
26 Feb 07 |
jari |
2386 |
if (adjMethod == Ttest.MAX_T) { |
2 |
26 Feb 07 |
jari |
2387 |
adjPVals = getMaxTPVals(); |
2 |
26 Feb 07 |
jari |
2388 |
} |
2 |
26 Feb 07 |
jari |
2389 |
|
2 |
26 Feb 07 |
jari |
2390 |
return adjPVals; |
2 |
26 Feb 07 |
jari |
2391 |
} |
2 |
26 Feb 07 |
jari |
2392 |
|
2 |
26 Feb 07 |
jari |
2393 |
private double[] getMaxTPVals() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
2394 |
double[] origTValues = tValues; |
2 |
26 Feb 07 |
jari |
2395 |
double[] descTValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2396 |
int[] descGeneIndices = new int[numGenes]; |
2 |
26 Feb 07 |
jari |
2397 |
double[] adjPValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2398 |
|
2 |
26 Feb 07 |
jari |
2399 |
double[][] permutedRankedTValues = new double[numCombs][numGenes]; |
2 |
26 Feb 07 |
jari |
2400 |
double[][] uMatrix = new double[numGenes][numCombs]; |
2 |
26 Feb 07 |
jari |
2401 |
AlgorithmEvent event2 = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numCombs); |
2 |
26 Feb 07 |
jari |
2402 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2403 |
event2.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
2404 |
|
2 |
26 Feb 07 |
jari |
2405 |
if (tTestDesign == Ttest.BETWEEN_SUBJECTS) { |
2 |
26 Feb 07 |
jari |
2406 |
QSort sortDescTValues = new QSort(origTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
2407 |
descTValues = sortDescTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2408 |
descGeneIndices = sortDescTValues.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
2409 |
|
2 |
26 Feb 07 |
jari |
//FloatMatrix orderedByTMatrix = getOrderedByTMatrix(expMatrix, descGeneIndices); |
2 |
26 Feb 07 |
jari |
2411 |
|
2 |
26 Feb 07 |
jari |
2412 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
2413 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2414 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2415 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2416 |
} |
2 |
26 Feb 07 |
jari |
2417 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2418 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
2419 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2420 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
2421 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
2422 |
|
2 |
26 Feb 07 |
jari |
2423 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
2424 |
if (groupAssignments[j] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
2425 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
2426 |
} |
2 |
26 Feb 07 |
jari |
2427 |
} |
2 |
26 Feb 07 |
jari |
2428 |
|
2 |
26 Feb 07 |
jari |
2429 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
2430 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
2431 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
2432 |
} |
2 |
26 Feb 07 |
jari |
2433 |
|
2 |
26 Feb 07 |
jari |
2434 |
permutedExpts = getPermutedValues(numExps, validArray); //returns an int array of size "numExps", with the valid values permuted |
2 |
26 Feb 07 |
jari |
2435 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
2436 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
2437 |
|
2 |
26 Feb 07 |
jari |
2438 |
if (Double.isNaN(currentPermTValues[descGeneIndices[numGenes - 1]])) { |
2 |
26 Feb 07 |
jari |
2439 |
uMatrix[numGenes - 1][i] = Double.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
2440 |
} else { |
2 |
26 Feb 07 |
jari |
2441 |
uMatrix[numGenes - 1][i] = currentPermTValues[descGeneIndices[numGenes - 1]]; |
2 |
26 Feb 07 |
jari |
2442 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + (numGenes - 1) + "][" + i + "] = " + uMatrix[numGenes - 1][i]); |
2 |
26 Feb 07 |
jari |
2444 |
|
2 |
26 Feb 07 |
jari |
2445 |
for (int j = numGenes - 2; j >= 0; j--) { |
2 |
26 Feb 07 |
jari |
2446 |
if (Double.isNaN(currentPermTValues[descGeneIndices[j]])) { |
2 |
26 Feb 07 |
jari |
2447 |
uMatrix[j][i] = uMatrix[j+1][i]; |
2 |
26 Feb 07 |
jari |
2448 |
} else { |
2 |
26 Feb 07 |
jari |
2449 |
uMatrix[j][i] = Math.max(uMatrix[j+1][i], currentPermTValues[descGeneIndices[j]]); |
2 |
26 Feb 07 |
jari |
2450 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + j + "][" + i + "] = " + uMatrix[j][i]); |
2 |
26 Feb 07 |
jari |
2452 |
} |
2 |
26 Feb 07 |
jari |
2453 |
|
2 |
26 Feb 07 |
jari |
2454 |
/* |
2 |
26 Feb 07 |
jari |
QSort sortDescCurrentPermTValues = new QSort(currentPermTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
double[] descCurrentPermTValues = sortDescCurrentPermTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2457 |
|
2 |
26 Feb 07 |
jari |
for (int j = 0; j < permutedRankedTValues[i].length; j++) { |
2 |
26 Feb 07 |
jari |
permutedRankedTValues[i][j] = descCurrentPermTValues[j]; |
2 |
26 Feb 07 |
jari |
2460 |
}*/ |
2 |
26 Feb 07 |
jari |
2461 |
} // end "for (int i = 0; i < numCombs; i++)" |
2 |
26 Feb 07 |
jari |
2462 |
|
2 |
26 Feb 07 |
jari |
2463 |
} else { // if (useAllCombs) |
2 |
26 Feb 07 |
jari |
2464 |
int[] permutedExpts = new int[numExps]; |
2 |
26 Feb 07 |
jari |
2465 |
|
2 |
26 Feb 07 |
jari |
2466 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
2467 |
permutedExpts[i] = i; |
2 |
26 Feb 07 |
jari |
2468 |
} |
2 |
26 Feb 07 |
jari |
2469 |
|
2 |
26 Feb 07 |
jari |
2470 |
Vector usedExptsVector = new Vector(); |
2 |
26 Feb 07 |
jari |
2471 |
int numGroupAValues = 0; |
2 |
26 Feb 07 |
jari |
2472 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
2473 |
if (groupAssignments[i] != Ttest.NEITHER_GROUP) { |
2 |
26 Feb 07 |
jari |
2474 |
usedExptsVector.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
2475 |
} |
2 |
26 Feb 07 |
jari |
2476 |
if (groupAssignments[i] == Ttest.GROUP_A) { |
2 |
26 Feb 07 |
jari |
2477 |
numGroupAValues++; |
2 |
26 Feb 07 |
jari |
2478 |
} |
2 |
26 Feb 07 |
jari |
2479 |
} |
2 |
26 Feb 07 |
jari |
2480 |
int[] usedExptsArray = new int[usedExptsVector.size()]; |
2 |
26 Feb 07 |
jari |
2481 |
|
2 |
26 Feb 07 |
jari |
2482 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2483 |
usedExptsArray[i] = ((Integer)(usedExptsVector.get(i))).intValue(); |
2 |
26 Feb 07 |
jari |
2484 |
} |
2 |
26 Feb 07 |
jari |
2485 |
|
2 |
26 Feb 07 |
jari |
2486 |
int[] combArray = new int[numGroupAValues]; |
2 |
26 Feb 07 |
jari |
2487 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2488 |
combArray[i] = -1; |
2 |
26 Feb 07 |
jari |
2489 |
} |
2 |
26 Feb 07 |
jari |
2490 |
|
2 |
26 Feb 07 |
jari |
2491 |
int numGroupBValues = usedExptsArray.length - numGroupAValues; |
2 |
26 Feb 07 |
jari |
2492 |
|
2 |
26 Feb 07 |
jari |
2493 |
int permCounter = 0; |
2 |
26 Feb 07 |
jari |
//System.out.println("All combs minP: up to here"); |
2 |
26 Feb 07 |
jari |
2495 |
while (Combinations.enumerateCombinations(usedExptsArray.length, numGroupAValues, combArray)) { |
2 |
26 Feb 07 |
jari |
2496 |
|
2 |
26 Feb 07 |
jari |
2497 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2498 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2499 |
} |
2 |
26 Feb 07 |
jari |
2500 |
event2.setIntValue(permCounter); |
2 |
26 Feb 07 |
jari |
2501 |
event2.setDescription("Permuting matrix: Current permutation = " + (permCounter+1)); |
2 |
26 Feb 07 |
jari |
2502 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2503 |
|
2 |
26 Feb 07 |
jari |
2504 |
int[] notInCombArray = new int[numGroupBValues]; |
2 |
26 Feb 07 |
jari |
2505 |
int notCombCounter = 0; |
2 |
26 Feb 07 |
jari |
2506 |
|
2 |
26 Feb 07 |
jari |
2507 |
for (int i = 0; i < usedExptsArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2508 |
if(!belongsInArray(i, combArray)) { |
2 |
26 Feb 07 |
jari |
2509 |
notInCombArray[notCombCounter] = i; |
2 |
26 Feb 07 |
jari |
2510 |
notCombCounter++; |
2 |
26 Feb 07 |
jari |
2511 |
} |
2 |
26 Feb 07 |
jari |
2512 |
} |
2 |
26 Feb 07 |
jari |
2513 |
|
2 |
26 Feb 07 |
jari |
2514 |
for (int i = 0; i < combArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2515 |
permutedExpts[usedExptsArray[i]] = usedExptsArray[combArray[i]]; |
2 |
26 Feb 07 |
jari |
2516 |
} |
2 |
26 Feb 07 |
jari |
2517 |
for (int i = 0; i < notInCombArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2518 |
permutedExpts[usedExptsArray[combArray.length + i]] = usedExptsArray[notInCombArray[i]]; |
2 |
26 Feb 07 |
jari |
2519 |
} |
2 |
26 Feb 07 |
jari |
2520 |
|
2 |
26 Feb 07 |
jari |
2521 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
2522 |
/* |
2 |
26 Feb 07 |
jari |
double[] permDArray = new double[permutedMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
for (int j = 0; j < permutedMatrix.getRowDimension(); j++) { |
2 |
26 Feb 07 |
jari |
permDArray[j] = getD(j, permutedMatrix); |
2 |
26 Feb 07 |
jari |
2526 |
} |
2 |
26 Feb 07 |
jari |
2527 |
|
2 |
26 Feb 07 |
jari |
QSort sortPermDArray = new QSort(permDArray); |
2 |
26 Feb 07 |
jari |
double[] sortedPermDArray = sortPermDArray.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2530 |
|
2 |
26 Feb 07 |
jari |
for (int j = 0; j < sortedPermDArray.length; j++) { |
2 |
26 Feb 07 |
jari |
permutedDValues[permCounter][j] = sortedPermDArray[j]; |
2 |
26 Feb 07 |
jari |
2533 |
} |
2 |
26 Feb 07 |
jari |
2534 |
*/ |
2 |
26 Feb 07 |
jari |
2535 |
double[] currentPermTValues = getTwoClassUnpairedTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
2536 |
|
2 |
26 Feb 07 |
jari |
2537 |
if (Double.isNaN(currentPermTValues[descGeneIndices[numGenes - 1]])) { |
2 |
26 Feb 07 |
jari |
2538 |
uMatrix[numGenes - 1][permCounter] = Double.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
2539 |
} else { |
2 |
26 Feb 07 |
jari |
2540 |
uMatrix[numGenes - 1][permCounter] = currentPermTValues[descGeneIndices[numGenes - 1]]; |
2 |
26 Feb 07 |
jari |
2541 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + (numGenes - 1) + "][" + i + "] = " + uMatrix[numGenes - 1][i]); |
2 |
26 Feb 07 |
jari |
2543 |
|
2 |
26 Feb 07 |
jari |
2544 |
for (int j = numGenes - 2; j >= 0; j--) { |
2 |
26 Feb 07 |
jari |
2545 |
if (Double.isNaN(currentPermTValues[descGeneIndices[j]])) { |
2 |
26 Feb 07 |
jari |
2546 |
uMatrix[j][permCounter] = uMatrix[j+1][permCounter]; |
2 |
26 Feb 07 |
jari |
2547 |
} else { |
2 |
26 Feb 07 |
jari |
2548 |
uMatrix[j][permCounter] = Math.max(uMatrix[j+1][permCounter], currentPermTValues[descGeneIndices[j]]); |
2 |
26 Feb 07 |
jari |
2549 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + j + "][" + i + "] = " + uMatrix[j][i]); |
2 |
26 Feb 07 |
jari |
2551 |
} |
2 |
26 Feb 07 |
jari |
2552 |
/* |
2 |
26 Feb 07 |
jari |
QSort sortDescCurrentPermTValues = new QSort(currentPermTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
double[] descCurrentPermTValues = sortDescCurrentPermTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2555 |
|
2 |
26 Feb 07 |
jari |
for (int j = 0; j < permutedRankedTValues[permCounter].length; j++) { |
2 |
26 Feb 07 |
jari |
permutedRankedTValues[permCounter][j] = descCurrentPermTValues[j]; |
2 |
26 Feb 07 |
jari |
2558 |
} */ |
2 |
26 Feb 07 |
jari |
2559 |
|
2 |
26 Feb 07 |
jari |
2560 |
permCounter++; |
2 |
26 Feb 07 |
jari |
2561 |
} |
2 |
26 Feb 07 |
jari |
2562 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("numCombs = " + numCombs + ", permCounter =" + permCounter); |
2 |
26 Feb 07 |
jari |
2564 |
} |
2 |
26 Feb 07 |
jari |
2565 |
} else if (tTestDesign == PAIRED) { |
2 |
26 Feb 07 |
jari |
2566 |
QSort sortDescTValues = new QSort(origTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
2567 |
descTValues = sortDescTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2568 |
descGeneIndices = sortDescTValues.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
2569 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
2570 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
2571 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2572 |
long randomSeed = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
2573 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2574 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2575 |
} |
2 |
26 Feb 07 |
jari |
2576 |
int[] permutedExpts = permuteWithinPairs(randomSeed); //returns an int array with some paired experiment indices permuted |
2 |
26 Feb 07 |
jari |
2577 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
2578 |
|
2 |
26 Feb 07 |
jari |
2579 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2580 |
event2.setDescription("Permuting matrix: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
2581 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2582 |
|
2 |
26 Feb 07 |
jari |
2583 |
double[] currentPermTValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2584 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
2585 |
currentPermTValues[gene] = getPairedTValue(gene, permutedMatrix); |
2 |
26 Feb 07 |
jari |
2586 |
} |
2 |
26 Feb 07 |
jari |
2587 |
|
2 |
26 Feb 07 |
jari |
2588 |
if (Double.isNaN(currentPermTValues[descGeneIndices[numGenes - 1]])) { |
2 |
26 Feb 07 |
jari |
2589 |
uMatrix[numGenes - 1][i] = Double.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
2590 |
} else { |
2 |
26 Feb 07 |
jari |
2591 |
uMatrix[numGenes - 1][i] = currentPermTValues[descGeneIndices[numGenes - 1]]; |
2 |
26 Feb 07 |
jari |
2592 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + (numGenes - 1) + "][" + i + "] = " + uMatrix[numGenes - 1][i]); |
2 |
26 Feb 07 |
jari |
2594 |
|
2 |
26 Feb 07 |
jari |
2595 |
for (int j = numGenes - 2; j >= 0; j--) { |
2 |
26 Feb 07 |
jari |
2596 |
if (Double.isNaN(currentPermTValues[descGeneIndices[j]])) { |
2 |
26 Feb 07 |
jari |
2597 |
uMatrix[j][i] = uMatrix[j+1][i]; |
2 |
26 Feb 07 |
jari |
2598 |
} else { |
2 |
26 Feb 07 |
jari |
2599 |
uMatrix[j][i] = Math.max(uMatrix[j+1][i], currentPermTValues[descGeneIndices[j]]); |
2 |
26 Feb 07 |
jari |
2600 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + j + "][" + i + "] = " + uMatrix[j][i]); |
2 |
26 Feb 07 |
jari |
2602 |
} |
2 |
26 Feb 07 |
jari |
2603 |
} |
2 |
26 Feb 07 |
jari |
2604 |
} else { // if (useAllCombs) |
2 |
26 Feb 07 |
jari |
2605 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2606 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2607 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2608 |
} |
2 |
26 Feb 07 |
jari |
2609 |
int[] permutedExpts = permuteWithinPairsAllPerms(i); |
2 |
26 Feb 07 |
jari |
2610 |
FloatMatrix permutedMatrix = getPermutedMatrix(expMatrix, permutedExpts); |
2 |
26 Feb 07 |
jari |
2611 |
|
2 |
26 Feb 07 |
jari |
2612 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2613 |
event2.setDescription("Permuting matrix: Current permutation = " + (i + 1)); |
2 |
26 Feb 07 |
jari |
2614 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2615 |
|
2 |
26 Feb 07 |
jari |
2616 |
double[] currentPermTValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2617 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
2618 |
currentPermTValues[gene] = getPairedTValue(gene, permutedMatrix); |
2 |
26 Feb 07 |
jari |
2619 |
} |
2 |
26 Feb 07 |
jari |
2620 |
|
2 |
26 Feb 07 |
jari |
2621 |
if (Double.isNaN(currentPermTValues[descGeneIndices[numGenes - 1]])) { |
2 |
26 Feb 07 |
jari |
2622 |
uMatrix[numGenes - 1][i] = Double.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
2623 |
} else { |
2 |
26 Feb 07 |
jari |
2624 |
uMatrix[numGenes - 1][i] = currentPermTValues[descGeneIndices[numGenes - 1]]; |
2 |
26 Feb 07 |
jari |
2625 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + (numGenes - 1) + "][" + i + "] = " + uMatrix[numGenes - 1][i]); |
2 |
26 Feb 07 |
jari |
2627 |
|
2 |
26 Feb 07 |
jari |
2628 |
for (int j = numGenes - 2; j >= 0; j--) { |
2 |
26 Feb 07 |
jari |
2629 |
if (Double.isNaN(currentPermTValues[descGeneIndices[j]])) { |
2 |
26 Feb 07 |
jari |
2630 |
uMatrix[j][i] = uMatrix[j+1][i]; |
2 |
26 Feb 07 |
jari |
2631 |
} else { |
2 |
26 Feb 07 |
jari |
2632 |
uMatrix[j][i] = Math.max(uMatrix[j+1][i], currentPermTValues[descGeneIndices[j]]); |
2 |
26 Feb 07 |
jari |
2633 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + j + "][" + i + "] = " + uMatrix[j][i]); |
2 |
26 Feb 07 |
jari |
2635 |
} |
2 |
26 Feb 07 |
jari |
2636 |
} |
2 |
26 Feb 07 |
jari |
2637 |
} |
2 |
26 Feb 07 |
jari |
2638 |
|
2 |
26 Feb 07 |
jari |
2639 |
} else if (tTestDesign == ONE_CLASS) { |
2 |
26 Feb 07 |
jari |
2640 |
QSort sortDescTValues = new QSort(origTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
2641 |
descTValues = sortDescTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2642 |
descGeneIndices = sortDescTValues.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
2643 |
|
2 |
26 Feb 07 |
jari |
2644 |
if (!useAllCombs) { |
2 |
26 Feb 07 |
jari |
2645 |
boolean[] changeSign = new boolean[1]; |
2 |
26 Feb 07 |
jari |
2646 |
|
2 |
26 Feb 07 |
jari |
2647 |
Random rand = new Random(); |
2 |
26 Feb 07 |
jari |
2648 |
long[] randomSeeds = new long[numCombs]; |
2 |
26 Feb 07 |
jari |
2649 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2650 |
randomSeeds[i] = rand.nextLong(); |
2 |
26 Feb 07 |
jari |
2651 |
} |
2 |
26 Feb 07 |
jari |
2652 |
|
2 |
26 Feb 07 |
jari |
2653 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2654 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2655 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2656 |
} |
2 |
26 Feb 07 |
jari |
2657 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2658 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
2659 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2660 |
int[] permutedExpts = new int[1]; |
2 |
26 Feb 07 |
jari |
2661 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
2662 |
|
2 |
26 Feb 07 |
jari |
2663 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
2664 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
2665 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
2666 |
} |
2 |
26 Feb 07 |
jari |
2667 |
} |
2 |
26 Feb 07 |
jari |
2668 |
|
2 |
26 Feb 07 |
jari |
2669 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
2670 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
2671 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
2672 |
} |
2 |
26 Feb 07 |
jari |
2673 |
|
2 |
26 Feb 07 |
jari |
2674 |
changeSign = getOneClassChangeSignArray(randomSeeds[i], validArray); |
2 |
26 Feb 07 |
jari |
2675 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
2676 |
|
2 |
26 Feb 07 |
jari |
2677 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
2678 |
|
2 |
26 Feb 07 |
jari |
2679 |
if (Double.isNaN(currentPermTValues[descGeneIndices[numGenes - 1]])) { |
2 |
26 Feb 07 |
jari |
2680 |
uMatrix[numGenes - 1][i] = Double.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
2681 |
} else { |
2 |
26 Feb 07 |
jari |
2682 |
uMatrix[numGenes - 1][i] = currentPermTValues[descGeneIndices[numGenes - 1]]; |
2 |
26 Feb 07 |
jari |
2683 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + (numGenes - 1) + "][" + i + "] = " + uMatrix[numGenes - 1][i]); |
2 |
26 Feb 07 |
jari |
2685 |
|
2 |
26 Feb 07 |
jari |
2686 |
for (int j = numGenes - 2; j >= 0; j--) { |
2 |
26 Feb 07 |
jari |
2687 |
if (Double.isNaN(currentPermTValues[descGeneIndices[j]])) { |
2 |
26 Feb 07 |
jari |
2688 |
uMatrix[j][i] = uMatrix[j+1][i]; |
2 |
26 Feb 07 |
jari |
2689 |
} else { |
2 |
26 Feb 07 |
jari |
2690 |
uMatrix[j][i] = Math.max(uMatrix[j+1][i], currentPermTValues[descGeneIndices[j]]); |
2 |
26 Feb 07 |
jari |
2691 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + j + "][" + i + "] = " + uMatrix[j][i]); |
2 |
26 Feb 07 |
jari |
2693 |
} |
2 |
26 Feb 07 |
jari |
2694 |
|
2 |
26 Feb 07 |
jari |
2695 |
/* |
2 |
26 Feb 07 |
jari |
QSort sortDescCurrentPermTValues = new QSort(currentPermTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
double[] descCurrentPermTValues = sortDescCurrentPermTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2698 |
|
2 |
26 Feb 07 |
jari |
for (int j = 0; j < permutedRankedTValues[i].length; j++) { |
2 |
26 Feb 07 |
jari |
permutedRankedTValues[i][j] = descCurrentPermTValues[j]; |
2 |
26 Feb 07 |
jari |
2701 |
} */ |
2 |
26 Feb 07 |
jari |
2702 |
} |
2 |
26 Feb 07 |
jari |
2703 |
} else { // if (useAllCombs) |
2 |
26 Feb 07 |
jari |
2704 |
for (int i = 0; i < numCombs; i++) { |
2 |
26 Feb 07 |
jari |
2705 |
if (stop) { |
2 |
26 Feb 07 |
jari |
2706 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
2707 |
} |
2 |
26 Feb 07 |
jari |
2708 |
event2.setIntValue(i); |
2 |
26 Feb 07 |
jari |
2709 |
event2.setDescription("Permuting matrix: Current permutation = " + (i+1)); |
2 |
26 Feb 07 |
jari |
2710 |
fireValueChanged(event2); |
2 |
26 Feb 07 |
jari |
2711 |
|
2 |
26 Feb 07 |
jari |
2712 |
Vector validExpts = new Vector(); |
2 |
26 Feb 07 |
jari |
2713 |
for (int j = 0; j < groupAssignments.length; j++) { |
2 |
26 Feb 07 |
jari |
2714 |
if (groupAssignments[j] == 1) { |
2 |
26 Feb 07 |
jari |
2715 |
validExpts.add(new Integer(j)); |
2 |
26 Feb 07 |
jari |
2716 |
} |
2 |
26 Feb 07 |
jari |
2717 |
} |
2 |
26 Feb 07 |
jari |
2718 |
|
2 |
26 Feb 07 |
jari |
2719 |
int[] validArray = new int[validExpts.size()]; |
2 |
26 Feb 07 |
jari |
2720 |
for (int j = 0; j < validArray.length; j++) { |
2 |
26 Feb 07 |
jari |
2721 |
validArray[j] = ((Integer)(validExpts.get(j))).intValue(); |
2 |
26 Feb 07 |
jari |
2722 |
} |
2 |
26 Feb 07 |
jari |
2723 |
|
2 |
26 Feb 07 |
jari |
2724 |
boolean[] changeSign = getOneClassChangeSignArrayAllUniquePerms(i, validArray); |
2 |
26 Feb 07 |
jari |
2725 |
FloatMatrix permutedMatrix = getOneClassPermMatrix(expMatrix, changeSign); |
2 |
26 Feb 07 |
jari |
2726 |
|
2 |
26 Feb 07 |
jari |
2727 |
double[] currentPermTValues = getOneClassTValues(permutedMatrix); |
2 |
26 Feb 07 |
jari |
2728 |
|
2 |
26 Feb 07 |
jari |
2729 |
if (Double.isNaN(currentPermTValues[descGeneIndices[numGenes - 1]])) { |
2 |
26 Feb 07 |
jari |
2730 |
uMatrix[numGenes - 1][i] = Double.NEGATIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
2731 |
} else { |
2 |
26 Feb 07 |
jari |
2732 |
uMatrix[numGenes - 1][i] = currentPermTValues[descGeneIndices[numGenes - 1]]; |
2 |
26 Feb 07 |
jari |
2733 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + (numGenes - 1) + "][" + i + "] = " + uMatrix[numGenes - 1][i]); |
2 |
26 Feb 07 |
jari |
2735 |
|
2 |
26 Feb 07 |
jari |
2736 |
for (int j = numGenes - 2; j >= 0; j--) { |
2 |
26 Feb 07 |
jari |
2737 |
if (Double.isNaN(currentPermTValues[descGeneIndices[j]])) { |
2 |
26 Feb 07 |
jari |
2738 |
uMatrix[j][i] = uMatrix[j+1][i]; |
2 |
26 Feb 07 |
jari |
2739 |
} else { |
2 |
26 Feb 07 |
jari |
2740 |
uMatrix[j][i] = Math.max(uMatrix[j+1][i], currentPermTValues[descGeneIndices[j]]); |
2 |
26 Feb 07 |
jari |
2741 |
} |
2 |
26 Feb 07 |
jari |
//System.out.println("uMatrix[" + j + "][" + i + "] = " + uMatrix[j][i]); |
2 |
26 Feb 07 |
jari |
2743 |
} |
2 |
26 Feb 07 |
jari |
2744 |
|
2 |
26 Feb 07 |
jari |
2745 |
/* |
2 |
26 Feb 07 |
jari |
QSort sortDescCurrentPermTValues = new QSort(currentPermTValues, QSort.DESCENDING); |
2 |
26 Feb 07 |
jari |
double[] descCurrentPermTValues = sortDescCurrentPermTValues.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2748 |
|
2 |
26 Feb 07 |
jari |
for (int j = 0; j < permutedRankedTValues[i].length; j++) { |
2 |
26 Feb 07 |
jari |
permutedRankedTValues[i][j] = descCurrentPermTValues[j]; |
2 |
26 Feb 07 |
jari |
2751 |
} */ |
2 |
26 Feb 07 |
jari |
2752 |
|
2 |
26 Feb 07 |
jari |
2753 |
} |
2 |
26 Feb 07 |
jari |
2754 |
} |
2 |
26 Feb 07 |
jari |
2755 |
} |
2 |
26 Feb 07 |
jari |
2756 |
|
2 |
26 Feb 07 |
jari |
2757 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2758 |
int pCounter = 0; |
2 |
26 Feb 07 |
jari |
2759 |
for (int j = 0; j < numCombs; j++) { |
2 |
26 Feb 07 |
jari |
2760 |
/* |
2 |
26 Feb 07 |
jari |
if (permutedRankedTValues[j][i] >= descTValues[i]) { |
2 |
26 Feb 07 |
jari |
pCounter++; |
2 |
26 Feb 07 |
jari |
2763 |
} |
2 |
26 Feb 07 |
jari |
2764 |
*/ |
2 |
26 Feb 07 |
jari |
2765 |
if (uMatrix[i][j] >= descTValues[i]) { |
2 |
26 Feb 07 |
jari |
2766 |
pCounter++; |
2 |
26 Feb 07 |
jari |
2767 |
} |
2 |
26 Feb 07 |
jari |
2768 |
} |
2 |
26 Feb 07 |
jari |
2769 |
adjPValues[descGeneIndices[i]] = (double)pCounter/(double)numCombs; |
2 |
26 Feb 07 |
jari |
//System.out.println("valid i = " + i + ", Valid index = " + descGeneIndices[i]); |
2 |
26 Feb 07 |
jari |
2771 |
/* |
2 |
26 Feb 07 |
jari |
if (Double.isNaN(origTValues[i])) { |
2 |
26 Feb 07 |
jari |
adjPValues[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
System.out.println("NaN index = " + i); |
2 |
26 Feb 07 |
jari |
} else { |
2 |
26 Feb 07 |
jari |
// UP TO HERE Dec 15 2003 |
2 |
26 Feb 07 |
jari |
int pCounter = 0; |
2 |
26 Feb 07 |
jari |
for (int j = 0; j < numCombs; j++) { |
2 |
26 Feb 07 |
jari |
if (permutedRankedTValues[j][i] >= descTValues[i]) { |
2 |
26 Feb 07 |
jari |
pCounter++; |
2 |
26 Feb 07 |
jari |
2781 |
} |
2 |
26 Feb 07 |
jari |
2782 |
} |
2 |
26 Feb 07 |
jari |
adjPValues[descGeneIndices[i]] = (double)pCounter/(double)numCombs; |
2 |
26 Feb 07 |
jari |
System.out.println("valid i = " + i + ", Valid index = " + descGeneIndices[i]); |
2 |
26 Feb 07 |
jari |
2785 |
} |
2 |
26 Feb 07 |
jari |
2786 |
*/ |
2 |
26 Feb 07 |
jari |
2787 |
} |
2 |
26 Feb 07 |
jari |
2788 |
|
2 |
26 Feb 07 |
jari |
2789 |
int NaNPCounter = 0; |
2 |
26 Feb 07 |
jari |
2790 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2791 |
if (Double.isNaN(origTValues[i])) { |
2 |
26 Feb 07 |
jari |
2792 |
adjPValues[i] = Double.NaN; |
2 |
26 Feb 07 |
jari |
2793 |
NaNPCounter++; |
2 |
26 Feb 07 |
jari |
//System.out.println("NaN index = " + i); |
2 |
26 Feb 07 |
jari |
2795 |
} |
2 |
26 Feb 07 |
jari |
2796 |
} |
2 |
26 Feb 07 |
jari |
//double[] pStarValues = new double[adjPValues]; |
2 |
26 Feb 07 |
jari |
//pStartValues[descGeneIndices[0]] |
2 |
26 Feb 07 |
jari |
2799 |
for (int i = 1; i < numGenes - NaNPCounter; i++) { // enforcing monotonicity |
2 |
26 Feb 07 |
jari |
2800 |
adjPValues[descGeneIndices[i]] = Math.max(adjPValues[descGeneIndices[i]], adjPValues[descGeneIndices[i - 1]]); |
2 |
26 Feb 07 |
jari |
2801 |
} |
2 |
26 Feb 07 |
jari |
2802 |
|
2 |
26 Feb 07 |
jari |
2803 |
return adjPValues; |
2 |
26 Feb 07 |
jari |
2804 |
} |
2 |
26 Feb 07 |
jari |
2805 |
|
2 |
26 Feb 07 |
jari |
2806 |
double[] getOneClassTValues(FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
2807 |
double[] tValsFromMatrix = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2808 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2809 |
tValsFromMatrix[i] = Math.abs(getOneClassTValue(i, inputMatrix)); |
2 |
26 Feb 07 |
jari |
2810 |
} |
2 |
26 Feb 07 |
jari |
2811 |
|
2 |
26 Feb 07 |
jari |
2812 |
return tValsFromMatrix; |
2 |
26 Feb 07 |
jari |
2813 |
} |
2 |
26 Feb 07 |
jari |
2814 |
|
2 |
26 Feb 07 |
jari |
2815 |
private boolean belongsInArray(int i, int[] arr) { |
2 |
26 Feb 07 |
jari |
2816 |
boolean belongs = false; |
2 |
26 Feb 07 |
jari |
2817 |
|
2 |
26 Feb 07 |
jari |
2818 |
for (int j = 0; j < arr.length; j++) { |
2 |
26 Feb 07 |
jari |
2819 |
if (i == arr[j]) { |
2 |
26 Feb 07 |
jari |
2820 |
belongs = true; |
2 |
26 Feb 07 |
jari |
2821 |
break; |
2 |
26 Feb 07 |
jari |
2822 |
} |
2 |
26 Feb 07 |
jari |
2823 |
} |
2 |
26 Feb 07 |
jari |
2824 |
|
2 |
26 Feb 07 |
jari |
2825 |
return belongs; |
2 |
26 Feb 07 |
jari |
2826 |
} |
2 |
26 Feb 07 |
jari |
2827 |
|
2 |
26 Feb 07 |
jari |
2828 |
private float getTValue(int gene, FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
2829 |
float[] geneValues = new float[numExps]; |
2 |
26 Feb 07 |
jari |
2830 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
2831 |
geneValues[i] = inputMatrix.A[gene][i]; |
2 |
26 Feb 07 |
jari |
2832 |
} |
2 |
26 Feb 07 |
jari |
2833 |
|
2 |
26 Feb 07 |
jari |
2834 |
int groupACounter = 0; |
2 |
26 Feb 07 |
jari |
2835 |
int groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
2836 |
|
2 |
26 Feb 07 |
jari |
2837 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
2838 |
if (groupAssignments[i] == Ttest.GROUP_A) { |
2 |
26 Feb 07 |
jari |
2839 |
groupACounter++; |
2 |
26 Feb 07 |
jari |
2840 |
} else if (groupAssignments[i] == Ttest.GROUP_B) { |
2 |
26 Feb 07 |
jari |
2841 |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
2842 |
} |
2 |
26 Feb 07 |
jari |
2843 |
} |
2 |
26 Feb 07 |
jari |
2844 |
|
2 |
26 Feb 07 |
jari |
2845 |
float[] groupAValues = new float[groupACounter]; |
2 |
26 Feb 07 |
jari |
2846 |
float[] groupBValues = new float[groupBCounter]; |
2 |
26 Feb 07 |
jari |
2847 |
|
2 |
26 Feb 07 |
jari |
2848 |
groupACounter = 0; |
2 |
26 Feb 07 |
jari |
2849 |
groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
2850 |
|
2 |
26 Feb 07 |
jari |
2851 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
2852 |
if (groupAssignments[i] == Ttest.GROUP_A) { |
2 |
26 Feb 07 |
jari |
2853 |
groupAValues[groupACounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
2854 |
groupACounter++; |
2 |
26 Feb 07 |
jari |
2855 |
} else if (groupAssignments[i] == Ttest.GROUP_B) { |
2 |
26 Feb 07 |
jari |
2856 |
groupBValues[groupBCounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
2857 |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
2858 |
} |
2 |
26 Feb 07 |
jari |
2859 |
} |
2 |
26 Feb 07 |
jari |
2860 |
|
2 |
26 Feb 07 |
jari |
2861 |
float tValue = calculateTValue(groupAValues, groupBValues); |
2 |
26 Feb 07 |
jari |
2862 |
return tValue; |
2 |
26 Feb 07 |
jari |
2863 |
} |
2 |
26 Feb 07 |
jari |
2864 |
|
2 |
26 Feb 07 |
jari |
2865 |
private double[] getTwoClassUnpairedTValues(FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
2866 |
double[] tValsFromMatrix = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
2867 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2868 |
tValsFromMatrix[i] = Math.abs(getTValue(i, inputMatrix)); |
2 |
26 Feb 07 |
jari |
2869 |
} |
2 |
26 Feb 07 |
jari |
2870 |
|
2 |
26 Feb 07 |
jari |
2871 |
return tValsFromMatrix; |
2 |
26 Feb 07 |
jari |
2872 |
} |
2 |
26 Feb 07 |
jari |
2873 |
|
2 |
26 Feb 07 |
jari |
2874 |
private FloatMatrix getPermutedMatrix(FloatMatrix inputMatrix, int[] permExpts) { |
2 |
26 Feb 07 |
jari |
2875 |
FloatMatrix permutedMatrix = new FloatMatrix(inputMatrix.getRowDimension(), inputMatrix.getColumnDimension()); |
2 |
26 Feb 07 |
jari |
2876 |
for (int i = 0; i < inputMatrix.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
2877 |
for (int j = 0; j < inputMatrix.getColumnDimension(); j++) { |
2 |
26 Feb 07 |
jari |
2878 |
permutedMatrix.A[i][j] = inputMatrix.A[i][permExpts[j]]; |
2 |
26 Feb 07 |
jari |
2879 |
} |
2 |
26 Feb 07 |
jari |
2880 |
} |
2 |
26 Feb 07 |
jari |
2881 |
return permutedMatrix; |
2 |
26 Feb 07 |
jari |
2882 |
} |
2 |
26 Feb 07 |
jari |
2883 |
|
2 |
26 Feb 07 |
jari |
2884 |
private int[] getPermutedValues(int arrayLength, int[] validArray) {//returns an integer array of length "arrayLength", with the valid values (the currently included experiments) permuted |
2 |
26 Feb 07 |
jari |
2885 |
int[] permutedValues = new int[arrayLength]; |
2 |
26 Feb 07 |
jari |
2886 |
for (int i = 0; i < permutedValues.length; i++) { |
2 |
26 Feb 07 |
jari |
2887 |
permutedValues[i] = i; |
2 |
26 Feb 07 |
jari |
2888 |
} |
2 |
26 Feb 07 |
jari |
2889 |
|
2 |
26 Feb 07 |
jari |
2890 |
int[] permutedValidArray = new int[validArray.length]; |
2 |
26 Feb 07 |
jari |
2891 |
for (int i = 0; i < validArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2892 |
permutedValidArray[i] = validArray[i]; |
2 |
26 Feb 07 |
jari |
2893 |
} |
2 |
26 Feb 07 |
jari |
2894 |
|
2 |
26 Feb 07 |
jari |
2895 |
for (int i = permutedValidArray.length; i > 1; i--) { |
2 |
26 Feb 07 |
jari |
2896 |
Random generator2 =new Random(); |
2 |
26 Feb 07 |
jari |
//Random generator2 = new Random(randomSeeds[i - 2]); |
2 |
26 Feb 07 |
jari |
2898 |
int randVal = generator2.nextInt(i - 1); |
2 |
26 Feb 07 |
jari |
2899 |
int temp = permutedValidArray[randVal]; |
2 |
26 Feb 07 |
jari |
2900 |
permutedValidArray[randVal] = permutedValidArray[i - 1]; |
2 |
26 Feb 07 |
jari |
2901 |
permutedValidArray[i - 1] = temp; |
2 |
26 Feb 07 |
jari |
2902 |
} |
2 |
26 Feb 07 |
jari |
2903 |
|
2 |
26 Feb 07 |
jari |
2904 |
for (int i = 0; i < validArray.length; i++) { |
2 |
26 Feb 07 |
jari |
//permutedValues[validArray[i]] = permutedValues[permutedValidArray[i]]; |
2 |
26 Feb 07 |
jari |
2906 |
permutedValues[validArray[i]] = permutedValidArray[i]; |
2 |
26 Feb 07 |
jari |
2907 |
} |
2 |
26 Feb 07 |
jari |
2908 |
|
2 |
26 Feb 07 |
jari |
2909 |
/* |
2 |
26 Feb 07 |
jari |
long[] randomSeeds = new long[permutedValues.length - 1]; |
2 |
26 Feb 07 |
jari |
2911 |
|
2 |
26 Feb 07 |
jari |
2912 |
|
2 |
26 Feb 07 |
jari |
for (int i = 0; i < randomSeeds.length; i++) { |
2 |
26 Feb 07 |
jari |
Random generator = new Random(i); |
2 |
26 Feb 07 |
jari |
randomSeeds[i] = generator.nextLong(); |
2 |
26 Feb 07 |
jari |
//System.out.println("randomSeeds[" + i + "] =" + randomSeeds[i]); |
2 |
26 Feb 07 |
jari |
2917 |
} |
2 |
26 Feb 07 |
jari |
2918 |
*/ |
2 |
26 Feb 07 |
jari |
2919 |
/* |
2 |
26 Feb 07 |
jari |
for (int i = permutedValues.length; i > 1; i--) { |
2 |
26 Feb 07 |
jari |
Random generator2 =new Random(); |
2 |
26 Feb 07 |
jari |
//Random generator2 = new Random(randomSeeds[i - 2]); |
2 |
26 Feb 07 |
jari |
int randVal = generator2.nextInt(i - 1); |
2 |
26 Feb 07 |
jari |
int temp = permutedValues[randVal]; |
2 |
26 Feb 07 |
jari |
permutedValues[randVal] = permutedValues[i - 1]; |
2 |
26 Feb 07 |
jari |
permutedValues[i - 1] = temp; |
2 |
26 Feb 07 |
jari |
2927 |
} |
2 |
26 Feb 07 |
jari |
2928 |
*/ |
2 |
26 Feb 07 |
jari |
2929 |
|
2 |
26 Feb 07 |
jari |
2930 |
try { |
2 |
26 Feb 07 |
jari |
2931 |
Thread.sleep(10); |
2 |
26 Feb 07 |
jari |
2932 |
} catch (Exception exc) { |
2 |
26 Feb 07 |
jari |
2933 |
exc.printStackTrace(); |
2 |
26 Feb 07 |
jari |
2934 |
} |
2 |
26 Feb 07 |
jari |
2935 |
|
2 |
26 Feb 07 |
jari |
2936 |
|
2 |
26 Feb 07 |
jari |
2937 |
return permutedValues; |
2 |
26 Feb 07 |
jari |
2938 |
|
2 |
26 Feb 07 |
jari |
2939 |
} |
2 |
26 Feb 07 |
jari |
2940 |
|
2 |
26 Feb 07 |
jari |
2941 |
private double[] getAdjBonfPVals(double[] rawPValArray) { |
2 |
26 Feb 07 |
jari |
2942 |
double[] adjPValArray = new double[rawPValArray.length]; |
2 |
26 Feb 07 |
jari |
2943 |
isSig = new boolean[rawPValArray.length]; |
2 |
26 Feb 07 |
jari |
2944 |
for (int i = 0; i < isSig.length; i++) { |
2 |
26 Feb 07 |
jari |
2945 |
isSig[i] = false; |
2 |
26 Feb 07 |
jari |
2946 |
} |
2 |
26 Feb 07 |
jari |
2947 |
QSort sortRawPs = new QSort(rawPValArray, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
2948 |
double[] sortedRawPVals = sortRawPs.getSortedDouble(); |
2 |
26 Feb 07 |
jari |
2949 |
int[] origIndices = sortRawPs.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
2950 |
int n = numGenes; |
2 |
26 Feb 07 |
jari |
2951 |
adjPValArray[origIndices[0]] = sortedRawPVals[0]*n; |
2 |
26 Feb 07 |
jari |
2952 |
for (int i = 1; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
2953 |
if (sortedRawPVals[i - 1] < sortedRawPVals[i]) n--; |
2 |
26 Feb 07 |
jari |
2954 |
if (n <= 0) n = 1; |
2 |
26 Feb 07 |
jari |
2955 |
adjPValArray[origIndices[i]] = sortedRawPVals[i]*n; |
2 |
26 Feb 07 |
jari |
2956 |
} |
2 |
26 Feb 07 |
jari |
2957 |
|
2 |
26 Feb 07 |
jari |
2958 |
for (int i = 0; i < adjPValArray.length; i++) { |
2 |
26 Feb 07 |
jari |
2959 |
if (adjPValArray[i] > 1.0d) adjPValArray[i] = 1.0d; |
2 |
26 Feb 07 |
jari |
2960 |
} |
2 |
26 Feb 07 |
jari |
2961 |
|
2 |
26 Feb 07 |
jari |
2962 |
for (int i = 0; i < origIndices.length; i++) {// break out of loop as soon as non-significant value is encountered |
2 |
26 Feb 07 |
jari |
2963 |
if (adjPValArray[origIndices[i]] > (double)alpha) { |
2 |
26 Feb 07 |
jari |
2964 |
break; |
2 |
26 Feb 07 |
jari |
2965 |
} else { |
2 |
26 Feb 07 |
jari |
2966 |
if (adjPValArray[origIndices[i]] <= (double)alpha) { |
2 |
26 Feb 07 |
jari |
2967 |
isSig[origIndices[i]] = true; |
2 |
26 Feb 07 |
jari |
2968 |
} |
2 |
26 Feb 07 |
jari |
2969 |
} |
2 |
26 Feb 07 |
jari |
2970 |
} |
2 |
26 Feb 07 |
jari |
2971 |
|
2 |
26 Feb 07 |
jari |
2972 |
return adjPValArray; |
2 |
26 Feb 07 |
jari |
2973 |
} |
2 |
26 Feb 07 |
jari |
2974 |
|
2 |
26 Feb 07 |
jari |
2975 |
private int[] getPairedDfs(FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
2976 |
int[] pairedDfs = new int[numGenes]; |
2 |
26 Feb 07 |
jari |
2977 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
2978 |
|
2 |
26 Feb 07 |
jari |
2979 |
float[] geneValues = new float[numExps]; |
2 |
26 Feb 07 |
jari |
2980 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
2981 |
geneValues[i] = inputMatrix.A[gene][i]; |
2 |
26 Feb 07 |
jari |
2982 |
} |
2 |
26 Feb 07 |
jari |
2983 |
|
2 |
26 Feb 07 |
jari |
2984 |
float[] groupAValues = new float[pairedGroupAExpts.length]; |
2 |
26 Feb 07 |
jari |
2985 |
float[] groupBValues = new float[pairedGroupBExpts.length]; |
2 |
26 Feb 07 |
jari |
2986 |
|
2 |
26 Feb 07 |
jari |
2987 |
int numbValidValuesA = 0; |
2 |
26 Feb 07 |
jari |
2988 |
int numbValidValuesB = 0; |
2 |
26 Feb 07 |
jari |
2989 |
|
2 |
26 Feb 07 |
jari |
2990 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
2991 |
groupAValues[i] = geneValues[pairedGroupAExpts[i]]; |
2 |
26 Feb 07 |
jari |
2992 |
if (!Float.isNaN(geneValues[pairedGroupAExpts[i]])) { |
2 |
26 Feb 07 |
jari |
2993 |
numbValidValuesA++; |
2 |
26 Feb 07 |
jari |
2994 |
} |
2 |
26 Feb 07 |
jari |
2995 |
groupBValues[i] = geneValues[pairedGroupBExpts[i]]; |
2 |
26 Feb 07 |
jari |
2996 |
if (!Float.isNaN(geneValues[pairedGroupBExpts[i]])) { |
2 |
26 Feb 07 |
jari |
2997 |
numbValidValuesB++; |
2 |
26 Feb 07 |
jari |
2998 |
} |
2 |
26 Feb 07 |
jari |
2999 |
} |
2 |
26 Feb 07 |
jari |
3000 |
|
2 |
26 Feb 07 |
jari |
3001 |
if ((numbValidValuesA < 2) || (numbValidValuesB < 2)) { |
2 |
26 Feb 07 |
jari |
3002 |
pairedDfs[gene] = -1; |
2 |
26 Feb 07 |
jari |
3003 |
} else { |
2 |
26 Feb 07 |
jari |
3004 |
int N = 0; |
2 |
26 Feb 07 |
jari |
3005 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
3006 |
if ( (!Double.isNaN(inputMatrix.A[gene][pairedGroupAExpts[i]])) && (!Double.isNaN(inputMatrix.A[gene][pairedGroupBExpts[i]])) ) { |
2 |
26 Feb 07 |
jari |
3007 |
N++; |
2 |
26 Feb 07 |
jari |
3008 |
} |
2 |
26 Feb 07 |
jari |
3009 |
} |
2 |
26 Feb 07 |
jari |
3010 |
pairedDfs[gene] = N - 1; |
2 |
26 Feb 07 |
jari |
3011 |
} |
2 |
26 Feb 07 |
jari |
3012 |
} |
2 |
26 Feb 07 |
jari |
3013 |
return pairedDfs; |
2 |
26 Feb 07 |
jari |
3014 |
} |
2 |
26 Feb 07 |
jari |
3015 |
|
2 |
26 Feb 07 |
jari |
3016 |
private int[] getTwoClassDfs(FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
3017 |
int[] twoClassDfs = new int[numGenes]; |
2 |
26 Feb 07 |
jari |
3018 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
3019 |
float[] geneValues = new float[numExps]; |
2 |
26 Feb 07 |
jari |
3020 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
3021 |
geneValues[i] = inputMatrix.A[gene][i]; |
2 |
26 Feb 07 |
jari |
3022 |
} |
2 |
26 Feb 07 |
jari |
3023 |
|
2 |
26 Feb 07 |
jari |
3024 |
int groupACounter = 0; |
2 |
26 Feb 07 |
jari |
3025 |
int groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
3026 |
|
2 |
26 Feb 07 |
jari |
3027 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
3028 |
if (groupAssignments[i] == GROUP_A) { |
2 |
26 Feb 07 |
jari |
3029 |
groupACounter++; |
2 |
26 Feb 07 |
jari |
3030 |
} else if (groupAssignments[i] == GROUP_B) { |
2 |
26 Feb 07 |
jari |
3031 |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
3032 |
} |
2 |
26 Feb 07 |
jari |
3033 |
} |
2 |
26 Feb 07 |
jari |
3034 |
|
2 |
26 Feb 07 |
jari |
3035 |
float[] groupAValues = new float[groupACounter]; |
2 |
26 Feb 07 |
jari |
3036 |
float[] groupBValues = new float[groupBCounter]; |
2 |
26 Feb 07 |
jari |
3037 |
|
2 |
26 Feb 07 |
jari |
3038 |
int numbValidValuesA = 0; |
2 |
26 Feb 07 |
jari |
3039 |
int numbValidValuesB = 0; |
2 |
26 Feb 07 |
jari |
3040 |
|
2 |
26 Feb 07 |
jari |
3041 |
groupACounter = 0; |
2 |
26 Feb 07 |
jari |
3042 |
groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
3043 |
|
2 |
26 Feb 07 |
jari |
3044 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
3045 |
if (groupAssignments[i] == GROUP_A) { |
2 |
26 Feb 07 |
jari |
3046 |
groupAValues[groupACounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
3047 |
if (!Float.isNaN(geneValues[i])) { |
2 |
26 Feb 07 |
jari |
3048 |
numbValidValuesA++; |
2 |
26 Feb 07 |
jari |
3049 |
} |
2 |
26 Feb 07 |
jari |
3050 |
groupACounter++; |
2 |
26 Feb 07 |
jari |
3051 |
} else if (groupAssignments[i] == GROUP_B) { |
2 |
26 Feb 07 |
jari |
3052 |
groupBValues[groupBCounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
3053 |
if (!Float.isNaN(geneValues[i])) { |
2 |
26 Feb 07 |
jari |
3054 |
numbValidValuesB++; |
2 |
26 Feb 07 |
jari |
3055 |
} |
2 |
26 Feb 07 |
jari |
3056 |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
3057 |
} |
2 |
26 Feb 07 |
jari |
3058 |
} |
2 |
26 Feb 07 |
jari |
3059 |
|
2 |
26 Feb 07 |
jari |
3060 |
if ((numbValidValuesA < 2) || (numbValidValuesB < 2)) { |
2 |
26 Feb 07 |
jari |
3061 |
twoClassDfs[gene] = -1; |
2 |
26 Feb 07 |
jari |
3062 |
} else { |
2 |
26 Feb 07 |
jari |
3063 |
twoClassDfs[gene] = calculateDf(groupAValues, groupBValues); |
2 |
26 Feb 07 |
jari |
3064 |
} |
2 |
26 Feb 07 |
jari |
3065 |
|
2 |
26 Feb 07 |
jari |
3066 |
} |
2 |
26 Feb 07 |
jari |
3067 |
|
2 |
26 Feb 07 |
jari |
3068 |
return twoClassDfs; |
2 |
26 Feb 07 |
jari |
3069 |
} |
2 |
26 Feb 07 |
jari |
3070 |
|
2 |
26 Feb 07 |
jari |
3071 |
private int[] getOneClassDfs(FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
3072 |
int[] oneClassDfValues = new int[numGenes]; |
2 |
26 Feb 07 |
jari |
3073 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
3074 |
Vector currentGene = new Vector(); |
2 |
26 Feb 07 |
jari |
3075 |
|
2 |
26 Feb 07 |
jari |
3076 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
3077 |
if (groupAssignments[i] == 1) { |
2 |
26 Feb 07 |
jari |
3078 |
currentGene.add(new Float(inputMatrix.A[gene][i])); |
2 |
26 Feb 07 |
jari |
3079 |
} |
2 |
26 Feb 07 |
jari |
3080 |
} |
2 |
26 Feb 07 |
jari |
3081 |
float[] currGeneArray = new float[currentGene.size()]; |
2 |
26 Feb 07 |
jari |
3082 |
|
2 |
26 Feb 07 |
jari |
3083 |
for (int i = 0; i < currGeneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
3084 |
currGeneArray[i] = ((Float)(currentGene.get(i))).floatValue(); |
2 |
26 Feb 07 |
jari |
3085 |
} |
2 |
26 Feb 07 |
jari |
3086 |
int validNum = 0; |
2 |
26 Feb 07 |
jari |
3087 |
for (int i = 0; i < currGeneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
3088 |
if (!Float.isNaN(currGeneArray[i])) { |
2 |
26 Feb 07 |
jari |
3089 |
validNum++; |
2 |
26 Feb 07 |
jari |
3090 |
} |
2 |
26 Feb 07 |
jari |
3091 |
} |
2 |
26 Feb 07 |
jari |
3092 |
|
2 |
26 Feb 07 |
jari |
3093 |
oneClassDfValues[gene] = validNum -1; |
2 |
26 Feb 07 |
jari |
3094 |
} |
2 |
26 Feb 07 |
jari |
3095 |
|
2 |
26 Feb 07 |
jari |
3096 |
return oneClassDfValues; |
2 |
26 Feb 07 |
jari |
3097 |
} |
2 |
26 Feb 07 |
jari |
3098 |
|
2 |
26 Feb 07 |
jari |
3099 |
private void computeOneClassOrigVals() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
3100 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numGenes); |
2 |
26 Feb 07 |
jari |
3101 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
3102 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
3103 |
|
2 |
26 Feb 07 |
jari |
3104 |
oneClassMeans = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3105 |
oneClassSDs = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3106 |
dfValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3107 |
tValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3108 |
|
2 |
26 Feb 07 |
jari |
3109 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
3110 |
if (stop) { |
2 |
26 Feb 07 |
jari |
3111 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
3112 |
} |
2 |
26 Feb 07 |
jari |
3113 |
event.setIntValue(gene); |
2 |
26 Feb 07 |
jari |
3114 |
event.setDescription("Calculating t values: Current gene = " + (gene + 1)); |
2 |
26 Feb 07 |
jari |
3115 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
3116 |
|
2 |
26 Feb 07 |
jari |
3117 |
Vector currentGene = new Vector(); |
2 |
26 Feb 07 |
jari |
3118 |
|
2 |
26 Feb 07 |
jari |
3119 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
3120 |
if (groupAssignments[i] == 1) { |
2 |
26 Feb 07 |
jari |
3121 |
currentGene.add(new Float(expMatrix.A[gene][i])); |
2 |
26 Feb 07 |
jari |
3122 |
} |
2 |
26 Feb 07 |
jari |
3123 |
} |
2 |
26 Feb 07 |
jari |
3124 |
|
2 |
26 Feb 07 |
jari |
3125 |
float[] currGeneArray = new float[currentGene.size()]; |
2 |
26 Feb 07 |
jari |
3126 |
|
2 |
26 Feb 07 |
jari |
3127 |
for (int i = 0; i < currGeneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
3128 |
currGeneArray[i] = ((Float)(currentGene.get(i))).floatValue(); |
2 |
26 Feb 07 |
jari |
3129 |
} |
2 |
26 Feb 07 |
jari |
3130 |
|
2 |
26 Feb 07 |
jari |
3131 |
tValues[gene] = getOneClassTValue(currGeneArray); |
2 |
26 Feb 07 |
jari |
3132 |
oneClassMeans[gene] = (double)(getMean(currGeneArray)); |
2 |
26 Feb 07 |
jari |
3133 |
oneClassSDs[gene] = Math.sqrt((double)(getVar(currGeneArray))); |
2 |
26 Feb 07 |
jari |
3134 |
|
2 |
26 Feb 07 |
jari |
3135 |
int validNum = 0; |
2 |
26 Feb 07 |
jari |
3136 |
for (int i = 0; i < currGeneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
3137 |
if (!Float.isNaN(currGeneArray[i])) { |
2 |
26 Feb 07 |
jari |
3138 |
validNum++; |
2 |
26 Feb 07 |
jari |
3139 |
} |
2 |
26 Feb 07 |
jari |
3140 |
} |
2 |
26 Feb 07 |
jari |
3141 |
|
2 |
26 Feb 07 |
jari |
3142 |
dfValues[gene] = (double)(validNum -1); |
2 |
26 Feb 07 |
jari |
3143 |
} |
2 |
26 Feb 07 |
jari |
3144 |
} |
2 |
26 Feb 07 |
jari |
3145 |
|
2 |
26 Feb 07 |
jari |
3146 |
private double getOneClassTValue(float[] geneArray) { |
2 |
26 Feb 07 |
jari |
3147 |
double tValue; |
2 |
26 Feb 07 |
jari |
3148 |
|
2 |
26 Feb 07 |
jari |
3149 |
float mean = getMean(geneArray); |
2 |
26 Feb 07 |
jari |
3150 |
double stdDev = Math.sqrt((double)(getVar(geneArray))); |
2 |
26 Feb 07 |
jari |
3151 |
|
2 |
26 Feb 07 |
jari |
3152 |
int validNum = 0; |
2 |
26 Feb 07 |
jari |
3153 |
for (int i = 0; i < geneArray.length; i++) { |
2 |
26 Feb 07 |
jari |
3154 |
if (!Float.isNaN(geneArray[i])) { |
2 |
26 Feb 07 |
jari |
3155 |
validNum++; |
2 |
26 Feb 07 |
jari |
3156 |
} |
2 |
26 Feb 07 |
jari |
3157 |
} |
2 |
26 Feb 07 |
jari |
3158 |
|
2 |
26 Feb 07 |
jari |
3159 |
double stdErr = stdDev / (Math.sqrt(validNum)); |
2 |
26 Feb 07 |
jari |
3160 |
|
2 |
26 Feb 07 |
jari |
3161 |
tValue = ((double)(mean - oneClassMean))/stdErr; |
2 |
26 Feb 07 |
jari |
3162 |
|
2 |
26 Feb 07 |
jari |
3163 |
|
2 |
26 Feb 07 |
jari |
3164 |
|
2 |
26 Feb 07 |
jari |
3165 |
return Math.abs(tValue); |
2 |
26 Feb 07 |
jari |
3166 |
} |
2 |
26 Feb 07 |
jari |
3167 |
|
2 |
26 Feb 07 |
jari |
3168 |
private void computePairedOrigVals() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
3169 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numGenes); |
2 |
26 Feb 07 |
jari |
3170 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
3171 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
3172 |
|
2 |
26 Feb 07 |
jari |
3173 |
groupAMeans = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3174 |
groupBMeans = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3175 |
groupASDs = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3176 |
groupBSDs = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3177 |
dfValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3178 |
tValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3179 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
3180 |
if (stop) { |
2 |
26 Feb 07 |
jari |
3181 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
3182 |
} |
2 |
26 Feb 07 |
jari |
3183 |
event.setIntValue(gene); |
2 |
26 Feb 07 |
jari |
3184 |
event.setDescription("Calculating t values: Current gene = " + (gene + 1)); |
2 |
26 Feb 07 |
jari |
3185 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
3186 |
|
2 |
26 Feb 07 |
jari |
3187 |
float[] geneValues = new float[numExps]; |
2 |
26 Feb 07 |
jari |
3188 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
3189 |
geneValues[i] = expMatrix.A[gene][i]; |
2 |
26 Feb 07 |
jari |
3190 |
} |
2 |
26 Feb 07 |
jari |
3191 |
|
2 |
26 Feb 07 |
jari |
3192 |
float[] groupAValues = new float[pairedGroupAExpts.length]; |
2 |
26 Feb 07 |
jari |
3193 |
float[] groupBValues = new float[pairedGroupBExpts.length]; |
2 |
26 Feb 07 |
jari |
3194 |
|
2 |
26 Feb 07 |
jari |
3195 |
int numbValidValuesA = 0; |
2 |
26 Feb 07 |
jari |
3196 |
int numbValidValuesB = 0; |
2 |
26 Feb 07 |
jari |
3197 |
|
2 |
26 Feb 07 |
jari |
3198 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
3199 |
groupAValues[i] = geneValues[pairedGroupAExpts[i]]; |
2 |
26 Feb 07 |
jari |
3200 |
if (!Float.isNaN(geneValues[pairedGroupAExpts[i]])) { |
2 |
26 Feb 07 |
jari |
3201 |
numbValidValuesA++; |
2 |
26 Feb 07 |
jari |
3202 |
} |
2 |
26 Feb 07 |
jari |
3203 |
groupBValues[i] = geneValues[pairedGroupBExpts[i]]; |
2 |
26 Feb 07 |
jari |
3204 |
if (!Float.isNaN(geneValues[pairedGroupBExpts[i]])) { |
2 |
26 Feb 07 |
jari |
3205 |
numbValidValuesB++; |
2 |
26 Feb 07 |
jari |
3206 |
} |
2 |
26 Feb 07 |
jari |
3207 |
} |
2 |
26 Feb 07 |
jari |
3208 |
|
2 |
26 Feb 07 |
jari |
3209 |
if ((numbValidValuesA < 2) || (numbValidValuesB < 2)) { |
2 |
26 Feb 07 |
jari |
3210 |
tValues[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3211 |
dfValues[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3212 |
groupAMeans[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3213 |
groupBMeans[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3214 |
groupASDs[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3215 |
groupBSDs[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3216 |
} else { |
2 |
26 Feb 07 |
jari |
3217 |
tValues[gene] = getPairedTValue(gene, expMatrix); |
2 |
26 Feb 07 |
jari |
3218 |
|
2 |
26 Feb 07 |
jari |
3219 |
int N = 0; |
2 |
26 Feb 07 |
jari |
3220 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
3221 |
if ( (!Double.isNaN(expMatrix.A[gene][pairedGroupAExpts[i]])) && (!Double.isNaN(expMatrix.A[gene][pairedGroupBExpts[i]])) ) { |
2 |
26 Feb 07 |
jari |
3222 |
N++; |
2 |
26 Feb 07 |
jari |
3223 |
} |
2 |
26 Feb 07 |
jari |
3224 |
} |
2 |
26 Feb 07 |
jari |
3225 |
|
2 |
26 Feb 07 |
jari |
3226 |
dfValues[gene] = (double)(N - 1); |
2 |
26 Feb 07 |
jari |
3227 |
groupAMeans[gene] = (double)(getMean(groupAValues)); |
2 |
26 Feb 07 |
jari |
3228 |
groupBMeans[gene] = (double)(getMean(groupBValues)); |
2 |
26 Feb 07 |
jari |
3229 |
groupASDs[gene] = (double)(Math.sqrt(getVar(groupAValues))); |
2 |
26 Feb 07 |
jari |
3230 |
groupBSDs[gene] = (double)(Math.sqrt(getVar(groupBValues))); |
2 |
26 Feb 07 |
jari |
3231 |
} |
2 |
26 Feb 07 |
jari |
3232 |
} |
2 |
26 Feb 07 |
jari |
3233 |
} |
2 |
26 Feb 07 |
jari |
3234 |
|
2 |
26 Feb 07 |
jari |
3235 |
private double getPairedTValue(int gene, FloatMatrix inputMatrix) {//Jaccard & Becker, 2nd ed. pg 250 |
2 |
26 Feb 07 |
jari |
3236 |
double sumDev = 0d; |
2 |
26 Feb 07 |
jari |
3237 |
int N = 0; |
2 |
26 Feb 07 |
jari |
3238 |
|
2 |
26 Feb 07 |
jari |
3239 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
3240 |
if ( (!Double.isNaN(inputMatrix.A[gene][pairedGroupAExpts[i]])) && (!Double.isNaN(inputMatrix.A[gene][pairedGroupBExpts[i]])) ) { |
2 |
26 Feb 07 |
jari |
3241 |
sumDev = sumDev + (double)(inputMatrix.A[gene][pairedGroupAExpts[i]] - inputMatrix.A[gene][pairedGroupBExpts[i]]); |
2 |
26 Feb 07 |
jari |
3242 |
N++; |
2 |
26 Feb 07 |
jari |
3243 |
} |
2 |
26 Feb 07 |
jari |
3244 |
} |
2 |
26 Feb 07 |
jari |
3245 |
|
2 |
26 Feb 07 |
jari |
3246 |
if (N < 2) return Double.NaN; |
2 |
26 Feb 07 |
jari |
3247 |
|
2 |
26 Feb 07 |
jari |
3248 |
double meanDev = sumDev/(double)N; |
2 |
26 Feb 07 |
jari |
3249 |
|
2 |
26 Feb 07 |
jari |
3250 |
double sumSquaredDev = 0d; |
2 |
26 Feb 07 |
jari |
3251 |
for (int i = 0; i < pairedGroupAExpts.length; i++) { |
2 |
26 Feb 07 |
jari |
3252 |
if ( (!Double.isNaN(inputMatrix.A[gene][pairedGroupAExpts[i]])) && (!Double.isNaN(inputMatrix.A[gene][pairedGroupBExpts[i]])) ) { |
2 |
26 Feb 07 |
jari |
3253 |
sumSquaredDev = sumSquaredDev + Math.pow((double)(inputMatrix.A[gene][pairedGroupAExpts[i]] - inputMatrix.A[gene][pairedGroupBExpts[i]]), 2); |
2 |
26 Feb 07 |
jari |
3254 |
} |
2 |
26 Feb 07 |
jari |
3255 |
} |
2 |
26 Feb 07 |
jari |
3256 |
|
2 |
26 Feb 07 |
jari |
//int N = pairedGroupAExpts.length; |
2 |
26 Feb 07 |
jari |
3258 |
|
2 |
26 Feb 07 |
jari |
3259 |
double ssD = sumSquaredDev - Math.pow(sumDev, 2)/(double)N; |
2 |
26 Feb 07 |
jari |
3260 |
double sHatDSquared = ssD/(double)(N - 1); |
2 |
26 Feb 07 |
jari |
3261 |
double sHatDBar = Math.sqrt(sHatDSquared/(double)N); |
2 |
26 Feb 07 |
jari |
3262 |
|
2 |
26 Feb 07 |
jari |
3263 |
return Math.abs((meanDev/sHatDBar)); |
2 |
26 Feb 07 |
jari |
3264 |
} |
2 |
26 Feb 07 |
jari |
3265 |
|
2 |
26 Feb 07 |
jari |
3266 |
private double[] getPairedTValues(FloatMatrix inputMatrix) { |
2 |
26 Feb 07 |
jari |
3267 |
double[] pairedTValues = new double[inputMatrix.getRowDimension()]; |
2 |
26 Feb 07 |
jari |
3268 |
for (int i = 0; i < pairedTValues.length; i++) { |
2 |
26 Feb 07 |
jari |
3269 |
pairedTValues[i] = getPairedTValue(i, inputMatrix); |
2 |
26 Feb 07 |
jari |
3270 |
} |
2 |
26 Feb 07 |
jari |
3271 |
return pairedTValues; |
2 |
26 Feb 07 |
jari |
3272 |
} |
2 |
26 Feb 07 |
jari |
3273 |
|
2 |
26 Feb 07 |
jari |
3274 |
private void computeBtnSubOrigVals() throws AlgorithmException { |
2 |
26 Feb 07 |
jari |
3275 |
event = new AlgorithmEvent(this, AlgorithmEvent.SET_UNITS, numGenes); |
2 |
26 Feb 07 |
jari |
3276 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
3277 |
event.setId(AlgorithmEvent.PROGRESS_VALUE); |
2 |
26 Feb 07 |
jari |
3278 |
|
2 |
26 Feb 07 |
jari |
3279 |
groupAMeans = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3280 |
groupBMeans = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3281 |
groupASDs = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3282 |
groupBSDs = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3283 |
dfValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3284 |
tValues = new double[numGenes]; |
2 |
26 Feb 07 |
jari |
3285 |
|
2 |
26 Feb 07 |
jari |
3286 |
for (int gene = 0; gene < numGenes; gene++) { |
2 |
26 Feb 07 |
jari |
3287 |
if (stop) { |
2 |
26 Feb 07 |
jari |
3288 |
throw new AbortException(); |
2 |
26 Feb 07 |
jari |
3289 |
} |
2 |
26 Feb 07 |
jari |
3290 |
event.setIntValue(gene); |
2 |
26 Feb 07 |
jari |
3291 |
event.setDescription("Calculating t values: Current gene = " + (gene + 1)); |
2 |
26 Feb 07 |
jari |
3292 |
fireValueChanged(event); |
2 |
26 Feb 07 |
jari |
3293 |
|
2 |
26 Feb 07 |
jari |
3294 |
float[] geneValues = new float[numExps]; |
2 |
26 Feb 07 |
jari |
3295 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
3296 |
geneValues[i] = expMatrix.A[gene][i]; |
2 |
26 Feb 07 |
jari |
3297 |
} |
2 |
26 Feb 07 |
jari |
3298 |
|
2 |
26 Feb 07 |
jari |
3299 |
int groupACounter = 0; |
2 |
26 Feb 07 |
jari |
3300 |
int groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
3301 |
|
2 |
26 Feb 07 |
jari |
3302 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
3303 |
if (groupAssignments[i] == GROUP_A) { |
2 |
26 Feb 07 |
jari |
3304 |
groupACounter++; |
2 |
26 Feb 07 |
jari |
3305 |
} else if (groupAssignments[i] == GROUP_B) { |
2 |
26 Feb 07 |
jari |
3306 |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
3307 |
} |
2 |
26 Feb 07 |
jari |
3308 |
} |
2 |
26 Feb 07 |
jari |
3309 |
|
2 |
26 Feb 07 |
jari |
3310 |
float[] groupAValues = new float[groupACounter]; |
2 |
26 Feb 07 |
jari |
3311 |
float[] groupBValues = new float[groupBCounter]; |
2 |
26 Feb 07 |
jari |
3312 |
|
2 |
26 Feb 07 |
jari |
3313 |
int numbValidValuesA = 0; |
2 |
26 Feb 07 |
jari |
3314 |
int numbValidValuesB = 0; |
2 |
26 Feb 07 |
jari |
3315 |
|
2 |
26 Feb 07 |
jari |
3316 |
groupACounter = 0; |
2 |
26 Feb 07 |
jari |
3317 |
groupBCounter = 0; |
2 |
26 Feb 07 |
jari |
3318 |
|
2 |
26 Feb 07 |
jari |
3319 |
for (int i = 0; i < groupAssignments.length; i++) { |
2 |
26 Feb 07 |
jari |
3320 |
if (groupAssignments[i] == GROUP_A) { |
2 |
26 Feb 07 |
jari |
3321 |
groupAValues[groupACounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
3322 |
if (!Float.isNaN(geneValues[i])) { |
2 |
26 Feb 07 |
jari |
3323 |
numbValidValuesA++; |
2 |
26 Feb 07 |
jari |
3324 |
} |
2 |
26 Feb 07 |
jari |
3325 |
groupACounter++; |
2 |
26 Feb 07 |
jari |
3326 |
} else if (groupAssignments[i] == GROUP_B) { |
2 |
26 Feb 07 |
jari |
3327 |
groupBValues[groupBCounter] = geneValues[i]; |
2 |
26 Feb 07 |
jari |
3328 |
if (!Float.isNaN(geneValues[i])) { |
2 |
26 Feb 07 |
jari |
3329 |
numbValidValuesB++; |
2 |
26 Feb 07 |
jari |
3330 |
} |
2 |
26 Feb 07 |
jari |
3331 |
groupBCounter++; |
2 |
26 Feb 07 |
jari |
3332 |
} |
2 |
26 Feb 07 |
jari |
3333 |
} |
2 |
26 Feb 07 |
jari |
3334 |
|
2 |
26 Feb 07 |
jari |
3335 |
if ((numbValidValuesA < 2) || (numbValidValuesB < 2)) { |
2 |
26 Feb 07 |
jari |
3336 |
tValues[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3337 |
dfValues[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3338 |
groupAMeans[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3339 |
groupBMeans[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3340 |
groupASDs[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3341 |
groupBSDs[gene] = Double.NaN; |
2 |
26 Feb 07 |
jari |
3342 |
} else { |
2 |
26 Feb 07 |
jari |
3343 |
tValues[gene] = (double)(calculateTValue(groupAValues, groupBValues)); |
2 |
26 Feb 07 |
jari |
3344 |
dfValues[gene] = (double)(calculateDf(groupAValues, groupBValues)); |
2 |
26 Feb 07 |
jari |
3345 |
groupAMeans[gene] = (double)(getMean(groupAValues)); |
2 |
26 Feb 07 |
jari |
3346 |
groupBMeans[gene] = (double)(getMean(groupBValues)); |
2 |
26 Feb 07 |
jari |
3347 |
groupASDs[gene] = (double)(Math.sqrt(getVar(groupAValues))); |
2 |
26 Feb 07 |
jari |
3348 |
groupBSDs[gene] = (double)(Math.sqrt(getVar(groupBValues))); |
2 |
26 Feb 07 |
jari |
3349 |
} |
2 |
26 Feb 07 |
jari |
3350 |
|
2 |
26 Feb 07 |
jari |
3351 |
} |
2 |
26 Feb 07 |
jari |
3352 |
} |
2 |
26 Feb 07 |
jari |
3353 |
|
2 |
26 Feb 07 |
jari |
3354 |
private float calculateTValue(float[] groupA, float[] groupB) { |
2 |
26 Feb 07 |
jari |
3355 |
if (useWelchDf) { |
2 |
26 Feb 07 |
jari |
3356 |
int kA = groupA.length; |
2 |
26 Feb 07 |
jari |
3357 |
int kB = groupB.length; |
2 |
26 Feb 07 |
jari |
3358 |
float meanA = getMean(groupA); |
2 |
26 Feb 07 |
jari |
3359 |
float meanB = getMean(groupB); |
2 |
26 Feb 07 |
jari |
3360 |
float varA = getVar(groupA); |
2 |
26 Feb 07 |
jari |
3361 |
float varB = getVar(groupB); |
2 |
26 Feb 07 |
jari |
3362 |
|
2 |
26 Feb 07 |
jari |
3363 |
int numbValidGroupAValues = 0; |
2 |
26 Feb 07 |
jari |
3364 |
int numbValidGroupBValues = 0; |
2 |
26 Feb 07 |
jari |
3365 |
|
2 |
26 Feb 07 |
jari |
3366 |
for (int i = 0; i < groupA.length; i++) { |
2 |
26 Feb 07 |
jari |
3367 |
if (!Float.isNaN(groupA[i])) { |
2 |
26 Feb 07 |
jari |
3368 |
numbValidGroupAValues++; |
2 |
26 Feb 07 |
jari |
3369 |
} |
2 |
26 Feb 07 |
jari |
3370 |
} |
2 |
26 Feb 07 |
jari |
3371 |
|
2 |
26 Feb 07 |
jari |
3372 |
for (int i = 0; i < groupB.length; i++) { |
2 |
26 Feb 07 |
jari |
3373 |
if (!Float.isNaN(groupB[i])) { |
2 |
26 Feb 07 |
jari |
3374 |
numbValidGroupBValues++; |
2 |
26 Feb 07 |
jari |
3375 |
} |
2 |
26 Feb 07 |
jari |
3376 |
} |
2 |
26 Feb 07 |
jari |
3377 |
|
2 |
26 Feb 07 |
jari |
3378 |
if ((numbValidGroupAValues < 2) || (numbValidGroupBValues < 2)) { |
2 |
26 Feb 07 |
jari |
3379 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3380 |
} |
2 |
26 Feb 07 |
jari |
3381 |
|
2 |
26 Feb 07 |
jari |
//float tValue = (float)((meanA - meanB) / Math.sqrt((varA/kA) + (varB/kB))); |
2 |
26 Feb 07 |
jari |
//changed to divide by valid n |
2 |
26 Feb 07 |
jari |
3384 |
float tValue = (float)((meanA - meanB) / Math.sqrt((varA/numbValidGroupAValues) + (varB/numbValidGroupBValues))); |
2 |
26 Feb 07 |
jari |
3385 |
|
2 |
26 Feb 07 |
jari |
3386 |
return Math.abs(tValue); |
2 |
26 Feb 07 |
jari |
3387 |
|
2 |
26 Feb 07 |
jari |
3388 |
} else { // if(!useWelchDf) |
2 |
26 Feb 07 |
jari |
3389 |
float tValue; |
2 |
26 Feb 07 |
jari |
3390 |
int numbValidGroupAValues = 0; |
2 |
26 Feb 07 |
jari |
3391 |
int numbValidGroupBValues = 0; |
2 |
26 Feb 07 |
jari |
3392 |
|
2 |
26 Feb 07 |
jari |
3393 |
for (int i = 0; i < groupA.length; i++) { |
2 |
26 Feb 07 |
jari |
3394 |
if (!Float.isNaN(groupA[i])) { |
2 |
26 Feb 07 |
jari |
3395 |
numbValidGroupAValues++; |
2 |
26 Feb 07 |
jari |
3396 |
} |
2 |
26 Feb 07 |
jari |
3397 |
} |
2 |
26 Feb 07 |
jari |
3398 |
|
2 |
26 Feb 07 |
jari |
3399 |
for (int i = 0; i < groupB.length; i++) { |
2 |
26 Feb 07 |
jari |
3400 |
if (!Float.isNaN(groupB[i])) { |
2 |
26 Feb 07 |
jari |
3401 |
numbValidGroupBValues++; |
2 |
26 Feb 07 |
jari |
3402 |
} |
2 |
26 Feb 07 |
jari |
3403 |
} |
2 |
26 Feb 07 |
jari |
3404 |
|
2 |
26 Feb 07 |
jari |
3405 |
if ((numbValidGroupAValues < 2) || (numbValidGroupBValues < 2)) { |
2 |
26 Feb 07 |
jari |
3406 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3407 |
} |
2 |
26 Feb 07 |
jari |
3408 |
|
2 |
26 Feb 07 |
jari |
3409 |
float ssA = getSumSquares(groupA); |
2 |
26 Feb 07 |
jari |
3410 |
float ssB = getSumSquares(groupB); |
2 |
26 Feb 07 |
jari |
3411 |
|
2 |
26 Feb 07 |
jari |
3412 |
float term1 = (float)(ssA + ssB); |
2 |
26 Feb 07 |
jari |
3413 |
float term2 = (float)(numbValidGroupAValues + numbValidGroupBValues - 2); |
2 |
26 Feb 07 |
jari |
3414 |
float term3 = (float)((1.0f/(float)numbValidGroupAValues) +(1.0f/(float)numbValidGroupBValues)); |
2 |
26 Feb 07 |
jari |
3415 |
|
2 |
26 Feb 07 |
jari |
3416 |
float denom = (float)Math.sqrt(((term1*term3)/term2)); |
2 |
26 Feb 07 |
jari |
//float denom = (float)Math.sqrt((((ssA + ssB)/(numbValidGroupAValues + numbValidGroupBValues - 2))*((1/numbValidGroupAValues) + (1/numbValidGroupBValues)))); |
2 |
26 Feb 07 |
jari |
//System.out.println("ssA = " + ssA + ", ssB = " + ssB + "nA = " + numbValidGroupAValues + ", nB = " + numbValidGroupBValues + ", denom = " + denom); |
2 |
26 Feb 07 |
jari |
3419 |
float meanA = getMean(groupA); |
2 |
26 Feb 07 |
jari |
3420 |
float meanB = getMean(groupB); |
2 |
26 Feb 07 |
jari |
3421 |
|
2 |
26 Feb 07 |
jari |
3422 |
tValue = (float)((meanA - meanB)/denom); |
2 |
26 Feb 07 |
jari |
3423 |
|
2 |
26 Feb 07 |
jari |
3424 |
return Math.abs(tValue); |
2 |
26 Feb 07 |
jari |
3425 |
} |
2 |
26 Feb 07 |
jari |
3426 |
} |
2 |
26 Feb 07 |
jari |
3427 |
|
2 |
26 Feb 07 |
jari |
3428 |
private float getSumSquares(float[] arr) { |
2 |
26 Feb 07 |
jari |
3429 |
int N = 0; |
2 |
26 Feb 07 |
jari |
3430 |
float sumX = 0f; |
2 |
26 Feb 07 |
jari |
3431 |
float sumXSquared = 0f; |
2 |
26 Feb 07 |
jari |
3432 |
for (int i = 0; i < arr.length; i++) { |
2 |
26 Feb 07 |
jari |
3433 |
if (!Float.isNaN(arr[i])) { |
2 |
26 Feb 07 |
jari |
3434 |
N++; |
2 |
26 Feb 07 |
jari |
3435 |
sumX += arr[i]; |
2 |
26 Feb 07 |
jari |
3436 |
sumXSquared += arr[i]*arr[i]; |
2 |
26 Feb 07 |
jari |
3437 |
} |
2 |
26 Feb 07 |
jari |
3438 |
} |
2 |
26 Feb 07 |
jari |
3439 |
if (N == 0) { |
2 |
26 Feb 07 |
jari |
3440 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3441 |
} else { |
2 |
26 Feb 07 |
jari |
3442 |
float sumSq = sumXSquared - ((sumX*sumX)/N); |
2 |
26 Feb 07 |
jari |
3443 |
return sumSq; |
2 |
26 Feb 07 |
jari |
3444 |
} |
2 |
26 Feb 07 |
jari |
3445 |
} |
2 |
26 Feb 07 |
jari |
3446 |
|
2 |
26 Feb 07 |
jari |
3447 |
private int calculateDf(float[] groupA, float[] groupB) { |
2 |
26 Feb 07 |
jari |
3448 |
int kA = 0; |
2 |
26 Feb 07 |
jari |
3449 |
int kB = 0; |
2 |
26 Feb 07 |
jari |
3450 |
for (int i =0; i < groupA.length; i++) { |
2 |
26 Feb 07 |
jari |
3451 |
if (!Float.isNaN(groupA[i])) { |
2 |
26 Feb 07 |
jari |
3452 |
kA++; |
2 |
26 Feb 07 |
jari |
3453 |
} |
2 |
26 Feb 07 |
jari |
3454 |
} |
2 |
26 Feb 07 |
jari |
3455 |
|
2 |
26 Feb 07 |
jari |
3456 |
for (int i =0; i < groupB.length; i++) { |
2 |
26 Feb 07 |
jari |
3457 |
if (!Float.isNaN(groupB[i])) { |
2 |
26 Feb 07 |
jari |
3458 |
kB++; |
2 |
26 Feb 07 |
jari |
3459 |
} |
2 |
26 Feb 07 |
jari |
3460 |
} |
2 |
26 Feb 07 |
jari |
3461 |
|
2 |
26 Feb 07 |
jari |
3462 |
if (!useWelchDf) { |
2 |
26 Feb 07 |
jari |
3463 |
int df = kA + kB - 2; |
2 |
26 Feb 07 |
jari |
3464 |
if (df < 0) df = 0; |
2 |
26 Feb 07 |
jari |
3465 |
return df; |
2 |
26 Feb 07 |
jari |
3466 |
} |
2 |
26 Feb 07 |
jari |
3467 |
|
2 |
26 Feb 07 |
jari |
3468 |
float meanA = getMean(groupA); |
2 |
26 Feb 07 |
jari |
3469 |
float meanB = getMean(groupB); |
2 |
26 Feb 07 |
jari |
3470 |
float varA = getVar(groupA); |
2 |
26 Feb 07 |
jari |
3471 |
float varB = getVar(groupB); |
2 |
26 Feb 07 |
jari |
3472 |
/* |
2 |
26 Feb 07 |
jari |
System.out.println("kA = " +kA); |
2 |
26 Feb 07 |
jari |
System.out.println("kB = " +kB); |
2 |
26 Feb 07 |
jari |
System.out.println("meanA = " +meanA); |
2 |
26 Feb 07 |
jari |
System.out.println("meanB = " +meanB); |
2 |
26 Feb 07 |
jari |
System.out.println("varA = " +varA); |
2 |
26 Feb 07 |
jari |
System.out.println("varB = " +varB); |
2 |
26 Feb 07 |
jari |
3479 |
*/ |
2 |
26 Feb 07 |
jari |
3480 |
float numerator = (float) (Math.pow(((varA/kA) + (varB/kB)), 2)); |
2 |
26 Feb 07 |
jari |
//System.out.println("numerator = " + numerator); |
2 |
26 Feb 07 |
jari |
3482 |
float denom = (float)((Math.pow((varA/kA), 2)/(kA - 1)) + (Math.pow((varB/kB), 2)/(kB - 1))); |
2 |
26 Feb 07 |
jari |
//System.out.println("denominator = " + denom); |
2 |
26 Feb 07 |
jari |
3484 |
|
2 |
26 Feb 07 |
jari |
//System.out.print(".. df(unrounded) = " + (numerator / denom) + " ... "); |
2 |
26 Feb 07 |
jari |
3486 |
|
2 |
26 Feb 07 |
jari |
3487 |
int df = (int)Math.floor(numerator / denom); |
2 |
26 Feb 07 |
jari |
3488 |
|
2 |
26 Feb 07 |
jari |
3489 |
return df; |
2 |
26 Feb 07 |
jari |
3490 |
} |
2 |
26 Feb 07 |
jari |
3491 |
|
2 |
26 Feb 07 |
jari |
3492 |
private float getMean(float[] group) { |
2 |
26 Feb 07 |
jari |
3493 |
float sum = 0; |
2 |
26 Feb 07 |
jari |
3494 |
int n = 0; |
2 |
26 Feb 07 |
jari |
3495 |
|
2 |
26 Feb 07 |
jari |
3496 |
for (int i = 0; i < group.length; i++) { |
2 |
26 Feb 07 |
jari |
//System.out.println("getMean(): group[" + i + "] = " + group[i]); |
2 |
26 Feb 07 |
jari |
3498 |
if (!Float.isNaN(group[i])) { |
2 |
26 Feb 07 |
jari |
3499 |
sum = sum + group[i]; |
2 |
26 Feb 07 |
jari |
3500 |
n++; |
2 |
26 Feb 07 |
jari |
3501 |
} |
2 |
26 Feb 07 |
jari |
3502 |
} |
2 |
26 Feb 07 |
jari |
3503 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("getMean(): sum = " +sum); |
2 |
26 Feb 07 |
jari |
3505 |
if (n == 0) { |
2 |
26 Feb 07 |
jari |
3506 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3507 |
} |
2 |
26 Feb 07 |
jari |
3508 |
float mean = sum / (float)n; |
2 |
26 Feb 07 |
jari |
3509 |
|
2 |
26 Feb 07 |
jari |
3510 |
if (Float.isInfinite(mean)) { |
2 |
26 Feb 07 |
jari |
3511 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3512 |
} |
2 |
26 Feb 07 |
jari |
3513 |
|
2 |
26 Feb 07 |
jari |
3514 |
return mean; |
2 |
26 Feb 07 |
jari |
3515 |
} |
2 |
26 Feb 07 |
jari |
3516 |
|
2 |
26 Feb 07 |
jari |
3517 |
private float getVar(float[] group) { |
2 |
26 Feb 07 |
jari |
3518 |
float mean = getMean(group); |
2 |
26 Feb 07 |
jari |
3519 |
int n = 0; |
2 |
26 Feb 07 |
jari |
3520 |
|
2 |
26 Feb 07 |
jari |
3521 |
float sumSquares = 0; |
2 |
26 Feb 07 |
jari |
3522 |
|
2 |
26 Feb 07 |
jari |
3523 |
for (int i = 0; i < group.length; i++) { |
2 |
26 Feb 07 |
jari |
3524 |
if (!Float.isNaN(group[i])) { |
2 |
26 Feb 07 |
jari |
3525 |
sumSquares = (float)(sumSquares + Math.pow((group[i] - mean), 2)); |
2 |
26 Feb 07 |
jari |
3526 |
n++; |
2 |
26 Feb 07 |
jari |
3527 |
} |
2 |
26 Feb 07 |
jari |
3528 |
} |
2 |
26 Feb 07 |
jari |
3529 |
|
2 |
26 Feb 07 |
jari |
3530 |
if (n < 2) { |
2 |
26 Feb 07 |
jari |
3531 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3532 |
} |
2 |
26 Feb 07 |
jari |
3533 |
|
2 |
26 Feb 07 |
jari |
3534 |
float var = sumSquares / (float)(n - 1); |
2 |
26 Feb 07 |
jari |
3535 |
if (Float.isInfinite(var)) { |
2 |
26 Feb 07 |
jari |
3536 |
return Float.NaN; |
2 |
26 Feb 07 |
jari |
3537 |
} |
2 |
26 Feb 07 |
jari |
3538 |
return var; |
2 |
26 Feb 07 |
jari |
3539 |
} |
2 |
26 Feb 07 |
jari |
3540 |
|
2 |
26 Feb 07 |
jari |
3541 |
} |