Skip to content

Commit f6436d5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b392e1b commit f6436d5

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

benchmarks/benchmarks/tools.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def peakmem_rank_genes_groups(self) -> None:
4646
sc.tl.rank_genes_groups(self.adata, "bulk_labels", method="wilcoxon")
4747

4848

49-
class CombatSuite: # noqa: D101
49+
class CombatSuite:
5050
"""Benchmark combat batch correction."""
5151

5252
def setup_cache(self) -> None:
@@ -58,9 +58,7 @@ def setup_cache(self) -> None:
5858
sc.pp.scale(adata, max_value=10)
5959
# assign cells to 3 batches deterministically
6060
np.random.seed(0)
61-
adata.obs["batch"] = np.random.choice(
62-
["A", "B", "C"], size=adata.n_obs
63-
)
61+
adata.obs["batch"] = np.random.choice(["A", "B", "C"], size=adata.n_obs)
6462
adata.write_h5ad("adata_combat.h5ad")
6563

6664
def setup(self) -> None:

src/scanpy/preprocessing/_combat.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def _standardize_data(
108108
# use numpty .values extration only once to avoid pandas overhead
109109
design_arr = design.values
110110
# compute pooled variance estimator
111-
b_hat = np.dot(np.dot(la.inv(np.dot(design_arr.T, design_arr)), design_arr.T), data.values.T)
111+
b_hat = np.dot(
112+
np.dot(la.inv(np.dot(design_arr.T, design_arr)), design_arr.T), data.values.T
113+
)
112114
grand_mean = np.dot((n_batches / n_array).T, b_hat[:n_batch, :])
113115
var_pooled = (data.values - np.dot(design_arr, b_hat).T) ** 2
114116
var_pooled = np.mean(var_pooled, axis=1, keepdims=True)
@@ -278,7 +280,10 @@ def combat( # noqa: PLR0915
278280
# of multiplicative batch effect to pooled variance and add the overall gene
279281
# wise mean
280282
dsq = np.sqrt(delta_star[j, :])
281-
numer = bayesdata_arr[:, batch_idxs] - np.dot(batch_design_arr[batch_idxs], gamma_star).T
283+
numer = (
284+
bayesdata_arr[:, batch_idxs]
285+
- np.dot(batch_design_arr[batch_idxs], gamma_star).T
286+
)
282287
bayesdata_arr[:, batch_idxs] = numer / dsq[:, np.newaxis]
283288

284289
bayesdata_arr = bayesdata_arr * np.sqrt(var_pooled) + stand_mean

0 commit comments

Comments
 (0)