-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from openproblems-bio/add_jsd
Add JSD metric
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
__merge__: ../../api/comp_metric.yaml | ||
|
||
name: jsd | ||
info: | ||
metrics: | ||
- name: jensen_shannon_distance | ||
label: Jensen-Shannon Distance | ||
summary: "Jensen-Shannon Distance measure the similarity between to probability distributions." | ||
description: | | ||
The Jensen-Shannon Distance, which is the square root of Jensen-Shannon Divergence is a symmetric method for measuring the similarity between two probability distributions. The similarity between the distributions is greater when the Jensen-Shannon distance is closer to zero. | ||
reference: 10.1109/18.61115 | ||
documentation_url: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.jensenshannon.html | ||
repository_url: https://github.com/scipy/scipy/ | ||
min: 0 | ||
max: 1 | ||
maximize: false | ||
|
||
resources: | ||
- type: python_script | ||
path: script.py | ||
|
||
engines: | ||
- type: docker | ||
image: ghcr.io/openproblems-bio/base_images/python:1.1.0 | ||
setup: | ||
- type: python | ||
packages: [numpy, scipy] | ||
|
||
runners: | ||
- type: executable | ||
- type: nextflow | ||
directives: | ||
label: [midtime, midmem, midcpu] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import anndata as ad | ||
import numpy as np | ||
from scipy.spatial.distance import jensenshannon | ||
|
||
## VIASH START | ||
par = { | ||
'input_method': 'resources_test/spatial_decomposition/cxg_mouse_pancreas_atlas/output.h5ad', | ||
'input_solution': 'resources_test/spatial_decomposition/cxg_mouse_pancreas_atlas/solution.h5ad', | ||
'output': 'score.h5ad' | ||
} | ||
meta = { | ||
'name': 'r2' | ||
} | ||
## VIASH END | ||
|
||
print('Reading input files', flush=True) | ||
input_method = ad.read_h5ad(par['input_method']) | ||
input_solution = ad.read_h5ad(par['input_solution']) | ||
|
||
print('Compute metrics', flush=True) | ||
jsd = jensenshannon(input_solution.obsm['proportions_true'], input_method.obsm['proportions_pred'], axis=0) | ||
uns_metric_ids = [ 'jsd' ] | ||
uns_metric_values = [ np.mean(jsd) ] | ||
|
||
print("Write output AnnData to file", flush=True) | ||
output = ad.AnnData( | ||
uns={ | ||
'dataset_id': input_method.uns['dataset_id'], | ||
'method_id': input_method.uns['method_id'], | ||
'metric_ids': uns_metric_ids, | ||
'metric_values': uns_metric_values | ||
} | ||
) | ||
output.write_h5ad(par['output'], compression='gzip') |