lineagetree.tree_approximation
¶
Classes:
| Name | Description |
|---|---|
TreeApproximationTemplate |
Template class to produce different tree styles to comapare LineageTrees. |
downsample_tree |
Downsamples a tree so every n nodes are being used as one. |
full_tree |
No approximations the whole tree is used here. Perfect accuracy, but heavy on ram and speed. |
mini_tree |
Each branch is converted to a node of length 1, it is useful for comparing synchronous developing cells, extremely fast. |
simple_tree |
Each branch is converted to one node with length the same as the life cycle of the cell. |
TreeApproximationTemplate
¶
TreeApproximationTemplate(
lT: LineageTree,
root: int,
downsample: int | None = None,
end_time: int | None = None,
time_scale: int = 1,
)
Bases: ABC
Template class to produce different tree styles to comapare LineageTrees. To add a new style you need to inherit this class or one of its children and add them to the tree_style enum, or use it immediately on the function called. The main products of this class are: - tree constructor (get_tree) that produces one dictionary that contains arbitary unique labels and one dictionary that contains the duration of each node. - delta function: A function that handles the cost of comparing nodes to each other. - normalization function, a function that returns the length of the tree or any interger.
Methods:
| Name | Description |
|---|---|
delta |
The distance of two nodes inside a tree. Behaves like a staticmethod. |
get_norm |
Returns the valid value for normalizing the edit distance. |
get_tree |
Get a tree version of the tree spawned by the node |
handle_resolutions |
Handle different time resolutions. |
Source code in src/lineagetree/tree_approximation.py
delta
abstractmethod
¶
delta(
x: int,
y: int,
corres1: dict[int, int],
corres2: dict[int, int],
times1: dict[int, float],
times2: dict[int, float],
) -> int | float
The distance of two nodes inside a tree. Behaves like a staticmethod. The corres1/2 and time1/2 should always be provided and will be handled accordingly by the specific delta of each tree style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The first node to compare, takes the names provided by the edist. |
required |
|
int
|
The second node to compare, takes the names provided by the edist |
required |
|
dict
|
Dictionary mapping node1 ids to the corresponding id in the original tree. |
required |
|
dict
|
Dictionary mapping node2 ids to the corresponding id in the original tree. |
required |
|
dict
|
The dictionary of the chain lengths of the tree that n1 is spawned from. |
required |
|
dict
|
The dictionary of the chain lengths of the tree that n2 is spawned from. |
required |
Returns:
| Type | Description |
|---|---|
int or float
|
The distance between 'x' and 'y'. |
Source code in src/lineagetree/tree_approximation.py
get_norm
abstractmethod
¶
Returns the valid value for normalizing the edit distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The starting node of the subtree. |
required |
Returns:
| Type | Description |
|---|---|
int or float
|
The number of nodes of each tree according to each style, or the sum of the length of all the nodes in a tree. |
Source code in src/lineagetree/tree_approximation.py
get_tree
abstractmethod
¶
Get a tree version of the tree spawned by the node r
Returns:
| Type | Description |
|---|---|
dict mapping an int to a list of int
|
an adjacency dictionnary where the ids are the ids of the
cells in the original tree at their first time point
(except for the cell |
dict mapping an int to a float
|
life time duration of the key cell |
Source code in src/lineagetree/tree_approximation.py
handle_resolutions
abstractmethod
staticmethod
¶
handle_resolutions(
time_resolution1: float | int,
time_resolution2: float | int,
gcd: int,
downsample: int,
) -> tuple[int | float, int | float]
Handle different time resolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int or float
|
Time resolution of the first dataset. (Extracted from lT._time_resolution) |
required |
|
int or float
|
Time resolution of the second dataset. (Extracted from lT._time_resolution) |
required |
Returns:
| Type | Description |
|---|---|
int or float
|
The time resolution fix for the first dataset |
int or float
|
The time resolution fix for the second dataset |
Source code in src/lineagetree/tree_approximation.py
downsample_tree
¶
Bases: TreeApproximationTemplate
Downsamples a tree so every n nodes are being used as one.
Source code in src/lineagetree/tree_approximation.py
full_tree
¶
full_tree(
lT: LineageTree,
root: int,
downsample: int | None = None,
end_time: int | None = None,
time_scale: int = 1,
)
Bases: TreeApproximationTemplate
No approximations the whole tree is used here. Perfect accuracy, but heavy on ram and speed. Not recommended to use on napari.
Source code in src/lineagetree/tree_approximation.py
_edist_format
¶
Formating the custom tree style to the format needed by edist. .. warning:: Modifying this function might break your code.
Returns:
| Type | Description |
|---|---|
list[int]
|
list[list] The adjacency list of these nodes dict[int,int] The correspondance between the nodes used in edist and LineageTree |
Source code in src/lineagetree/tree_approximation.py
mini_tree
¶
Bases: TreeApproximationTemplate
Each branch is converted to a node of length 1, it is useful for comparing synchronous developing cells, extremely fast. Mainly used for testing.
Source code in src/lineagetree/tree_approximation.py
simple_tree
¶
Bases: TreeApproximationTemplate
Each branch is converted to one node with length the same as the life cycle of the cell. This method is fast, but imprecise, especialy for small trees (recommended height of the trees should be 100 at least). Use with CAUTION.