Skip to content

Commit d6e678a

Browse files
ENH DeseqStats n_cpus (#379)
* n_cpu argument for DeseqStats * Match n_cpus logic in DeseqStats to the logic in DeseqDataSet * Add n_cpus to test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e586f10 commit d6e678a

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Diff for: pydeseq2/dds.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,17 @@ def __init__(
321321
self.filtered_genes = None
322322

323323
if inference:
324-
if hasattr(inference, "n_cpus"):
325-
if n_cpus:
324+
if n_cpus:
325+
if hasattr(inference, "n_cpus"):
326326
inference.n_cpus = n_cpus
327-
else:
328-
warnings.warn(
329-
"The provided inference object does not have an n_cpus "
330-
"attribute, cannot override `n_cpus`.",
331-
UserWarning,
332-
stacklevel=2,
333-
)
327+
else:
328+
warnings.warn(
329+
"The provided inference object does not have an n_cpus "
330+
"attribute, cannot override `n_cpus`.",
331+
UserWarning,
332+
stacklevel=2,
333+
)
334+
334335
# Initialize the inference object.
335336
self.inference = inference or DefaultInference(n_cpus=n_cpus)
336337

Diff for: pydeseq2/ds.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import time
3+
import warnings
34
from typing import Literal
45

56
# import anndata as ad
@@ -141,6 +142,7 @@ def __init__(
141142
) = None,
142143
inference: Inference | None = None,
143144
quiet: bool = False,
145+
n_cpus: int | None = None,
144146
) -> None:
145147
assert (
146148
"LFC" in dds.varm
@@ -188,8 +190,20 @@ def __init__(
188190
self.shrunk_LFCs = False
189191
self.quiet = quiet
190192

193+
if inference:
194+
if n_cpus:
195+
if hasattr(inference, "n_cpus"):
196+
inference.n_cpus = n_cpus
197+
else:
198+
warnings.warn(
199+
"The provided inference object does not have an n_cpus "
200+
"attribute, cannot override `n_cpus`.",
201+
UserWarning,
202+
stacklevel=2,
203+
)
204+
191205
# Initialize the inference object.
192-
self.inference = inference or DefaultInference()
206+
self.inference = inference or DefaultInference(n_cpus=n_cpus)
193207

194208
# If the `refit_cooks` attribute of the dds object is True, check that outliers
195209
# were actually refitted.

Diff for: tests/test_pydeseq2.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ def test_alt_hypothesis(alt_hypothesis, counts_df, metadata, tol=0.02):
194194
)
195195

196196
dds = DeseqDataSet(
197-
counts=counts_df,
198-
metadata=metadata,
199-
design="~condition",
197+
counts=counts_df, metadata=metadata, design="~condition", n_cpus=2
200198
)
201199
dds.deseq2()
202200

@@ -205,6 +203,7 @@ def test_alt_hypothesis(alt_hypothesis, counts_df, metadata, tol=0.02):
205203
contrast=["condition", "B", "A"],
206204
lfc_null=-0.5 if alt_hypothesis == "less" else 0.5,
207205
alt_hypothesis=alt_hypothesis,
206+
n_cpus=2,
208207
)
209208
ds.summary()
210209

0 commit comments

Comments
 (0)