| 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.treelikelihood; |
| 27 |
|
| 28 |
import dr.app.util.OSType; |
| 29 |
|
| 30 |
import java.io.File; |
| 31 |
import java.net.URISyntaxException; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
@Deprecated |
| 45 |
public class NativeNucleotideLikelihoodCore extends AbstractLikelihoodCore { |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public NativeNucleotideLikelihoodCore() { |
| 51 |
|
| 52 |
super(4); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
protected void calculateStatesStatesPruning(int[] states1, double[] matrices1, |
| 57 |
int[] states2, double[] matrices2, |
| 58 |
double[] partials3) { |
| 59 |
nativeStatesStatesPruning(states1, matrices1, states2, matrices2, patternCount, matrixCount, partials3); |
| 60 |
} |
| 61 |
|
| 62 |
protected void calculateStatesPartialsPruning( int[] states1, double[] matrices1, |
| 63 |
double[] partials2, double[] matrices2, |
| 64 |
double[] partials3) { |
| 65 |
nativeStatesPartialsPruning(states1, matrices1, partials2, matrices2, patternCount, matrixCount, partials3); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
protected void calculatePartialsPartialsPruning(double[] partials1, double[] matrices1, |
| 75 |
double[] partials2, double[] matrices2, |
| 76 |
double[] partials3) { |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
nativePartialsPartialsPruning(partials1, matrices1, partials2, matrices2, patternCount, matrixCount, partials3); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
protected void calculateStatesStatesPruning(int[] states1, double[] matrices1, |
| 92 |
int[] states2, double[] matrices2, |
| 93 |
double[] partials3, int[] matrixMap) |
| 94 |
{ |
| 95 |
throw new RuntimeException("calculateStatesStatesPruning not implemented using matrixMap"); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
protected void calculateStatesPartialsPruning( int[] states1, double[] matrices1, |
| 102 |
double[] partials2, double[] matrices2, |
| 103 |
double[] partials3, int[] matrixMap) |
| 104 |
{ |
| 105 |
throw new RuntimeException("calculateStatesStatesPruning not implemented using matrixMap"); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
protected void calculatePartialsPartialsPruning(double[] partials1, double[] matrices1, |
| 112 |
double[] partials2, double[] matrices2, |
| 113 |
double[] partials3, int[] matrixMap) |
| 114 |
{ |
| 115 |
throw new RuntimeException("calculateStatesStatesPruning not implemented using matrixMap"); |
| 116 |
} |
| 117 |
|
| 118 |
protected void calculateIntegratePartials(double[] inPartials, double[] proportions, double[] outPartials) |
| 119 |
{ |
| 120 |
nativeIntegratePartials(inPartials, proportions, patternCount, matrixCount, outPartials); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
protected native void nativeStatesStatesPruning( int[] states1, double[] matrices1, |
| 128 |
int[] states2, double[] matrices2, |
| 129 |
int patternCount, int matrixCount, |
| 130 |
double[] partials3); |
| 131 |
protected native void nativeStatesPartialsPruning( int[] states1, double[] matrices1, |
| 132 |
double[] partials2, double[] matrices2, |
| 133 |
int patternCount, int matrixCount, |
| 134 |
double[] partials3); |
| 135 |
protected native void nativePartialsPartialsPruning(double[] partials1, double[] matrices1, |
| 136 |
double[] partials2, double[] matrices2, |
| 137 |
int patternCount, int matrixCount, |
| 138 |
double[] partials3); |
| 139 |
public native void nativeIntegratePartials( double[] partials, double[] proportions, |
| 140 |
int patternCount, int matrixCount, |
| 141 |
double[] outPartials); |
| 142 |
|
| 143 |
public void calculateLogLikelihoods(double[] partials, double[] frequencies, double[] outLogLikelihoods) |
| 144 |
{ |
| 145 |
int v = 0; |
| 146 |
for (int k = 0; k < patternCount; k++) { |
| 147 |
|
| 148 |
double sum = frequencies[0] * partials[v]; v++; |
| 149 |
sum += frequencies[1] * partials[v]; v++; |
| 150 |
sum += frequencies[2] * partials[v]; v++; |
| 151 |
sum += frequencies[3] * partials[v]; v++; |
| 152 |
outLogLikelihoods[k] = Math.log(sum) + getLogScalingFactor(k); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
public static boolean isAvailable() { return isNativeAvailable; } |
| 157 |
|
| 158 |
private static boolean isNativeAvailable = false; |
| 159 |
|
| 160 |
static { |
| 161 |
String currentDir = null; |
| 162 |
try { |
| 163 |
currentDir = new File(NativeNucleotideLikelihoodCore.class.getProtectionDomain().getCodeSource(). |
| 164 |
getLocation().toURI()).getParent() + System.getProperty("file.separator") |
| 165 |
+ "lib" + System.getProperty("file.separator"); |
| 166 |
|
| 167 |
} catch (URISyntaxException e) { |
| 168 |
e.printStackTrace(); |
| 169 |
} |
| 170 |
try { |
| 171 |
if (OSType.isWindows()) { |
| 172 |
System.load(currentDir + "NucleotideLikelihoodCore.dll"); |
| 173 |
} else { |
| 174 |
currentDir = System.getProperty("user.dir"); |
| 175 |
System.loadLibrary("NucleotideLikelihoodCore"); |
| 176 |
} |
| 177 |
isNativeAvailable = true; |
| 178 |
System.out.println("Loading native NucleotideLikelihoodCore successfully from " + currentDir); |
| 179 |
} catch (UnsatisfiedLinkError e) { |
| 180 |
System.err.println("Failed to load native NucleotideLikelihoodCore in : " + currentDir); |
| 181 |
System.err.println("Using Java nucleotide likelihood core because " + e.toString()); |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
} |
| 188 |
} |
| 189 |
|