How to use the scvelo.settings function in scvelo

To help you get started, we’ve selected a few scvelo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theislab / scvelo / scvelo / plotting / utils.py View on Github external
def get_figure_params(figsize, dpi=None, ncols=1):
    figsize = rcParams["figure.figsize"] if figsize is None else figsize
    dpi = rcParams["figure.dpi"] if dpi is None else dpi
    if settings.presenter_view and figsize[0] * ncols * (dpi / 80) > 12:
        figscale = 12 / (figsize[0] * ncols)
        figsize = (figsize[0] * figscale, figsize[1] * figscale)
        dpi = min(80, dpi)
    return figsize, dpi
github theislab / scvelo / scvelo / plotting / velocity_graph.py View on Github external
with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        X_emb = adata.obsm[f"X_{basis}"][:, get_components(components, basis)]
        node_size = (kwargs["size"] if "size" in kwargs else default_size(adata)) / 4
        edges = draw_networkx_edges(
            DiGraph(T) if arrows else Graph(T),
            X_emb,
            node_size=node_size,
            width=edge_width,
            edge_color=edge_color,
            arrowsize=arrowsize,
            ax=ax,
        )
        if not arrows and not edges_on_top:
            edges.set_zorder(-2)
            edges.set_rasterized(settings._vector_friendly)

    savefig_or_show(dpi=dpi, save=save, show=show)
    if show is False:
        return ax
github theislab / scvelo / scvelo / logging.py View on Github external
def update(self):
        self.count += 1
        if settings.verbosity > 1 and (
            get_time() - self.timestamp > self.interval or self.count == self.total
        ):
            self.timestamp = get_time()
            percent = int(self.count * 100 / self.total)
            stdout.write(f"\r... {percent}%")
            stdout.flush()
github theislab / scvelo / scvelo / plotting / utils.py View on Github external
def savefig_or_show(writekey=None, show=None, dpi=None, ext=None, save=None):
    if isinstance(save, str):
        # check whether `save` contains a figure extension
        if ext is None:
            for try_ext in [".svg", ".pdf", ".png"]:
                if save.endswith(try_ext):
                    ext = try_ext[1:]
                    save = save.replace(try_ext, "")
                    break
        # append it
        writekey = (
            f"{writekey}_{save}" if writekey is not None and len(writekey) > 0 else save
        )
        save = True
    save = settings.autosave if save is None else save
    show = settings.autoshow if show is None else show

    if save:
        if dpi is None:
            # needed in nb b/c internal figures are also influenced by 'savefig.dpi'.
            if (
                not isinstance(rcParams["savefig.dpi"], str)
                and rcParams["savefig.dpi"] < 150
            ):
                if settings._low_resolution_warning:
                    logg.warn(
                        "You are using a low resolution (dpi<150) for saving figures.\n"
                        "Consider running `set_figure_params(dpi_save=...)`, which "
                        "will adjust `matplotlib.rcParams['savefig.dpi']`"
                    )
                    settings._low_resolution_warning = False
            else:
github theislab / scvelo / scvelo / tools / dynamical_model.py View on Github external
key = "rank_dynamical_genes"
    if key not in adata.uns.keys():
        adata.uns[key] = {}

    adata.uns[key] = {
        "names": np.rec.fromarrays(
            [n for n in rankings_gene_names], dtype=[(f"{rn}", "U50") for rn in groups],
        ),
        "scores": np.rec.fromarrays(
            [n.round(2) for n in rankings_gene_scores],
            dtype=[(f"{rn}", "float32") for rn in groups],
        ),
    }

    logg.info("    finished", time=True, end=" " if settings.verbosity > 2 else "\n")
    logg.hint("added \n" f"    '{key}', sorted scores by group ids (adata.uns)")

    return adata if copy else None
github theislab / scvelo / scvelo / tools / terminal_states.py View on Github external
eigvecs_ends = eigs(T, eps=eps, perc=[2, 98], random_state=random_state)[1]
        ends = csr_matrix.dot(connectivities, eigvecs_ends).sum(1)
        ends = scale(np.clip(ends, 0, np.percentile(ends, 98)))
        write_to_obs(adata, "end_points", ends, cell_subset)

        n_roots, n_ends = eigvecs_roots.shape[1], eigvecs_ends.shape[1]
        groups_str = f" ({groups})" if isinstance(groups, str) else ""
        roots_str = f"{n_roots} {'regions' if n_roots > 1 else 'region'}"
        ends_str = f"{n_ends} {'regions' if n_ends > 1 else 'region'}"

        logg.info(
            f"    identified {roots_str} of root cells "
            f"and {ends_str} of end points {groups_str}."
        )

    logg.info("    finished", time=True, end=" " if settings.verbosity > 2 else "\n")
    logg.hint(
        "added\n"
        "    'root_cells', root cells of Markov diffusion process (adata.obs)\n"
        "    'end_points', end points of Markov diffusion process (adata.obs)"
    )
    return adata if copy else None
github theislab / scvelo / scvelo / tools / rank_velocity_genes.py View on Github external
all_names = rankings_gene_names.T.flatten()
    all_scores = rankings_gene_scores.T.flatten()
    vscore = np.zeros(adata.n_vars, dtype=np.int)
    for i, name in enumerate(adata.var_names):
        if name in all_names: vscore[i] = all_scores[np.where(name == all_names)[0][0]]
    adata.var['velocity_score'] = vscore

    key = 'rank_velocity_genes'
    if key not in adata.uns.keys(): adata.uns[key] = {}

    adata.uns[key] = \
        {'names': np.rec.fromarrays([n for n in rankings_gene_names], dtype=[(f"{rn}", 'U50') for rn in groups]),
         'scores': np.rec.fromarrays([n.round(2) for n in rankings_gene_scores], dtype=[(f"{rn}", 'float32') for rn in groups]),
         'params': {'groupby': groupby, 'reference': 'rest', 'method': 't-test_overestim_var', 'use_raw': True}}

    logg.info('    finished', time=True, end=' ' if settings.verbosity > 2 else '\n')
    logg.hint(
        'added \n'
        f'    \'{key}\', sorted scores by group ids (adata.uns) \n'
        '    \'spearmans_score\', spearmans correlation scores (adata.var)')

    return adata if copy else None