| 1 |
package dna; |
| 2 |
import java.util.HashMap; |
| 3 |
import java.util.Set; |
| 4 |
|
| 5 |
import fileIO.MatrixFile; |
| 6 |
|
| 7 |
|
| 8 |
public class Matrix { |
| 9 |
|
| 10 |
|
| 11 |
public Matrix(float[][] g, int pre, String nm){ |
| 12 |
grid=g; |
| 13 |
prefix=pre; |
| 14 |
name=nm; |
| 15 |
} |
| 16 |
|
| 17 |
public float[][] subGrid(int prefixLength, int length){ |
| 18 |
float[][] r=new float[length][]; |
| 19 |
int start=prefix-prefixLength; |
| 20 |
for(int i=0; i<length; i++){ |
| 21 |
r[i]=grid[i+start].clone(); |
| 22 |
} |
| 23 |
return r; |
| 24 |
} |
| 25 |
|
| 26 |
public float[][] grid; |
| 27 |
public int prefix; |
| 28 |
public String name; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
private static HashMap<String, Matrix> table=null; |
| 34 |
|
| 35 |
public static Set<?> keys(){return table.keySet();} |
| 36 |
|
| 37 |
public static Matrix get(String s){ |
| 38 |
if(table==null){ |
| 39 |
table=new HashMap<String, Matrix>(64); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
fillTable("matrix_build37_N1.txt"); |
| 49 |
fillTable("matrix_build37_N2.txt"); |
| 50 |
fillTable("matrix_build37_N3.txt"); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
fillTable("SplicePercentiles_b37_Nov24.txt"); |
| 65 |
|
| 66 |
} |
| 67 |
Matrix m=table.get(s); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
if(!table.containsKey(s) || m==null){ |
| 73 |
if(!table.containsKey(s)){throw new RuntimeException("Can't find "+s+" in\n\n"+table.keySet()+"\n");} |
| 74 |
if(m==null){throw new RuntimeException("\nValue for "+s+" is null");} |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
return m; |
| 79 |
} |
| 80 |
|
| 81 |
private static void fillTable(String fname){ |
| 82 |
MatrixFile mf=new MatrixFile(fname); |
| 83 |
Matrix mat=mf.nextMatrix(); |
| 84 |
while(mat!=null){ |
| 85 |
|
| 86 |
table.put(mat.name, mat); |
| 87 |
table.put(mat.name.toLowerCase(), mat); |
| 88 |
mat=mf.nextMatrix(); |
| 89 |
} |
| 90 |
mf.close(); |
| 91 |
} |
| 92 |
|
| 93 |
} |