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: JacknifedMatrixByGenes.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.2 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:59 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.util; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.util.Random; |
2 |
26 Feb 07 |
jari |
15 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
16 |
|
2 |
26 Feb 07 |
jari |
17 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
public class JacknifedMatrixByGenes { |
2 |
26 Feb 07 |
jari |
20 |
|
2 |
26 Feb 07 |
jari |
21 |
public Vector resampledIndices = new Vector(); |
2 |
26 Feb 07 |
jari |
22 |
int jackknifedGene; |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
//the following method "extracts" the 2D array from an ExpressionMatrix object to be used by the subsampleMatrix method in creating a resampled matrix. |
2 |
26 Feb 07 |
jari |
26 |
float[][] get2DArrFromExpMatrix(FloatMatrix expMatrix) { |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
int geneDim = expMatrix.getRowDimension(); |
2 |
26 Feb 07 |
jari |
29 |
int expDim = expMatrix.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
30 |
float[][] expArray = new float[geneDim][expDim]; |
2 |
26 Feb 07 |
jari |
31 |
int x, y; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
for (x = 0; x < geneDim; x++) { |
2 |
26 Feb 07 |
jari |
34 |
for (y = 0; y < expDim; y++) { |
2 |
26 Feb 07 |
jari |
35 |
expArray[x][y] = expMatrix.get(x,y); |
2 |
26 Feb 07 |
jari |
36 |
} |
2 |
26 Feb 07 |
jari |
37 |
} |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
return expArray; |
2 |
26 Feb 07 |
jari |
40 |
} |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
float[][] resampleMatrix(FloatMatrix expMatrix) {//create a jacknifed 2D array by genes |
2 |
26 Feb 07 |
jari |
44 |
|
2 |
26 Feb 07 |
jari |
45 |
float[][] aMatrix = get2DArrFromExpMatrix(expMatrix); |
2 |
26 Feb 07 |
jari |
46 |
float[][] newMatrix = new float[aMatrix.length - 1][aMatrix[0].length]; |
2 |
26 Feb 07 |
jari |
47 |
int numGenes = aMatrix.length; |
2 |
26 Feb 07 |
jari |
48 |
int numExps = aMatrix[0].length; |
2 |
26 Feb 07 |
jari |
49 |
int randGene; |
2 |
26 Feb 07 |
jari |
50 |
int k = 0; |
2 |
26 Feb 07 |
jari |
51 |
Random generator = new Random(); |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
randGene = generator.nextInt(numGenes); |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
for (int i = 0; i < numExps; i++) { |
2 |
26 Feb 07 |
jari |
56 |
k = 0; |
2 |
26 Feb 07 |
jari |
57 |
for (int j = 0; j < numGenes; j++) { |
2 |
26 Feb 07 |
jari |
58 |
if (j != randGene) { |
2 |
26 Feb 07 |
jari |
59 |
newMatrix[k][i] = aMatrix[j][i]; |
2 |
26 Feb 07 |
jari |
60 |
k++; |
2 |
26 Feb 07 |
jari |
61 |
} |
2 |
26 Feb 07 |
jari |
62 |
} |
2 |
26 Feb 07 |
jari |
63 |
} |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
65 |
jackknifedGene = randGene; |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
for (int i = 0; i < numGenes; i++) { |
2 |
26 Feb 07 |
jari |
68 |
if (i != jackknifedGene) { |
2 |
26 Feb 07 |
jari |
69 |
resampledIndices.add(new Integer(i)); |
2 |
26 Feb 07 |
jari |
70 |
} |
2 |
26 Feb 07 |
jari |
71 |
} |
2 |
26 Feb 07 |
jari |
72 |
|
2 |
26 Feb 07 |
jari |
73 |
return newMatrix; |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
} |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
public FloatMatrix createResampExpMatrixObject(FloatMatrix ExpMatrix) { |
2 |
26 Feb 07 |
jari |
79 |
|
2 |
26 Feb 07 |
jari |
80 |
int x, y; |
2 |
26 Feb 07 |
jari |
81 |
float[][] resampledArray = resampleMatrix(ExpMatrix); |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
FloatMatrix resampMatrixObject = new FloatMatrix(resampledArray); |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
85 |
return resampMatrixObject; |
2 |
26 Feb 07 |
jari |
86 |
} |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
|
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
void printMatrix(float[][] matrix) { |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
92 |
int i, j = 0; |
2 |
26 Feb 07 |
jari |
93 |
for (i = 0; i < matrix[0].length; i++) { |
2 |
26 Feb 07 |
jari |
94 |
for (j = 0; j < matrix.length; j++) { |
2 |
26 Feb 07 |
jari |
95 |
System.out.print(((int) (matrix[j][i] * 100)) / 100 + " "); |
2 |
26 Feb 07 |
jari |
96 |
} |
2 |
26 Feb 07 |
jari |
97 |
System.out.println(); |
2 |
26 Feb 07 |
jari |
98 |
} |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
} |