skbio.tree.TreeNode.from_taxonomy

classmethod TreeNode.from_taxonomy(lineage_map)[source]

Construct a tree from a taxonomy

Parameters:

lineage_map : iterable of tuple

A id to lineage mapping where the first index is an ID and the second index is an iterable of the lineage.

Returns:

TreeNode

The constructed taxonomy

Examples

>>> from skbio.tree import TreeNode
>>> lineages = {'1': ['Bacteria', 'Firmicutes', 'Clostridia'],
...             '2': ['Bacteria', 'Firmicutes', 'Bacilli'],
...             '3': ['Bacteria', 'Bacteroidetes', 'Sphingobacteria'],
...             '4': ['Archaea', 'Euryarchaeota', 'Thermoplasmata'],
...             '5': ['Archaea', 'Euryarchaeota', 'Thermoplasmata'],
...             '6': ['Archaea', 'Euryarchaeota', 'Halobacteria'],
...             '7': ['Archaea', 'Euryarchaeota', 'Halobacteria'],
...             '8': ['Bacteria', 'Bacteroidetes', 'Sphingobacteria'],
...             '9': ['Bacteria', 'Bacteroidetes', 'Cytophagia']}
>>> tree = TreeNode.from_taxonomy(lineages.items())
>>> print(tree.ascii_art())
                              /Clostridia-1
                    /Firmicutes
                   |          \Bacilli- /-2
          /Bacteria|
         |         |                    /-3
         |         |          /Sphingobacteria
         |          \Bacteroidetes      \-8
         |                   |
---------|                    \Cytophagia-9
         |
         |                              /-5
         |                    /Thermoplasmata
         |                   |          \-4
          \Archaea- /Euryarchaeota
                             |          /-7
                              \Halobacteria
                                        \-6