alifestd_from_newick_polars
- alifestd_from_newick_polars(newick: str, *, allow_forest: bool | None = None, branch_length_dtype: type = <class 'float'>, create_ancestor_list: bool = False, dtype_id: ~polars.datatypes.classes.DataType | None = Int64, replace_unquoted: ~typing.Mapping[str, str] = mappingproxy({})) DataFrame
Convert a Newick format string to a phylogeny dataframe.
Parses a Newick tree string and returns a polars DataFrame in alife standard format with columns: id, ancestor_id, taxon_label, origin_time_delta, and branch_length. Optionally includes ancestor_list.
Parameters
- newickstr
A phylogeny in Newick format.
- allow_forestbool or None, default None
Policy for a Newick string holding multiple
;-terminated trees (a forest).Noneparses the forest but warns;Trueparses it silently;FalseraisesValueErrorunless there is a single tree.- branch_length_dtypetype, default float
Dtype for branch length values. Use
intto get nullable integer columns (pl.Int64). Missing branch lengths will benullfor integer dtypes orNaNfor float dtypes.- create_ancestor_listbool, default False
If True, include an
ancestor_listcolumn in the result.- dtype_idpl.DataType or None, default pl.Int64
Polars dtype for the
idandancestor_idcolumns. If None, the smallest signed integer dtype that can hold all node ids is chosen automatically based on the node count of the Newick string.- replace_unquotedMapping[str, str], optional
Character substitutions to apply to unquoted taxon labels only, leaving quoted labels verbatim. Keys must be single characters. Pass
{"_": " "}to follow the strict Newick convention in which an unquoted underscore denotes a space.
Returns
- pl.DataFrame
Phylogeny dataframe in alife standard format.
Notes
By default, unquoted underscores in taxon labels are preserved literally; they are not converted to spaces. This diverges from the strict Newick convention (in which an unquoted
_denotes a space), but matches the round-trip behavior ofalifestd_as_newick_asexual. Passreplace_unquoted={"_": " "}to follow the strict convention.See Also
- alifestd_from_newick :
Pandas-based implementation.
- alifestd_as_newick_asexual :
Inverse conversion, from alife standard to Newick format.