dynamo.tl.moments

dynamo.tl.moments(adata, X_data=None, genes=None, group=None, conn=None, use_gaussian_kernel=False, normalize=True, use_mnn=False, layers='all', n_pca_components=30, n_neighbors=30, copy=False)[source]

Calculate kNN based first and second moments (including uncentered covariance) for different layers of data.

Parameters:
  • adata (AnnData) – An AnnData object.

  • X_data (Optional[ndarray]) – The user supplied data that will be used for constructing the nearest neighbor graph directly. Defaults to None.

  • genes (Optional[list]) – 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. Defaults to None.

  • group (Optional[str]) – 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. Defaults to None.

  • conn (Optional[csr_matrix]) – The connectivity graph that will be used for moment calculations. Defaults to None.

  • use_gaussian_kernel (bool) – Whether to normalize the kNN graph via a Gaussian kernel. Defaults to False.

  • normalize (bool) – 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 by dividing each row the total number of connections. Defaults to True.

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

  • layers (Union[List[str], str]) – The layers that will be used for calculating the moments. Defaults to “all”.

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

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

  • copy (bool) – Whether to return a new updated AnnData object or update inplace. Defaults to False.

Raises:
  • Exceptiongroup is invalid.

  • ValueErrorconn is invalid. It should be a square array with dimension equal to the cell number.

Return type:

Optional[AnnData]

Returns:

The updated AnnData object if copy is true. Otherwise, the AnnData object passed in would be updated inplace and None would be returned.