Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,19 +91,21 @@ if query:
|
|
| 91 |
table = (pd.DataFrame(table))
|
| 92 |
table.index.name = 'Rank'
|
| 93 |
table.columns = ['Word', 'SIMILARITY']
|
| 94 |
-
|
| 95 |
-
print(
|
|
|
|
| 96 |
pd.set_option('display.max_rows', None)
|
| 97 |
-
|
|
|
|
| 98 |
# table.head(10).to_csv("clotting_sim1.csv", index=True)
|
| 99 |
# short_table = table.head(50)
|
| 100 |
# print(table)
|
| 101 |
|
| 102 |
|
| 103 |
# calculate the sizes of the squares in the treemap
|
| 104 |
-
short_table =
|
| 105 |
short_table.index += 1
|
| 106 |
-
short_table.index = 1 / short_table.index
|
| 107 |
sizes = short_table.index.tolist()
|
| 108 |
|
| 109 |
cmap = plt.cm.Greens(np.linspace(0.05, .5, len(sizes)))
|
|
@@ -118,47 +120,52 @@ if query:
|
|
| 118 |
# plt.legend("upper right", bbox_to_anchor=(-.2, 0))
|
| 119 |
fig = plt.gcf()
|
| 120 |
fig.patch.set_facecolor('#CCFFFF')
|
|
|
|
| 121 |
# # display the treemap in Streamlit
|
| 122 |
-
|
| 123 |
-
rank_num = list(short_table.index.tolist())
|
| 124 |
-
avg_size = sum(sizes) / len(short_table.index)
|
| 125 |
-
print(rank_num)
|
| 126 |
# print(sizes)
|
| 127 |
-
fig = px.treemap(
|
| 128 |
-
color_continuous_midpoint=avg_size)
|
| 129 |
fig.update(layout_coloraxis_showscale=False)
|
| 130 |
fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
-
treemap1, treemap2 = st.columns(2)
|
| 134 |
-
with treemap1:
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
csv = table.head(100).to_csv().encode('utf-8')
|
| 141 |
-
st.download_button(label="download top 100 words (csv)", data=csv, file_name=f'{database_name}_words.csv', mime='text/csv')
|
| 142 |
|
|
|
|
|
|
|
|
|
|
| 143 |
# st.write(short_table)
|
| 144 |
#
|
| 145 |
|
| 146 |
-
print()
|
| 147 |
-
print("Human genes similar to " + str(query))
|
| 148 |
df1 = table
|
| 149 |
df2 = pd.read_csv('Human_Genes.csv')
|
| 150 |
m = df1.Word.isin(df2.symbol)
|
| 151 |
df1 = df1[m]
|
| 152 |
df1.rename(columns={'Word': 'Human Gene'}, inplace=True)
|
| 153 |
df1["Human Gene"] = df1["Human Gene"].str.upper()
|
| 154 |
-
print(df1.head(50))
|
| 155 |
print()
|
| 156 |
# df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
|
| 157 |
# time.sleep(2)
|
| 158 |
|
| 159 |
|
| 160 |
df10 = df1.head(10)
|
| 161 |
-
df10.index = 1 / df10.index
|
| 162 |
sizes = df10.index.tolist()
|
| 163 |
|
| 164 |
cmap2 = plt.cm.Blues(np.linspace(0.05, .5, len(sizes)))
|
|
@@ -174,30 +181,27 @@ if query:
|
|
| 174 |
fig2 = plt.gcf()
|
| 175 |
fig2.patch.set_facecolor('#CCFFFF')
|
| 176 |
#
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
rank_num = list(df10.index.tolist())
|
| 183 |
-
avg_size = sum(sizes) / len(df10.index)
|
| 184 |
-
print(rank_num)
|
| 185 |
-
# print(sizes)
|
| 186 |
-
fig = px.treemap(path=[df10.index], values=sizes, color=sizes, color_continuous_scale='greens',
|
| 187 |
-
color_continuous_midpoint=avg_size)
|
| 188 |
fig.update(layout_coloraxis_showscale=False)
|
| 189 |
-
fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF"
|
| 190 |
-
fig.
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
# # display the treemap in Streamlit
|
| 194 |
-
with treemap2:
|
| 195 |
-
|
| 196 |
# st.pyplot(fig2)
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
mime='text/csv')
|
| 202 |
st.markdown("---")
|
| 203 |
st.subheader("Cancer-related videos")
|
|
|
|
| 91 |
table = (pd.DataFrame(table))
|
| 92 |
table.index.name = 'Rank'
|
| 93 |
table.columns = ['Word', 'SIMILARITY']
|
| 94 |
+
|
| 95 |
+
# print()
|
| 96 |
+
# print("Similarity to " + str(query))
|
| 97 |
pd.set_option('display.max_rows', None)
|
| 98 |
+
table2 = table.copy()
|
| 99 |
+
# print(table.head(50))
|
| 100 |
# table.head(10).to_csv("clotting_sim1.csv", index=True)
|
| 101 |
# short_table = table.head(50)
|
| 102 |
# print(table)
|
| 103 |
|
| 104 |
|
| 105 |
# calculate the sizes of the squares in the treemap
|
| 106 |
+
short_table = table2.head(10).round(2)
|
| 107 |
short_table.index += 1
|
| 108 |
+
short_table.index = (1 / short_table.index)*10
|
| 109 |
sizes = short_table.index.tolist()
|
| 110 |
|
| 111 |
cmap = plt.cm.Greens(np.linspace(0.05, .5, len(sizes)))
|
|
|
|
| 120 |
# plt.legend("upper right", bbox_to_anchor=(-.2, 0))
|
| 121 |
fig = plt.gcf()
|
| 122 |
fig.patch.set_facecolor('#CCFFFF')
|
| 123 |
+
# print(table.head(10)["SIMILARITY"])
|
| 124 |
# # display the treemap in Streamlit
|
| 125 |
+
table2["SIMILARITY"] = 'Similarity Score ' + table2.head(10)["SIMILARITY"].round(2).astype(str)
|
| 126 |
+
# rank_num = list(short_table.index.tolist())
|
| 127 |
+
# avg_size = sum(sizes) / len(short_table.index)
|
| 128 |
+
# print(rank_num)
|
| 129 |
# print(sizes)
|
| 130 |
+
fig = px.treemap(path=[short_table.index], values=sizes, hover_name=(table2.head(10)['SIMILARITY']))
|
|
|
|
| 131 |
fig.update(layout_coloraxis_showscale=False)
|
| 132 |
fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF")
|
| 133 |
+
fig.update_annotations(visible=False)
|
| 134 |
+
fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
|
| 135 |
+
hoverlabel_bgcolor="lightgreen", hoverlabel_bordercolor="#000000")
|
| 136 |
+
fig.update_layout(uniformtext=dict(minsize=15, mode='hide'), treemapcolorway=["lightgreen"])
|
| 137 |
|
| 138 |
|
| 139 |
+
# treemap1, treemap2 = st.columns(2)
|
| 140 |
+
# with treemap1:
|
| 141 |
+
st.subheader(f"Top 10 Words closely related to {query}")
|
| 142 |
+
# st.pyplot(fig)
|
| 143 |
+
# plt.clf()
|
| 144 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 145 |
|
|
|
|
|
|
|
| 146 |
|
| 147 |
+
csv = table.head(100).to_csv().encode('utf-8')
|
| 148 |
+
st.download_button(label="download top 100 words (csv)", data=csv, file_name=f'{database_name}_words.csv', mime='text/csv')
|
| 149 |
+
st.markdown("---")
|
| 150 |
# st.write(short_table)
|
| 151 |
#
|
| 152 |
|
| 153 |
+
# print()
|
| 154 |
+
# print("Human genes similar to " + str(query))
|
| 155 |
df1 = table
|
| 156 |
df2 = pd.read_csv('Human_Genes.csv')
|
| 157 |
m = df1.Word.isin(df2.symbol)
|
| 158 |
df1 = df1[m]
|
| 159 |
df1.rename(columns={'Word': 'Human Gene'}, inplace=True)
|
| 160 |
df1["Human Gene"] = df1["Human Gene"].str.upper()
|
| 161 |
+
# print(df1.head(50))
|
| 162 |
print()
|
| 163 |
# df1.head(50).to_csv("clotting_sim2.csv", index=True, header=False)
|
| 164 |
# time.sleep(2)
|
| 165 |
|
| 166 |
|
| 167 |
df10 = df1.head(10)
|
| 168 |
+
df10.index = (1 / df10.index)*10000
|
| 169 |
sizes = df10.index.tolist()
|
| 170 |
|
| 171 |
cmap2 = plt.cm.Blues(np.linspace(0.05, .5, len(sizes)))
|
|
|
|
| 181 |
fig2 = plt.gcf()
|
| 182 |
fig2.patch.set_facecolor('#CCFFFF')
|
| 183 |
#
|
| 184 |
+
print(df10["SIMILARITY"])
|
| 185 |
+
# rank_num = list(df10.index.tolist())
|
| 186 |
+
# avg_size = sum(sizes) / len(df10.index)
|
| 187 |
+
df10["SIMILARITY"] = 'Similarity Score ' + df10["SIMILARITY"].round(2).astype(str)
|
| 188 |
+
fig = px.treemap(path=[df10.index], values=sizes, hover_name=(df10['SIMILARITY']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
fig.update(layout_coloraxis_showscale=False)
|
| 190 |
+
fig.update_layout(autosize=True, paper_bgcolor="#CCFFFF")
|
| 191 |
+
fig.update_annotations(visible=False)
|
| 192 |
+
fig.update_traces(marker=dict(cornerradius=5), root_color="#CCFFFF", hovertemplate=None,
|
| 193 |
+
hoverlabel_bgcolor="lightblue", hoverlabel_bordercolor="#000000")
|
| 194 |
+
fig.update_layout(uniformtext=dict(minsize=20, mode='hide'), treemapcolorway=["lightblue"])
|
| 195 |
|
| 196 |
|
| 197 |
# # display the treemap in Streamlit
|
| 198 |
+
# with treemap2:
|
| 199 |
+
st.subheader(f"Top 10 Genes closely related to {query}")
|
| 200 |
# st.pyplot(fig2)
|
| 201 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 202 |
|
| 203 |
+
csv = df1.head(100).to_csv().encode('utf-8')
|
| 204 |
+
st.download_button(label="download top 100 genes (csv)", data=csv, file_name=f'{database_name}_genes.csv',
|
| 205 |
mime='text/csv')
|
| 206 |
st.markdown("---")
|
| 207 |
st.subheader("Cancer-related videos")
|