hlnicholls commited on
Commit
85ec45f
·
1 Parent(s): 110f578

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -84
app.py CHANGED
@@ -78,36 +78,6 @@ def convert_df(df):
78
  return df.to_csv(index=False).encode('utf-8')
79
 
80
 
81
- cdict1 = {
82
- 'red': ((0.0, 0.11764705882352941, 0.11764705882352941),
83
- (1.0, 0.9607843137254902, 0.9607843137254902)),
84
-
85
- 'green': ((0.0, 0.5333333333333333, 0.5333333333333333),
86
- (1.0, 0.15294117647058825, 0.15294117647058825)),
87
-
88
- 'blue': ((0.0, 0.8980392156862745, 0.8980392156862745),
89
- (1.0, 0.3411764705882353, 0.3411764705882353)),
90
-
91
- 'alpha': ((0.0, 1, 1),
92
- (0.5, 1, 1),
93
- (1.0, 1, 1))
94
- } # #1E88E5 -> #ff0052
95
- red_blue = LinearSegmentedColormap('RedBlue', cdict1)
96
-
97
- '''
98
- def matplotlib_to_plotly(cmap, pl_entries):
99
- h = 1.0/(pl_entries-1)
100
- pl_colorscale = []
101
-
102
- for k in range(pl_entries):
103
- C = list(map(np.uint8, np.array(cmap(k*h)[:3])*255))
104
- pl_colorscale.append([k*h, 'rgb'+str((C[0], C[1], C[2]))])
105
-
106
- return pl_colorscale
107
-
108
- red_blue = matplotlib_to_plotly(red_blue, 255)
109
- '''
110
-
111
  if len(gene_list) > 1:
112
  df = df_total[df_total.index.isin(gene_list)]
113
  df['Gene'] = df.index
@@ -137,60 +107,6 @@ if len(gene_list) > 1:
137
  feature_order = np.argsort(np.sum(np.abs(shap_values), axis=0)[:-1])
138
  feature_order = feature_order[-min(8, len(feature_order)):]
139
  col_order = [df_shap.columns[i] for i in feature_order]
140
- '''
141
- st.caption("Interactive SHAP Summary Plot of All Input Genes")
142
- mpl_fig = shap_summary_plot(shap_values, df_shap, max_display=8, show=False, feature_names=col_order)
143
- plotly_fig = tls.mpl_to_plotly(mpl_fig)
144
- plotly_fig['layout'] = {'xaxis': {'title': 'SHAP value (impact on model output)'}}
145
- max_display=8
146
- feature_names=df_shap.columns
147
- gene_index = df_shap.index
148
- for i in range(1, len(plotly_fig['data']), 2):
149
- t = gene_index #plotly_fig['data']
150
- plotly_fig['data'][i]['name'] = ''
151
- plotly_fig['data'][i]['text'] = t
152
- plotly_fig['data'][i]['hoverinfo'] = 'text'
153
- colorbar_trace = go.Scatter(x=[None],
154
- y=col_order, # [None],
155
- visible=True,
156
- mode='markers',
157
- marker=dict(
158
- colorscale=red_blue,
159
- showscale=True,
160
- cmin=-5,
161
- cmax=5,
162
- colorbar=dict(thickness=5, tickvals=[-5, 5], ticktext=['Low', 'High'], outlinewidth=0)
163
- ),
164
- hoverinfo='none'
165
- )
166
- plotly_fig['layout']['showlegend'] = False
167
- plotly_fig['layout']['hovermode'] = 'closest'
168
- plotly_fig['layout']['height']=600
169
- plotly_fig['layout']['width']=500
170
- plotly_fig['layout']['xaxis'].update(zeroline=True, showline=True, ticklen=4, showgrid=False)
171
- #plotly_fig['layout']['yaxis'].update(dict(visible=True))
172
- plotly_fig.add_trace(colorbar_trace)
173
- plotly_fig.layout.update(
174
- annotations=[dict(
175
- x=1.18,
176
- align="right",
177
- valign="top",
178
- text='Feature value',
179
- showarrow=False,
180
- xref="paper",
181
- yref="paper",
182
- xanchor="right",
183
- yanchor="middle",
184
- textangle=-90,
185
- font=dict(family='Calibri', size=14),
186
- )
187
- ],
188
- margin=dict(t=20)
189
- )
190
-
191
-
192
- st.plotly_chart(plotly_fig)
193
- '''
194
  else:
195
  pass
196
 
 
78
  return df.to_csv(index=False).encode('utf-8')
79
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  if len(gene_list) > 1:
82
  df = df_total[df_total.index.isin(gene_list)]
83
  df['Gene'] = df.index
 
107
  feature_order = np.argsort(np.sum(np.abs(shap_values), axis=0)[:-1])
108
  feature_order = feature_order[-min(8, len(feature_order)):]
109
  col_order = [df_shap.columns[i] for i in feature_order]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  else:
111
  pass
112