Last active
August 29, 2015 14:22
-
-
Save mtholder/25633ad86b0c14221e18 to your computer and use it in GitHub Desktop.
used dendropy4 to assure tree and matrix have the same taxon set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from dendropy import DnaCharacterMatrix, Tree | |
| import sys | |
| d = DnaCharacterMatrix.get(path=sys.argv[1], | |
| schema='fasta') | |
| # make the taxon_namespace immutable, so the tree does not add | |
| # new labels... | |
| d.taxon_namespace.is_mutable = False | |
| tree = Tree.get(path=sys.argv[2], | |
| schema='newick', | |
| preserve_underscores=True, | |
| taxon_namespace=d.taxon_namespace) | |
| # get all of the taxa associated with tips of the tree, and make sure that | |
| # they include all of the members of the data's taxon_namespace... | |
| treed_taxa = [i.taxon for i in tree.leaf_nodes()] | |
| if len(treed_taxa) != len(d.taxon_namespace): | |
| missing = [i.label for i in d.taxon_namespace if i not in treed_taxa] | |
| emf = 'Some of the taxa are not in the tree. Missing "{}"\n' | |
| em = emf.format('", "'.join(missing)) | |
| raise ValueError(em) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment