Skip to content

Commit a3c94c9

Browse files
committed
update spatial metric
1 parent a58b18c commit a3c94c9

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

src/metrics/ks_statistic_spatial/config.vsh.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ info:
3838
min: -Inf
3939
max: +Inf
4040
maximize: false
41+
- name: ks_statistic_transition_scalef
42+
label: Frobenius norm of transition matrix
43+
summary: Frobenius norm of the transition matrix.
44+
description: |
45+
The Frobenius norm of the difference between two matrices is calculated to assess the closeness of the spatial pattern of cell types between the simulated and real data.
46+
references:
47+
doi: 10.1201/9780429485572
48+
min: -Inf
49+
max: +Inf
50+
maximize: false
51+
- name: ks_statistic_central_score_scalef
52+
label: Frobenius norm of centralized score
53+
summary: Frobenius norm of the centralized score matrix.
54+
description: |
55+
The Frobenius norm of the difference between two matrices is calculated to assess the closeness of the spatial pattern of cell types between the simulated and real data.
56+
references:
57+
doi: 10.1201/9780429485572
58+
min: -Inf
59+
max: +Inf
60+
maximize: false
61+
- name: ks_statistic_enrichment_scalef
62+
label: Frobenius norm of neighborhood enrichment
63+
summary: Frobenius norm of the neighborhood enrichment.
64+
description: |
65+
The Frobenius norm of the difference between two matrices is calculated to assess the closeness of the spatial pattern of cell types between the simulated and real data.
66+
references:
67+
doi: 10.1201/9780429485572
68+
min: -Inf
69+
max: +Inf
70+
maximize: false
4171

4272
resources:
4373
- type: python_script

src/metrics/ks_statistic_spatial/script.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
## VIASH START
99
par = {
10-
"input_spatial_dataset": "resources_test/spatialsimbench_mobnew/dataset_sp.h5ad",
11-
"input_simulated_dataset": "resources_test/spatialsimbench_mobnew/simulated_dataset.h5ad",
10+
"input_spatial_dataset": "temp_brain.zinbwave.ks_statistic_sc_features/_viash_par/input_spatial_dataset_1/output_sp.h5ad",
11+
"input_simulated_dataset": "temp_brain.zinbwave.ks_statistic_sc_features/_viash_par/input_simulated_dataset_1/brain.zinbwave.generate_sim_spatialcluster.output_sp.h5ad",
1212
"output": "output.h5ad"
1313
}
1414
meta = {
@@ -86,8 +86,8 @@ def get_trans(adata=None, ct=None):
8686
target_enrich_sim = input_simulated_dataset.uns["celltype_nhood_enrichment"]["zscore"]
8787
target_enrich_scale_sim = target_enrich_sim/np.max(target_enrich_sim)
8888

89-
#error_enrich = np.linalg.norm(target_enrich_sim - target_enrich_real)
90-
#error_enrich_scale = np.linalg.norm(target_enrich_scale_sim - target_enrich_scale_real)
89+
error_enrich = np.linalg.norm(target_enrich_sim - target_enrich_real)
90+
# error_enrich_scale = np.linalg.norm(target_enrich_scale_sim - target_enrich_scale_real)
9191

9292
target_enrich_real_ds = target_enrich_real.flatten()
9393
target_enrich_sim_ds = target_enrich_sim.flatten()
@@ -97,7 +97,8 @@ def get_trans(adata=None, ct=None):
9797

9898
real_central_real = np.array(input_spatial_dataset.uns["celltype_centrality_scores"])
9999
real_central_sim = np.array(input_simulated_dataset.uns["celltype_centrality_scores"])
100-
100+
101+
error_central = np.linalg.norm(real_central_sim - real_central_real)
101102
real_central_real_ds = real_central_real.flatten()
102103
real_central_sim_ds = real_central_sim.flatten()
103104
ks_central, p_value = ks_2samp(real_central_real_ds, real_central_sim_ds)
@@ -110,7 +111,7 @@ def get_trans(adata=None, ct=None):
110111
transition_matrix_real = get_trans(adata=input_spatial_dataset, ct=real)
111112
transition_matrix_sim = get_trans(adata=input_simulated_dataset, ct=sim)
112113

113-
# error = np.linalg.norm(transition_matrix_sim - transition_matrix_real)
114+
error_tran = np.linalg.norm(transition_matrix_sim - transition_matrix_real)
114115
transition_matrix_real_ds = transition_matrix_real.flatten()
115116
transition_matrix_sim_ds = transition_matrix_sim.flatten()
116117
ks_stat_error, p_value = ks_2samp(transition_matrix_real_ds, transition_matrix_sim_ds)
@@ -119,13 +120,21 @@ def get_trans(adata=None, ct=None):
119120
uns_metric_ids = [
120121
"ks_statistic_transition_matrix",
121122
"ks_statistic_central_score",
122-
"ks_statistic_enrichment"
123+
"ks_statistic_enrichment",
124+
125+
"ks_statistic_enrichment_scalef",
126+
"ks_statistic_central_score_scalef",
127+
"ks_statistic_transition_scalef"
123128
]
124129

125130
uns_metric_values = [
126131
ks_stat_error,
127132
ks_central,
128-
ks_enrich
133+
ks_enrich,
134+
135+
error_enrich,
136+
error_central,
137+
error_tran
129138
]
130139

131140
print("Write output AnnData to file", flush=True)

0 commit comments

Comments
 (0)