phylovelo.pseudo_time ===================== .. py:module:: phylovelo.pseudo_time Functions --------- .. autoapisummary:: phylovelo.pseudo_time.get_nearest_neighbor phylovelo.pseudo_time._as_float_array phylovelo.pseudo_time._normalize_01 phylovelo.pseudo_time._normalize_with_bounds phylovelo.pseudo_time._time_intervals phylovelo.pseudo_time.time_interval phylovelo.pseudo_time._build_knn_adjacency phylovelo.pseudo_time._connected_components phylovelo.pseudo_time._bridge_components phylovelo.pseudo_time._prim_edges phylovelo.pseudo_time._graph_pseudotime phylovelo.pseudo_time.graph_dict phylovelo.pseudo_time.prim phylovelo.pseudo_time._sample_cells phylovelo.pseudo_time._positions_for_names phylovelo.pseudo_time._get_expression_data phylovelo.pseudo_time._meg_pseudotime_scores phylovelo.pseudo_time.calc_phylo_pseudotime phylovelo.pseudo_time.calc_meg_pseudotime Module Contents --------------- .. py:function:: get_nearest_neighbor(data: numpy.ndarray, target: int, n_neighbors: int = 10) Get nearest neighbors of the target Args: data: Data to train knn target: Target point to get nearest neighbors n_neighbors: How many nearest neighbors to return Returns: list: Euclidean distance from target to neighbors list: Neighbors' indices .. py:function:: _as_float_array(x) .. py:function:: _normalize_01(x, robust_quantiles=None) .. py:function:: _normalize_with_bounds(x, lo, hi) .. py:function:: _time_intervals(pt1, pt2, v1, v2) .. py:function:: time_interval(pt1: numpy.ndarry, pt2: numpy.ndarry, v1: numpy.ndarry, v2: numpy.ndarry) Given two points' coordinate and velocity, calculate the time interval Args: pt1: Coordinate of one point pt2: Coordinate of the other point v1: Velocity of one point v2: Velocity of the other point Return: float: Time interval .. py:function:: _build_knn_adjacency(pts, v, n_neighbors=30) .. py:function:: _connected_components(adjacency) .. py:function:: _bridge_components(adjacency, pts, v, root=0) .. py:function:: _prim_edges(adjacency, root=0) .. py:function:: _graph_pseudotime(pts, v, n_neighbors=30, root=0, robust_quantiles=(0.01, 0.99)) .. py:function:: graph_dict(pts: numpy.ndarry, v: numpy.ndarry, n_neighbors: int = 30) Build graph to construct MST Args: pts: All cells' coordinate in embedding v: Phylo velocity n_neighbors: N nearest neighbors to build MST Return: dict: Graph to build MSt .. py:function:: prim(graph, root) Prim algorithm to build MST from graph .. py:function:: _sample_cells(index, r_sample, random_state=None) .. py:function:: _positions_for_names(index, names) .. py:function:: _get_expression_data(obj, target) .. py:function:: _meg_pseudotime_scores(X, lo, spread, signs, weights, aggregation) .. py:function:: calc_phylo_pseudotime(sd: scData, n_neighbors: int = 30, r_sample: float = 1, method: str = 'graph', target: str = 'x_normed', random_state: int = None) Calculate the phyloVelo pseudotime Args: sd: sc data n_neighbors: N nearest neighbors to build MST. The smaller the number, the faster the calculation, but there is a chance of error r_sample: [0-1], random sample a subset calculate pseudotime. method: 'graph' uses embedding velocities and a kNN MST; 'meg' uses robust MEG expression. target: Expression matrix used when method='meg'. random_state: Seed for subsampling. Return: scData.phylo_pseudotime .. py:function:: calc_meg_pseudotime(sd: scData, target: str = 'x_normed', genes: list = None, robust_quantiles: tuple = (0.05, 0.95), aggregation: str = 'median', min_genes: int = 3, query_data=None, query_sd: scData = None, query_target: str = None) Calculate pseudotime directly from robustly oriented MEG expression. Args: sd: sc data target: Expression matrix to use, usually 'x_normed' or 'count'. genes: MEGs to use. Default uses sd.megs. robust_quantiles: Lower and upper quantiles used to clip per-gene expression. aggregation: 'median' for robust L1 aggregation or 'weighted_mean'. min_genes: Minimum number of usable MEGs. query_data: Independent expression matrix (cells x genes) to score with the reference dataset's MEGs, velocity directions, and robust scaling. query_sd: Independent scData object. Uses query_target or target as expression matrix and writes query pseudotime to query_sd.phylo_pseudotime. query_target: Expression matrix name for query_sd. Default: same as target. Return: sd if no query is provided; query pseudotime array if query_data is provided; query_sd if query_sd is provided.