2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* Created on Oct 28, 2004 |
2 |
26 Feb 07 |
jari |
3 |
*/ |
2 |
26 Feb 07 |
jari |
4 |
package org.tigr.microarray.mev.cluster.gui.impl.usc; |
2 |
26 Feb 07 |
jari |
5 |
|
2 |
26 Feb 07 |
jari |
6 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
7 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
8 |
import java.util.Random; |
2 |
26 Feb 07 |
jari |
9 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
/** |
2 |
26 Feb 07 |
jari |
* A set of USCHyb objects. Basically used to separate a training set from a |
2 |
26 Feb 07 |
jari |
* test set. |
2 |
26 Feb 07 |
jari |
14 |
* |
2 |
26 Feb 07 |
jari |
* @author vu |
2 |
26 Feb 07 |
jari |
16 |
*/ |
2 |
26 Feb 07 |
jari |
17 |
public class USCHybSet { |
2 |
26 Feb 07 |
jari |
18 |
private int hybKount; |
2 |
26 Feb 07 |
jari |
19 |
private int numClasses; |
2 |
26 Feb 07 |
jari |
20 |
private int foldKount; |
2 |
26 Feb 07 |
jari |
21 |
private int hybPerFold; |
2 |
26 Feb 07 |
jari |
22 |
private int hybRemain; |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
private int[] iPermuted; |
2 |
26 Feb 07 |
jari |
//private int[] geneIndices; //uid is common for all hybs |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
private float s0; |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
private float[] sis; //s value for each gene |
2 |
26 Feb 07 |
jari |
30 |
private float[] geneCentroids; //mean ratio for each gene across all hybs |
2 |
26 Feb 07 |
jari |
31 |
private float[][] classCentroids; //mean ratio within each class for each gene |
2 |
26 Feb 07 |
jari |
32 |
private float[] classMks; //mk for each class |
2 |
26 Feb 07 |
jari |
33 |
private String[] uniqueClasses; //class names |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
private USCHyb[] hybs; |
2 |
26 Feb 07 |
jari |
36 |
private USCHyb[][] testArray; //[ foldIndex ][ hybPerFold ] |
2 |
26 Feb 07 |
jari |
37 |
private USCHyb[][] trainArray; //same |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
private USCGene[] genes; |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
/** |
2 |
26 Feb 07 |
jari |
* Constructor for Testing Data from MeV |
2 |
26 Feb 07 |
jari |
* @param hybArray |
2 |
26 Feb 07 |
jari |
* @param hybSetTypeP |
2 |
26 Feb 07 |
jari |
* @param hybKountP |
2 |
26 Feb 07 |
jari |
* @param geneKountP |
2 |
26 Feb 07 |
jari |
* @param geneNamesP |
2 |
26 Feb 07 |
jari |
49 |
*/ |
2 |
26 Feb 07 |
jari |
50 |
public USCHybSet( USCHyb[] hybArray, USCGene[] geneListP ) { |
2 |
26 Feb 07 |
jari |
51 |
this.hybs = hybArray; |
2 |
26 Feb 07 |
jari |
52 |
this.hybKount = hybArray.length; |
2 |
26 Feb 07 |
jari |
53 |
this.genes = geneListP; |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
this.uniqueClasses = this.findUniqueClasses( this ); |
2 |
26 Feb 07 |
jari |
56 |
this.numClasses = this.uniqueClasses.length; |
2 |
26 Feb 07 |
jari |
57 |
this.assignClassIndices(); |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
this.iPermuted = this.randomize( this.hybKount ); |
2 |
26 Feb 07 |
jari |
60 |
}//end constructor |
2 |
26 Feb 07 |
jari |
61 |
/* |
2 |
26 Feb 07 |
jari |
public USCHybSet( USCHyb[] hybArray ) { |
2 |
26 Feb 07 |
jari |
this.hybs = hybArray; |
2 |
26 Feb 07 |
jari |
this.hybKount = hybArray.length; |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
this.uniqueClasses = this.findUniqueClasses( this ); |
2 |
26 Feb 07 |
jari |
this.numClasses = this.uniqueClasses.length; |
2 |
26 Feb 07 |
jari |
this.assignClassIndices(); |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
this.iPermuted = this.randomize( this.hybKount ); |
2 |
26 Feb 07 |
jari |
}//end constructor |
2 |
26 Feb 07 |
jari |
public USCHybSet( USCHyb[] hybArray, int[] uidP ) { |
2 |
26 Feb 07 |
jari |
this.uid = uidP; |
2 |
26 Feb 07 |
jari |
this.hybs = hybArray; |
2 |
26 Feb 07 |
jari |
this.hybKount = hybArray.length; |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
this.uniqueClasses = this.findUniqueClasses( this ); |
2 |
26 Feb 07 |
jari |
this.numClasses = this.uniqueClasses.length; |
2 |
26 Feb 07 |
jari |
this.assignClassIndices(); |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
this.iPermuted = this.randomize( this.hybKount ); |
2 |
26 Feb 07 |
jari |
}//end constructor |
2 |
26 Feb 07 |
jari |
public USCHybSet( USCHyb[] hybArray, int[] uidP, USCGeneList geneListP ) { |
2 |
26 Feb 07 |
jari |
this.geneIndices = uidP; |
2 |
26 Feb 07 |
jari |
this.hybs = hybArray; |
2 |
26 Feb 07 |
jari |
this.hybKount = hybArray.length; |
2 |
26 Feb 07 |
jari |
this.geneList = geneListP; |
2 |
26 Feb 07 |
jari |
88 |
|
2 |
26 Feb 07 |
jari |
this.uniqueClasses = this.findUniqueClasses( this ); |
2 |
26 Feb 07 |
jari |
this.numClasses = this.uniqueClasses.length; |
2 |
26 Feb 07 |
jari |
this.assignClassIndices(); |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
this.iPermuted = this.randomize( this.hybKount ); |
2 |
26 Feb 07 |
jari |
}//end constructor |
2 |
26 Feb 07 |
jari |
95 |
*/ |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
/** |
2 |
26 Feb 07 |
jari |
99 |
* |
2 |
26 Feb 07 |
jari |
100 |
*/ |
2 |
26 Feb 07 |
jari |
101 |
private void assignClassIndices() { |
2 |
26 Feb 07 |
jari |
//loop through the hybs in this hybset |
2 |
26 Feb 07 |
jari |
103 |
for( int h = 0; h < this.hybs.length; h ++ ) { |
2 |
26 Feb 07 |
jari |
104 |
String sLabel = this.hybs[ h ].getHybLabel(); |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
//loop through the uniqueClasse |
2 |
26 Feb 07 |
jari |
107 |
for( int c = 0; c < this.uniqueClasses.length; c ++ ) { |
2 |
26 Feb 07 |
jari |
108 |
if( sLabel.equals( this.uniqueClasses[ c ] ) ) { |
2 |
26 Feb 07 |
jari |
109 |
this.hybs[ h ].setUniqueLabelIndex( c ); |
2 |
26 Feb 07 |
jari |
110 |
break; |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
}//end assignClassIndices() |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
|
2 |
26 Feb 07 |
jari |
117 |
/** |
2 |
26 Feb 07 |
jari |
* Permute calls randomize() and createTestArrays() |
2 |
26 Feb 07 |
jari |
* @param foldKountP |
2 |
26 Feb 07 |
jari |
120 |
*/ |
2 |
26 Feb 07 |
jari |
121 |
public void permute( int foldKountP ) { |
2 |
26 Feb 07 |
jari |
122 |
this.foldKount = foldKountP; |
2 |
26 Feb 07 |
jari |
123 |
this.hybPerFold = this.hybKount / this.foldKount; |
2 |
26 Feb 07 |
jari |
124 |
this.hybRemain = this.hybKount % this.foldKount; |
2 |
26 Feb 07 |
jari |
125 |
this.createTestArrays(); |
2 |
26 Feb 07 |
jari |
126 |
}//end permute() |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
/** |
2 |
26 Feb 07 |
jari |
* Creates 2 2D USCHyb[ foldKount ][ hybPerFold ] |
2 |
26 Feb 07 |
jari |
131 |
*/ |
2 |
26 Feb 07 |
jari |
132 |
private void createTestArrays() { |
2 |
26 Feb 07 |
jari |
133 |
this.testArray = new USCHyb[ this.foldKount ][]; |
2 |
26 Feb 07 |
jari |
134 |
this.trainArray = new USCHyb[ this.foldKount ][]; |
2 |
26 Feb 07 |
jari |
135 |
|
2 |
26 Feb 07 |
jari |
//when foldKount=1, the entire set should be used to find relevant/uncorr genes |
2 |
26 Feb 07 |
jari |
137 |
if( this.foldKount == 1 ) { |
2 |
26 Feb 07 |
jari |
138 |
this.testArray[ 0 ] = new USCHyb[ 0 ]; |
2 |
26 Feb 07 |
jari |
139 |
this.trainArray[ 0 ] = this.hybs; |
2 |
26 Feb 07 |
jari |
140 |
} else { |
2 |
26 Feb 07 |
jari |
141 |
// |
2 |
26 Feb 07 |
jari |
142 |
for( int i = 0; i < this.foldKount; i ++ ) { |
2 |
26 Feb 07 |
jari |
//System.out.println( "Fold:" + i ); |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
int iStart = i * this.hybPerFold; |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
if( i == ( this.foldKount - 1 ) ) { |
2 |
26 Feb 07 |
jari |
148 |
this.testArray[ i ] = new USCHyb[ ( this.hybPerFold + this.hybRemain ) ]; |
2 |
26 Feb 07 |
jari |
149 |
this.trainArray[ i ] = new USCHyb[ this.hybKount - ( this.hybPerFold + this.hybRemain ) ]; |
2 |
26 Feb 07 |
jari |
150 |
} else { |
2 |
26 Feb 07 |
jari |
151 |
this.testArray[ i ] = new USCHyb[ this.hybPerFold ]; |
2 |
26 Feb 07 |
jari |
152 |
this.trainArray[ i ] = new USCHyb[ this.hybKount - this.hybPerFold ]; |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
155 |
// |
2 |
26 Feb 07 |
jari |
156 |
for( int j = 0; j < this.testArray[ i ].length; j ++ ) { |
2 |
26 Feb 07 |
jari |
157 |
this.testArray[ i ][ j ] = this.getHyb( this.iPermuted[ iStart + j ] ); |
2 |
26 Feb 07 |
jari |
//System.out.println( this.testArray[ i ][ j ].getHybName() + " added to testArray" ); |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
|
2 |
26 Feb 07 |
jari |
161 |
int index = 0; |
2 |
26 Feb 07 |
jari |
162 |
// |
2 |
26 Feb 07 |
jari |
163 |
for( int j = 0; j < this.hybKount; j ++ ) { |
2 |
26 Feb 07 |
jari |
164 |
boolean add = true; |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
for( int k = 0; k < this.testArray[ i ].length; k ++ ) { |
2 |
26 Feb 07 |
jari |
167 |
if( this.getHyb( j ).getIndexInFullSet() == this.testArray[ i ][ k ].getIndexInFullSet() ) { |
2 |
26 Feb 07 |
jari |
168 |
add = false; |
2 |
26 Feb 07 |
jari |
169 |
break; |
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( add ) { |
2 |
26 Feb 07 |
jari |
174 |
this.trainArray[ i ][ index ] = this.getHyb( j ); |
2 |
26 Feb 07 |
jari |
//System.out.println( this.trainArray[ i ][ index ].getHybName() + " added to trainArray" ); |
2 |
26 Feb 07 |
jari |
176 |
index ++; |
2 |
26 Feb 07 |
jari |
177 |
} |
2 |
26 Feb 07 |
jari |
178 |
}//end j(testHybs) |
2 |
26 Feb 07 |
jari |
179 |
}//end i(folds) |
2 |
26 Feb 07 |
jari |
180 |
}//end else |
2 |
26 Feb 07 |
jari |
181 |
}//end createTestArrays() |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
/** |
2 |
26 Feb 07 |
jari |
* Randomize kount integers (0-based) and store in hybIndices array |
2 |
26 Feb 07 |
jari |
* @param kount The # of integers to randomize |
2 |
26 Feb 07 |
jari |
187 |
*/ |
2 |
26 Feb 07 |
jari |
188 |
public int[] randomize( int hybKount ) { |
2 |
26 Feb 07 |
jari |
189 |
Vector vIndices = new Vector(); |
2 |
26 Feb 07 |
jari |
190 |
int[] toReturn = new int[ hybKount ]; |
2 |
26 Feb 07 |
jari |
191 |
|
2 |
26 Feb 07 |
jari |
192 |
Random r = new Random(); |
2 |
26 Feb 07 |
jari |
193 |
|
2 |
26 Feb 07 |
jari |
194 |
for( int i = 0; i < toReturn.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
195 |
int iTry = -1; |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
while( ! isNew( iTry, vIndices ) ) { |
2 |
26 Feb 07 |
jari |
198 |
iTry = r.nextInt( hybKount ); |
2 |
26 Feb 07 |
jari |
199 |
} |
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
vIndices.add( new Integer( iTry ) ); |
2 |
26 Feb 07 |
jari |
202 |
toReturn[ i ] = iTry; |
2 |
26 Feb 07 |
jari |
//System.out.println( "iTry:" + ( iTry + 1 ) ); |
2 |
26 Feb 07 |
jari |
204 |
}//end i |
2 |
26 Feb 07 |
jari |
205 |
|
2 |
26 Feb 07 |
jari |
206 |
return toReturn; |
2 |
26 Feb 07 |
jari |
207 |
}//end constructor |
2 |
26 Feb 07 |
jari |
208 |
/** |
2 |
26 Feb 07 |
jari |
* Tests to see if this integer has already been recorded |
2 |
26 Feb 07 |
jari |
* @param iTry int to test |
2 |
26 Feb 07 |
jari |
* @param v Vector of recorded Integer objects |
2 |
26 Feb 07 |
jari |
* @return true if this is a new int, false if this int has already been recorded |
2 |
26 Feb 07 |
jari |
213 |
*/ |
2 |
26 Feb 07 |
jari |
214 |
private boolean isNew( int iTry, Vector v ) { |
2 |
26 Feb 07 |
jari |
215 |
if( iTry == -1 ) { |
2 |
26 Feb 07 |
jari |
216 |
return false; |
2 |
26 Feb 07 |
jari |
217 |
} else { |
2 |
26 Feb 07 |
jari |
218 |
boolean toReturn = true; |
2 |
26 Feb 07 |
jari |
219 |
|
2 |
26 Feb 07 |
jari |
220 |
for( int i = 0; i < v.size(); i ++ ) { |
2 |
26 Feb 07 |
jari |
221 |
Integer I = ( Integer ) v.elementAt( i ); |
2 |
26 Feb 07 |
jari |
222 |
if( iTry == I.intValue() ) { |
2 |
26 Feb 07 |
jari |
223 |
toReturn = false; |
2 |
26 Feb 07 |
jari |
224 |
break; |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
226 |
} |
2 |
26 Feb 07 |
jari |
227 |
|
2 |
26 Feb 07 |
jari |
228 |
return toReturn; |
2 |
26 Feb 07 |
jari |
229 |
} |
2 |
26 Feb 07 |
jari |
230 |
}//end isNew() |
2 |
26 Feb 07 |
jari |
231 |
|
2 |
26 Feb 07 |
jari |
232 |
|
2 |
26 Feb 07 |
jari |
233 |
/** |
2 |
26 Feb 07 |
jari |
* Look through the classes and store the unique class labels in uniqueClassArray |
2 |
26 Feb 07 |
jari |
* @param hybSet |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
237 |
*/ |
2 |
26 Feb 07 |
jari |
238 |
private String[] findUniqueClasses( USCHybSet hybSet ) { |
2 |
26 Feb 07 |
jari |
239 |
String[] toReturn; |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
/* |
2 |
26 Feb 07 |
jari |
Hashtable ht = new Hashtable(); |
2 |
26 Feb 07 |
jari |
243 |
|
2 |
26 Feb 07 |
jari |
for( int i = 0; i < hybSet.getHybs().length; i ++ ) { |
2 |
26 Feb 07 |
jari |
ht.put( hybSet.getHyb( i ).getHybLabel(), hybSet.getHyb( i ).getHybLabel() ); |
2 |
26 Feb 07 |
jari |
246 |
} |
2 |
26 Feb 07 |
jari |
247 |
|
2 |
26 Feb 07 |
jari |
toReturn = new String[ ht.size() ]; |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
Enumeration en = ht.elements(); |
2 |
26 Feb 07 |
jari |
int index = 0; |
2 |
26 Feb 07 |
jari |
while( en.hasMoreElements() ) { |
2 |
26 Feb 07 |
jari |
String s = ( String ) en.nextElement(); |
2 |
26 Feb 07 |
jari |
toReturn[ index ] = s; |
2 |
26 Feb 07 |
jari |
index ++; |
2 |
26 Feb 07 |
jari |
}//end while |
2 |
26 Feb 07 |
jari |
257 |
|
2 |
26 Feb 07 |
jari |
Arrays.sort( toReturn ); |
2 |
26 Feb 07 |
jari |
259 |
*/ |
2 |
26 Feb 07 |
jari |
260 |
|
2 |
26 Feb 07 |
jari |
261 |
Vector vUniqueLabel = new Vector(); |
2 |
26 Feb 07 |
jari |
262 |
|
2 |
26 Feb 07 |
jari |
263 |
for( int i = 0; i < hybSet.getHybs().length; i ++ ) { |
2 |
26 Feb 07 |
jari |
264 |
String sLabel = hybSet.getHyb( i ).getHybLabel(); |
2 |
26 Feb 07 |
jari |
265 |
|
2 |
26 Feb 07 |
jari |
266 |
boolean labelFound = false; |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
//loop through the |
2 |
26 Feb 07 |
jari |
269 |
for( int j = 0; j < vUniqueLabel.size(); j ++ ) { |
2 |
26 Feb 07 |
jari |
270 |
String jLabel = ( String ) vUniqueLabel.elementAt( j ); |
2 |
26 Feb 07 |
jari |
271 |
if( sLabel.equals( jLabel ) ) { |
2 |
26 Feb 07 |
jari |
272 |
labelFound = true; |
2 |
26 Feb 07 |
jari |
273 |
break; |
2 |
26 Feb 07 |
jari |
274 |
} |
2 |
26 Feb 07 |
jari |
275 |
} |
2 |
26 Feb 07 |
jari |
276 |
|
2 |
26 Feb 07 |
jari |
277 |
if( ! labelFound ) { |
2 |
26 Feb 07 |
jari |
278 |
vUniqueLabel.add( sLabel ); |
2 |
26 Feb 07 |
jari |
279 |
} |
2 |
26 Feb 07 |
jari |
280 |
}//i |
2 |
26 Feb 07 |
jari |
281 |
|
2 |
26 Feb 07 |
jari |
282 |
toReturn = new String[ vUniqueLabel.size() ]; |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
for(int i = 0; i < vUniqueLabel.size(); i ++ ) { |
2 |
26 Feb 07 |
jari |
285 |
toReturn[ i ] = ( String ) vUniqueLabel.elementAt( i ); |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
return toReturn; |
2 |
26 Feb 07 |
jari |
289 |
}//end parseClass() |
2 |
26 Feb 07 |
jari |
290 |
|
2 |
26 Feb 07 |
jari |
291 |
|
2 |
26 Feb 07 |
jari |
/*------------------------------Getters & Setters--------------------------------*/ |
2 |
26 Feb 07 |
jari |
293 |
/* |
2 |
26 Feb 07 |
jari |
public void setGeneIndex( int geneIndex, int uid ) { |
2 |
26 Feb 07 |
jari |
this.geneIndices[ geneIndex ] = uid; |
2 |
26 Feb 07 |
jari |
296 |
} |
2 |
26 Feb 07 |
jari |
public void setGeneIndices( int[] uids ) { |
2 |
26 Feb 07 |
jari |
this.geneIndices = uids; |
2 |
26 Feb 07 |
jari |
299 |
} |
2 |
26 Feb 07 |
jari |
public int getGeneIndex( int geneIndex ) { |
2 |
26 Feb 07 |
jari |
return this.geneIndices[ geneIndex ]; |
2 |
26 Feb 07 |
jari |
302 |
} |
2 |
26 Feb 07 |
jari |
public int[] getGeneIndices() { |
2 |
26 Feb 07 |
jari |
return this.geneIndices; |
2 |
26 Feb 07 |
jari |
305 |
} |
2 |
26 Feb 07 |
jari |
306 |
*/ |
2 |
26 Feb 07 |
jari |
307 |
public int getHybKount() { |
2 |
26 Feb 07 |
jari |
308 |
return this.hybKount; |
2 |
26 Feb 07 |
jari |
309 |
} |
2 |
26 Feb 07 |
jari |
310 |
public USCHyb[] getHybs() { |
2 |
26 Feb 07 |
jari |
311 |
return this.hybs; |
2 |
26 Feb 07 |
jari |
312 |
} |
2 |
26 Feb 07 |
jari |
313 |
public USCHyb getHyb( int index ) { |
2 |
26 Feb 07 |
jari |
314 |
return this.hybs[ index ]; |
2 |
26 Feb 07 |
jari |
315 |
} |
2 |
26 Feb 07 |
jari |
316 |
public USCGene[] getGenes() { |
2 |
26 Feb 07 |
jari |
317 |
return this.genes; |
2 |
26 Feb 07 |
jari |
318 |
} |
2 |
26 Feb 07 |
jari |
319 |
public USCGene getGene( int iGene ) { |
2 |
26 Feb 07 |
jari |
320 |
return this.genes[ iGene ]; |
2 |
26 Feb 07 |
jari |
321 |
} |
2 |
26 Feb 07 |
jari |
322 |
public int getNumClasses() { |
2 |
26 Feb 07 |
jari |
323 |
return this.numClasses; |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
public int getNumGenes() { |
2 |
26 Feb 07 |
jari |
326 |
return this.getHyb( 0 ).getNumGenes(); |
2 |
26 Feb 07 |
jari |
327 |
} |
2 |
26 Feb 07 |
jari |
328 |
public void setS0( float s0P ) { |
2 |
26 Feb 07 |
jari |
329 |
this.s0 = s0P; |
2 |
26 Feb 07 |
jari |
330 |
} |
2 |
26 Feb 07 |
jari |
331 |
public float getS0() { |
2 |
26 Feb 07 |
jari |
332 |
return this.s0; |
2 |
26 Feb 07 |
jari |
333 |
} |
2 |
26 Feb 07 |
jari |
334 |
public void setSis( float[] sisP ) { |
2 |
26 Feb 07 |
jari |
335 |
this.sis = sisP; |
2 |
26 Feb 07 |
jari |
336 |
} |
2 |
26 Feb 07 |
jari |
337 |
public void setSi( float siP, int geneIndex ) { |
2 |
26 Feb 07 |
jari |
338 |
this.sis[ geneIndex ] = siP; |
2 |
26 Feb 07 |
jari |
339 |
} |
2 |
26 Feb 07 |
jari |
340 |
public float getSi( int geneIndex ) { |
2 |
26 Feb 07 |
jari |
341 |
return this.sis[ geneIndex ]; |
2 |
26 Feb 07 |
jari |
342 |
} |
2 |
26 Feb 07 |
jari |
343 |
public float[] getSis() { |
2 |
26 Feb 07 |
jari |
344 |
return this.sis; |
2 |
26 Feb 07 |
jari |
345 |
} |
2 |
26 Feb 07 |
jari |
346 |
public void setGeneCentroids( float[] geneCentroidsP ) { |
2 |
26 Feb 07 |
jari |
347 |
this.geneCentroids = geneCentroidsP; |
2 |
26 Feb 07 |
jari |
348 |
} |
2 |
26 Feb 07 |
jari |
349 |
public void setGeneCentroid( float geneCentroid, int geneIndex ) { |
2 |
26 Feb 07 |
jari |
350 |
this.geneCentroids[ geneIndex ] = geneCentroid; |
2 |
26 Feb 07 |
jari |
351 |
} |
2 |
26 Feb 07 |
jari |
352 |
public float getGeneCentroid( int geneIndex ) { |
2 |
26 Feb 07 |
jari |
353 |
return this.geneCentroids[ geneIndex ]; |
2 |
26 Feb 07 |
jari |
354 |
} |
2 |
26 Feb 07 |
jari |
355 |
public float[] getGeneCentroids() { |
2 |
26 Feb 07 |
jari |
356 |
return this.geneCentroids; |
2 |
26 Feb 07 |
jari |
357 |
} |
2 |
26 Feb 07 |
jari |
358 |
public void setClassCentroids( float[] classCentroidsP, int geneIndex ) { |
2 |
26 Feb 07 |
jari |
359 |
this.classCentroids[ geneIndex ] = classCentroidsP; |
2 |
26 Feb 07 |
jari |
360 |
} |
2 |
26 Feb 07 |
jari |
361 |
public float[][] getClassCentroids() { |
2 |
26 Feb 07 |
jari |
362 |
return this.classCentroids; |
2 |
26 Feb 07 |
jari |
363 |
} |
2 |
26 Feb 07 |
jari |
364 |
public float getClassCentroid( int classIndex, int geneIndex ) { |
2 |
26 Feb 07 |
jari |
365 |
return this.classCentroids[ geneIndex ][ classIndex ]; |
2 |
26 Feb 07 |
jari |
366 |
} |
2 |
26 Feb 07 |
jari |
367 |
public void setClassMks( float[] classMksP ) { |
2 |
26 Feb 07 |
jari |
368 |
this.classMks = classMksP; |
2 |
26 Feb 07 |
jari |
369 |
} |
2 |
26 Feb 07 |
jari |
370 |
public float[] getClassMks() { |
2 |
26 Feb 07 |
jari |
371 |
return this.classMks; |
2 |
26 Feb 07 |
jari |
372 |
} |
2 |
26 Feb 07 |
jari |
373 |
public float getClassMk( int classIndex ) { |
2 |
26 Feb 07 |
jari |
374 |
return this.classMks[ classIndex ]; |
2 |
26 Feb 07 |
jari |
375 |
} |
2 |
26 Feb 07 |
jari |
376 |
public String[] getUniqueClasses() { |
2 |
26 Feb 07 |
jari |
377 |
return this.uniqueClasses; |
2 |
26 Feb 07 |
jari |
378 |
} |
2 |
26 Feb 07 |
jari |
379 |
public String getUniqueClass( int classIndex ) { |
2 |
26 Feb 07 |
jari |
380 |
return this.uniqueClasses[ classIndex ]; |
2 |
26 Feb 07 |
jari |
381 |
} |
2 |
26 Feb 07 |
jari |
382 |
public USCHyb[] getHybsInClass( int classIndex ) { |
2 |
26 Feb 07 |
jari |
383 |
Vector v = new Vector(); |
2 |
26 Feb 07 |
jari |
384 |
String classLabel = this.uniqueClasses[ classIndex ]; |
2 |
26 Feb 07 |
jari |
385 |
|
2 |
26 Feb 07 |
jari |
386 |
for( int i = 0; i < this.hybKount; i ++ ) { |
2 |
26 Feb 07 |
jari |
387 |
USCHyb hyb = this.hybs[ i ]; |
2 |
26 Feb 07 |
jari |
388 |
if( hyb.getHybLabel().equalsIgnoreCase( classLabel ) ) { |
2 |
26 Feb 07 |
jari |
389 |
v.add( hyb ); |
2 |
26 Feb 07 |
jari |
390 |
} |
2 |
26 Feb 07 |
jari |
391 |
}//end i |
2 |
26 Feb 07 |
jari |
392 |
|
2 |
26 Feb 07 |
jari |
393 |
USCHyb[] toReturn = new USCHyb[ v.size() ]; |
2 |
26 Feb 07 |
jari |
394 |
for( int i = 0; i < v.size(); i ++ ) { |
2 |
26 Feb 07 |
jari |
395 |
USCHyb hyb = ( USCHyb ) v.elementAt( i ); |
2 |
26 Feb 07 |
jari |
396 |
toReturn[ i ] = hyb; |
2 |
26 Feb 07 |
jari |
397 |
} |
2 |
26 Feb 07 |
jari |
398 |
|
2 |
26 Feb 07 |
jari |
399 |
return toReturn; |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
public int getNumHybsInClass( int classIndex ) { |
2 |
26 Feb 07 |
jari |
402 |
Vector v = new Vector(); |
2 |
26 Feb 07 |
jari |
403 |
String classLabel = this.uniqueClasses[ classIndex ]; |
2 |
26 Feb 07 |
jari |
404 |
|
2 |
26 Feb 07 |
jari |
405 |
for( int i = 0; i < this.hybKount; i ++ ) { |
2 |
26 Feb 07 |
jari |
406 |
USCHyb hyb = this.hybs[ i ]; |
2 |
26 Feb 07 |
jari |
407 |
if( hyb.getHybLabel().equalsIgnoreCase( classLabel ) ) { |
2 |
26 Feb 07 |
jari |
408 |
v.add( hyb ); |
2 |
26 Feb 07 |
jari |
409 |
} |
2 |
26 Feb 07 |
jari |
410 |
}//end i |
2 |
26 Feb 07 |
jari |
411 |
|
2 |
26 Feb 07 |
jari |
412 |
return v.size(); |
2 |
26 Feb 07 |
jari |
413 |
} |
2 |
26 Feb 07 |
jari |
414 |
/** |
2 |
26 Feb 07 |
jari |
* Create and return a 2 D matrix of the ratios for the hybs in the hyb set. |
2 |
26 Feb 07 |
jari |
* @return float[ Hybs ][ Genes ] |
2 |
26 Feb 07 |
jari |
417 |
*/ |
2 |
26 Feb 07 |
jari |
418 |
public double[][] getRatioMatrix() { |
2 |
26 Feb 07 |
jari |
419 |
double[][] toReturn = new double[ this.hybs.length ][]; |
2 |
26 Feb 07 |
jari |
420 |
|
2 |
26 Feb 07 |
jari |
421 |
for( int i = 0; i < this.hybs.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
422 |
USCHyb hyb = ( USCHyb ) this.hybs[ i ]; |
2 |
26 Feb 07 |
jari |
423 |
toReturn[ i ] = hyb.getRatios(); |
2 |
26 Feb 07 |
jari |
424 |
} |
2 |
26 Feb 07 |
jari |
425 |
|
2 |
26 Feb 07 |
jari |
426 |
return toReturn; |
2 |
26 Feb 07 |
jari |
427 |
}//end getRatioMatrix() |
2 |
26 Feb 07 |
jari |
428 |
public USCHyb[] getTestArray( int foldIndex ) { |
2 |
26 Feb 07 |
jari |
429 |
return this.testArray[ foldIndex ]; |
2 |
26 Feb 07 |
jari |
430 |
} |
2 |
26 Feb 07 |
jari |
431 |
public USCHyb[] getTrainArray( int foldIndex ) { |
2 |
26 Feb 07 |
jari |
432 |
return this.trainArray[ foldIndex ]; |
2 |
26 Feb 07 |
jari |
433 |
} |
2 |
26 Feb 07 |
jari |
434 |
|
2 |
26 Feb 07 |
jari |
435 |
|
2 |
26 Feb 07 |
jari |
436 |
public static void main( String [] args ) { |
2 |
26 Feb 07 |
jari |
437 |
System.out.println( "Invoked by main" ); |
2 |
26 Feb 07 |
jari |
438 |
|
2 |
26 Feb 07 |
jari |
439 |
File f = new File( "C:" + File.separator + "Dev" + File.separator + "MeV" + |
2 |
26 Feb 07 |
jari |
440 |
File.separator + "files" + File.separator + "human" + File.separator + |
2 |
26 Feb 07 |
jari |
441 |
"NewTrainFormat.txt" ); |
2 |
26 Feb 07 |
jari |
442 |
|
2 |
26 Feb 07 |
jari |
443 |
try { |
2 |
26 Feb 07 |
jari |
444 |
USCTrainFileLoader loader = new USCTrainFileLoader( f ); |
2 |
26 Feb 07 |
jari |
445 |
USCHybSet hs = loader.getTrainHybSet(); |
2 |
26 Feb 07 |
jari |
446 |
hs.permute( 5 ); |
2 |
26 Feb 07 |
jari |
//USCCrossValidation cv = new USCCrossValidation( hs, 50, 20, 0.5, 1.0, 0.1, 5 ); |
2 |
26 Feb 07 |
jari |
//cv.crossValidate(); |
2 |
26 Feb 07 |
jari |
449 |
|
2 |
26 Feb 07 |
jari |
450 |
/* |
2 |
26 Feb 07 |
jari |
System.out.println( "hybKount:" + hs.getHybKount() ); |
2 |
26 Feb 07 |
jari |
for( int j = 0; j < hs.getHybs().length; j ++ ) { |
2 |
26 Feb 07 |
jari |
USCHyb hyb = ( USCHyb ) hs.getHybs()[ j ]; |
2 |
26 Feb 07 |
jari |
System.out.println( "\r\nlabel:" + hyb.getHybLabel() + "\tname:" + hyb.getHybName() ); |
2 |
26 Feb 07 |
jari |
float[] ratios = hyb.getRatios(); |
2 |
26 Feb 07 |
jari |
for( int i = 0; i < ratios.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
System.out.println( ratios[ i ] ); |
2 |
26 Feb 07 |
jari |
458 |
} |
2 |
26 Feb 07 |
jari |
459 |
} |
2 |
26 Feb 07 |
jari |
460 |
*/ |
2 |
26 Feb 07 |
jari |
461 |
} catch (IOException e) { |
2 |
26 Feb 07 |
jari |
462 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
463 |
} |
2 |
26 Feb 07 |
jari |
464 |
}//end main |
2 |
26 Feb 07 |
jari |
465 |
}//end class |