Spaces:
Sleeping
Sleeping
File size: 21,239 Bytes
16c6962 f88cb30 16c6962 f88cb30 16c6962 f88cb30 16c6962 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
import os
import numpy as np
import pandas as pd
import streamlit as st
import scanpy as sc
#import mpld3
import matplotlib.pyplot as plt
#import seaborn as sns
#import streamlit.components.v1 as components
#from IPython.display import Markdown as md
from functions import pathway_analyses
# SMALL_SIZE = 2
# MEDIUM_SIZE = 2
# BIGGER_SIZE = 2
# plt.rc('font', size=SMALL_SIZE) # controls default text sizes
# plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title
# plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
# plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
# plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
# plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
# plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
sc.settings.set_figure_params(dpi=80, facecolor='white')
#disable st.pyplot warning
st.set_page_config(layout="wide")
st.markdown(
"""
<style>
.streamlit-expanderHeader {
font-size: x-large;
}
</style>
""",
unsafe_allow_html=True,
)
m=st.markdown("""
<style>
div.stTitle {
font-size:40px;
}
</style>"""
,unsafe_allow_html=True)
st.set_option('deprecation.showPyplotGlobalUse', False)
#load Data
cwd=os.getcwd()+'/'#+'data/'
@st.cache_data
def get_data():
if 'adata_annot' not in st.session_state:
adata_annot = sc.read_h5ad(cwd+'multiregion_brainaging_annotated.h5ad')
st.session_state['adata_annot'] = adata_annot
if 'genes_list' not in st.session_state:
genes=adata_annot.var.index
#genes_list=sorted(genes.unique())
st.session_state['genes_list'] = sorted(genes.unique())
if 'cell_type' not in st.session_state:
#cell_type=diff_fdr[diff_fdr.type=='cell_type']['tissue']
#cell_type=sorted(cell_type.unique())
anno=adata_annot.obs.new_anno
#cell_type=sorted(anno.unique())
st.session_state['cell_type'] = sorted(anno.unique())
if 'broad_type' not in st.session_state:
broad_celltype=adata_annot.obs.broad_celltype
#broad_type=sorted(broad_type.unique())
st.session_state['broad_type'] = sorted(broad_celltype.unique())
#Also load Go Terms
if 'go_table' not in st.session_state:
bp = pathway_analyses.read_pathways('pathway_databases/GO_Biological_Process_2021.txt')
# cy = pathway_analyses.read_pathways('pathway_databases/HumanCyc_2016.txt')
# ke = pathway_analyses.read_pathways('pathway_databases/KEGG_2019_Human.txt')
# re = pathway_analyses.read_pathways('pathway_databases/Reactome_2016.txt')
# all_paths = pd.concat([bp, cy, ke, re], join='outer', axis=0, ignore_index=True)
# all_paths.set_index(0, inplace=True)
# all_paths.fillna("", inplace=True)
# all_paths_dict = all_paths.to_dict(orient='index')
go_bp_paths = bp.set_index(0)
go_bp_paths.fillna("", inplace=True)
go_bp_paths_dict = go_bp_paths.to_dict(orient='index')
gene_set_by_path = {key: [val for val in value.values() if val != ""] for key, value in go_bp_paths_dict.items()}
gene_set_by_path = pd.DataFrame.from_dict(gene_set_by_path, orient='index').transpose()
st.session_state['path_ways']=gene_set_by_path.columns
st.session_state['go_table']=gene_set_by_path
#done load Data
#st.title('Single nuclei atlas of human aging in brain regions')
st.title('Brain Age Browser')
#genes_list,adata_annot=get_data()
get_data()
tab1, tab2,readme = st.tabs(["Gene Expression by CellType", "Age associations for multiple genes", "README"])
data = np.random.randn(10, 1)
with tab1:
with st.form(key='columns_in_form'):
#c1, c2, c3 = st.columns([4,4,2])
c1, c2 = st.columns(2)
with c1:
selected_gene = st.selectbox(
'Please select a gene',
st.session_state['genes_list'])
with c2:
selected_celltype = st.selectbox(
'Please select CellType',
st.session_state['cell_type']
)
# with c3:
# plot_choice = st.checkbox(
# "Which Plots",
# ('Gene','Old/Young'))
Updated=st.form_submit_button(label = 'Go')
if not isinstance(selected_gene, type(None)) and not isinstance(selected_celltype, type(None)) and Updated:
# fig11, axx1 = plt.subplots()
# 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)
# st.pyplot(plt.gcf().set_size_inches(4, 4))
col1,col2= st.columns([1,1])
with col1:
fig11, axx11 = plt.subplots(figsize=(5,5))
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)
st.pyplot(fig11)
with col2:
fig12, axx12 = plt.subplots(figsize=(5,5))
#sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
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')
#plt.xticks(rotation = 45)
st.pyplot(fig12)
#Subset Younv and Old
adata_Young = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='young']
adata_Old = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='old']
#Young/Old but for cell_type
adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
adata_OldAst = adata_Old[adata_Old.obs['new_anno']==selected_celltype]
# # #Young/Old but for cell_type
# # adata_YoungAst = adata_Young[adata_Young.obs['broad_celltype']==selected_celltype]
# # adata_OldAst = adata_Old[adata_Old.obs['broad_celltype']==selected_celltype]
#Young
dot_size=.05
col1,col2= st.columns([1,1])
with col1:
#st.markdown('<div style="text-align: center;">**Young**</div>', unsafe_allow_html=True)
str_title='Young: '+selected_gene
#st.markdown("<h3 style='text-align: center; color: red;'>str_title</h3>", unsafe_allow_html=True)
st.markdown("# {} ".format(str_title))#,align_text='center')
#md("# {} ".format(str_title))
fig21, axx21 = plt.subplots(figsize=(1,1))
#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)
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)
#st.pyplot(fig21)
st.pyplot(plt.gcf())
with col2:
str_title='Young: '+selected_gene+" ("+selected_celltype+")"
st.markdown("# {} ".format(str_title))#,align_text='center')
fig22, axx22 = plt.subplots(figsize=(1,1))
#sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
#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')
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)
#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)
#plt.xticks(rotation = 45)
#st.pyplot(fig22)
st.pyplot(plt.gcf())
#Old
col1,col2= st.columns([1,1])
with col1:
str_title='Old: '+selected_gene+" ("+selected_celltype+")"
st.markdown("# {} ".format(str_title))#,align_text='center')
fig31, axx31 = plt.subplots(figsize=(1,1))
#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)
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)
st.pyplot(fig31)
with col2:
str_title='Old: '+selected_gene+" ("+selected_celltype+")"
st.markdown("# {} ".format(str_title))#,align_text='center')
fig32, axx32 = plt.subplots(figsize=(1,1))
#sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
#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')
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)
#plt.xticks(rotation = 45)
st.pyplot(fig32)
# fig, ax = plt.subplots(3,2)
# sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=ax[0,0])
# 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')
# #Subset Younv and Old
# adata_Young = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='young']
# adata_Old = st.session_state['adata_annot'][st.session_state['adata_annot'].obs['Age_group']=='old']
# 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])
# 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])
# # #Young/Old but for cell_type
# # adata_YoungAst = adata_Young[adata_Young.obs['broad_celltype']==selected_celltype]
# # adata_OldAst = adata_Old[adata_Old.obs['broad_celltype']==selected_celltype]
# #Young/Old but for cell_type
# adata_YoungAst = adata_Young[adata_Young.obs['new_anno']==selected_celltype]
# adata_OldAst = adata_Old[adata_Old.obs['new_anno']==selected_celltype]
# 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])
# 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])
# #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])
# #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])
# #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])
# st.pyplot(plt.gcf().set_size_inches(15, 30))
with tab2:
with st.form(key='multiselect_form'):
c1, c2, c3 = st.columns([4,4,2])
with c1:
multi_genes = st.multiselect(
'Select Genes List',
st.session_state['genes_list'])
with c2:
go_term = st.selectbox(
'Select GO Term',
st.session_state['path_ways'])
with c3:
Choice = st.radio(
"",
('Gene Set','GO Term'))
Updated_tab2=st.form_submit_button(label = 'Show Results')
if not isinstance(multi_genes, type(None)) and Updated_tab2:
if Choice=='Gene Set':
multi_genes = np.sort(multi_genes)
else:
multi_genes=st.session_state['go_table'].loc[:,go_term]
multi_genes=multi_genes.dropna().values
#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']
#########
#sns.clustermap(st.session_state['adata_annot'], figsize=(14,12),
# pivot_kws={'index': 'country',
# 'columns': 'year',
# 'values': 'lifeExp'})
# col1,col2= st.columns([1,1])
# #fig_szx=2*len(st.session_state['cell_type'])
# #fig_szy=100*len(multi_genes)
# with col1:
# figa, axxaa = plt.subplots(figsize=(5, 5))
# #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)
# 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)
# #st.pyplot(fig11)
# #st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
# st.pyplot(plt.gcf())
col1,col2= st.columns([1,1])
#fig_szx=2*len(st.session_state['cell_type'])
#fig_szy=100*len(multi_genes)
with col1:
fig11, axx11 = plt.subplots(figsize=(5, 5))
#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)
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)
#st.pyplot(fig11)
#st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
st.pyplot(plt.gcf())
with col2:
fig12, axx12 = plt.subplots(figsize=(5, 5))
#sc.pl.umap(st.session_state['adata_annot'], color='new_anno', title='', legend_loc='on data', frameon=False,show=False, ax=axx2)
#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')
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)
#plt.xticks(rotation = 45)
#st.pyplot(fig12)
#st.pyplot(plt.gcf().set_size_inches(fig_szx, fig_szy))
st.pyplot(plt.gcf())
#######
#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']
#multi_genes=np.sort(multi_genes)
# fig, ax1 = plt.subplots(1,2)
# 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])
# st.pyplot(plt.gcf().set_size_inches(10, 10))
# fig, ax2 = plt.subplots(1,2)
# 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)
# st.pyplot(plt.gcf().set_size_inches(10, 10))
#ax[0]=sc.pl.dotplot(st.session_state['adata_annot'],multi_genes,'new_anno',show=False)
#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,4), gridspec_kw={'wspace':0.9})
#commented these-working ones
# fig, (ax1) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
# #ax = plt.subplot()
# 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)
# #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)
# st.pyplot(plt.gcf().set_size_inches(10, 15))
# #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)
# fig, (ax2) = plt.subplots(1, 1, figsize=(20,4), gridspec_kw={'wspace':0.9})
# #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)
# #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))
# 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)
# st.pyplot(plt.gcf().set_size_inches(10, 15))
with readme:
expander = st.expander("How to use this app")
#st.header('How to use this app')
expander.markdown('Please select **Results Menue** checkbox from the sidebar')
expander.markdown('Select a Gene from the dropdown list')
expander.markdown('A table showing all reference gudies from three LISTS will appear in the main panel')
expander.markdown('To see results for each of the selected reference guide from ListA, ListB and ListC, Please select respective checkbox')
expander.markdown('Results are shown as two tables, **MATCHED** and **MUTATED** guides tables and **NOT FOUND** table if guides are not found in GRCh38 and LR reference fasta files')
expander.markdown('**MATCHED** guides table shows the genomic postion in GRCh38 and LR Fasta file along other fields. **If a guide is found in GRCh38 but not in LR fasta, then corresponding columns will be NA**')
expander.markdown('**MUTATED** guides table shows the genomic postion in GRCh38 and LR Fasta file along other fields. **If a guide is found in GRCh38 but not in LR fasta, then corresponding columns will be NA**')
expander1 = st.expander('Introduction')
expander1.markdown(
""" This app helps navigate all probable genomic **miss-matched/Mutations (upto 2 bp)** for a given sgRNA (from 3 lists of CRISPRi dual sgRNA libraries) in GRCh38 reference fasta and a Reference fasta generated from BAM generated against KOLF2.1J longread data.
"""
)
expander1.markdown('Merged bam file was converted to fasta file using following steps:')
expander1.markdown('- samtools mpileup to generate bcf file')
expander1.markdown('- bcftools to generate vcf file')
expander1.markdown('- bcftools consensus to generate fasta file')
expander1.markdown('A GPU based [Cas-OFFinder](http://www.rgenome.net/cas-offinder/) tool was used to find off-target sequences (upto 2 miss-matched) for each geiven reference guide against GRCh38 and LR fasta references.')
css = '''
<style>
.stTabs [data-baseweb="tab-list"] button [data-testid="stMarkdownContainer"] p {
font-size:1.5rem;
}
</style>
'''
st.markdown(css, unsafe_allow_html=True) |