Skip to content

Commit

Permalink
Make progress bar optional (#1234)
Browse files Browse the repository at this point in the history
* Update `recover_dynamics`

Add option to show progressbar or not.

* Update `velocity_graph.py`

Add argument `show_progress_bar` to `VelocityGraph::compute_cosines` and
`velocity_graph`.
  • Loading branch information
WeilerP authored Apr 12, 2024
1 parent 6a0b63d commit 31226cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion scvelo/tools/_em_model_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def recover_dynamics(
copy=False,
n_jobs=None,
backend="loky",
show_progress_bar: bool = True,
**kwargs,
):
"""Recovers the full splicing kinetics of specified genes.
Expand Down Expand Up @@ -476,6 +477,8 @@ def recover_dynamics(
backend: `str` (default: "loky")
Backend used for multiprocessing. See :class:`joblib.Parallel` for valid
options.
show_progress_bar
Whether to show a progress bar.
Returns
-------
Expand Down Expand Up @@ -557,7 +560,7 @@ def recover_dynamics(
unit="gene",
as_array=False,
backend=backend,
show_progress_bar=len(var_names) > 9,
show_progress_bar=show_progress_bar,
)(
adata=adata,
use_raw=use_raw,
Expand Down
12 changes: 10 additions & 2 deletions scvelo/tools/velocity_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def __init__(
self.adata = adata

# TODO: Add docstrings
def compute_cosines(self, n_jobs=None, backend="loky"):
def compute_cosines(
self, n_jobs=None, backend="loky", show_progress_bar: bool = True
):
"""TODO."""
n_jobs = get_n_jobs(n_jobs=n_jobs)

Expand All @@ -189,6 +191,7 @@ def compute_cosines(self, n_jobs=None, backend="loky"):
unit="cells",
backend=backend,
as_array=False,
show_progress_bar=show_progress_bar,
)()
uncertainties, vals, rows, cols = map(_flatten, zip(*res))

Expand Down Expand Up @@ -277,6 +280,7 @@ def velocity_graph(
copy=False,
n_jobs=None,
backend="loky",
show_progress_bar: bool = True,
):
r"""Computes velocity graph based on cosine similarities.
Expand Down Expand Up @@ -329,6 +333,8 @@ def velocity_graph(
backend: `str` (default: "loky")
Backend used for multiprocessing. See :class:`joblib.Parallel` for valid
options.
show_progress_bar
Whether to show a progress bar.
Returns
-------
Expand Down Expand Up @@ -370,7 +376,9 @@ def velocity_graph(
logg.info(
f"computing velocity graph (using {n_jobs}/{os.cpu_count()} cores)", r=True
)
vgraph.compute_cosines(n_jobs=n_jobs, backend=backend)
vgraph.compute_cosines(
n_jobs=n_jobs, backend=backend, show_progress_bar=show_progress_bar
)

adata.uns[f"{vkey}_graph"] = vgraph.graph
adata.uns[f"{vkey}_graph_neg"] = vgraph.graph_neg
Expand Down

0 comments on commit 31226cd

Please sign in to comment.