Comments (4)
Hmmm. I don't think prune_taxa
returns a tree. Did you mean some other function in the first line?
from dendropy.
'Returns' was not the right way to phrase that. Looking at the source, it looks like prune_taxa just prunes the listed taxa on the tree object that's in memory. So, if I'm understanding this right, prune_taxa won't return anything, so trying to write the results of the command to a new object will give me nothing? So if I want to maintain a copy of the unpruned tree in memory, I should make a copy of the tree before pruning, and perform the pruning on the copy. Is that right?
from dendropy.
Python functions return None
by default. So, your assignment state does bind tree
to the implicit return value of the function, which is None
.
For what you want to do, yes, making a copy of the unpruned tree before pruning will work. But note that Python has name binding semantics, and not memory-binding semantics like C++.
So if you say:
tree_copy = tree1 # NOT actually a copy!!
tree1.prune_taxa()
assert tree_copy is tree1 # True
you will not get anywhere, because tree_copy
is a name bound to the same object as the tree1
name. Unlike C/C++, a value is NOT assigned to a memory slot, but one name is bound to the same object/reference to which the other name is bound. You will need to explicitly clone or deep-copy the tree:
tree_copy = tree1.clone()
and then go ahead and make changes to tree1
.
Apologies if all of this is already familiar to you! But sometimes, especially if you switch back-and-forth between C/C++ and Python, it is easy to get tripped up by Python name-binding semantics vs. C/C++ memory-value assignment semantics.
Note that if you do not need/use any metadata annotations, you should consider using the extract_tree
family of methods (https://pythonhosted.org/DendroPy/primer/treemanips.html#extracting-trees-and-subtrees-from-an-existing-tree):
- Tree.extract_tree
- Tree.extract_tree_with_taxa
- Tree.extract_tree_without_taxa
- Tree.extract_tree_with_taxa_labels
- Tree.extract_tree_without_taxa_labels
Much faster and more efficient than cloning and then pruning.
from dendropy.
OK, thanks! That answers my question.
I'll give the extract methods a try, since I'm not using metadata.
from dendropy.
Related Issues (20)
- `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 2
- 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?
- Support values written as quoted node labels since >4.6.1 HOT 4
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.