syedislamuddin commited on
Commit
1c602ce
·
1 Parent(s): 69c0c38

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -131
app.py CHANGED
@@ -7,28 +7,25 @@ import scanpy as sc
7
 
8
  #import mpld3
9
  import matplotlib.pyplot as plt
10
- #import seaborn as sns
11
 
 
12
 
13
- #import streamlit.components.v1 as components
14
 
15
- #from IPython.display import Markdown as md
16
 
17
- from functions import pathway_analyses
18
 
19
- # SMALL_SIZE = 2
20
- # MEDIUM_SIZE = 2
21
- # BIGGER_SIZE = 2
 
 
 
 
22
 
23
- # plt.rc('font', size=SMALL_SIZE) # controls default text sizes
24
- # plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title
25
- # plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
26
- # plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
27
- # plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
28
- # plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
29
- # plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
30
 
31
- sc.settings.set_figure_params(dpi=80, facecolor='white')
 
32
 
33
  #disable st.pyplot warning
34
  st.set_page_config(layout="wide")
@@ -83,16 +80,6 @@ def get_data():
83
  if 'go_table' not in st.session_state:
84
  bp = pathway_analyses.read_pathways('pathway_databases/GO_Biological_Process_2021.txt')
85
 
86
- # cy = pathway_analyses.read_pathways('pathway_databases/HumanCyc_2016.txt')
87
- # ke = pathway_analyses.read_pathways('pathway_databases/KEGG_2019_Human.txt')
88
- # re = pathway_analyses.read_pathways('pathway_databases/Reactome_2016.txt')
89
-
90
- # all_paths = pd.concat([bp, cy, ke, re], join='outer', axis=0, ignore_index=True)
91
- # all_paths.set_index(0, inplace=True)
92
- # all_paths.fillna("", inplace=True)
93
- # all_paths_dict = all_paths.to_dict(orient='index')
94
-
95
-
96
  go_bp_paths = bp.set_index(0)
97
  go_bp_paths.fillna("", inplace=True)
98
  go_bp_paths_dict = go_bp_paths.to_dict(orient='index')
@@ -128,21 +115,10 @@ with tab1:
128
  'Please select CellType',
129
  st.session_state['cell_type']
130
  )
131
- # with c3:
132
- # plot_choice = st.checkbox(
133
- # "Which Plots",
134
- # ('Gene','Old/Young'))
135
-
136
-
137
-
138
  Updated=st.form_submit_button(label = 'Go')
139
  if not isinstance(selected_gene, type(None)) and not isinstance(selected_celltype, type(None)) and Updated:
140
-
141
-
142
- # fig11, axx1 = plt.subplots()
143
- # sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data',legend_fontsize='4', frameon=False,show=False, ax=axx1)
144
- # st.pyplot(plt.gcf().set_size_inches(4, 4))
145
-
146
  col1,col2= st.columns([1,1])
147
  with col1:
148
  fig11, axx11 = plt.subplots(figsize=(5,5))
@@ -152,8 +128,11 @@ with tab1:
152
  with col2:
153
  fig12, axx12 = plt.subplots(figsize=(5,5))
154
  #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
155
- sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False,legend_fontsize='xx-small', ax=axx12)#,vmax='p99')
156
  #plt.xticks(rotation = 45)
 
 
 
157
  st.pyplot(fig12)
158
 
159
  #Subset Younv and Old
@@ -170,83 +149,42 @@ with tab1:
170
 
171
  #Young
172
  dot_size=.05
173
- col1,col2= st.columns([1,1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
- with col1:
176
-
177
- #st.markdown('<div style="text-align: center;">**Young**</div>', unsafe_allow_html=True)
178
- str_title='Young: '+selected_gene
179
- #st.markdown("<h3 style='text-align: center; color: red;'>str_title</h3>", unsafe_allow_html=True)
180
- st.markdown("# {} ".format(str_title))#,align_text='center')
181
- #md("# {} ".format(str_title))
182
-
183
- fig21, axx21 = plt.subplots(figsize=(1,1))
184
- #sc.pl.umap(adata_Young, color=selected_gene, title="Young: "+selected_gene, legend_loc='right margin', color_map='viridis',frameon=False,show=False,size=dot_size, legend_fontsize='4',colorbar_loc=None,ax=axx21)
185
- sc.pl.umap(adata_Young, color=selected_gene, title="", legend_loc='right margin', color_map='viridis',frameon=False,show=False,size=dot_size, legend_fontsize='xx-small',colorbar_loc=None,ax=axx21)
186
- #st.pyplot(fig21)
187
- st.pyplot(plt.gcf())
188
- with col2:
189
- str_title='Young: '+selected_gene+" ("+selected_celltype+")"
190
- st.markdown("# {} ".format(str_title))#,align_text='center')
191
- fig22, axx22 = plt.subplots(figsize=(1,1))
192
- #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
193
- #sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False, ax=axx2)#,vmax='p99')
194
- sc.pl.umap(adata_YoungAst, color=selected_gene, title="", legend_loc='right margin', color_map='viridis', frameon=False,show=False,size=dot_size,legend_fontsize='xx-small',colorbar_loc=None, ax=axx22)
195
- #sc.pl.umap(adata_Old, color=selected_gene, title="Old: "+selected_gene, legend_loc='right margin', color_map='viridis', frameon=False,show=False, ax=axx22)
196
- #plt.xticks(rotation = 45)
197
- #st.pyplot(fig22)
198
- st.pyplot(plt.gcf())
199
- #Old
200
- col1,col2= st.columns([1,1])
201
- with col1:
202
- str_title='Old: '+selected_gene+" ("+selected_celltype+")"
203
- st.markdown("# {} ".format(str_title))#,align_text='center')
204
-
205
- fig31, axx31 = plt.subplots(figsize=(1,1))
206
- #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data',legend_fontsize='8', frameon=False,show=False, ax=axx1)
207
- sc.pl.umap(adata_Old, color=selected_gene, title="", legend_loc='right margin', color_map='viridis', frameon=False,show=False,size=dot_size,legend_fontsize='xx-small', colorbar_loc="bottom",ax=axx31)
208
- st.pyplot(fig31)
209
- with col2:
210
- str_title='Old: '+selected_gene+" ("+selected_celltype+")"
211
- st.markdown("# {} ".format(str_title))#,align_text='center')
212
-
213
- fig32, axx32 = plt.subplots(figsize=(1,1))
214
- #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
215
- #sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False, ax=axx2)#,vmax='p99')
216
- sc.pl.umap(adata_OldAst, color=selected_gene, title="", legend_loc='right margin', color_map='viridis', frameon=False,show=False,size=dot_size,legend_fontsize='xx-small', colorbar_loc="bottom",ax=axx32)
217
- #plt.xticks(rotation = 45)
218
- st.pyplot(fig32)
219
-
220
- # fig, ax = plt.subplots(3,2)
221
- # sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=ax[0,0])
222
- # sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False, ax=ax[0,1],vmax='p99')
223
-
224
- # #Subset Younv and Old
225
- # adata_Young = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='young']
226
- # adata_Old = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='old']
227
- # sc.pl.umap(adata_Young, color=selected_gene, title="Young: "+selected_gene, legend_loc='right margin', color_map='viridis',frameon=False,show=False, ax=ax[1,0])
228
- # sc.pl.umap(adata_Old, color=selected_gene, title="Old: "+selected_gene, legend_loc='right margin', color_map='viridis', frameon=False,show=False, ax=ax[2,0])
229
-
230
- # # #Young/Old but for cell_type
231
- # # adata_YoungAst = adata_Young[adata_Young.obs['broad_celltype']==selected_celltype]
232
- # # adata_OldAst = adata_Old[adata_Old.obs['broad_celltype']==selected_celltype]
233
-
234
- # #Young/Old but for cell_type
235
- # adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
236
- # adata_OldAst = adata_Old[adata_Old.obs['new_anno']==selected_celltype]
237
-
238
-
239
- # sc.pl.umap(adata_YoungAst, color=selected_gene, title=selected_celltype, legend_loc='right margin', color_map='viridis', frameon=False,show=False, ax=ax[1,1])
240
- # sc.pl.umap(adata_OldAst, color=selected_gene, title=selected_celltype, legend_loc='right margin', color_map='viridis', frameon=False,show=False, ax=ax[2,1])
241
-
242
- # #sc.pl.umap(st.session_state['adata_annot'], color='Brain_region', title='Brain Region', legend_loc='right margin', frameon=False,show=False, ax=ax[1,1])
243
- # #sc.pl.umap(st.session_state['adata_annot'], color='Age_group', title='Age Group', legend_loc='right margin', frameon=False,show=False, ax=ax[2,0])
244
- # #sc.pl.umap(st.session_state['adata_annot'], color=selected_celltype, title=selected_celltype, legend_loc='on data', frameon=False,show=False, ax=ax[2,1])
245
 
 
246
 
247
- # st.pyplot(plt.gcf().set_size_inches(15, 30))
248
-
249
-
250
 
251
  with tab2:
252
  with st.form(key='multiselect_form'):
@@ -271,25 +209,19 @@ with tab2:
271
  else:
272
  multi_genes=st.session_state['go_table'].loc[:,go_term]
273
  multi_genes=multi_genes.dropna().values
 
274
  #multi_genes=['WNT3', 'VPS13C', 'VAMP4', 'UBTF', 'UBAP2', 'TMEM175', 'TMEM163', 'SYT17', 'STK39', 'SPPL2B', 'SIPA1L2', 'SH3GL2', 'SCARB2', 'SCAF11', 'RPS6KL1', 'RPS12', 'RIT2', 'RIMS1', 'RETREG3', 'PMVK', 'PAM', 'NOD2', 'MIPOL1', 'MEX3C', 'MED12L', 'MCCC1', 'MBNL2', 'MAPT', 'LRRK2', 'KRTCAP2', 'KCNS3', 'KCNIP3', 'ITGA8', 'IP6K2', 'GPNMB', 'GCH1', 'GBA', 'FYN', 'FCGR2A', 'FBRSL1', 'FAM49B', 'FAM171A2', 'ELOVL7', 'DYRK1A', 'DNAH17', 'DLG2', 'CTSB', 'CRLS1', 'CRHR1', 'CLCN3', 'CHRNB1', 'CAMK2D', 'CAB39L', 'BRIP1', 'BIN3', 'ASXL3', 'SNCA']
275
  #########
276
-
277
- #sns.clustermap(st.session_state['adata_annot'], figsize=(14,12),
278
- # pivot_kws={'index': 'country',
279
- # 'columns': 'year',
280
- # 'values': 'lifeExp'})
281
- # col1,col2= st.columns([1,1])
282
- # #fig_szx=2*len(st.session_state['cell_type'])
283
- # #fig_szy=100*len(multi_genes)
284
- # with col1:
285
- # figa, axxaa = plt.subplots(figsize=(5, 5))
286
- # #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data',legend_fontsize='8', frameon=False,show=False, ax=axx11)
287
- # axxaa=sc.pl.clustermap(st.session_state['adata_annot'], obs_keys=multi_genes) #,'new_anno',size_title='Fraction of\n Expressing Cells',colorbar_title='Mean\nExpression',cmap='BuPu',swap_axes=True,show=False,vmax=5)
288
- # #st.pyplot(fig11)
289
- # #st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
290
- # st.pyplot(plt.gcf())
291
-
292
-
293
 
294
  col1,col2= st.columns([1,1])
295
  #fig_szx=2*len(st.session_state['cell_type'])
@@ -303,9 +235,11 @@ with tab2:
303
  st.pyplot(plt.gcf())
304
  with col2:
305
  fig12, axx12 = plt.subplots(figsize=(5, 5))
 
306
  #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
307
  #sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False,legend_fontsize='xx-small', ax=axx12)#,vmax='p99')
308
- axx12=sc.pl.heatmap(st.session_state['adata_annot'], multi_genes, groupby='new_anno', vmin=-1, vmax=1, cmap='BuPu', dendrogram=True, swap_axes=True)#,ax=ax2)
 
309
  #plt.xticks(rotation = 45)
310
  #st.pyplot(fig12)
311
  #st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
 
7
 
8
  #import mpld3
9
  import matplotlib.pyplot as plt
 
10
 
11
+ #from mpl_toolkits.axes_grid1 import make_axes_locatable
12
 
13
+ #import matplotlib.gridspec as gridspec
14
 
15
+ #from sunbird.categorical_encoding import frequency_encoding
16
 
 
17
 
18
+ import seaborn as sns
19
+
20
+ plt.rcParams.update({'figure.autolayout': True})
21
+ plt.rcParams['axes.linewidth'] = 0.0001
22
+
23
+
24
+ from functions import pathway_analyses
25
 
 
 
 
 
 
 
 
26
 
27
+ #sc.settings.set_figure_params(dpi=80, facecolor='white',fontsize=4)
28
+ sc.settings.set_figure_params(dpi=80, facecolor='white',fontsize=12)
29
 
30
  #disable st.pyplot warning
31
  st.set_page_config(layout="wide")
 
80
  if 'go_table' not in st.session_state:
81
  bp = pathway_analyses.read_pathways('pathway_databases/GO_Biological_Process_2021.txt')
82
 
 
 
 
 
 
 
 
 
 
 
83
  go_bp_paths = bp.set_index(0)
84
  go_bp_paths.fillna("", inplace=True)
85
  go_bp_paths_dict = go_bp_paths.to_dict(orient='index')
 
115
  'Please select CellType',
116
  st.session_state['cell_type']
117
  )
 
 
 
 
 
 
 
118
  Updated=st.form_submit_button(label = 'Go')
119
  if not isinstance(selected_gene, type(None)) and not isinstance(selected_celltype, type(None)) and Updated:
120
+ fig = plt.figure(figsize=(6, 6))
121
+
 
 
 
 
122
  col1,col2= st.columns([1,1])
123
  with col1:
124
  fig11, axx11 = plt.subplots(figsize=(5,5))
 
128
  with col2:
129
  fig12, axx12 = plt.subplots(figsize=(5,5))
130
  #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
131
+ sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title='', legend_loc='best', frameon=False,show=False,legend_fontsize='xx-small', ax=axx12)#,vmax='p99')
132
  #plt.xticks(rotation = 45)
133
+ #plt.colorbar(cax=cax)
134
+ axx12.set_title(selected_gene, fontsize=12)
135
+
136
  st.pyplot(fig12)
137
 
138
  #Subset Younv and Old
 
149
 
150
  #Young
151
  dot_size=.05
152
+ font_sz=4
153
+ fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2,figsize=(3,3))
154
+ #plt.subplots_adjust(wspace=0, hspace=0)
155
+ #plt.tight_layout()
156
+ #fig.tight_layout(rect=[0, 0.03, 1, 0.95]) #[left, bottom, right, top]
157
+ sc.pl.umap(adata_Young, color=selected_gene, title="", legend_loc='right margin', color_map='viridis',frameon=True,show=False,size=dot_size, legend_fontsize='xx-small',colorbar_loc=None,ax=ax1)
158
+ ax1.set_title('All', fontsize=font_sz)
159
+ ax1.set_ylabel('Young', fontsize=font_sz)
160
+ #ax1.set_xlabel('', fontsize=0)
161
+ ax1.get_xaxis().set_visible(False)
162
+ sc.pl.umap(adata_YoungAst, color=selected_gene, title="", legend_loc='right margin', color_map='viridis', frameon=True,show=False,size=dot_size,legend_fontsize='xx-small',colorbar_loc=None, ax=ax2)
163
+ ax2.set_title(selected_celltype, fontsize=font_sz)
164
+ #ax2.set_xlabel('', fontsize=0)
165
+ ax2.set_ylabel('', fontsize=0)
166
+ ax2.get_xaxis().set_visible(False)
167
+ ax2.get_yaxis().set_visible(False)
168
+ sc.pl.umap(adata_Old, color=selected_gene, title="", legend_loc='right margin', color_map='viridis', frameon=True,show=False,size=dot_size,legend_fontsize='xx-small', colorbar_loc="bottom",ax=ax3)
169
 
170
+ #ax3.set_xlabel('x-label', fontsize=12)
171
+ ax3.set_ylabel('Old', fontsize=font_sz)
172
+ #ax3.set_xlabel('', fontsize=0)
173
+ ax3.get_xaxis().set_visible(False)
174
+ #ax3.get_title().set_visible(False)
175
+ sc.pl.umap(adata_OldAst, color=selected_gene, title="", legend_loc='right margin', color_map='viridis', frameon=True,show=False,size=dot_size,legend_fontsize='xx-small', colorbar_loc="bottom",ax=ax4)
176
+ #ax4.set_xlabel('', fontsize=0)
177
+ #ax4.set_ylabel('', fontsize=0)
178
+ ax4.get_xaxis().set_visible(False)
179
+ ax4.get_yaxis().set_visible(False)
180
+ #ax4.get_title().set_visible(False)
181
+ plt.suptitle(selected_gene+"\ncoefficient estimate: 0.24 | BH-FDR p=7.91x$10^{-3}$",fontsize=font_sz)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
+ #plt.subplots_adjust(top=0.95)
184
 
185
+ #plt.tight_layout(pad=0, w_pad=0, h_pad=0)
186
+ #plt.tight_layout()
187
+ st.pyplot(plt.gcf())
188
 
189
  with tab2:
190
  with st.form(key='multiselect_form'):
 
209
  else:
210
  multi_genes=st.session_state['go_table'].loc[:,go_term]
211
  multi_genes=multi_genes.dropna().values
212
+ multi_genes=np.sort(multi_genes)
213
  #multi_genes=['WNT3', 'VPS13C', 'VAMP4', 'UBTF', 'UBAP2', 'TMEM175', 'TMEM163', 'SYT17', 'STK39', 'SPPL2B', 'SIPA1L2', 'SH3GL2', 'SCARB2', 'SCAF11', 'RPS6KL1', 'RPS12', 'RIT2', 'RIMS1', 'RETREG3', 'PMVK', 'PAM', 'NOD2', 'MIPOL1', 'MEX3C', 'MED12L', 'MCCC1', 'MBNL2', 'MAPT', 'LRRK2', 'KRTCAP2', 'KCNS3', 'KCNIP3', 'ITGA8', 'IP6K2', 'GPNMB', 'GCH1', 'GBA', 'FYN', 'FCGR2A', 'FBRSL1', 'FAM49B', 'FAM171A2', 'ELOVL7', 'DYRK1A', 'DNAH17', 'DLG2', 'CTSB', 'CRLS1', 'CRHR1', 'CLCN3', 'CHRNB1', 'CAMK2D', 'CAB39L', 'BRIP1', 'BIN3', 'ASXL3', 'SNCA']
214
  #########
215
+ figxx = plt.subplots(figsize=(5, 5))
216
+ hmpdat=st.session_state['adata_annot'][:, multi_genes] #.to_df()
217
+ #st.write(hmpdat)
218
+ samples=hmpdat.obs.new_anno
219
+ dfh = pd.DataFrame(hmpdat.X.toarray(), columns = multi_genes)
220
+ dfh=dfh.T
221
+ dfh.columns=samples.values.to_list()
222
+ sns.clustermap(dfh)
223
+ st.pyplot(plt.gcf())
224
+ ######
 
 
 
 
 
 
 
225
 
226
  col1,col2= st.columns([1,1])
227
  #fig_szx=2*len(st.session_state['cell_type'])
 
235
  st.pyplot(plt.gcf())
236
  with col2:
237
  fig12, axx12 = plt.subplots(figsize=(5, 5))
238
+
239
  #sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
240
  #sc.pl.umap(st.session_state['adata_annot'], color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False,legend_fontsize='xx-small', ax=axx12)#,vmax='p99')
241
+ axx12=sc.pl.heatmap(st.session_state['adata_annot'], multi_genes, groupby='new_anno', vmin=-1, vmax=1, cmap='BuPu', dendrogram=True, swap_axes=True,var_group_rotation="45")#,ax=ax2)
242
+ plt.xticks(rotation = 45)
243
  #plt.xticks(rotation = 45)
244
  #st.pyplot(fig12)
245
  #st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))