File size: 5,413 Bytes
b05addc 4ef11cb 1afd1de 3186404 b05addc d441c32 b05addc 7e470c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | 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"
)
]
)
@callback(
Output("drugname", "options"),
Input("tcga", "value"),
)
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())
@callback(
Output("tcga", "options"),
Input("drugname", "value"),
)
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())
@callback(
Output("graph", "figure"),
Input("drugname", "value"),
Input("tcga", "value"),
)
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
@callback(
Output("explaination", "children"),
[Input("tcga", "value"), Input("drugname", "value")]
)
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) |