Spaces:
Sleeping
Sleeping
Commit
·
31e86bb
1
Parent(s):
4c9462b
Upload app.py
Browse files
app.py
CHANGED
|
@@ -60,21 +60,21 @@ cwd=os.getcwd()+'/'#+'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 |
-
|
| 64 |
-
if 'genes_list' not in st.session_state:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 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 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
if 'broad_type' not in st.session_state:
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
#Also load Go Terms
|
| 80 |
# if 'go_table' not in st.session_state:
|
|
@@ -87,8 +87,10 @@ def get_data():
|
|
| 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 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
#done load Data
|
| 93 |
|
| 94 |
|
|
@@ -98,7 +100,7 @@ st.title('Brain Age Browser')
|
|
| 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,11 +111,11 @@ with tab1:
|
|
| 109 |
with c1:
|
| 110 |
selected_gene = st.selectbox(
|
| 111 |
'Please select a gene',
|
| 112 |
-
|
| 113 |
with c2:
|
| 114 |
selected_celltype = st.selectbox(
|
| 115 |
'Please select CellType',
|
| 116 |
-
|
| 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,13 +124,13 @@ with tab1:
|
|
| 122 |
col1,col2= st.columns([1,1])
|
| 123 |
with col1:
|
| 124 |
fig11, axx11 = plt.subplots(figsize=(5,5))
|
| 125 |
-
sc.pl.umap(
|
| 126 |
st.pyplot(fig11)
|
| 127 |
|
| 128 |
with col2:
|
| 129 |
fig12, axx12 = plt.subplots(figsize=(5,5))
|
| 130 |
-
#sc.pl.umap(
|
| 131 |
-
sc.pl.umap(
|
| 132 |
#plt.xticks(rotation = 45)
|
| 133 |
#plt.colorbar(cax=cax)
|
| 134 |
axx12.set_title(selected_gene, fontsize=12)
|
|
@@ -136,8 +138,8 @@ with tab1:
|
|
| 136 |
st.pyplot(fig12)
|
| 137 |
|
| 138 |
#Subset Younv and Old
|
| 139 |
-
adata_Young =
|
| 140 |
-
adata_Old =
|
| 141 |
|
| 142 |
#Young/Old but for cell_type
|
| 143 |
adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
|
|
@@ -192,11 +194,11 @@ with tab2:
|
|
| 192 |
with c1:
|
| 193 |
multi_genes = st.multiselect(
|
| 194 |
'Select Genes List',
|
| 195 |
-
|
| 196 |
with c2:
|
| 197 |
go_term = st.selectbox(
|
| 198 |
'Select GO Term',
|
| 199 |
-
|
| 200 |
with c3:
|
| 201 |
Choice = st.radio(
|
| 202 |
"",
|
|
@@ -207,13 +209,13 @@ with tab2:
|
|
| 207 |
if Choice=='Gene Set':
|
| 208 |
multi_genes = np.sort(multi_genes)
|
| 209 |
else:
|
| 210 |
-
multi_genes=
|
| 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=
|
| 217 |
# #st.write(hmpdat)
|
| 218 |
# samples=hmpdat.obs.new_anno
|
| 219 |
# dfh = pd.DataFrame(hmpdat.X.toarray(), columns = multi_genes)
|
|
@@ -224,21 +226,21 @@ with tab2:
|
|
| 224 |
######
|
| 225 |
|
| 226 |
#col1,col2= st.columns([1,1])
|
| 227 |
-
#fig_szx=2*len(
|
| 228 |
#fig_szy=100*len(multi_genes)
|
| 229 |
#with col1:
|
| 230 |
fig11, axx11 = plt.subplots(figsize=(5, 5))
|
| 231 |
-
#sc.pl.umap(
|
| 232 |
-
axx11=sc.pl.dotplot(
|
| 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(
|
| 240 |
-
#sc.pl.umap(
|
| 241 |
-
axx12=sc.pl.heatmap(
|
| 242 |
plt.xticks(rotation = 45)
|
| 243 |
#plt.xticks(rotation = 45)
|
| 244 |
#st.pyplot(fig12)
|
|
@@ -250,12 +252,12 @@ with tab2:
|
|
| 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(
|
| 254 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
| 255 |
# fig, ax2 = plt.subplots(1,2)
|
| 256 |
-
# ax2=sc.pl.heatmap(
|
| 257 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
| 258 |
-
#ax[0]=sc.pl.dotplot(
|
| 259 |
#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
| 260 |
|
| 261 |
|
|
@@ -264,15 +266,15 @@ with tab2:
|
|
| 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(
|
| 268 |
-
# #ax_dict=sc.pl.dotplot(
|
| 269 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
| 270 |
-
# #ax2_dict=sc.pl.dotplot(
|
| 271 |
# fig, (ax2) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
| 272 |
-
# #ax2_dict=sc.pl.matrixplot(
|
| 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(
|
| 276 |
|
| 277 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
| 278 |
|
|
|
|
| 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 |
+
full_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 |
+
all_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 |
+
all_celltype_list = 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:
|
|
|
|
| 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 |
+
all_path_ways=gene_set_by_path.columns
|
| 91 |
+
full_go_table=gene_set_by_path
|
| 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 |
|
| 101 |
#genes_list,adata_annot=get_data()
|
| 102 |
|
| 103 |
+
full_adata_annot,all_genes_list,all_celltype_list,broad_celltype,all_path_ways,full_go_table=get_data()
|
| 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 |
with c1:
|
| 112 |
selected_gene = st.selectbox(
|
| 113 |
'Please select a gene',
|
| 114 |
+
all_genes_list)
|
| 115 |
with c2:
|
| 116 |
selected_celltype = st.selectbox(
|
| 117 |
'Please select CellType',
|
| 118 |
+
all_celltype_list
|
| 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 |
col1,col2= st.columns([1,1])
|
| 125 |
with col1:
|
| 126 |
fig11, axx11 = plt.subplots(figsize=(5,5))
|
| 127 |
+
sc.pl.umap(full_adata_annot, color='new_anno', title='', legend_loc='on data',legend_fontsize='8', frameon=False,show=False, ax=axx11)
|
| 128 |
st.pyplot(fig11)
|
| 129 |
|
| 130 |
with col2:
|
| 131 |
fig12, axx12 = plt.subplots(figsize=(5,5))
|
| 132 |
+
#sc.pl.umap(full_adata_annot, color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
|
| 133 |
+
sc.pl.umap(full_adata_annot, color=selected_gene, title='', legend_loc='best', frameon=False,show=False,legend_fontsize='xx-small', ax=axx12)#,vmax='p99')
|
| 134 |
#plt.xticks(rotation = 45)
|
| 135 |
#plt.colorbar(cax=cax)
|
| 136 |
axx12.set_title(selected_gene, fontsize=12)
|
|
|
|
| 138 |
st.pyplot(fig12)
|
| 139 |
|
| 140 |
#Subset Younv and Old
|
| 141 |
+
adata_Young = full_adata_annot[full_adata_annot.obs['Age_group']=='young']
|
| 142 |
+
adata_Old = full_adata_annot[full_adata_annot.obs['Age_group']=='old']
|
| 143 |
|
| 144 |
#Young/Old but for cell_type
|
| 145 |
adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
|
|
|
|
| 194 |
with c1:
|
| 195 |
multi_genes = st.multiselect(
|
| 196 |
'Select Genes List',
|
| 197 |
+
all_genes_list)
|
| 198 |
with c2:
|
| 199 |
go_term = st.selectbox(
|
| 200 |
'Select GO Term',
|
| 201 |
+
all_path_ways)
|
| 202 |
with c3:
|
| 203 |
Choice = st.radio(
|
| 204 |
"",
|
|
|
|
| 209 |
if Choice=='Gene Set':
|
| 210 |
multi_genes = np.sort(multi_genes)
|
| 211 |
else:
|
| 212 |
+
multi_genes=full_go_table.loc[:,go_term]
|
| 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=full_adata_annot[:, multi_genes] #.to_df()
|
| 219 |
# #st.write(hmpdat)
|
| 220 |
# samples=hmpdat.obs.new_anno
|
| 221 |
# dfh = pd.DataFrame(hmpdat.X.toarray(), columns = multi_genes)
|
|
|
|
| 226 |
######
|
| 227 |
|
| 228 |
#col1,col2= st.columns([1,1])
|
| 229 |
+
#fig_szx=2*len(all_celltype_list)
|
| 230 |
#fig_szy=100*len(multi_genes)
|
| 231 |
#with col1:
|
| 232 |
fig11, axx11 = plt.subplots(figsize=(5, 5))
|
| 233 |
+
#sc.pl.umap(full_adata_annot, color='new_anno', title='', legend_loc='on data',legend_fontsize='8', frameon=False,show=False, ax=axx11)
|
| 234 |
+
axx11=sc.pl.dotplot(full_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)
|
| 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(full_adata_annot, color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
|
| 242 |
+
#sc.pl.umap(full_adata_annot, color=selected_gene, title=selected_gene, legend_loc='best', frameon=False,show=False,legend_fontsize='xx-small', ax=axx12)#,vmax='p99')
|
| 243 |
+
axx12=sc.pl.heatmap(full_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)
|
| 244 |
plt.xticks(rotation = 45)
|
| 245 |
#plt.xticks(rotation = 45)
|
| 246 |
#st.pyplot(fig12)
|
|
|
|
| 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(full_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])
|
| 256 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
| 257 |
# fig, ax2 = plt.subplots(1,2)
|
| 258 |
+
# ax2=sc.pl.heatmap(full_adata_annot, multi_genes, 'new_anno', vmin=-1, vmax=1, cmap='RdBu_r', dendrogram=True, swap_axes=True)
|
| 259 |
# st.pyplot(plt.gcf().set_size_inches(10, 10))
|
| 260 |
+
#ax[0]=sc.pl.dotplot(full_adata_annot,multi_genes,'new_anno',show=False)
|
| 261 |
#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
| 262 |
|
| 263 |
|
|
|
|
| 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(full_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)
|
| 270 |
+
# #ax_dict=sc.pl.dotplot(full_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)
|
| 271 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
| 272 |
+
# #ax2_dict=sc.pl.dotplot(full_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)
|
| 273 |
# fig, (ax2) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
|
| 274 |
+
# #ax2_dict=sc.pl.matrixplot(full_adata_annot, multi_genes, 'new_anno', vmin=-1, vmax=1, show=False, cmap='BuPu',dendrogram=True, swap_axes=True, ax=ax2)
|
| 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(full_adata_annot, multi_genes, groupby='new_anno', vmin=-1, vmax=1, cmap='BuPu', dendrogram=True, swap_axes=True)#,ax=ax2)
|
| 278 |
|
| 279 |
# st.pyplot(plt.gcf().set_size_inches(10, 15))
|
| 280 |
|