tasccoda.tree_utils.df2newick

tasccoda.tree_utils.df2newick(df, levels, inner_label=True)

Converts a pandas DataFrame with hierarchical information into a newick string. Adapted from https://stackoverflow.com/questions/15343338/how-to-convert-a-data-frame-to-tree-structure-object-such-as-dendrogram

Parameters
df : DataFrameDataFrame

Pandas DataFrame that has one row for each leaf of the tree and columns that indicate a hierarchical ordering. See the tascCODA tutorial for an example.

levels : List[str]List[str]

list that indicates how the columns in df are ordered as tree levels. Begins with the root level, ends with the leaf level

inner_label : boolbool (default: True)

Indicator whether labels for inner nodes should be included in the newick string

Return type

strstr

Returns

  • Newick string describing the tree structure from df

  • newick – A newick string