use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.
the class YuleModel method validateInputs.
@Override
public void validateInputs() {
if (conditionalOnRootInput.get()) {
// make sure there is an MRCAPrior on the root
TreeInterface tree = treeInput.get();
int n = tree.getTaxonset().getTaxonCount();
boolean found = false;
for (BEASTInterface o : ((BEASTInterface) tree).getOutputs()) {
if (o instanceof MRCAPrior) {
MRCAPrior prior = (MRCAPrior) o;
int n2 = prior.taxonsetInput.get().taxonsetInput.get().size();
if (n2 == n) {
found = true;
}
}
}
if (!found) {
Log.warning("WARNING: There must be an MRCAPrior on the root when conditionalOnRoot=true, but could not find any");
}
}
super.validateInputs();
}
use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.
the class BeautiAlignmentProvider method getAlignments.
/**
* return new alignment given files
* @param doc
* @param files
* @return
*/
public List<BEASTInterface> getAlignments(BeautiDoc doc, File[] files) {
if (files == null) {
// merge "+ button" and "drag drop" function
return getAlignments(doc);
}
if (importers == null) {
initImporters();
}
List<BEASTInterface> selectedBEASTObjects = new ArrayList<>();
List<MRCAPrior> calibrations = new ArrayList<>();
for (File file : files) {
// create list of importers that can handle the file
List<AlignmentImporter> availableImporters = new ArrayList<>();
for (AlignmentImporter importer : importers) {
if (importer.canHandleFile(file)) {
availableImporters.add(importer);
}
}
if (availableImporters.size() > 0) {
AlignmentImporter importer = availableImporters.get(0);
if (availableImporters.size() > 1) {
// let user choose an importer
List<String> descriptions = new ArrayList<>();
for (AlignmentImporter i : availableImporters) {
descriptions.add(((BEASTInterface) i).getDescription());
}
String option = (String) JOptionPane.showInputDialog(null, "Which importer is appropriate", "Option", JOptionPane.WARNING_MESSAGE, null, descriptions.toArray(), descriptions.get(0));
if (option == null) {
return selectedBEASTObjects;
}
int i = descriptions.indexOf(option);
importer = availableImporters.get(i);
}
// get a fresh instance
// try {
// importer = importer.getClass().newInstance();
// } catch (InstantiationException | IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
List<BEASTInterface> list = importer.loadFile(file);
selectedBEASTObjects.addAll(list);
} else {
JOptionPane.showMessageDialog(null, "Unsupported sequence file.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
addAlignments(doc, selectedBEASTObjects);
if (calibrations != null) {
selectedBEASTObjects.addAll(calibrations);
}
// doc.addMRCAPriors(calibrations);
return selectedBEASTObjects;
}
use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.
the class MRCAPriorTest method testMRCATimePrior.
@Test
public void testMRCATimePrior() throws Exception {
Alignment data = BEASTTestCase.getAlignment();
TreeParser tree = new TreeParser();
tree.initByName("taxa", data, "newick", "((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035," + "(gorilla:0.024003,(orangutan:0.010772,siamang:0.010772):0.013231):0.012035);", "IsLabelledNewick", true);
Taxon human = new Taxon();
human.setID("human");
Taxon bonobo = new Taxon();
bonobo.setID("bonobo");
Taxon chimp = new Taxon();
chimp.setID("chimp");
Taxon gorilla = new Taxon();
gorilla.setID("gorilla");
Taxon orangutan = new Taxon();
orangutan.setID("orangutan");
Taxon siamang = new Taxon();
siamang.setID("siamang");
MRCAPrior prior = new MRCAPrior();
TaxonSet set = new TaxonSet();
set.initByName("taxon", human, "taxon", bonobo, "taxon", chimp);
Exponential exp = new Exponential();
/* get distribution for set (human, bonobo, chimp) */
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true, "distr", exp);
double logP = prior.calculateLogP();
assertEquals(-0.024003, logP, BEASTTestCase.PRECISION);
/* get distribution for set (human, chimp), do not require the set to by monophyletic */
set = new TaxonSet();
set.initByName("taxon", human, "taxon", chimp);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", false);
logP = prior.calculateLogP();
assertEquals(-0.024003, logP, BEASTTestCase.PRECISION);
/* get distribution for set (human, chimp), DO require the set to by monophyletic */
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
logP = prior.calculateLogP();
assertEquals(Double.NEGATIVE_INFINITY, logP, 0);
/* get distribution for set (human, gorilla) = root, not monophyletic */
set = new TaxonSet();
set.initByName("taxon", human, "taxon", gorilla);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", false);
logP = prior.calculateLogP();
assertEquals(-0.024003 - 0.012035, logP, BEASTTestCase.PRECISION);
}
use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.
the class MRCAPriorTest method testSingleMonophyleticConstraint.
@Test
public void testSingleMonophyleticConstraint() throws Exception {
Alignment data = BEASTTestCase.getAlignment();
TreeParser tree = new TreeParser();
tree.initByName("taxa", data, "newick", "((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035," + "(gorilla:0.024003,(orangutan:0.010772,siamang:0.010772):0.013231):0.012035);", "IsLabelledNewick", true);
Taxon human = new Taxon();
human.setID("human");
Taxon bonobo = new Taxon();
bonobo.setID("bonobo");
Taxon chimp = new Taxon();
chimp.setID("chimp");
Taxon gorilla = new Taxon();
gorilla.setID("gorilla");
Taxon orangutan = new Taxon();
orangutan.setID("orangutan");
Taxon siamang = new Taxon();
siamang.setID("siamang");
MRCAPrior prior = new MRCAPrior();
/* check (human, bonobo, chimp) is monophyletic **/
TaxonSet set = new TaxonSet();
set.initByName("taxon", human, "taxon", bonobo, "taxon", chimp);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
double logP = prior.calculateLogP();
assertEquals(logP, 0, 0);
/* check (gorilla, siamang) is NOT monophyletic **/
set = new TaxonSet();
set.initByName("taxon", gorilla, "taxon", siamang);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
logP = prior.calculateLogP();
assertEquals(logP, Double.NEGATIVE_INFINITY, 0);
/* check (gorilla, orangutan, siamang) is monophyletic **/
set = new TaxonSet();
set.initByName("taxon", gorilla, "taxon", orangutan, "taxon", siamang);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
logP = prior.calculateLogP();
assertEquals(logP, 0, 0);
/* check (human, gorilla) is NOT monophyletic **/
set = new TaxonSet();
set.initByName("taxon", human, "taxon", gorilla);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
logP = prior.calculateLogP();
assertEquals(logP, Double.NEGATIVE_INFINITY, 0);
set.setID("test");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
prior.init(ps);
String log = new String(baos.toByteArray(), StandardCharsets.UTF_8);
assertEquals(log, "mrcatime(test)\t");
baos = new ByteArrayOutputStream();
ps = new PrintStream(baos);
prior.initByName("tree", tree, "taxonset", set, "monophyletic", true, "useOriginate", true);
prior.init(ps);
log = new String(baos.toByteArray(), StandardCharsets.UTF_8);
assertEquals(log, "mrcatime(test.originate)\t");
}
use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.
the class PriorListInputEditor method init.
@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
List<?> list = (List<?>) input.get();
Collections.sort(list, (Object o1, Object o2) -> {
if (o1 instanceof BEASTInterface && o2 instanceof BEASTInterface) {
String d1 = ((BEASTInterface) o1).getID();
String id2 = ((BEASTInterface) o2).getID();
// first the tree priors
if (o1 instanceof TreeDistribution) {
if (o2 instanceof TreeDistribution) {
TreeInterface tree1 = ((TreeDistribution) o1).treeInput.get();
if (tree1 == null) {
tree1 = ((TreeDistribution) o1).treeIntervalsInput.get().treeInput.get();
}
TreeInterface tree2 = ((TreeDistribution) o2).treeInput.get();
if (tree2 == null) {
tree2 = ((TreeDistribution) o2).treeIntervalsInput.get().treeInput.get();
}
return d1.compareTo(id2);
} else {
return -1;
}
} else if (o1 instanceof MRCAPrior) {
// last MRCA priors
if (o2 instanceof MRCAPrior) {
return d1.compareTo(id2);
} else {
return 1;
}
} else {
if (o2 instanceof TreeDistribution) {
return 1;
}
if (o2 instanceof MRCAPrior) {
return -1;
}
if (o1 instanceof Prior) {
d1 = ((Prior) o1).getParameterName();
}
if (o2 instanceof Prior) {
id2 = ((Prior) o2).getParameterName();
}
return d1.compareTo(id2);
}
}
return 0;
});
rangeButtons = new ArrayList<>();
taxonButtons = new ArrayList<>();
// m_buttonStatus = ButtonStatus.NONE;
super.init(input, beastObject, itemNr, isExpandOption, addButtons);
if (beastObject instanceof BeautiPanelConfig) {
BeautiPanelConfig config = (BeautiPanelConfig) beastObject;
if (config.parentBEASTObjects != null && config.parentBEASTObjects.size() > 0 && config.parentBEASTObjects.get(0).getID().equals("speciescoalescent")) {
m_buttonStatus = ButtonStatus.NONE;
}
}
if (m_buttonStatus == ButtonStatus.ALL || m_buttonStatus == ButtonStatus.ADD_ONLY) {
addButton = new SmallButton("+ Add Prior", true);
addButton.setName("addItem");
addButton.setToolTipText("Add new prior (like an MRCA-prior) to the list of priors");
addButton.addActionListener(e -> {
addItem();
});
buttonBox.add(addButton);
buttonBox.add(Box.createHorizontalGlue());
}
}
Aggregations