| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.oldevomodel.substmodel; |
| 27 |
|
| 28 |
import dr.evolution.datatype.Codons; |
| 29 |
import java.util.*; |
| 30 |
import java.io.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class PCARateMatrixMammalia extends AbstractPCARateMatrix{ |
| 39 |
|
| 40 |
|
| 41 |
public static final String FREQS_FILE = "freqs.csv"; |
| 42 |
public static final String SCALES_FILE = "scales.csv"; |
| 43 |
public static final String MEANS_FILE = "means.csv"; |
| 44 |
public static final String FACTORS_FILE = "startfacs.csv"; |
| 45 |
public static final String PCS_FILE = "pcs.csv"; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public PCARateMatrixMammalia(int nrOfPCs, String dir) { |
| 54 |
super("mammalia", Codons.UNIVERSAL, dir); |
| 55 |
|
| 56 |
|
| 57 |
setupMeans(); |
| 58 |
setupFreqs(); |
| 59 |
setupScales(); |
| 60 |
setupStartFacs(); |
| 61 |
setupPCs(nrOfPCs); |
| 62 |
} |
| 63 |
|
| 64 |
private void setupFreqs() { |
| 65 |
|
| 66 |
double[] f = readSingleArray(FREQS_FILE, 61); |
| 67 |
setFrequencies(f); |
| 68 |
} |
| 69 |
|
| 70 |
private void setupScales() { |
| 71 |
|
| 72 |
double[] s = readSingleArray(SCALES_FILE, 1830); |
| 73 |
setScales(s); |
| 74 |
} |
| 75 |
|
| 76 |
private void setupMeans() { |
| 77 |
|
| 78 |
double[] m = readSingleArray(MEANS_FILE, 1830); |
| 79 |
setMeans(m); |
| 80 |
} |
| 81 |
|
| 82 |
private void setupStartFacs() { |
| 83 |
|
| 84 |
double[] sf = readSingleArray(FACTORS_FILE, 1830); |
| 85 |
setStartFacs(sf); |
| 86 |
} |
| 87 |
|
| 88 |
private void setupPCs(int nr) { |
| 89 |
double[][] p = new double[nr][1830]; |
| 90 |
|
| 91 |
File file = new File(dataDir, PCS_FILE); |
| 92 |
|
| 93 |
try { |
| 94 |
BufferedReader bufRdr = new BufferedReader(new FileReader(file)); |
| 95 |
|
| 96 |
String line = null; |
| 97 |
int row = 0; |
| 98 |
int col = 0; |
| 99 |
|
| 100 |
|
| 101 |
while(((line = bufRdr.readLine()) != null) && (row < nr)) |
| 102 |
{ |
| 103 |
col = 0; |
| 104 |
StringTokenizer st = new StringTokenizer(line,","); |
| 105 |
while (st.hasMoreTokens()) |
| 106 |
{ |
| 107 |
|
| 108 |
p[row][col] = Double.valueOf(st.nextToken()).doubleValue(); |
| 109 |
col++; |
| 110 |
} |
| 111 |
row++; |
| 112 |
} |
| 113 |
bufRdr.close(); |
| 114 |
} catch (FileNotFoundException e) { |
| 115 |
System.err.println("Caught FileNotFoundException: " + e.getMessage()); |
| 116 |
} catch (IOException e) { |
| 117 |
System.err.println("Caught IOException: " + e.getMessage()); |
| 118 |
} finally { |
| 119 |
} |
| 120 |
setPCs(p); |
| 121 |
} |
| 122 |
|
| 123 |
private double[] readSingleArray(String filename, int dim) { |
| 124 |
File file = new File(dataDir, filename); |
| 125 |
double[] arr = new double[dim]; |
| 126 |
|
| 127 |
try { |
| 128 |
BufferedReader bufRdr = new BufferedReader(new FileReader(file)); |
| 129 |
String line = null; |
| 130 |
int col = 0; |
| 131 |
|
| 132 |
while((line = bufRdr.readLine()) != null) { |
| 133 |
StringTokenizer st = new StringTokenizer(line,","); |
| 134 |
while (st.hasMoreTokens()) { |
| 135 |
arr[col] = Double.valueOf(st.nextToken()).doubleValue(); |
| 136 |
col++; |
| 137 |
} |
| 138 |
} |
| 139 |
bufRdr.close(); |
| 140 |
} catch (FileNotFoundException e) { |
| 141 |
System.err.println("Caught FileNotFoundException: " + e.getMessage()); |
| 142 |
} catch (IOException e) { |
| 143 |
System.err.println("Caught IOException: " + e.getMessage()); |
| 144 |
} finally { |
| 145 |
} |
| 146 |
return arr; |
| 147 |
} |
| 148 |
} |