dynamo.tl.moments

dynamo.tl.moments(adata, genes=None, group=None, use_gaussian_kernel=False, normalize=True, use_mnn=False, layers='all', n_pca_components=30, n_neighbors=30)[source]
Calculate kNN based first and second moments (including uncentered covariance) for

different layers of data.

Parameters
  • adata (AnnData) – AnnData object.

  • genes (np.array (default: None)) – The one-dimensional numpy array of the genes that you want to perform pca analysis (if adata.obsm[‘X’] is not available). X keyname (instead of X_pca) was used to enable you use a different set of genes for flexible connectivity graph construction. If None, by default it will select genes based use_for_pca key in .var attributes if it exists otherwise it will also all genes stored in adata.X

  • group (str or None (default: None)) – The column key/name that identifies the grouping information (for example, clusters that correspond to different cell types or different time points) of cells. This will be used to compute kNN graph for each group (i.e cell-type/time-point). This is important, for example, we don’t want cells from different labeling time points to be mixed when performing the kNN graph for calculating the moments.

  • use_gaussian_kernel (bool (default: True)) – Whether to normalize the kNN graph via a Guasian kernel.

  • normalize (bool (default: True)) – Whether to normalize the connectivity matrix so that each row sums up to 1. When use_gaussian_kernel is False, this will be reset to be False because we will already normalize the connectivity matrix matrix by dividing each row the total number of connections.

  • use_mnn (bool (default: False)) – Whether to use mutual kNN across different layers as for the moment calculation.

  • layers (str or a list of str (default: str)) – The layers that will be used for calculating the moments.

  • n_pca_components (int (default: 30)) – The number of pca components to use for constructing nearest neighbor graph and calculating 1/2-st moments.

  • n_neighbors (int (default: 30)) – The number of neighbors for constructing nearest neighbor graph used to calculate 1/2-st moments.

Returns

adata – A updated AnnData object with calculated first/second moments (including uncentered covariance) included.

Return type

AnnData