You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Methods like Node.isDirectAncestor and Node.isFake assume a tree in which branches of length 0 can occur, and this is an important case for me to include in a BEAST package I'm writing. In theory, we can allow for zero-length branches by setting the adjustTreeNodeHeights attribute of the tree element in our input to false. But in practice, I find that if I do this, many of the branches in my starting tree have negative lengths, which I still don't want. That said, I'd like to have a version of the Tree.adjustTreeNodeHeights method that cleans up negative branch lengths, but leaves branch lengths of 0 intact.
Currently, this method is defined as follows:
/** * Ensure no negative branch lengths exist in tree. This can occur if * leaf heights given as a trait are incompatible with the existing tree. */finalstaticdoubleEPSILON = 0.0000001;
protectedvoidadjustTreeNodeHeights(finalNodenode) {
if (!node.isLeaf() && adjustTreeNodeHeightsInput.get()) {
for (finalNodechild : node.getChildren()) {
adjustTreeNodeHeights(child);
}
for (finalNodechild : node.getChildren()) {
finaldoubleminHeight = child.getHeight() + EPSILON;
if (node.getHeight() < minHeight) {
node.setHeight(minHeight);
}
}
}
}
Notably, the description of the method already suggests what I have in mind: "no negative branch lengths". The problem is that the EPSILON constant is strictly positive, which makes branch lengths of 0 impossible.
Would the following modification be acceptable?
/** * Ensure no negative branch lengths exist in tree. This can occur if * leaf heights given as a trait are incompatible with the existing tree. * If adjustTreeNodeHeightsInput is set to true, then all non-positive branch lengths * are coerced to be small positive lengths. */finalstaticdoubleEPSILON = 0.0000001;
protectedvoidadjustTreeNodeHeights(finalNodenode) {
if (!node.isLeaf()) {
for (finalNodechild : node.getChildren()) {
adjustTreeNodeHeights(child);
}
for (finalNodechild : node.getChildren()) {
if (adjustTreeNodeHeightsInput.get()) {
finaldoubleminHeight = child.getHeight() + EPSILON;
if (node.getHeight() < minHeight) {
node.setHeight(minHeight);
}
} else {
finaldoubleminHeight = child.getHeight();
if (node.getHeight() < minHeight) {
node.setHeight(minHeight);
}
}
}
}
}
I don't see any use case for negative branch lengths, but if it's better for backwards compatibility to allow them, then a more precise solution would be to add support for an allowZeroBranchLengths attribute and modify the method as follows:
/** * Ensure no negative branch lengths exist in tree. This can occur if * leaf heights given as a trait are incompatible with the existing tree. * If allowZeroBranchLengths is false, then all non-positive branch lengths * are coerced to be small positive lengths. */finalstaticdoubleEPSILON = 0.0000001;
protectedvoidadjustTreeNodeHeights(finalNodenode) {
if (!node.isLeaf() && adjustTreeNodeHeightsInput.get()) {
for (finalNodechild : node.getChildren()) {
adjustTreeNodeHeights(child);
}
for (finalNodechild : node.getChildren()) {
if (allowZeroBranchLengthsInput.get()) {
finaldoubleminHeight = child.getHeight();
if (node.getHeight() < minHeight) {
node.setHeight(minHeight);
}
} else {
finaldoubleminHeight = child.getHeight() + EPSILON;
if (node.getHeight() < minHeight) {
node.setHeight(minHeight);
}
}
}
}
The text was updated successfully, but these errors were encountered:
Methods like
Node.isDirectAncestor
andNode.isFake
assume a tree in which branches of length 0 can occur, and this is an important case for me to include in a BEAST package I'm writing. In theory, we can allow for zero-length branches by setting theadjustTreeNodeHeights
attribute of thetree
element in our input tofalse
. But in practice, I find that if I do this, many of the branches in my starting tree have negative lengths, which I still don't want. That said, I'd like to have a version of theTree.adjustTreeNodeHeights
method that cleans up negative branch lengths, but leaves branch lengths of 0 intact.Currently, this method is defined as follows:
Notably, the description of the method already suggests what I have in mind: "no negative branch lengths". The problem is that the
EPSILON
constant is strictly positive, which makes branch lengths of 0 impossible.Would the following modification be acceptable?
I don't see any use case for negative branch lengths, but if it's better for backwards compatibility to allow them, then a more precise solution would be to add support for an
allowZeroBranchLengths
attribute and modify the method as follows:The text was updated successfully, but these errors were encountered: