pseudodynamics.functions.reader_funs¶
Functions
|
lr scheduler rule 1, quickly decay then steady |
|
lr scheduler rule 2, decay then grow |
|
This function takes a CDF defined on a grid x and augments it to a finer grid x_a by duplicating the CDF values within intervals defined by x. |
|
Evaluate the cell density at time point t_b using the pre-defined density function |
|
Estimating the density high dimensional cell state coordinates and its change by experimental time. |
|
wrapping mellon time-sense density |
|
|
|
extract the cell density at time point t_b, this function works for 1 dimensional data |
|
extract the cell density at time point t_b. |
|
func for multi-process density estimate inside time-point loop |
|
generate pseudo-bulk (meta-cell) using super-high resolution clustering |
|
from a given ckpt , load the MLP model |
|
construct adata based on cellstate coodinates from expression matrix based adata the new adata is mainly for visualizing v |
|
use to reshape prediction |
|
the Key function defines the noise sampling process given the starting point i |
|
the Key function defines the noise sampling process given the starting point i |
|
the Key function defines the delta-X sampling process given the transition matrix, then sample the delta x |
|
scale dpt array to 0 and 1 |
|
Use super-high resolution leiden algorithm to generate pseudo-bulk |
|
|
|
- pseudodynamics.functions.reader_funs.Lambda1(epoch, gamma=0.2)[source]¶
lr scheduler rule 1, quickly decay then steady
- pseudodynamics.functions.reader_funs.Lambda2(epoch, gamma=0.15, changepoint=150)[source]¶
lr scheduler rule 2, decay then grow
- pseudodynamics.functions.reader_funs.augment_cdf(x, x_a, y)[source]¶
This function takes a CDF defined on a grid x and augments it to a finer grid x_a by duplicating the CDF values within intervals defined by x. zeros or ones accordingly were added for where x_a values are outside the range of x
- pseudodynamics.functions.reader_funs.boundary_density_at(D, t_b, x, density_fn=None)[source]¶
Evaluate the cell density at time point t_b using the pre-defined density function
- Parameters:
D (the extracted data dictionary)
t_b (the boundary time point)
x (the grided cell state coordiante)
density_fn (
callable)
- Returns:
u_t : smoothed cell density over s and adjusted by pop size
- pseudodynamics.functions.reader_funs.compute_guassian_u(Cellstate_ay, dimension=10)[source]¶
Estimating the density high dimensional cell state coordinates and its change by experimental time. The density estimation function is
- Parameters:
Cellstate_ay (ndarray of shape (N_cell, dimension), the high dimensional cell state representation, i.e. PC, Diffusion Map (DM) , SCVI-latent)
dimension (control the nubmer of the first few dimension to use for density esitmation)
- Returns:
gussian_kde_u : ndarray of shape (N_cell, 1), the density of each cell
Example
>>> timepoints = sorted(ad.obs.timepoint_tx_days.unique()) # get timepoints >>> cbs_t = [ad.obs.query("`timepoint_tx_days` == @t").index for t in timepoints] >>> DM_ay = [ad[cb].obsm['DM_eigen'] for cb in cbs_t] >>> gussian_kde_u = guassian_u(DM_ay, dimension=5) >>> ad.obs['DM5_gaussisn_u']= gussian_kde_u
- pseudodynamics.functions.reader_funs.compute_mellon_timesense_u(adata, cellstate_key, timepoint_key, ls_time_estimate=None, n_dimension=None)[source]¶
wrapping mellon time-sense density
Args:¶
adata : the cells from which for estimating density cellstate_key : the low dimensional representation timepoint_key : the obs key that record tiempoint, dtype should be int or float ls_time_estimate : float, the length scaler for time n_dimension : [int, None] ,
Returns:¶
: log_u : np.array of shape (n_timepoints, n_cells), the log density density_predictor : trained mellon.TimeSensitiveDensityEstimator.predict
Example:¶
>>> import pseudodynamics as pdp >>> # a simple example for estimating density of a specific condition >>> adata_c1 = adata[adata.obs['condition'] == 'condition_1'].copy() >>> timepoints = adata_c1.obs['time'].unique()
>>> # time ls for exploration >>> ls_time_estimate = 1.5 * np.mean(np.diff(np.sort(timepoints))) >>> # timesensitive estimator >>> log_u, estimator = pdp.tl.compute_mellon_timesense_u(adata_c1, 'DM_EigenVectors', 'time', ls_time_estimate)
- pseudodynamics.functions.reader_funs.evaluate_1d_density(D, t_b, x)[source]¶
extract the cell density at time point t_b, this function works for 1 dimensional data
- Parameters:
D (the extracted data dictionary)
t_b (the boundary time point)
x (the grided cell state coordiante)
- Returns:
u_t : smoothed cell density over s and adjusted by pop size
- pseudodynamics.functions.reader_funs.evaluate_2d_mesh_density(D, t_b, x)[source]¶
extract the cell density at time point t_b. this function works for 2 dimensional mesh grid
- Parameters:
D (the extracted data dictionary)
t_b (the boundary time point)
x (the mesh grided cell state s1, s2)
- Returns:
u_t : smoothed cell density over s and adjusted by pop size
- pseudodynamics.functions.reader_funs.evaluate_u_ds(cid, cellstate, u_tb, delta_s, den_fn, scaler)[source]¶
func for multi-process density estimate inside time-point loop
- Parameters:
cid (cell index , numerical index, not cell barcode)
cellstate (array [n_cell, n_dim] high-dimensional coordinate (representation) of all cells)
u_tb (array [n_cell,] , the density of each cell at a timepoint)
delta_s ([n_dim, ] the small perturbation add to cell state)
den_fn (callable([n_dim, n_cell]) , the density estimation function)
scaler (density scaler , normlized)
- Returns:
the duds : [n_cell, n_dim] , the density chagne along each dimension
- pseudodynamics.functions.reader_funs.get_pseudobulk(adata, cellstate_key, n_dimension=None, pseudobulk_key='pseudo_bulk', keep_index=False)[source]¶
generate pseudo-bulk (meta-cell) using super-high resolution clustering
- Parameters:
adata_DM (adata with DM was X)
pseudobulk_key (str, a obs key to specify the pseudobulk_key to use)
- Returns:
pdata : anndata with [n_pseudobulk, n_dimension]
Example
>>> adata = super_resolution_pseudobulk(adata, resolution=400, key_added='pseudo_bulk') # leiden clustering >>> adata_DM = make_coord_adata(adata, cellstate_key='DM_scaled', n_dimesion=10) # rebase data on low dimension >>> pdata = get_pseudobulk(adata_DM, 'pseudo_bulk') # generate pseudobulk >>> pdata.shape
- pseudodynamics.functions.reader_funs.load_model(ckptvx)[source]¶
from a given ckpt , load the MLP model
- pseudodynamics.functions.reader_funs.make_coord_adata(adata, cellstate_key, n_dimension, v=None)[source]¶
construct adata based on cellstate coodinates from expression matrix based adata the new adata is mainly for visualizing v
Args:¶
adata : anndata, the source anndata to extract info cellstate_key : which representation to use n_dimesion : the number of first dimeion of cellstate to use v : ndarray of shape [t, n_dim], default none
- pseudodynamics.functions.reader_funs.pred_to_nday(x, n_timepoint=5, n_dim=5)[source]¶
use to reshape prediction
- pseudodynamics.functions.reader_funs.sample_deltax(adata, transition_matrix=None, max_degree=1, k=None, xkey=None, pseudotimekey='palantir_pseudotime', progressbar=True, temperature=1, repeat=1)[source]¶
the Key function defines the noise sampling process given the starting point i
Return:¶
: delta_X, neighbor_ls
- pseudodynamics.functions.reader_funs.sample_deltax_from_knn(adata, max_degree=1, k=None, xkey=None, pseudotimekey='palantir_pseudotime', progressbar=False, temperature=1, repeat=1)[source]¶
the Key function defines the noise sampling process given the starting point i
Return:¶
- :
delta_X, neighbor_ls
- pseudodynamics.functions.reader_funs.sample_deltax_from_transition(adata, transition_matrix, xkey=None, pseudotimekey='palantir_pseudotime', progressbar=False, repeat=1)[source]¶
the Key function defines the delta-X sampling process given the transition matrix, then sample the delta x
Args:¶
transition_matrix : nd array of shape (n_cell, n_cell), i.e : cell rank transition matrix xkey : obsm_key or layer_key of the adata, from which space we sample the delta x
Return:¶
- :
delta_X, neighbor_ls
Example:¶
>>> ck = cr.kernels.ConnectivityKernel(adata) >>> ck.compute_transition_matrix() >>> pk = cr.kernels.PseudotimeKernel(adata, time_key="palantir_pseudotime") >>> pk.compute_transition_matrix() >>> combined_kernel = 0.8 * pk + 0.2 * ck >>> combined_kernel.compute_transition_matrix() >>> adata.obsp['combined_transition_matrix'] = combined_kernel.transition_matrix
- pseudodynamics.functions.reader_funs.super_resolution_pseudobulk(adata, resolution=200, n_pseudobulk=None, key_added='pseudo_bulk', seed=42, rapids_singlecell=False)[source]¶
Use super-high resolution leiden algorithm to generate pseudo-bulk
Augments¶
n_pseudobulk : int, defult None -> adata.shape[0] / 20, the number of pseudo bulk to end with pseudobulk_key : str, default ‘pseudo_bulk’ resolution : int, default None -> 40, the resolution pass to leiden algorithm
- returns:
adata with pseudo bulk key