Download app.py from Jayet010/bioxnet: direct link, hf CLI and curl.
- Browser
- Download file 5.41 kB
-
https://huggingface.co/spaces/Jayet010/bioxnet/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jayet010/bioxnet/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jayet010/bioxnet/resolve/main/app.py
5.41 kB
| from dash import Dash, Input, Output, callback, dcc, html | |
| import copy | |
| import plotly.graph_objects as go | |
| import pandas as pd | |
| # # open a file, where you stored the pickled data | |
| file = open('./sankey_data_y145.pkl', 'rb') | |
| # # dump information to that file | |
| data = pd.read_pickle(file) | |
| df = pd.read_csv("./chatgpt_explanation.csv") | |
| external_script = ["https://tailwindcss.com/", {"src": "https://cdn.tailwindcss.com"}] | |
| app = Dash( | |
| __name__, | |
| external_scripts=external_script, | |
| ) | |
| app.scripts.config.serve_locally = True | |
| app.layout = html.Div( | |
| [ | |
| html.Div( | |
| [ | |
| html.Div( | |
| [ | |
| html.H1("BioXNet: a biologically inspired neural network for deciphering anti-cancer drug response in precision medicine", className="text-black text-4xl font-bold pb-8 pt-32"), | |
| html.H2("https://doi.org/10.1101/2024.01.29.576766", className="text-black flex text-left text-lg font-semibold pb-8"), | |
| html.H3("For an improved experience, it is recommended to use either Chrome or Edge.", className="text-black flex text-left text-lg font-semibold pb-8"), | |
| html.Hr(className="border-t-2 border-slate-500") | |
| ],className="max-w-6xl flex flex-col justify-center mx-auto px-8 mx-8 pb-4 bg" | |
| ) | |
| ],id="background-container" | |
| ), | |
| html.Div( | |
| [ | |
| html.Div( | |
| [ | |
| html.Div( | |
| [ | |
| html.H5("Drug Name", className="text-lg font-medium pb-2 text-slate-500"), | |
| dcc.Dropdown( | |
| id="drugname", | |
| options=sorted(df["drug_name"].unique()), | |
| value='bevacizumab', | |
| className="w-80" | |
| ), | |
| ], className="flex flex-col" | |
| ), | |
| html.Div( | |
| [ | |
| html.H5("Cancer type in TCGA", className="text-lg font-medium pb-2 text-slate-500"), | |
| dcc.Dropdown( | |
| id="tcga", options=sorted(df["tcga_id"].unique()), | |
| value='BRCA', | |
| className="w-80" | |
| ), | |
| ], className="flex flex-col" | |
| ), | |
| ], className="flex flex-row max-md:flex-col gap-20 items-center mx-auto" | |
| ), | |
| ],className="max-w-6xl flex flex-col justify-center mx-auto mt-8 px-8 mx-8" | |
| ), | |
| html.H3("Interpretable paths", className="px-8 mx-8 flex mx-auto max-w-6xl font-extrabold text-transparent text-4xl bg-clip-text bg-gradient-to-r from-purple-400 to-pink-600 pb-8 text-left pt-12"), | |
| html.Div( | |
| [ | |
| dcc.Graph(id="graph", style={'width': '60vw', 'height': '70vh','align':'justify-center'}), | |
| ],className="max-w-6xl flex flex-col items-center mx-auto mt-8 px-8 mx-8" | |
| ), | |
| html.Div( | |
| [ | |
| html.H3("Readable interpretations generate by ChatGPT", className="text-left font-extrabold text-transparent text-4xl max-md:text-2xl bg-clip-text bg-gradient-to-r from-purple-400 to-pink-600 pb-12"), | |
| html.P(id="explaination", className="text-lg max-md:text-base leading-10 text-justify") | |
| ],className="max-w-6xl flex flex-col mx-auto mt-8 px-8 mx-8 pb-32" | |
| ) | |
| ] | |
| ) | |
| def chained_callback_drugname(tcga): | |
| dff = copy.deepcopy(df) | |
| if tcga is not None: | |
| dff = dff.query("tcga_id == @tcga") | |
| return sorted(dff["drug_name"].unique()) | |
| def chained_callback_tcga(drugname): | |
| dff = copy.deepcopy(df) | |
| if drugname is not None: | |
| dff = dff.query("drug_name == @drugname") | |
| return sorted(dff["tcga_id"].unique()) | |
| def graph_chart(drugname, tcga): | |
| comb_name= tcga+'_'+drugname | |
| node = data[comb_name]['node'] | |
| # node["y"]=[ x * 1.45 for x in node["y"] ] | |
| link = data[comb_name]['link'] | |
| fig = go.Figure(go.Sankey(link=link, node=node,)) | |
| # fig.update_layout(data[comb_name]['layout']) | |
| fig.update_layout( | |
| margin=dict( l= 0, r=0, t=8,b= 0, autoexpand=False,), | |
| font= { | |
| "size": 12, | |
| "family": "Helvetica" | |
| }, | |
| paper_bgcolor='rgba(0,0,0,0)', | |
| plot_bgcolor='rgba(0,0,0,0)' | |
| ) | |
| return fig | |
| def update_explanation(tcga, drugname): | |
| dff = copy.deepcopy(df) | |
| if tcga is not None: | |
| dff = dff.query("tcga_id == @tcga") | |
| if drugname is not None: | |
| dff = dff.query("drug_name == @drugname") | |
| explanation = dff["explanation"].values[0] if not dff.empty else "" | |
| return explanation | |
| if __name__ == "__main__": | |
| app.run(debug=False, host="0.0.0.0", port=7860) |