alifestd_sort_children_asexual
- alifestd_sort_children_asexual(phylogeny_df: DataFrame, criterion: str, reverse: bool = False, mutate: bool = False) DataFrame
Reorder rows so children are sorted by the given criterion column, gathering children into contiguous rows.
Reorders rows so that among siblings, they appear in order of ascending
criterioncolumn values. Setreverse=Trueto sort descending (higher values first).The
criterioncolumn must already be present in the dataframe (e.g., added viaalifestd_mark_num_leaves_asexual).A topological sort will be applied if phylogeny_df is not topologically sorted. Dataframe reindexing (e.g., df.index) may be applied.
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.
Note: after sorting, ids will no longer be contiguous with respect to row indices. Call
alifestd_assign_contiguous_idson the result to reassign contiguous ids if needed.Parameters
- phylogeny_dfpandas.DataFrame
The phylogeny as a dataframe in alife standard format.
- criterionstr
Name of the column to sort children by.
- reversebool, default False
If True, sort descending (higher values first).
- mutatebool, default False
If True, allow mutation of the input dataframe.
Returns
- pandas.DataFrame
The phylogeny with rows reordered by sorted children traversal.
See Also
- alifestd_sort_children_polars :
Polars-based implementation.
- alifestd_ladderize_asexual :
Convenience wrapper that sorts by
num_leaves.- alifestd_assign_contiguous_ids :
Reassign contiguous ids after reordering.