pseudodynamics.models._density_transport¶
Classes
|
class to analyze the density transport result from saved files |
|
Wrap up the density transfer function into a nn Module, for calling odeint_adjoint |
- class pseudodynamics.models._density_transport.DT_analysis(adata, result_dir, celltype=None)[source]¶
Bases:
objectclass to analyze the density transport result from saved files
- Parameters:
adata (anndata) – the single cell type object with annotaion
result_dir (Path) – the abs path to the result directory where Density_Transfer results are saved
celltype (str) – the cell type to analyze
Example
>>> dta_obj = DT_analysis(adata, result_dir, celltype) >>> TM = DT.TM_dict[time] >>> celltypes = ['Ery','HSC','Int prog','Meg'] >>> ct_prop = dta_obj.density_by_celltype_step(celltypes) >>> agg_density = dta_obj.density_by_celltype_step(celltypes, step=-1, norm=False) >>> clusters, row_linkage, reorded_i = DT.hierarchical_clustering(density_matrix=laststep_TM, n_clusters=n_clusters, log_normalize=log_normalize) >>> g = DT.clustermap( density_matrix = laststep_TM, clusters = clusters, row_linkage = row_linkage, celltypes = tick_labels, cmap = 'viridis', cbar_pos = [1, 0.4, 0.03,0.2], figsize = (7,8), log_normalize=True )
- annotate_trajectory(cellstate_key, obs_key, copy=False)[source]¶
Use the nearest celltype to annotate each step along the simulated trajectory
Inputs: cellstate_key: which cellstate space for the simulation to map to obs_key: the key to store the annotation in adata
Returns: celltype_trajectory: with the annotation added
- clustermap(clusters, row_linkage, celltypes, density_matrix=None, value=None, log_normalize=False, cluster_colors=None, **kwargs)[source]¶
This function is a wrapper for seaborn.clustermap() that truncates the dendrogram and returns cluster assignments and reordered indices.
- Two input mode, given:
density_matrix or
value and celltypes
- heatmap_cell_proportions(celltypes, value='assignment_probability', step=-1, paletter=None, log_normalize=False, **kwargs)[source]¶
heatmap for cell proportions with
Args:¶
celltypes: list of cell types (the columns in self.ct_prop) value : ‘assignment_probability’, ‘density’ , ‘agg_density’ step : which step of the trajectory to plot paletter : color palette for day cmap : matplotlib colormap **kwargs: kwargs for seaborn clustermap
Returns:¶
: g : seaborn cluster grid
- hierarchical_clustering(density_matrix=None, value=None, celltypes=None, n_clusters=5, cluster_colors=None, log_normalize=False)[source]¶
This function performs hierarchical clustering on the given density matrix. Two input mode, given:
density_matrix or
value and celltypes
- load_result(result_dir)[source]¶
load the result from saved files, this method returns 4 dictionary with timepoint as key
Saved Properties:¶
cb_dict: a dictionary of cell barcode at its corresponding time point TM_dict: a dictionary of raw transport map at its corresponding time point TM_norm_dict: a dictionary of normalized transport map at its corresponding time point trajectory_dict: a dictionary of trajectory at its corresponding time point
- summarize_cell_proportions(df, celltype_list)[source]¶
Summarizes the proportion of cell types mapped from neighbors for each cell
Inputs¶
- dfpd.DataFrame
Input DataFrame where each column represents a cell and each row a sample.
- celltype_listlist
List of cell types to include in the output as columns.
- class pseudodynamics.models._density_transport.Density_Transfer(pde_model=None, stochastic=False, noise_schedule=None, n_repeat=30)[source]¶
Bases:
ModuleWrap up the density transfer function into a nn Module, for calling odeint_adjoint
- Parameters:
pde_model (nn.Modules from pdp.models) – the pde model (pde_params, log_pde_params)
stochastic (bool, default False) – whether to add noise to the cell state simulation
noise_schedule (callable, default None) – the noise schedule for the cell state
n_repeat (int) – the number of times to repeat the cell state simulation
Example
>>> pde_model = models.pde_params.load_from_checkpoint(model_ckpt) >>> pde_model = pde_model.to(device) >>> DT = models.Density_Transfer(pde_model) >>> # prepare initial condition >>> integrate_time = np.linspace(t/t0, timepoint_tx_days[it+1]/t0 ,n_interval+1) / pde_model.time_scale_factor >>> cell_index = ? >>> u0 = Dataset.u_b[it, cell_index].float().to(device) >>> s0 = torch.from_numpy(Dataset.cellstate[cell_index]).float().to(device) >>> # perform simulation >>> S_trajectory = DT.cellstate_drift(s0, integrate_time) >>> # infer dynamic transport map >>> Tmaps_t, Tmaps_t_norm = DT.transition_by_batch(s0, u0, integrate_time, n_interval=n_interval, ncell=ncell)
- forward(t, states)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.