Skip to content

Commit 1b82b36

Browse files
Backport PR #3418 on branch 1.3.x (Fix: DE) (#3438)
Backport PR #3418: Fix: DE Co-authored-by: Ori Kronfeld <[email protected]>
1 parent a31dc92 commit 1b82b36

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ to [Semantic Versioning]. Full commit history is available in the
2525

2626
#### Fixed
2727

28+
- Add a fix to {func}`~scvi.model.SCVI.differential_expression`, {pr}`3418`.
2829
- Add SupervisedModuleClass to the classifier, {pr}`3430`.
2930

3031
#### Changed

src/scvi/model/base/_differential.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,8 @@ def m1_domain_fn(samples):
361361
proba_m2 = np.mean(is_de_minus, 0)
362362
if test_mode == "two":
363363
proba_de = proba_m1 + proba_m2
364-
sign = 1.0
365364
else:
366365
proba_de = np.maximum(proba_m1, proba_m2)
367-
sign = np.sign(proba_m1 - proba_m2)
368366
change_distribution_props = describe_continuous_distrib(
369367
samples=change_fn(scales_1, scales_2, 1e-3 * pseudocounts),
370368
credible_intervals_levels=cred_interval_lvls,
@@ -376,7 +374,7 @@ def m1_domain_fn(samples):
376374
res = dict(
377375
proba_de=proba_de,
378376
proba_not_de=1.0 - proba_de,
379-
bayes_factor=sign * (np.log(proba_de + eps) - np.log(1.0 - proba_de + eps)),
377+
bayes_factor=np.log(proba_de + eps) - np.log(1.0 - proba_de + eps),
380378
scale1=px_scale_mean1,
381379
scale2=px_scale_mean2,
382380
pseudocounts=pseudocounts,
@@ -560,15 +558,15 @@ def estimate_pseudocounts_offset(
560558
artefact_scales_a = max_scales_a[where_zero_a]
561559
eps_a = np.quantile(artefact_scales_a, q=quantile)
562560
else:
563-
eps_a = 1e-5
561+
eps_a = 1e-10
564562

565563
if where_zero_b.sum() >= 1:
566564
artefact_scales_b = max_scales_b[where_zero_b]
567565
eps_b = np.quantile(artefact_scales_b, q=quantile)
568566
else:
569-
eps_b = 1e-5
567+
eps_b = 1e-10
570568
res = np.maximum(eps_a, eps_b)
571-
return np.maximum(1e-5, res)
569+
return np.maximum(1e-10, res / len(max_scales_a))
572570

573571

574572
def pairs_sampler(
@@ -597,7 +595,7 @@ def pairs_sampler(
597595
param sanity_check_perm: If True, resulting mixed arrays arr1 and arr2 are mixed together
598596
In most cases, this parameter should remain False
599597
sanity_check_perm
600-
TODO
598+
do permutation
601599
weights1
602600
probabilities associated to array 1 for random sampling
603601
weights2

tests/external/poissonvi/test_poissonvi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_poissonvi():
1616
model.get_normalized_expression()
1717
model.get_normalized_expression(transform_batch="batch_1")
1818
model.get_normalized_expression(n_samples=2)
19+
model.differential_accessibility(groupby="labels", group1="label_1", mode="vanilla")
1920

2021

2122
def test_poissonvi_default_params():

0 commit comments

Comments
 (0)