Spaces:
Sleeping
Sleeping
Commit
·
d300034
1
Parent(s):
31e86bb
Upload app.py
Browse files
app.py
CHANGED
@@ -58,39 +58,37 @@ st.set_option('deprecation.showPyplotGlobalUse', False)
|
|
58 |
cwd=os.getcwd()+'/'#+'data/'
|
59 |
@st.cache_data
|
60 |
def get_data():
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
|
79 |
#Also load Go Terms
|
80 |
-
|
81 |
-
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
return full_adata_annot,all_genes_list,all_celltype_list,broad_celltype,all_path_ways,full_go_table
|
94 |
#done load Data
|
95 |
|
96 |
|
@@ -100,7 +98,7 @@ st.title('Brain Age Browser')
|
|
100 |
|
101 |
#genes_list,adata_annot=get_data()
|
102 |
|
103 |
-
|
104 |
|
105 |
tab1, tab2,readme = st.tabs(["Gene Expression by CellType", "Age associations for multiple genes", "README"])
|
106 |
data = np.random.randn(10, 1)
|
@@ -111,11 +109,11 @@ with tab1:
|
|
111 |
with c1:
|
112 |
selected_gene = st.selectbox(
|
113 |
'Please select a gene',
|
114 |
-
|
115 |
with c2:
|
116 |
selected_celltype = st.selectbox(
|
117 |
'Please select CellType',
|
118 |
-
|
119 |
)
|
120 |
Updated=st.form_submit_button(label = 'Go')
|
121 |
if not isinstance(selected_gene, type(None)) and not isinstance(selected_celltype, type(None)) and Updated:
|
@@ -124,13 +122,13 @@ with tab1:
|
|
124 |
col1,col2= st.columns([1,1])
|
125 |
with col1:
|
126 |
fig11, axx11 = plt.subplots(figsize=(5,5))
|
127 |
-
sc.pl.umap(
|
128 |
st.pyplot(fig11)
|
129 |
|
130 |
with col2:
|
131 |
fig12, axx12 = plt.subplots(figsize=(5,5))
|
132 |
-
#sc.pl.umap(
|
133 |
-
sc.pl.umap(
|
134 |
#plt.xticks(rotation = 45)
|
135 |
#plt.colorbar(cax=cax)
|
136 |
axx12.set_title(selected_gene, fontsize=12)
|
@@ -138,8 +136,8 @@ with tab1:
|
|
138 |
st.pyplot(fig12)
|
139 |
|
140 |
#Subset Younv and Old
|
141 |
-
adata_Young =
|
142 |
-
adata_Old =
|
143 |
|
144 |
#Young/Old but for cell_type
|
145 |
adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
|
@@ -194,11 +192,11 @@ with tab2:
|
|
194 |
with c1:
|
195 |
multi_genes = st.multiselect(
|
196 |
'Select Genes List',
|
197 |
-
|
198 |
with c2:
|
199 |
go_term = st.selectbox(
|
200 |
'Select GO Term',
|
201 |
-
|
202 |
with c3:
|
203 |
Choice = st.radio(
|
204 |
"",
|
@@ -209,13 +207,13 @@ with tab2:
|
|
209 |
if Choice=='Gene Set':
|
210 |
multi_genes = np.sort(multi_genes)
|
211 |
else:
|
212 |
-
multi_genes=
|
213 |
multi_genes=multi_genes.dropna().values
|
214 |
multi_genes=np.sort(multi_genes)
|
215 |
#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']
|
216 |
######### THIS IS FOR CLUSTERMAP
|
217 |
# figxx = plt.subplots(figsize=(5, 5))
|
218 |
-
# hmpdat=
|
219 |
# #st.write(hmpdat)
|
220 |
# samples=hmpdat.obs.new_anno
|
221 |
# dfh = pd.DataFrame(hmpdat.X.toarray(), columns = multi_genes)
|
@@ -226,21 +224,21 @@ with tab2:
|
|
226 |
######
|
227 |
|
228 |
#col1,col2= st.columns([1,1])
|
229 |
-
#fig_szx=2*len(
|
230 |
#fig_szy=100*len(multi_genes)
|
231 |
#with col1:
|
232 |
fig11, axx11 = plt.subplots(figsize=(5, 5))
|
233 |
-
#sc.pl.umap(
|
234 |
-
axx11=sc.pl.dotplot(
|
235 |
#st.pyplot(fig11)
|
236 |
#st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
|
237 |
st.pyplot(plt.gcf())
|
238 |
# with col2:
|
239 |
fig12, axx12 = plt.subplots(figsize=(5, 5))
|
240 |
|
241 |
-
#sc.pl.umap(
|
242 |
-
#sc.pl.umap(
|
243 |
-
axx12=sc.pl.heatmap(
|
244 |
plt.xticks(rotation = 45)
|
245 |
#plt.xticks(rotation = 45)
|
246 |
#st.pyplot(fig12)
|
@@ -252,12 +250,12 @@ with tab2:
|
|
252 |
#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']
|
253 |
#multi_genes=np.sort(multi_genes)
|
254 |
# fig, ax1 = plt.subplots(1,2)
|
255 |
-
# sc.pl.dotplot(
|
256 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
257 |
# fig, ax2 = plt.subplots(1,2)
|
258 |
-
# ax2=sc.pl.heatmap(
|
259 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
260 |
-
#ax[0]=sc.pl.dotplot(
|
261 |
#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
262 |
|
263 |
|
@@ -266,15 +264,15 @@ with tab2:
|
|
266 |
|
267 |
# fig, (ax1) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
268 |
# #ax = plt.subplot()
|
269 |
-
# ax1_dict=sc.pl.dotplot(
|
270 |
-
# #ax_dict=sc.pl.dotplot(
|
271 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
272 |
-
# #ax2_dict=sc.pl.dotplot(
|
273 |
# fig, (ax2) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
274 |
-
# #ax2_dict=sc.pl.matrixplot(
|
275 |
|
276 |
# #sc.pl.heatmap(adata_annot, genes_lst, groupby='new_anno', vmin=-1, vmax=1, cmap='RdBu_r', dendrogram=True, swap_axes=True, figsize=(11,4))
|
277 |
-
# ax2_dict=sc.pl.heatmap(
|
278 |
|
279 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
280 |
|
|
|
58 |
cwd=os.getcwd()+'/'#+'data/'
|
59 |
@st.cache_data
|
60 |
def get_data():
|
61 |
+
if 'adata_annot' not in st.session_state or 'cell_type' not in st.session_state or 'broad_type' not in st.session_state:
|
62 |
+
adata_annot = sc.read_h5ad(cwd+'multiregion_brainaging_annotated.h5ad')
|
63 |
+
st.session_state['adata_annot'] = adata_annot
|
64 |
+
if 'genes_list' not in st.session_state:
|
65 |
+
genes=adata_annot.var.index
|
66 |
+
#genes_list=sorted(genes.unique())
|
67 |
+
st.session_state['genes_list'] = sorted(genes.unique())
|
68 |
+
if 'cell_type' not in st.session_state:
|
69 |
+
#cell_type=diff_fdr[diff_fdr.type=='cell_type']['tissue']
|
70 |
+
#cell_type=sorted(cell_type.unique())
|
71 |
+
anno=adata_annot.obs.new_anno
|
72 |
+
#cell_type=sorted(anno.unique())
|
73 |
+
st.session_state['cell_type'] = sorted(anno.unique())
|
74 |
+
if 'broad_type' not in st.session_state:
|
75 |
+
broad_celltype=adata_annot.obs.broad_celltype
|
76 |
+
#broad_type=sorted(broad_type.unique())
|
77 |
+
st.session_state['broad_type'] = sorted(broad_celltype.unique())
|
78 |
|
79 |
#Also load Go Terms
|
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')
|
86 |
|
87 |
|
88 |
+
gene_set_by_path = {key: [val for val in value.values() if val != ""] for key, value in go_bp_paths_dict.items()}
|
89 |
+
gene_set_by_path = pd.DataFrame.from_dict(gene_set_by_path, orient='index').transpose()
|
90 |
+
st.session_state['path_ways']=gene_set_by_path.columns
|
91 |
+
st.session_state['go_table']=gene_set_by_path
|
|
|
|
|
92 |
#done load Data
|
93 |
|
94 |
|
|
|
98 |
|
99 |
#genes_list,adata_annot=get_data()
|
100 |
|
101 |
+
get_data()
|
102 |
|
103 |
tab1, tab2,readme = st.tabs(["Gene Expression by CellType", "Age associations for multiple genes", "README"])
|
104 |
data = np.random.randn(10, 1)
|
|
|
109 |
with c1:
|
110 |
selected_gene = st.selectbox(
|
111 |
'Please select a gene',
|
112 |
+
st.session_state['genes_list'])
|
113 |
with c2:
|
114 |
selected_celltype = st.selectbox(
|
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:
|
|
|
122 |
col1,col2= st.columns([1,1])
|
123 |
with col1:
|
124 |
fig11, axx11 = plt.subplots(figsize=(5,5))
|
125 |
+
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)
|
126 |
st.pyplot(fig11)
|
127 |
|
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)
|
|
|
136 |
st.pyplot(fig12)
|
137 |
|
138 |
#Subset Younv and Old
|
139 |
+
adata_Young = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='young']
|
140 |
+
adata_Old = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='old']
|
141 |
|
142 |
#Young/Old but for cell_type
|
143 |
adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
|
|
|
192 |
with c1:
|
193 |
multi_genes = st.multiselect(
|
194 |
'Select Genes List',
|
195 |
+
st.session_state['genes_list'])
|
196 |
with c2:
|
197 |
go_term = st.selectbox(
|
198 |
'Select GO Term',
|
199 |
+
st.session_state['path_ways'])
|
200 |
with c3:
|
201 |
Choice = st.radio(
|
202 |
"",
|
|
|
207 |
if Choice=='Gene Set':
|
208 |
multi_genes = np.sort(multi_genes)
|
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 |
######### THIS IS FOR CLUSTERMAP
|
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)
|
|
|
224 |
######
|
225 |
|
226 |
#col1,col2= st.columns([1,1])
|
227 |
+
#fig_szx=2*len(st.session_state['cell_type'])
|
228 |
#fig_szy=100*len(multi_genes)
|
229 |
#with col1:
|
230 |
fig11, axx11 = plt.subplots(figsize=(5, 5))
|
231 |
+
#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)
|
232 |
+
axx11=sc.pl.dotplot(st.session_state['adata_annot'], multi_genes,'new_anno',size_title='Fraction of\n Expressing Cells',colorbar_title='Mean\nExpression',cmap='BuPu',swap_axes=True,show=False,vmax=5)
|
233 |
#st.pyplot(fig11)
|
234 |
#st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
|
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, show_gene_labels=True,var_group_rotation=45)#,ax=ax2)
|
242 |
plt.xticks(rotation = 45)
|
243 |
#plt.xticks(rotation = 45)
|
244 |
#st.pyplot(fig12)
|
|
|
250 |
#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']
|
251 |
#multi_genes=np.sort(multi_genes)
|
252 |
# fig, ax1 = plt.subplots(1,2)
|
253 |
+
# sc.pl.dotplot(st.session_state['adata_annot'], multi_genes,'new_anno',size_title='Fraction of\n Expressing Cells',colorbar_title='Mean\nExpression',cmap='RdBu_r',show=False, ax=ax1[0])
|
254 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
255 |
# fig, ax2 = plt.subplots(1,2)
|
256 |
+
# ax2=sc.pl.heatmap(st.session_state['adata_annot'], multi_genes, 'new_anno', vmin=-1, vmax=1, cmap='RdBu_r', dendrogram=True, swap_axes=True)
|
257 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
258 |
+
#ax[0]=sc.pl.dotplot(st.session_state['adata_annot'],multi_genes,'new_anno',show=False)
|
259 |
#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
260 |
|
261 |
|
|
|
264 |
|
265 |
# fig, (ax1) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
266 |
# #ax = plt.subplot()
|
267 |
+
# ax1_dict=sc.pl.dotplot(st.session_state['adata_annot'], multi_genes,'new_anno',size_title='Fraction of\n Expressing Cells',colorbar_title='Mean\nExpression',cmap='BuPu',swap_axes=True,show=False, ax=ax1,vmax=5)
|
268 |
+
# #ax_dict=sc.pl.dotplot(st.session_state['adata_annot'], multi_genes,'new_anno',size_title='Fraction of\n Expressing Cells',colorbar_title='Mean\nExpression',cmap='RdBu_r',swap_axes=True,show=False, ax=ax)
|
269 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
270 |
+
# #ax2_dict=sc.pl.dotplot(st.session_state['adata_annot'], multi_genes,'Sex',size_title='Fraction of\n Expressing Cells',colorbar_title='Mean\nExpression',cmap='RdBu_r',swap_axes=True,show=False, ax=ax2)
|
271 |
# fig, (ax2) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
272 |
+
# #ax2_dict=sc.pl.matrixplot(st.session_state['adata_annot'], multi_genes, 'new_anno', vmin=-1, vmax=1, show=False, cmap='BuPu',dendrogram=True, swap_axes=True, ax=ax2)
|
273 |
|
274 |
# #sc.pl.heatmap(adata_annot, genes_lst, groupby='new_anno', vmin=-1, vmax=1, cmap='RdBu_r', dendrogram=True, swap_axes=True, figsize=(11,4))
|
275 |
+
# ax2_dict=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)
|
276 |
|
277 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
278 |
|