scHopfield.tools.compute_reconstructed_velocity

scHopfield.tools.compute_reconstructed_velocity(adata: AnnData, cluster: str | None = None, spliced_key: str = 'Ms', degradation_key: str = 'gamma', cluster_key: str = 'cell_type', layer_key: str | None = None, copy: bool = False) AnnData | ndarray[source]

Compute reconstructed velocity from Hopfield model.

The velocity is computed as: v = W @ sigmoid(X) - gamma * X + I

Parameters:
  • adata (AnnData) – Annotated data object with fitted interactions

  • cluster (str, optional) – Cluster to compute velocity for. If None, computes for all cells using their respective cluster parameters

  • spliced_key (str, optional (default: 'Ms')) – Key in adata.layers for spliced counts

  • degradation_key (str, optional (default: 'gamma')) – Key in adata.var for degradation rates

  • cluster_key (str, optional (default: 'cell_type')) – Key in adata.obs for cluster labels

  • layer_key (str, optional) – If provided, stores reconstructed velocity in adata.layers[layer_key] If cluster is specified, uses f’{layer_key}_{cluster}’

  • copy (bool, optional (default: False)) – If True, return a copy instead of modifying in-place

Returns:

If layer_key is provided and copy=False: None (modifies adata in-place) If layer_key is provided and copy=True: modified copy of adata If layer_key is None: np.ndarray with reconstructed velocities

Return type:

AnnData or np.ndarray