lineage.LineageTree

This file contains the LineageTree class.

Module Contents

class lineage.LineageTree.LineageTree(list_of_cells: list, E: list)

A class for lineage trees. This class also handles algorithms for walking the tree to calculate various properties.

pi :npt.NDArray[np.float64]
T :npt.NDArray[np.float64]
leaves_idx :npt.NDArray[np.uintp]
idx_by_gen :list[np.ndarray]
output_lineage :list[CellVar]
cell_to_parent :np.ndarray
cell_to_daughters :np.ndarray
classmethod rand_init(cls, pi: np.ndarray, T: np.ndarray, E: list, desired_num_cells: int, censor_condition=0, desired_experiment_time=2000000000000.0, rng=None)

Constructor method

:param \(\pi\): The initial probability matrix; its shape must be the same as the number of states and all of them must sum up to 1. :param T: The transition probability matrix; every row must sum up to 1. :param E: A list containing state distribution objects, the length of it is the same as the number of states. :param desired_num_cells: The desired number of cells we want the lineage to end up with. :param censor_condition: An integer \(\in\) {0, 1, 2, 3} that decides the type of censoring.

Censoring guide - 0 means no pruning - 1 means censor based on the fate of the cell - 2 means censor based on the length of the experiment - 3 means censor based on both the ‘fate’ and ‘time’ conditions

__len__(self)

Defines the length of a lineage by returning the number of cells it contains.

lineage.LineageTree.get_Emission_Likelihoods(X: list[LineageTree], E: list) → list

Emission Likelihood (EL) matrix.

Each element in this N by K matrix represents the probability

\(P(x_n = x | z_n = k)\),

for all \(x_n\) and \(z_n\) in our observed and hidden state tree and for all possible discrete states k. :param tHMMobj: A class object with properties of the lineages of cells :param E: The emissions likelihood :return: The marginal state distribution

lineage.LineageTree.generate_lineage_list(pi: npt.NDArray[np.float64], T: npt.NDArray[np.float64], desired_num_cells: int) → list

Generates a single lineage tree given Markov variables. This only generates the hidden variables (i.e., the states) in a output binary tree manner. It keeps generating cells in the tree until it reaches the desired number of cells in the lineage. :param pi: An array of the initial probability of a cell being a certain state. :param T: An array of the probability of a cell switching states or remaining in the same state. :param desired_num_cells: The desired number of cells in a lineage. :return full_lineage: A list of the generated cell lineage.

lineage.LineageTree.output_assign_obs(state: int, full_lineage: list[CellVar], E: list)

Observation assignment give a state. Given the lineageTree object and the intended state, this function assigns the corresponding observations coming from specific distributions for that state. :param state: The integer value of the state that is being observed. :param full_lineage: The list of cells within the lineageTree object. :param E: The list of observations assignments.

lineage.LineageTree.max_gen(lineage: list[CellVar]) → list[np.ndarray]

Finds the maximal generation in the tree, and cells organized by their generations. This walks through the cells in a given lineage, finds the maximal generation, and the group of cells belonging to a same generation and creates a list of them, appends the lists leading to have a list of the lists of cells in specific generations. :param lineage: The list of cells in a lineageTree object. :return max: The maximal generation in the tree. :return cells_by_gen: The list of lists of cells belonging to the same generation separated by specific generations.

lineage.LineageTree.cell_to_parent(lineage: list[CellVar]) → np.ndarray
lineage.LineageTree.cell_to_daughters(lineage: list[CellVar]) → np.ndarray
lineage.LineageTree.get_leaves_idx(lineage: list[CellVar]) → npt.NDArray[np.uintp]

A function to find the leaves and their indexes in the lineage list. :param lineage: The list of cells in a lineageTree object. :return leaf_indices: The list of cell indexes. :return leaves: The last cells in the lineage branch.