Comments (8)
Actually, both update_bipartitions()
and mrca
collapse the basal split in an unrooted tree. This is not just a common cause of confusion/irritation for many, but the non-intuitiveness of this tends to drive a fairly respectable portion of folks to very strong expressions of counter-opinion. It really is technically correct though, and the only way to handle bipartition hashes on unrooted trees to avoid the duplicate hash.
Immediate solution is to simply force the tree to be rooted, using [&R]
or passing in the keyword rooting="force-rooted"
.
If you are dealing with trees that should be rooted, that's all there is to it.
If are dealing with unrooted trees, then it becomes a little trickier. IIRC, the PhylogeneticDistanceMatrix class (which has an mrca
method) does not calculate bipartition hashes, so this avoids the basal split being collapsed on unrooted trees. (NOTE: depending on your application you may actually prefer to use the PhylogeneticDistanceMatrix class anyway, as this can be quite a bit more efficient than the naive mrca
function if called multiple times).
Some day, I will write up a short piece with a few examples of why the basal split must be collapsed on an unrooted trees when calculating bipartition hashes. Just a few trivial examples will make it clear. In the mean time, some discussion of this can also be found here:
from dendropy.
OK, thanks for the explanations. It does seem to be counter-intuitive that mrca
would actually modify underlying tree - I expected it to be a read-only operation. Maybe a quick note in the mrca
documentation is warranted?
I wish to treat the tree as rooted, so the fix is straight-forward.
Thanks for the quick reply.
from dendropy.
It does seem to be counter-intuitive that |mrca| would actually modify
underlying tree - I expected it to be a read-only operation. Maybe a quick note in the |mrca| documentation is warranted?
Yep, should do so (i.e. update documentation warning about side-effects of mrca).
The reason it does is that it calculates the bipartition hashes to get
to the MRCA's, which results in the collapsing. Note that,
strictly-speaking, technically, if actually an unrooted tree, then tree
is not really modified in terms of the relationships it is modeling. if
the tree is unrooted, then the basal split that is collapsed does not
actually exist. It is simply an artifact of the tree representation.
But, in your case, you are dealing with rooted trees (even though
DendroPy thinks it is dealing with unrooted trees), so the modification
done by the operation has actual and incorrect results.
from dendropy.
ok. Is it possible force rerooting after parsing from the newick so that the tree is as if it was read in with rooting="force-rooted"
? I'm hoping to write a method that assumes a rooted tree has been given without actually requiring is_rooted=True
.
from dendropy.
If you have not already tried it, when reading the tree just using the rooting-specification keyword argument:
trees = dendropy.get(
path="foo.tre",
schema="newick",
rooting="force-rooted")
This would be the cleanest approach.
Other approaches, in increasing "dirtiness":
(1) Set the is_rooted
property on each tree to True
(2) insert the rooting statement token in front of the tree string, "[&R]"
(3) hack the newick parser to assume all trees are rooted
from dendropy.
alrighty, even (1) seems a little brittle, I'll try to stick with the parse-approach. Thanks for all the help.
from dendropy.
(1) is actually the "best-practice" approach. It is a formal part of the API and is wrapped up in tests.
from dendropy.
Sorry, not (1), but (0), i.e. the rooting="force-rooted"
is the "best-practice"/recommend approach.
(1) is OK, too. Basically, (0) does (1) under the hood at parse time.
from dendropy.
Related Issues (20)
- API docs HOT 1
- `Tree.mrca` has side effect of changing rooting state HOT 6
- `shuffle_taxa` raises `DeprecationWarning`
- Keep supporting Python2.7? HOT 3
- Some examples in `/docs/source/examples` are broken
- Add developer documentation
- Track PyPi URL change for project homepage
- Chore: Fix `ResourceWarning`s from tests
- Chore: fix `distutils` deprecation warning HOT 1
- `paup_estimate_tree_nj` example experiences intermittent failure HOT 1
- Provide public interface for `_convert_node_to_root_polytomy` HOT 1
- quote_underscores argument unrecognized HOT 1
- Documentation Deployment
- Create smoke tests
- Multithreaded option fails with no error message - leaf labels issue? HOT 1
- Error runnig picrust due to cannot import name '_convert_node_to_root_polytomy' HOT 2
- Website dendropy.org is down HOT 5
- treesim.birth_death_tree() raises division by zero error when used to extend an existing tree HOT 4
- Final Steps for Version 5 Release
- JOSS Paper?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dendropy.