use of beast.evolution.sitemodel.SiteModel in project beast2 by CompEvol.
the class SiteModelInputEditor method createGammaCategoryCountEditor.
public InputEditor createGammaCategoryCountEditor() {
SiteModel sitemodel = ((SiteModel) m_input.get());
final Input<?> input = sitemodel.gammaCategoryCount;
categoryCountEditor = new IntegerInputEditor(doc) {
private static final long serialVersionUID = 1L;
@Override
public void validateInput() {
super.validateInput();
SiteModel sitemodel = (SiteModel) m_beastObject;
if (sitemodel.gammaCategoryCount.get() < 2 && sitemodel.shapeParameterInput.get().isEstimatedInput.get()) {
m_validateLabel.m_circleColor = Color.orange;
m_validateLabel.setToolTipText("shape parameter is estimated, but not used");
m_validateLabel.setVisible(true);
}
}
};
categoryCountEditor.init(input, sitemodel, -1, ExpandOption.FALSE, true);
categoryCountEntry = categoryCountEditor.getEntry();
categoryCountEntry.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
processEntry2();
}
@Override
public void insertUpdate(DocumentEvent e) {
processEntry2();
}
@Override
public void changedUpdate(DocumentEvent e) {
processEntry2();
}
});
categoryCountEditor.validateInput();
return categoryCountEditor;
}
use of beast.evolution.sitemodel.SiteModel in project beast2 by CompEvol.
the class Utils method main.
public static void main(String[] args) {
try {
Sequence a = new Sequence("A", "A");
Sequence b = new Sequence("B", "A");
Sequence c = new Sequence("C", "A");
Sequence d = new Sequence("D", "A");
Alignment data = new Alignment();
data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
TreeParser tree = new TreeParser();
tree.initByName("taxa", data, "newick", "(((A:1,B:1):1,C:2):1,D:3)", "IsLabelledNewick", true);
JukesCantor JC = new JukesCantor();
JC.initAndValidate();
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
BeagleTreeLikelihood likelihood = new BeagleTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Success");
// if we got this far, exit with status 0
System.exit(0);
}
use of beast.evolution.sitemodel.SiteModel in project beast2 by CompEvol.
the class TreeLikelihoodTest method testHKY85GILikelihood.
@Test
public void testHKY85GILikelihood() throws Exception {
// Set up HKY85+G+I model: estimated freqs, kappa = 39.464538, 4 gamma categories, shape = 0.587649, prop invariant = 0.486548
Alignment data = BEASTTestCase.getAlignment();
Tree tree = BEASTTestCase.getTree(data);
Frequencies freqs = new Frequencies();
freqs.initByName("data", data);
HKY hky = new HKY();
hky.initByName("kappa", "39.464538", "frequencies", freqs);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.587649", "proportionInvariant", "0.486548", "substModel", hky);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
logP = likelihood.calculateLogP();
assertEquals(logP, -1789.639227747059, BEASTTestCase.PRECISION);
likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
assertEquals(logP, -1789.639227747059, BEASTTestCase.PRECISION);
}
use of beast.evolution.sitemodel.SiteModel in project beast2 by CompEvol.
the class TreeLikelihoodTest method testMarginalisationOfLikelihoodBinary.
@Test
public void testMarginalisationOfLikelihoodBinary() throws Exception {
// test summation over all patterns adds to 1 for binary data
Sequence German_ST = new Sequence("German_ST", " 10110010");
Sequence Dutch_List = new Sequence("Dutch_List", " 11010100");
Sequence English_ST = new Sequence("English_ST", " 11101000");
Alignment data = new Alignment();
data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "dataType", "binary");
Tree tree = BEASTTestCase.getTree(data, "(English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):0.0;");
RealParameter frequencies = new RealParameter("0.683 0.317");
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", frequencies);
GeneralSubstitutionModel covarion = new GeneralSubstitutionModel();
covarion.initByName("frequencies", freqs, "rates", new RealParameter("1.0 1.0"));
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
likelihood.calculateLogP();
double[] logPs = likelihood.getPatternLogLikelihoods();
double P = 0;
for (double d : logPs) {
P += Math.exp(d);
}
assertEquals(P, 1.0, BEASTTestCase.PRECISION);
}
use of beast.evolution.sitemodel.SiteModel in project beast2 by CompEvol.
the class TreeLikelihoodTest method testBeagleRNALikelihood.
/**
* Test only effective when BEAGLE installed - otherwise it will always
* pass since BEAGLE code will never be run.
*
* @throws Exception
*/
@Test
public void testBeagleRNALikelihood() throws Exception {
Sequence seq1 = new Sequence("t1", "GUACGUACGUAC");
Sequence seq2 = new Sequence("t2", "UACGUACGUACG");
Sequence seq3 = new Sequence("t3", "ACGUACGUACGU");
Alignment data = new Alignment();
data.initByName("sequence", seq1, "sequence", seq2, "sequence", seq3, "dataType", "nucleotide");
Tree tree = BEASTTestCase.getTree(data, "((t1:0.5,t2:0.5):0.5,t3:1.0):0.0;");
SiteModel siteModel = new SiteModel();
siteModel.initByName("gammaCategoryCount", 1, "substModel", new JukesCantor());
TreeLikelihood likelihoodNoBeagle = newTreeLikelihood();
likelihoodNoBeagle.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logLnoBeagle = likelihoodNoBeagle.calculateLogP();
System.setProperty("java.only", "false");
TreeLikelihood likelihoodBeagle = new TreeLikelihood();
likelihoodBeagle.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logLBeagle = likelihoodBeagle.calculateLogP();
assertEquals(logLBeagle, logLnoBeagle, BEASTTestCase.PRECISION);
}
Aggregations