pycea.tl.sort#
- pycea.tl.sort(tdata, key, reverse=False, tree=None)#
Reorders branches based on a node attribute.
For every internal node with multiple children, reorders outgoing edges (child branches) based on a given node attribute. The order is applied in-place preserving all node and edge metadata.
Sorting allows for consistent or meaningful ordering of descendants in tree visualizations, e.g., ordering by inferred ancestral state values or other numeric or categorical metrics.
- Parameters:
- Return type:
- Returns:
Returns
Noneand does not set any fields.
Examples
Sort branches by number of descendant leaves:
>>> tdata = py.datasets.yang22() >>> tdata.obs["n"] = 1 >>> py.tl.ancestral_states(tdata, keys="n", method="sum") >>> py.tl.sort(tdata, key="n")