augur.import_beast module

Parse a BEAST MCC tree for further analysis in augur or export for auspice v2+ (using augur export v2 or greater).

augur.import_beast.calc_tree_dates(tree, most_recent_tip_date, tip_date_regex, tip_date_format, tip_date_delimeter)

Extract date information from the tree

  • tree (<class 'Bio.Phylo.BaseTree.Tree'>) –

  • time_units (#) –

  • tip_date (#) –

  • most_recent_tip_data_fmt (#) –

  • most_recent_tip_date (numeric) –

  • tip_date_regex (string) –

  • tip_date_format (string) –

  • tip_date_delimeter (string) –


  • tuple


    The root date offset


    The date of the most recent tip in the tree

  • TODO (Time units are taken as years, but days are also common for BEAST analysis)

augur.import_beast.collect_node_data(tree, root_date_offset, most_recent_tip_date)

Collect & summarise the BEAST traits included on the tree in a format applicable for augur to use (i.e. the “node_data.json” file).

  • tree (<class 'Bio.Phylo.BaseTree.Tree'>) –

  • root_date_offset (float) –

  • most_recent_tip_date (float) –


the keys are dependent on the content of the BEAST input

Return type



Computes entropies for discrete traits. Discrete traits are assumed to be those where the value is a dictionary. This will set a “entropy” value for each identified discrete trait on all applicable nodes in the tree.

tree<class ‘Bio.Phylo.BaseTree.Tree’>

BEAST traits are set as key-value pairs on node.attrs

Author: James Hadfield


Fake alignment to appease treetime when only using it for naming nodes… This is lifted from and ideally could be imported


T (<class 'Bio.Phylo.BaseTree.Tree'>) –

Return type

<class ‘Bio.Align.MultipleSeqAlignment’>

augur.import_beast.find_most_recent_tip(tree, tip_date_regex, tip_date_format, tip_date_delimeter)

Find the most recent tip in the tree

  • tree (<class 'Bio.Phylo.BaseTree.Tree'>) –

  • tip_date_regex (string) – The regex used to extract the date (e.g. isolate collection date from each tip in the string. default: hyphen delimited numbers at the end of tip name

  • tip_date_format (string) – The format of the extracted date. (e.g. “%Y-%m-%d” goes with “2012-10-30”)

  • tip_date_delimeter (string) – The delimeter in tip_date_format


AssertionError – If any tips were not matched by the regex


  • float – The date of the most recent tip in the tree in decimal format

  • Author (Gytis Dudas)


years from most recent tip of the root

augur.import_beast.parse_beast_tree(data, tipMap, verbose=False)

Parses the BEAST tree (and attributes etc) as encoded in NEXUS.

  • data (string) – The (really long) line in the NEXUS file beginning with “tree”, pruned to start at the first “(” character.

  • tipMap (dict) – Mapping of tips (as encoded in data) to their names

  • verbose (bool, optional (default: false)) – Should output be printed?


  • <class ‘Bio.Phylo.Newick.Clade’>

  • Author (Gytis Dudas)

augur.import_beast.parse_nexus(tree_path, treestring_regex='tree [A-Za-z\\_]+([0-9]+)', verbose=False)

Parses the BEAST MCC tree (NEXUS format)

  • tree_path (string or file handle open for reading) – The nexus tree file

  • treestring_regex (string) – The regex to match the tree string in the nexus file (the really long string which typically starts with “tree” and looks similar to a newick tree)

  • verbose (bool, optional (default: False)) – Should output be printed?


AssertionError – If the tree was not correctly parsed


  • <class ‘Bio.Phylo.BaseTree.Tree’> – A tree with BEAST attrs set on each node (as applicable)

  • Author (Gytis Dudas)

augur.import_beast.print_what_to_do_next(nodes, mcc_path, tree_path, node_data_path)

Print a suggested auspice_config.json file, which the user will have to configure and provide to augur export. There is not enough information in a MCC tree to do this automatically.


Arguments available to augur import beast


BEAST MCC tree to newick and node-data JSON for further augur processing / export


tree (<class 'Bio.Phylo.BaseTree.Tree'>) –