phylovelo.pseudo_time

Functions

get_nearest_neighbor(data, target[, n_neighbors])

Get nearest neighbors of the target

_as_float_array(x)

_normalize_01(x[, robust_quantiles])

_normalize_with_bounds(x, lo, hi)

_time_intervals(pt1, pt2, v1, v2)

time_interval(pt1, pt2, v1, v2)

Given two points' coordinate and velocity, calculate the time interval

_build_knn_adjacency(pts, v[, n_neighbors])

_connected_components(adjacency)

_bridge_components(adjacency, pts, v[, root])

_prim_edges(adjacency[, root])

_graph_pseudotime(pts, v[, n_neighbors, root, ...])

graph_dict(pts, v[, n_neighbors])

Build graph to construct MST

prim(graph, root)

Prim algorithm to build MST from graph

_sample_cells(index, r_sample[, random_state])

_positions_for_names(index, names)

_get_expression_data(obj, target)

_meg_pseudotime_scores(X, lo, spread, signs, weights, ...)

calc_phylo_pseudotime(sd[, n_neighbors, r_sample, ...])

Calculate the phyloVelo pseudotime

calc_meg_pseudotime(sd[, target, genes, ...])

Calculate pseudotime directly from robustly oriented MEG expression.

Module Contents

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

_as_float_array(x)
_normalize_01(x, robust_quantiles=None)
_normalize_with_bounds(x, lo, hi)
_time_intervals(pt1, pt2, v1, v2)
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

_build_knn_adjacency(pts, v, n_neighbors=30)
_connected_components(adjacency)
_bridge_components(adjacency, pts, v, root=0)
_prim_edges(adjacency, root=0)
_graph_pseudotime(pts, v, n_neighbors=30, root=0, robust_quantiles=(0.01, 0.99))
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

prim(graph, root)

Prim algorithm to build MST from graph

_sample_cells(index, r_sample, random_state=None)
_positions_for_names(index, names)
_get_expression_data(obj, target)
_meg_pseudotime_scores(X, lo, spread, signs, weights, aggregation)
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

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.