brokilon.core.read_nexus module

This module reads nexus tree files that are created by BEAST2. The function read_nexus_trees() has options to make it compatible with trees that were generated by the BREATH package and read transmission trees.

brokilon.core.read_nexus._cast_to_int(value)[source]

Custom function to cast a value to an integer. Fallbacks are either float or the original value. :param value: Input value to cast :return: Integer value or float or original value

brokilon.core.read_nexus._meta_label_nodes(tree: TreeNode, node_meta_data) None[source]

Annotating the node names and blockcount values to a Tree. This only works if the nodes names follow the name convention from above. That is %Node-label/blockcount% which is extracted in replace_match() above.

Parameters:

tree – Tree that will get blockcount annotations from node names

brokilon.core.read_nexus.count_trees_in_nexus(file) int[source]
brokilon.core.read_nexus.read_nexus_trees(file, parse_taxon_map: bool = False, burn_in: float = 0.0) list[TreeNode] | tuple[list[TreeNode], dict[str, str]][source]

Function to read a nexus file that contains transmission trees. This assumes that trees are generated by BREATH BEAST2 package. The necessary information is the blockcount for every node/edge. This function will fully label the transmission history onto the tree.

By setting breath_trees to false the transmission history labeling is also disabled.

Parameters:
  • file – Input file

  • parse_taxon_map – If true returns tuple of trees and taxon map

  • burn_in – Fraction of trees at beginning of file to discard

Returns:

list of trees with metadata annotation, optionally also a taxon map as dict