use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class TreeLikelihoodTest method testGTRGLikelihood.
@Test
public void testGTRGLikelihood() throws Exception {
// Set up GTR model: 4 gamma categories, gamma shape = 0.5
Alignment data = BEASTTestCase.getAlignment();
Tree tree = BEASTTestCase.getTree(data);
Frequencies freqs = new Frequencies();
freqs.initByName("data", data);
GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "frequencies", freqs);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.5", "substModel", gsm);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
logP = likelihood.calculateLogP();
assertEquals(logP, -1949.0360143622, BEASTTestCase.PRECISION);
likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
assertEquals(logP, -1949.0360143622, BEASTTestCase.PRECISION);
}
use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class BinaryCovarionModelTest method doWithUnEqualHFreqs.
private void doWithUnEqualHFreqs(String mode) {
Frequencies dummyFreqs = new Frequencies();
dummyFreqs.initByName("frequencies", "0.25 0.25 0.25 0.25", "estimate", false);
BinaryCovarion substModel;
double d = 0.05 + Randomizer.nextDouble() * 0.9;
RealParameter hfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
d = 0.05 + Randomizer.nextDouble() * 0.9;
RealParameter vfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
substModel = new BinaryCovarion();
substModel.initByName("frequencies", dummyFreqs, "hfrequencies", hfrequencies, /* [f0, f1] */
"vfrequencies", vfrequencies, /* [p0, p1] */
"alpha", "0.01", "switchRate", "0.1", // "eigenSystem", "beast.evolution.substitutionmodel.RobustEigenSystem",
"mode", mode);
double[] matrix = new double[16];
substModel.getTransitionProbabilities(null, 1000, 0, 1.0, matrix);
double[] baseFreqs = new double[] { (vfrequencies.getValue(0) * hfrequencies.getValue(0)), (vfrequencies.getValue(1) * hfrequencies.getValue(0)), (vfrequencies.getValue(0) * hfrequencies.getValue(1)), (vfrequencies.getValue(1) * hfrequencies.getValue(1)) };
System.err.println("Expected: " + Arrays.toString(baseFreqs));
System.err.println("Calculat: " + Arrays.toString(matrix));
for (int j = 0; j < 4; j++) {
assertEquals(baseFreqs[j], matrix[j], 1e-3);
}
}
use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class HKYTest method testHKY.
public void testHKY() throws Exception {
for (Instance test : all) {
RealParameter f = new RealParameter(test.getPi());
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", f, "estimate", false);
HKY hky = new HKY();
hky.initByName("kappa", test.getKappa().toString(), "frequencies", freqs);
double distance = test.getDistance();
double[] mat = new double[4 * 4];
hky.getTransitionProbabilities(null, distance, 0, 1, mat);
final double[] result = test.getExpectedResult();
for (int k = 0; k < mat.length; ++k) {
assertEquals(mat[k], result[k], 1e-10);
System.out.println(k + " : " + (mat[k] - result[k]));
}
}
}
use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class GTRTest method testGTR.
public void testGTR() throws Exception {
for (Instance test : all) {
RealParameter f = new RealParameter(test.getPi());
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", f, "estimate", false);
GTR gtr = new GTR();
Double[] rates = test.getRates();
gtr.initByName("rateAC", new RealParameter(rates[0] + ""), "rateAG", new RealParameter(rates[1] + ""), "rateAT", new RealParameter(rates[2] + ""), "rateCG", new RealParameter(rates[3] + ""), "rateCT", new RealParameter(rates[4] + ""), "rateGT", new RealParameter(rates[5] + ""), "frequencies", freqs);
double distance = test.getDistance();
double[] mat = new double[4 * 4];
gtr.getTransitionProbabilities(null, distance, 0, 1, mat);
final double[] result = test.getExpectedResult();
for (int k = 0; k < mat.length; ++k) {
assertEquals(mat[k], result[k], 1e-10);
System.out.println(k + " : " + (mat[k] - result[k]));
}
}
}
use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class FrequenciesInputEditor method addComboBox.
// init
@Override
protected /**
* suppress combobox *
*/
void addComboBox(JComponent box, Input<?> input, BEASTInterface beastObject) {
Frequencies freqs = (Frequencies) input.get();
JComboBox<String> comboBox = new JComboBox<>(new String[] { "Estimated", "Empirical", "All equal" });
if (freqs.frequenciesInput.get() != null) {
comboBox.setSelectedIndex(0);
freqsParameter = freqs.frequenciesInput.get();
alignment = (Alignment) getCandidate(freqs.dataInput, freqs);
} else if (freqs.estimateInput.get()) {
comboBox.setSelectedIndex(1);
alignment = freqs.dataInput.get();
freqsParameter = (RealParameter) getCandidate(freqs.frequenciesInput, freqs);
} else {
comboBox.setSelectedIndex(2);
alignment = freqs.dataInput.get();
freqsParameter = (RealParameter) getCandidate(freqs.frequenciesInput, freqs);
}
comboBox.addActionListener(e -> {
// @SuppressWarnings("unchecked")
// JComboBox<String> comboBox = (JComboBox<String>) e.getSource();
int selected = comboBox.getSelectedIndex();
// Frequencies freqs = (Frequencies) m_input.get();
try {
switch(selected) {
case 0:
freqs.frequenciesInput.setValue(freqsParameter, freqs);
freqs.dataInput.setValue(null, freqs);
break;
case 1:
freqs.frequenciesInput.setValue(null, freqs);
freqs.dataInput.setValue(alignment, freqs);
freqs.estimateInput.setValue(true, freqs);
break;
case 2:
freqs.frequenciesInput.setValue(null, freqs);
freqs.dataInput.setValue(alignment, freqs);
freqs.estimateInput.setValue(false, freqs);
break;
}
} catch (Exception e2) {
e2.printStackTrace();
}
// System.err.println(freqs.frequencies.get() + " " + freqs.m_data.get() + " " + freqs.m_bEstimate.get());
});
box.add(comboBox);
}
Aggregations