forked from openproblems-bio/task_perturbation_prediction
-
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.
Multiple fixes (openproblems-bio#47)
* increase lstm memory * clean up descriptions * add mean pearson / spearman component * fix metric * add to wf
- Loading branch information
Showing
7 changed files
with
119 additions
and
61 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
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,44 @@ | ||
__merge__: ../../api/comp_metric.yaml | ||
functionality: | ||
name: mean_correlation | ||
info: | ||
metrics: | ||
- name: mean_pearson | ||
label: Mean Pearson | ||
summary: The mean of Pearson correlations per row (perturbation). | ||
description: | | ||
We use the **Mean Pearson Correlation** to score submissions, computed as follows: | ||
$$ | ||
\textrm{Mean-Pearson} = \frac{1}{R} \sum_{i=1}^R \frac{\sum_{j=1}^n (y_{ij} - \bar{y}_i)(\hat{y}_{ij} - \bar{\hat{y}}_i)}{\sqrt{\sum_{j=1}^n (y_{ij} - \bar{y}_i)^2 \sum_{j=1}^n (\hat{y}_{ij} - \bar{\hat{y}}_i)^2}} | ||
$$ | ||
where $(R)$ is the number of scored rows, and $(y_{ij})$ and $(\hat{y}_{ij})$ are the actual and predicted values, respectively, for row $(i)$ and column $(j)$. | ||
repository_url: null | ||
documentation_url: null | ||
min: -1 | ||
max: 1 | ||
maximize: true | ||
- name: mean_spearman | ||
label: Mean Spearman | ||
summary: The mean of Spearman correlations per row (perturbation). | ||
description: | | ||
We use the **Mean Spearman Correlation** to score submissions, computed as follows: | ||
$$ | ||
\textrm{Mean-Spearman} = \frac{1}{R} \sum_{i=1}^R \frac{\sum_{j=1}^n (\text{rank}(y_{ij}) - \bar{\text{rank}}_i)(\text{rank}(\hat{y}_{ij}) - \bar{\text{rank}}_i)}{\sqrt{\sum_{j=1}^n (\text{rank}(y_{ij}) - \bar{\text{rank}}_i)^2 \sum_{j=1}^n (\text{rank}(\hat{y}_{ij}) - \bar{\text{rank}}_i)^2}} | ||
$$ | ||
where $(R)$ is the number of scored rows, and $(y_{ij})$ and $(\hat{y}_{ij})$ are the actual and predicted values, respectively, for row $(i)$ and column $(j)$. | ||
resources: | ||
- type: python_script | ||
path: script.py | ||
platforms: | ||
- type: docker | ||
image: ghcr.io/openproblems-bio/base_python:1.0.4 | ||
setup: | ||
- type: python | ||
packages: [ fastparquet ] | ||
- type: nextflow | ||
directives: | ||
label: [ midtime, highmem, highcpu ] |
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,54 @@ | ||
import pandas as pd | ||
import anndata as ad | ||
import numpy as np | ||
|
||
## VIASH START | ||
par = { | ||
"de_test_h5ad": "resources/neurips-2023-kaggle/de_test.h5ad", | ||
"prediction": "resources/neurips-2023-kaggle/prediction.parquet", | ||
"method_id": "foo", | ||
"output": "resources/neurips-2023-data/score.h5ad", | ||
} | ||
## VIASH END | ||
|
||
print("Load data", flush=True) | ||
de_test = ad.read_h5ad(par["de_test_h5ad"]) | ||
prediction = pd.read_parquet(par["prediction"]).set_index('id') | ||
|
||
print("Select genes", flush=True) | ||
genes = list(de_test.var_names) | ||
de_test_X = de_test.layers["sign_log10_pval"] | ||
prediction = prediction[genes] | ||
|
||
print("Calculate mean pearson", flush=True) | ||
mean_pearson = 0 | ||
mean_spearman = 0 | ||
for i in range(de_test_X.shape[0]): | ||
y_i = de_test_X[i,] | ||
y_hat_i = prediction.iloc[i] | ||
|
||
# compute ranks | ||
r_i = y_i.argsort().argsort() | ||
r_hat_i = y_hat_i.argsort().argsort() | ||
|
||
pearson = np.corrcoef(y_i, y_hat_i)[0, 1] | ||
spearman = np.corrcoef(r_i, r_hat_i)[0, 1] | ||
|
||
mean_pearson += pearson | ||
mean_spearman += spearman | ||
|
||
mean_pearson /= de_test_X.shape[0] | ||
mean_spearman /= de_test_X.shape[0] | ||
|
||
print("Create output", flush=True) | ||
output = ad.AnnData( | ||
uns={ | ||
"dataset_id": de_test.uns["dataset_id"], | ||
"method_id": par["method_id"], | ||
"metric_ids": ["mean_pearson", "mean_spearman"], | ||
"metric_values": [mean_pearson, mean_spearman] | ||
} | ||
) | ||
|
||
print("Write output", flush=True) | ||
output.write_h5ad(par["output"], compression="gzip") |
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
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
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
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