alifestd_add_global_root

alifestd_add_global_root(phylogeny_df: DataFrame, mutate: bool = False, root_attrs: Mapping[str, Any] = mappingproxy({})) DataFrame

Add a new global root node that all existing roots point to.

The new root node will have columns id, ancestor_id (if applicable), ancestor_list (if applicable), and any columns specified in root_attrs. All other columns will be NaN for the new root row.

Parameters

phylogeny_dfpd.DataFrame

Phylogeny dataframe in alife standard format.

mutatebool, default False

If True, allows mutation of the input dataframe.

root_attrsMapping[str, Any], default {}

Column values to set on the new global root row, e.g., {"origin_time": 0.0, "taxon_label": "root"}.

Keys "id", "ancestor_id", and "ancestor_list" are reserved and may not be specified; a ValueError is raised if any are present.

Returns

pd.DataFrame

The phylogeny dataframe with a new global root added.

Raises

ValueError

If root_attrs contains reserved keys.

Input dataframe is not mutated by this operation unless mutate set True. If mutate set True, operation does not occur in place; still use return value to get transformed phylogeny dataframe.