skbio.tree.TreeNode.from_taxonomy

classmethod TreeNode.from_taxonomy(lineage_map)[source]

Construct a tree from a taxonomy

State: Experimental as of 0.4.0.

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

The constructed taxonomy

Return type

TreeNode

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)
>>> print(tree.ascii_art())
                              /Clostridia-1
                    /Firmicutes
                   |          \Bacilli- /-2
          /Bacteria|
         |         |                    /-3
         |         |          /Sphingobacteria
         |          \Bacteroidetes      \-8
         |                   |
---------|                    \Cytophagia-9
         |
         |                              /-4
         |                    /Thermoplasmata
         |                   |          \-5
          \Archaea- /Euryarchaeota
                             |          /-6
                              \Halobacteria
                                        \-7