Skip to content

Commit 3074bec

Browse files
committed
Added z-score scaling before peak calling to reduce the number of false positives. Updated description in config file. metric re-enabled (commented statusfield in config file).
1 parent 4d29a78 commit 3074bec

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/metrics/n_inconsistent_peaks/config.vsh.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__merge__: ../../api/comp_metric.yaml
33

44
name: n_inconsistent_peaks
5-
status: disabled
5+
# status: disabled
66

77
info:
88
metrics:
@@ -14,12 +14,11 @@ info:
1414
# A multi-line description of how this component works (required). Used
1515
# when rendering reference documentation.
1616
description: |
17-
The metric compares the number of marker expression peaks between the validation and batch-normalized data.
18-
The number of peaks is calculated using the `scipy.signal.find_peaks` function.
19-
The metric is calculated as the absolute difference between the number of peaks in the validation and batch-normalized data.
20-
The marker expression profiles are first smoothed using kernel density estimation (KDE) (`scipy.stats.gaussian_kde`),
21-
and then peaks are then identified using the `scipy.signal.find_peaks` function.
22-
For peak calling, the `prominence` parameter is set to 0.1 and the `height` parameter is set to 0.05*max_density.
17+
The metric compares the number of marker expression peaks between batch integrated technical replicates (split 1 and split 2).
18+
The metric is calculated as the absolute difference between the number of peaks in the technical replicates.
19+
The marker expression profiles are first z-score scaled (with common mu and sigma) and then smoothed using kernel density estimation (KDE) (`scipy.stats.gaussian_kde`).
20+
Finally, peaks are identified using the `scipy.signal.find_peaks` function.
21+
For peak calling, the `prominence` parameter is set to 0.01 and the `height` parameter is set to 0.1.
2322
references:
2423
doi:
2524
- 10.1038/s41592-019-0686-2

src/metrics/n_inconsistent_peaks/script.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@
5656
s2_view = integrated_s2[integrated_s2.obs['donor'] == donor]
5757

5858
for marker in s1_view.var.index:
59-
mexp_s1 = np.array(s1_view[:,marker].layers["integrated"])
60-
mexp_s2 = np.array(s2_view[:,marker].layers["integrated"])
61-
density_s1 = get_kde_density(mexp_s1)
59+
marker_expression_s1_unscaled = np.array(s1_view[:,marker].layers["integrated"])
60+
marker_expression_s2_unscaled = np.array(s2_view[:,marker].layers["integrated"])
61+
62+
pooled = np.concatenate([marker_expression_s1_unscaled, marker_expression_s2_unscaled])
63+
mu, sd = pooled.mean(), pooled.std()
64+
marker_expression_s1 = (marker_expression_s1_unscaled - mu) / (sd)
65+
marker_expression_s2 = (marker_expression_s2_unscaled - mu) / (sd)
66+
67+
density_s1 = get_kde_density(marker_expression_s1)
6268
peaks_s1 = call_peaks(density_s1)
63-
density_s2 = get_kde_density(mexp_s2)
69+
density_s2 = get_kde_density(marker_expression_s2)
6470
peaks_s2 = call_peaks(density_s2)
6571

6672
if peaks_s1 != peaks_s2:
@@ -83,11 +89,17 @@
8389
continue
8490

8591
for marker in s1_view_ct.var.index:
86-
mexp_s1 = np.array(s1_view_ct[:, marker].layers["integrated"])
87-
mexp_s2 = np.array(s2_view_ct[:, marker].layers["integrated"])
88-
density_s1 = get_kde_density(mexp_s1)
92+
marker_expression_s1_unscaled = np.array(s1_view_ct[:, marker].layers["integrated"])
93+
marker_expression_s2_unscaled = np.array(s2_view_ct[:, marker].layers["integrated"])
94+
95+
pooled = np.concatenate([marker_expression_s1_unscaled, marker_expression_s2_unscaled])
96+
mu, sd = pooled.mean(), pooled.std()
97+
marker_expression_s1 = (marker_expression_s1_unscaled - mu) / (sd)
98+
marker_expression_s2 = (marker_expression_s2_unscaled - mu) / (sd)
99+
100+
density_s1 = get_kde_density(marker_expression_s1)
89101
peaks_s1 = call_peaks(density_s1)
90-
density_s2 = get_kde_density(mexp_s2)
102+
density_s2 = get_kde_density(marker_expression_s2)
91103
peaks_s2 = call_peaks(density_s2)
92104

93105
if peaks_s1 != peaks_s2:

0 commit comments

Comments
 (0)