Skip to content

Commit 4b8c2d9

Browse files
author
Starlitnightly
committed
update omicverse to 1.3.1
### single module - add `get_celltype_marker` method in `single` - add `GLUE_pair`, `pyMOFA`, `pyMOFAART` module in `single` - add tutorial of `Multi omics analysis by MOFA and GLUE` - update tutorial of `Multi omics analysis by MOFA`
1 parent 126b312 commit 4b8c2d9

File tree

7 files changed

+835
-115
lines changed

7 files changed

+835
-115
lines changed

.DS_Store

2 KB
Binary file not shown.

omicverse/mofapy2/run/entry_point.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ def set_train_options(self,
671671
if gpu_mode:
672672
try:
673673
import cupy as cp
674+
674675
print("\nGPU mode is activated\n")
675676
except ImportError:
676677
print("\nGPU mode is activated, but GPU not found... switching to CPU mode")

omicverse/single/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"""
44

55
from ._cosg import cosg
6-
from ._anno import pySCSA,scanpy_lazy,scanpy_cellanno_from_dict
6+
from ._anno import pySCSA,scanpy_lazy,scanpy_cellanno_from_dict,get_celltype_marker
77
from ._nocd import scnocd
8-
from ._mofa import mofa,factor_exact,factor_correlation,get_weights
8+
from ._mofa import pyMOFAART,pyMOFA,GLUE_pair,factor_exact,factor_correlation,get_weights,glue_pair
99
from ._scdrug import autoResolution,writeGEP,Drug_Response
1010
from ._cpdb import cpdb_network_cal,cpdb_plot_network,cpdb_plot_interaction,cpdb_interaction_filtered,cpdb_submeans_exacted
1111
from ._scgsea import geneset_aucell,pathway_aucell,pathway_aucell_enrichment,pathway_enrichment,pathway_enrichment_plot

omicverse/single/_anno.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,38 @@ def scanpy_cellanno_from_dict(adata:anndata.AnnData,
275275
adata.obs[anno_name+'_celltype'] = adata.obs[clustertype].map(anno_dict).astype('category')
276276
print('...cell type added to {}_celltype on obs of anndata'.format(anno_name))
277277

278+
def get_celltype_marker(adata:anndata.AnnData,
279+
clustertype:str='leiden',
280+
log2fc_min:int=2,scores_type='scores',
281+
pval_cutoff:float=0.05,rank:bool=False)->dict:
282+
r"""Get marker genes for each clusters.
283+
284+
Arguments:
285+
adata: anndata object
286+
clustertype: Clustering name used in scanpy. (leiden)
287+
log2fc_min: Minimum log2 fold change of marker genes. (2)
288+
pval_cutoff: Maximum p value of marker genes. (0.05)
289+
rank: Whether to rank genes by wilcoxon test. (True)
290+
scores_type: The type of scores. can be selected from `scores` and `logfoldchanges`
291+
292+
Returns:
293+
cellmarker: A dictionary of marker genes for each clusters.
294+
"""
295+
print('...get cell type marker')
296+
celltypes = sorted(adata.obs[clustertype].unique())
297+
cell_marker_dict={}
298+
if rank==False:
299+
sc.tl.rank_genes_groups(adata, clustertype, method='wilcoxon')
300+
for celltype in celltypes:
301+
degs = sc.get.rank_genes_groups_df(adata, group=celltype, key='rank_genes_groups', log2fc_min=log2fc_min,
302+
pval_cutoff=pval_cutoff)
303+
foldp=np.histogram(degs[scores_type])
304+
foldchange=(foldp[1][np.where(foldp[1]>0)[0][-5]]+foldp[1][np.where(foldp[1]>0)[0][-6]])/2
305+
306+
cellmarker=degs.loc[degs[scores_type]>foldchange]['names'].values
307+
cell_marker_dict[celltype]=cellmarker
308+
309+
return cell_marker_dict
278310

279311
class pySCSA(object):
280312

@@ -433,7 +465,7 @@ def cell_auto_anno(self,adata:anndata.AnnData,clustertype:str='leiden')->None:
433465

434466
def get_celltype_marker(self,adata:anndata.AnnData,
435467
clustertype:str='leiden',
436-
log2fc_min:int=2,
468+
log2fc_min:int=2,scores_type='scores',
437469
pval_cutoff:float=0.05,rank:bool=True)->dict:
438470
r"""Get marker genes for each clusters.
439471
@@ -443,22 +475,15 @@ def get_celltype_marker(self,adata:anndata.AnnData,
443475
log2fc_min: Minimum log2 fold change of marker genes. (2)
444476
pval_cutoff: Maximum p value of marker genes. (0.05)
445477
rank: Whether to rank genes by wilcoxon test. (True)
478+
scores_type: The type of scores. can be selected from `scores` and `logfoldchanges`
446479
447480
Returns:
448481
cellmarker: A dictionary of marker genes for each clusters.
449482
"""
450483
print('...get cell type marker')
451-
celltypes = sorted(adata.obs[clustertype].unique())
452-
cell_marker_dict={}
453-
if rank==False and 'rank_genes_groups' in adata.uns.keys():
454-
sc.tl.rank_genes_groups(adata, clustertype, method='wilcoxon')
455-
for celltype in celltypes:
456-
degs = sc.get.rank_genes_groups_df(adata, group=celltype, key='rank_genes_groups', log2fc_min=log2fc_min,
457-
pval_cutoff=pval_cutoff)
458-
foldp=np.histogram(degs['scores'])
459-
foldchange=(foldp[1][np.where(foldp[1]>0)[0][-5]]+foldp[1][np.where(foldp[1]>0)[0][-6]])/2
460-
461-
cellmarker=degs.loc[degs['scores']>foldchange]['names'].values
462-
cell_marker_dict[celltype]=cellmarker
484+
cell_marker_dict=get_celltype_marker(adata=adata,
485+
clustertype=clustertype,
486+
log2fc_min=log2fc_min,scores_type=scores_type,
487+
pval_cutoff=pval_cutoff,rank=rank)
463488

464489
return cell_marker_dict

0 commit comments

Comments
 (0)