KeTuTu's picture
Upload 46 files
2999286 verified
raw
history blame
3.35 kB
import omicverse as ov
import scanpy as sc
import scvelo as scv
ov.utils.ov_plot_set()
ov.utils.download_pathway_database()
ov.utils.download_geneid_annotation_pair()
adata = scv.datasets.pancreas()
adata
adata.X.max()
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
adata.X.max()
pathway_dict=ov.utils.geneset_prepare('genesets/GO_Biological_Process_2021.txt',organism='Mouse')
##Assest one geneset
geneset_name='response to vitamin (GO:0033273)'
ov.single.geneset_aucell(adata,
geneset_name=geneset_name,
geneset=pathway_dict[geneset_name])
sc.pl.embedding(adata,
basis='umap',
color=["{}_aucell".format(geneset_name)])
##Assest more than one geneset
geneset_names=['response to vitamin (GO:0033273)','response to vitamin D (GO:0033280)']
ov.single.pathway_aucell(adata,
pathway_names=geneset_names,
pathways_dict=pathway_dict)
sc.pl.embedding(adata,
basis='umap',
color=[i+'_aucell' for i in geneset_names])
##Assest test geneset
ov.single.geneset_aucell(adata,
geneset_name='Sox',
geneset=['Sox17', 'Sox4', 'Sox7', 'Sox18', 'Sox5'])
sc.pl.embedding(adata,
basis='umap',
color=["Sox_aucell"])
##Assest all pathways
adata_aucs=ov.single.pathway_aucell_enrichment(adata,
pathways_dict=pathway_dict,
num_workers=8)
adata_aucs.obs=adata[adata_aucs.obs.index].obs
adata_aucs.obsm=adata[adata_aucs.obs.index].obsm
adata_aucs.obsp=adata[adata_aucs.obs.index].obsp
adata_aucs
adata_aucs.write_h5ad('data/pancreas_auce.h5ad',compression='gzip')
adata_aucs=sc.read('data/pancreas_auce.h5ad')
sc.pl.embedding(adata_aucs,
basis='umap',
color=geneset_names)
#adata_aucs.uns['log1p']['base']=None
sc.tl.rank_genes_groups(adata_aucs, 'clusters', method='t-test',n_genes=100)
sc.pl.rank_genes_groups_dotplot(adata_aucs,groupby='clusters',
cmap='Spectral_r',
standard_scale='var',n_genes=3)
degs = sc.get.rank_genes_groups_df(adata_aucs, group='Beta', key='rank_genes_groups', log2fc_min=2,
pval_cutoff=0.05)['names'].squeeze()
degs
import matplotlib.pyplot as plt
#fig, axes = plt.subplots(4,3,figsize=(12,9))
axes=sc.pl.embedding(adata_aucs,ncols=3,
basis='umap',show=False,return_fig=True,wspace=0.55,hspace=0.65,
color=['clusters']+degs.values.tolist(),
title=[ov.utils.plot_text_set(i,3,20)for i in ['clusters']+degs.values.tolist()])
axes.tight_layout()
adata.uns['log1p']['base']=None
sc.tl.rank_genes_groups(adata, 'clusters', method='t-test',n_genes=100)
res=ov.single.pathway_enrichment(adata,pathways_dict=pathway_dict,organism='Mouse',
group_by='clusters',plot=True)
ax=ov.single.pathway_enrichment_plot(res,plot_title='Enrichment',cmap='Reds',
xticklabels=True,cbar=False,square=True,vmax=10,
yticklabels=True,cbar_kws={'label': '-log10(qvalue)','shrink': 0.5,})