def velocity_graph(data, vkey='velocity', xkey='Ms', tkey=None, basis=None, n_neighbors=None, n_recurse_neighbors=None,
                   random_neighbors_at_max=None, sqrt_transform=False, approx=False, copy=False):
    """Computes velocity graph based on cosine similarities.

    The cosine similarities are computed between velocities and potential cell state transitions.

    Arguments
    ---------
    data: :class:`~anndata.AnnData`
        Annotated data matrix.
    vkey: `str` (default: `'velocity'`)
        Name of velocity estimates to be used.
    n_neighbors: `int` or `None` (default: None)
        Use fixed number of neighbors or do recursive neighbor search (if `None`).
    n_recurse_neighbors: `int` (default: 2)
        Number of recursions to be done for neighbors search.
    random_neighbors_at_max: `int` or `None` (default: `None`)
        If number of iterative neighbors for an individual cell is higher than this threshold,
        a random selection of such are chosen as reference neighbors.
    sqrt_transform: `bool` (default: `False`)
        Whether to variance-transform the cell states changes and velocities before computing cosine similarities.
    copy: `bool` (default: `False`)
        Return a copy instead of writing to adata.

    Returns
    -------
    Returns or updates `adata` with the attributes
    velocity_graph: `.uns`
        sparse matrix with transition probabilities
    """
    adata = data.copy() if copy else data
    if vkey not in adata.layers.keys(): velocity(adata, vkey=vkey)

    vgraph = VelocityGraph(adata, vkey=vkey, xkey=xkey, tkey=tkey, basis=basis, n_neighbors=n_neighbors, approx=approx,
                           n_recurse_neighbors=n_recurse_neighbors, random_neighbors_at_max=random_neighbors_at_max,
                           sqrt_transform=sqrt_transform, report=True)

    logg.info('computing velocity graph', r=True)
    vgraph.compute_cosines()

    adata.uns[vkey+'_graph'] = vgraph.graph
    adata.uns[vkey+'_graph_neg'] = vgraph.graph_neg

    logg.info('    finished', time=True, end=' ' if settings.verbosity > 2 else '\n')
    logg.hint(
        'added \n'
        '    \'' + vkey + '_graph\', sparse matrix with cosine correlations (adata.uns)')

    return adata if copy else None
def velocity_graph ( data , vkey = 'velocity' , xkey = 'Ms' , tkey = None , basis = None , n_neighbors = None , n_recurse_neighbors = None , random_neighbors_at_max = None , sqrt_transform = False , approx = False , copy = False ) : adata = data . copy ( ) if copy else data if vkey not in adata . layers . keys ( ) : velocity ( adata , vkey = vkey ) vgraph = VelocityGraph ( adata , vkey = vkey , xkey = xkey , tkey = tkey , basis = basis , n_neighbors = n_neighbors , approx = approx , n_recurse_neighbors = n_recurse_neighbors , random_neighbors_at_max = random_neighbors_at_max , sqrt_transform = sqrt_transform , report = True ) logg . info ( 'computing velocity graph' , r = True ) vgraph . compute_cosines ( ) adata . uns [ vkey + '_graph' ] = vgraph . graph adata . uns [ vkey + '_graph_neg' ] = vgraph . graph_neg logg . info ( '    finished' , time = True , end = ' ' if settings . verbosity > 2 else '\n' ) logg . hint ( 'added \n' '    \'' + vkey + '_graph\', sparse matrix with cosine correlations (adata.uns)' ) return adata if copy else None
Computes velocity graph based on cosine similarities.

    The cosine similarities are computed between velocities and potential cell state transitions.

    Arguments
    ---------
    data: :class:`~anndata.AnnData`
        Annotated data matrix.
    vkey: `str` (default: `'velocity'`)
        Name of velocity estimates to be used.
    n_neighbors: `int` or `None` (default: None)
        Use fixed number of neighbors or do recursive neighbor search (if `None`).
    n_recurse_neighbors: `int` (default: 2)
        Number of recursions to be done for neighbors search.
    random_neighbors_at_max: `int` or `None` (default: `None`)
        If number of iterative neighbors for an individual cell is higher than this threshold,
        a random selection of such are chosen as reference neighbors.
    sqrt_transform: `bool` (default: `False`)
        Whether to variance-transform the cell states changes and velocities before computing cosine similarities.
    copy: `bool` (default: `False`)
        Return a copy instead of writing to adata.

    Returns
    -------
    Returns or updates `adata` with the attributes
    velocity_graph: `.uns`
        sparse matrix with transition probabilities