Spaces:
Running
Running
update
Browse files
app.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
import logging
|
|
|
|
| 2 |
import pathlib
|
|
|
|
| 3 |
from typing import List, Optional
|
| 4 |
|
| 5 |
-
from rdkit import Chem
|
| 6 |
-
from tqdm import tqdm
|
| 7 |
import gradio as gr
|
| 8 |
-
from submission import submission
|
| 9 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
| 10 |
from configuration import GENE_EXPRESSION_METADATA
|
|
|
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
logger.addHandler(logging.NullHandler())
|
|
@@ -26,13 +29,16 @@ def run_inference(
|
|
| 26 |
omic_path: Optional[str],
|
| 27 |
confidence: bool,
|
| 28 |
):
|
|
|
|
|
|
|
|
|
|
| 29 |
# Read SMILES
|
| 30 |
if not isinstance(smiles_path, (str, type(None))):
|
| 31 |
raise TypeError(
|
| 32 |
f"SMILES file pass has to be None or str, not {type(smiles_path)}"
|
| 33 |
)
|
| 34 |
if smiles is None and smiles_path is None:
|
| 35 |
-
raise TypeError(
|
| 36 |
elif smiles is not None:
|
| 37 |
smiles = [smiles]
|
| 38 |
elif smiles_path is not None:
|
|
@@ -70,13 +76,11 @@ def run_inference(
|
|
| 70 |
results[f"epistemic_confidence_{smi}"] = (
|
| 71 |
result["aleatoric_confidence"].squeeze().round(3)
|
| 72 |
)
|
| 73 |
-
print(results)
|
| 74 |
predicted_df = pd.DataFrame(results)
|
| 75 |
|
| 76 |
# Prepare DF to visualize
|
| 77 |
if omic_path is None:
|
| 78 |
-
df = GENE_EXPRESSION_METADATA
|
| 79 |
-
print(df.columns)
|
| 80 |
df.drop(
|
| 81 |
[
|
| 82 |
"histology",
|
|
@@ -96,7 +100,11 @@ def run_inference(
|
|
| 96 |
[df["cell_line"], predicted_df, df.drop(["cell_line"], axis=1)], axis=1
|
| 97 |
)
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
if __name__ == "__main__":
|
|
@@ -104,10 +112,11 @@ if __name__ == "__main__":
|
|
| 104 |
# Load metadata
|
| 105 |
metadata_root = pathlib.Path(__file__).parent.joinpath("model_cards")
|
| 106 |
|
| 107 |
-
examples =
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
| 111 |
with open(metadata_root.joinpath("article.md"), "r") as f:
|
| 112 |
article = f.read()
|
| 113 |
with open(metadata_root.joinpath("description.md"), "r") as f:
|
|
@@ -124,17 +133,20 @@ if __name__ == "__main__":
|
|
| 124 |
),
|
| 125 |
gr.File(
|
| 126 |
file_types=[".smi", ".tsv"],
|
| 127 |
-
label="
|
| 128 |
),
|
| 129 |
gr.File(
|
| 130 |
file_types=[".csv"],
|
| 131 |
-
label="Transcriptomics data
|
| 132 |
),
|
| 133 |
gr.Radio(choices=[True, False], label="Estimate confidence", value=False),
|
| 134 |
],
|
| 135 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
| 136 |
article=article,
|
| 137 |
description=description,
|
| 138 |
-
|
| 139 |
)
|
| 140 |
demo.launch(debug=True, show_error=True)
|
|
|
|
| 1 |
import logging
|
| 2 |
+
import os
|
| 3 |
import pathlib
|
| 4 |
+
import tempfile
|
| 5 |
from typing import List, Optional
|
| 6 |
|
|
|
|
|
|
|
| 7 |
import gradio as gr
|
|
|
|
| 8 |
import pandas as pd
|
| 9 |
+
from rdkit import Chem
|
| 10 |
+
from tqdm import tqdm
|
| 11 |
+
|
| 12 |
from configuration import GENE_EXPRESSION_METADATA
|
| 13 |
+
from submission import submission
|
| 14 |
|
| 15 |
logger = logging.getLogger(__name__)
|
| 16 |
logger.addHandler(logging.NullHandler())
|
|
|
|
| 29 |
omic_path: Optional[str],
|
| 30 |
confidence: bool,
|
| 31 |
):
|
| 32 |
+
|
| 33 |
+
print(smiles)
|
| 34 |
+
print(smiles_path)
|
| 35 |
# Read SMILES
|
| 36 |
if not isinstance(smiles_path, (str, type(None))):
|
| 37 |
raise TypeError(
|
| 38 |
f"SMILES file pass has to be None or str, not {type(smiles_path)}"
|
| 39 |
)
|
| 40 |
if smiles is None and smiles_path is None:
|
| 41 |
+
raise TypeError("Pass either single SMILES or a file")
|
| 42 |
elif smiles is not None:
|
| 43 |
smiles = [smiles]
|
| 44 |
elif smiles_path is not None:
|
|
|
|
| 76 |
results[f"epistemic_confidence_{smi}"] = (
|
| 77 |
result["aleatoric_confidence"].squeeze().round(3)
|
| 78 |
)
|
|
|
|
| 79 |
predicted_df = pd.DataFrame(results)
|
| 80 |
|
| 81 |
# Prepare DF to visualize
|
| 82 |
if omic_path is None:
|
| 83 |
+
df = GENE_EXPRESSION_METADATA.copy()
|
|
|
|
| 84 |
df.drop(
|
| 85 |
[
|
| 86 |
"histology",
|
|
|
|
| 100 |
[df["cell_line"], predicted_df, df.drop(["cell_line"], axis=1)], axis=1
|
| 101 |
)
|
| 102 |
|
| 103 |
+
# Save to temporary dir
|
| 104 |
+
temp_path = os.path.join(tempfile.gettempdir(), "paccmann_result.csv")
|
| 105 |
+
result_df.to_csv(temp_path)
|
| 106 |
+
|
| 107 |
+
return temp_path, result_df.head(25)
|
| 108 |
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
|
|
|
| 112 |
# Load metadata
|
| 113 |
metadata_root = pathlib.Path(__file__).parent.joinpath("model_cards")
|
| 114 |
|
| 115 |
+
examples = [
|
| 116 |
+
["COc1cc(O)c2c(c1)C=CCC(O)C(O)C(=O)C=CCC(C)OC2=O", "", "", False],
|
| 117 |
+
["COC1=C(C=C2C(=C1)N=CN=C2NC3=CC(=C(C=C3)F)Cl)OCCCN4CCOCC4", "", "", True],
|
| 118 |
+
["", metadata_root.joinpath("molecules.smi"), "", False],
|
| 119 |
+
]
|
| 120 |
with open(metadata_root.joinpath("article.md"), "r") as f:
|
| 121 |
article = f.read()
|
| 122 |
with open(metadata_root.joinpath("description.md"), "r") as f:
|
|
|
|
| 133 |
),
|
| 134 |
gr.File(
|
| 135 |
file_types=[".smi", ".tsv"],
|
| 136 |
+
label="Tab-separated file with SMILES in 1st column)",
|
| 137 |
),
|
| 138 |
gr.File(
|
| 139 |
file_types=[".csv"],
|
| 140 |
+
label="Transcriptomics data file",
|
| 141 |
),
|
| 142 |
gr.Radio(choices=[True, False], label="Estimate confidence", value=False),
|
| 143 |
],
|
| 144 |
+
outputs=[
|
| 145 |
+
gr.File(label="Download full results"),
|
| 146 |
+
gr.DataFrame(label="Preview of results for 25 cell lines"),
|
| 147 |
+
],
|
| 148 |
article=article,
|
| 149 |
description=description,
|
| 150 |
+
examples=examples,
|
| 151 |
)
|
| 152 |
demo.launch(debug=True, show_error=True)
|