pycea.tl.clades#
- pycea.tl.clades(tdata, depth=None, depth_key='depth', clades=None, key_added='clade', update=False, dtype=<class 'str'>, tree=None, copy=False)#
- Overloads:
tdata (td.TreeData), depth (float | None), depth_key (str), clades (Mapping[Any, Any] | None), key_added (str), update (bool), dtype (type | str), tree (str | Sequence[str] | None), copy (Literal[True, False]) → pd.DataFrame
tdata (td.TreeData), depth (float | None), depth_key (str), clades (Mapping[Any, Any] | None), key_added (str), update (bool), dtype (type | str), tree (str | Sequence[str] | None), copy (Literal[True, False]) → None
Marks clades in a tree.
A clade is defined by a ancestral node; all nodes and edges in the ancestral node’s descendant subtree inherit the same clade label. You can specify clades in two ways:
- Depth-based:
Given a
depththreshold, all nodes that are extant at that depth are considered ancestral nodes. Each ancestral node and its descendants are assigned a unique clade label.
- Explicit mapping:
When
clades, a dictionary mapping nodes to clade labels is provided, those nodes are considered ancestral nodes. Each such node and its descendants are assigned the corresponding clade label.
- Parameters:
tdata (
TreeData) – The TreeData object.depth (
float|None(default:None)) – Depth to cut tree at. Must be specified if clades is None.depth_key (
str(default:'depth')) – Attribute oftdata.obst[tree].nodeswhere depth is stored.clades (
Mapping[Any,Any] |None(default:None)) – A dictionary mapping nodes to clades.key_added (
str(default:'clade')) – Key to store clades in.update (
bool(default:False)) – If True, updates existing clades instead of overwriting.dtype (
type|str(default:<class 'str'>)) – Data type of clade names. One ofstr,int, orfloat.tree (
str|Sequence[str] |None(default:None)) – Theobstkey or keys of the trees to use. IfNone, all trees are used.copy (
Literal[True,False] (default:False)) – If True, returns aDataFramewith clades.
- Returns:
Returns
Noneifcopy=False, else returns aDataFrame.Sets the following fields:
tdata.obs[key_added]Series(dtypeObject)Clade assignment for each observation.
tdata.obst[tree].nodes[key_added]ObjectClade assignment for each node.
Modifies the following fields:
tdata.uns[f"{key_added}_colors"]ListRemoved if its length does not match the number of unique clades.
Examples
Mark clades at specified depth
>>> tdata = pycea.datasets.koblan25() >>> pycea.tl.clades(tdata, depth=4, depth_key="time")
Highlight descendants of ‘node6’
>>> pycea.tl.clades(tdata, clades={"node6": "node6_descendants"}, key_added="highlight")