use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.
the class OldTreesPanel method createTree.
private void createTree() {
if (generateTreeDialog == null) {
generateTreeDialog = new GenerateTreeDialog(frame);
}
int result = generateTreeDialog.showDialog(options);
if (result != JOptionPane.CANCEL_OPTION) {
GenerateTreeDialog.MethodTypes methodType = generateTreeDialog.getMethodType();
PartitionData partition = generateTreeDialog.getDataPartition();
Patterns patterns = new Patterns(partition.getAlignment());
DistanceMatrix distances = new F84DistanceMatrix(patterns);
Tree tree;
TemporalRooting temporalRooting;
switch(methodType) {
case NJ:
tree = new NeighborJoiningTree(distances);
temporalRooting = new TemporalRooting(tree);
tree = temporalRooting.findRoot(tree, TemporalRooting.RootingFunction.CORRELATION);
break;
case UPGMA:
tree = new UPGMATree(distances);
temporalRooting = new TemporalRooting(tree);
break;
default:
throw new IllegalArgumentException("unknown method type");
}
tree.setId(generateTreeDialog.getName());
options.userTrees.add(tree);
treesTableModel.fireTableDataChanged();
int row = options.userTrees.size() - 1;
treesTable.getSelectionModel().setSelectionInterval(row, row);
}
fireTreePriorsChanged();
}
use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.
the class ApproximatePoissonTreeLikelihoodParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
int sequenceLength = xo.getIntegerAttribute("sequenceLength");
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
BranchLengthProvider branchLengthProvider;
if (xo.getElementFirstChild(DATA) instanceof Tree) {
Tree dataTree = (Tree) xo.getElementFirstChild(DATA);
CladeNodeModel cladeNodeModel = null;
try {
cladeNodeModel = new CladeNodeModel(dataTree, treeModel);
} catch (TreeUtils.MissingTaxonException e) {
e.printStackTrace();
}
branchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeNodeModel);
} else if (xo.getElementFirstChild(DATA) instanceof CladeNodeModel) {
CladeNodeModel cladeNodeModel = (CladeNodeModel) xo.getElementFirstChild(DATA);
branchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeNodeModel);
} else {
DistanceMatrix dataMatrix = (DistanceMatrix) xo.getElementFirstChild(DATA);
branchLengthProvider = new RzhetskyNeiBranchLengthProvider(dataMatrix, treeModel);
}
BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
return new ApproximatePoissonTreeLikelihood(TREE_LIKELIHOOD, sequenceLength, treeModel, branchRateModel, branchLengthProvider);
}
use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.
the class DistanceMatrixParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
PatternList patterns = (PatternList) xo.getChild(PatternList.class);
DistanceMatrix matrix = null;
String type = xo.getStringAttribute(CORRECTION);
if (type.equals(Nucleotides.JC)) {
Logger.getLogger("dr.evoxml").info("Creating Jukes-Cantor distance matrix");
matrix = new JukesCantorDistanceMatrix(patterns);
} else if (type.equals(Nucleotides.F84)) {
Logger.getLogger("dr.evoxml").info("Creating F84 distance matrix");
matrix = new F84DistanceMatrix(patterns);
} else if (type.equals("SMM")) {
Logger.getLogger("dr.evoxml").info("Creating SMM distance matrix");
matrix = new SMMDistanceMatrix(patterns);
} else {
matrix = new DistanceMatrix(patterns);
}
return matrix;
}
use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.
the class UPGMATreeParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
boolean usingDatesSpecified = false;
boolean usingDates = true;
double rootHeight = xo.getAttribute(ROOT_HEIGHT, -1.0);
if (xo.hasAttribute(SimpleTreeParser.USING_DATES)) {
usingDatesSpecified = true;
usingDates = xo.getBooleanAttribute(SimpleTreeParser.USING_DATES);
}
DistanceMatrix distances = (DistanceMatrix) xo.getChild(DistanceMatrix.class);
UPGMATree tree = new UPGMATree(distances);
if (rootHeight > 0) {
double scaleFactor = rootHeight / tree.getNodeHeight(tree.getRoot());
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
NodeRef node = tree.getInternalNode(i);
double height = tree.getNodeHeight(node);
tree.setNodeHeight(node, height * scaleFactor);
}
}
if (usingDates) {
dr.evolution.util.Date mostRecent = null;
for (int i = 0; i < tree.getTaxonCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, dr.evolution.util.Date.DATE);
if (date == null) {
date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), dr.evolution.util.Date.DATE);
}
if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
mostRecent = date;
}
}
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), dr.evolution.util.Date.DATE);
if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
mostRecent = date;
}
}
if (mostRecent == null) {
if (usingDatesSpecified) {
throw new XMLParseException("no date elements in tree (and usingDates attribute set)");
}
} else {
TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
for (int i = 0; i < tree.getTaxonCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, dr.evolution.util.Date.DATE);
if (date == null) {
date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), dr.evolution.util.Date.DATE);
}
if (date != null) {
double height = timeScale.convertTime(date.getTimeValue(), date);
tree.setNodeHeight(tree.getExternalNode(i), height);
}
}
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), dr.evolution.util.Date.DATE);
if (date != null) {
double height = timeScale.convertTime(date.getTimeValue(), date);
tree.setNodeHeight(tree.getInternalNode(i), height);
}
}
MutableTree.Utils.correctHeightsForTips(tree);
}
}
if (rootHeight > 0) {
double scaleFactor = rootHeight / tree.getNodeHeight(tree.getRoot());
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
NodeRef node = tree.getInternalNode(i);
double height = tree.getNodeHeight(node);
tree.setNodeHeight(node, height * scaleFactor);
}
}
if (xo.getAttribute(RANDOMIZE, false)) {
shakeTree(tree);
}
return tree;
}
use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.
the class RzhetskyNeiBranchLengthsTreeTrest method setUp.
// +------------------------------------------------ 0
// +----------------------- |
// | +------------------------------------------------ 1
// |
// +-------------------------------------------------------------------------------------------------- 2
public void setUp() throws Exception {
super.setUp();
MathUtils.setSeed(1);
NewickImporter importer = new NewickImporter("((0:1,1:1):0.5,2:2);");
timeTree = new BigFastTreeModel(importer.importTree(null));
m = new DistanceMatrix(timeTree);
m.setElement(0, 0, 0);
m.setElement(0, 1, 2);
m.setElement(0, 2, 3.5);
m.setElement(1, 0, 2);
m.setElement(1, 1, 0);
m.setElement(1, 2, 3.5);
m.setElement(2, 0, 3.5);
m.setElement(2, 1, 3.5);
m.setElement(2, 2, 0);
}
Aggregations