Skip to content

Commit

Permalink
add new
Browse files Browse the repository at this point in the history
  • Loading branch information
genecell committed Jul 31, 2024
1 parent 77f1a1e commit dd7deb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion piaso/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._runSVD import runSVD
from ._runSVD import runSVD, runSVDLazy

from ._runGDR import runGDR, predictCellTypeByGDR

Expand Down
32 changes: 21 additions & 11 deletions piaso/tools/_runGDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,29 @@ def runGDR(adata,
runSVDLazy(
adata,
copy=False,
n_components=n_dims,
n_components=n_svd_dims,
n_top_genes=n_highly_variable_genes,
use_highly_variable=use_highly_variable,
verbosity=verbosity,
batch_key=None,
trim_value=None,
key_added='X_svd'
)
### Because the verbosity will be reset in the above function
sc.settings.verbosity=0

### Run clustering
sc.pp.neighbors(adata,
use_rep='X_svd',
n_neighbors=15,random_state=10,knn=True,
method="umap")
sc.tl.leiden(adata, resolution=resolution, key_added='gdr_local')

groupby='gdr_local'


print('Number of clusters: ',len(np.unique(adata.obs[groupby])))
if verbosity>0:
print('Number of clusters: ',len(np.unique(adata.obs[groupby])))

### Run marker gene identification
if layer is None:
cosg.cosg(adata,
Expand All @@ -82,7 +87,7 @@ def runGDR(adata,
n_genes_user=n_gene,
groupby=groupby
)

marker_gene=pd.DataFrame(adata.uns['cosg']['names'])


Expand Down Expand Up @@ -128,7 +133,7 @@ def runGDR(adata,
### Store the cell barcodes info
cellbarcode_info=list()
for batch_i in batch_list:
adata_i=adata[adata.obs[batch_key]==batch_i]
adata_i=adata[adata.obs[batch_key]==batch_i].copy()

### Extract marker gene signatures
### Calculate clustering labels if no clustering info was specified
Expand All @@ -137,24 +142,29 @@ def runGDR(adata,
runSVDLazy(
adata_i,
copy=False,
n_components=n_dims,
n_components=n_svd_dims,
n_top_genes=n_highly_variable_genes,
use_highly_variable=use_highly_variable,
verbosity=verbosity,
batch_key=None,
trim_value=None,
key_added='X_svd'
)
### Because the verbosity will be reset in the above function, the good way is to remember the previous state of verbosity
sc.settings.verbosity=0

### Run clustering
sc.pp.neighbors(adata_i,
use_rep='X_svd',
n_neighbors=15,random_state=10,knn=True,
method="umap")
sc.tl.leiden(adata_i,resolution=resolution,key_added='gdr_local')
groupby='gdr_local'
groupby_i='gdr_local'
else:
groupby_i=groupby


print('Processing the batch ', batch_i ,' which contains ',len(np.unique(adata_i.obs[groupby])), ' clusters.')
if verbosity>0:
print('Processing the batch ', batch_i ,' which contains ',len(np.unique(adata_i.obs[groupby_i])), ' clusters.')
cellbarcode_info.append(adata_i.obs_names.values)
### Run marker gene identification
if layer is None:
Expand All @@ -166,7 +176,7 @@ def runGDR(adata,
expressed_pct=0.1,
remove_lowly_expressed=True,
n_genes_user=n_gene,
groupby=groupby
groupby=groupby_i
)
else:
cosg.cosg(adata_i,
Expand All @@ -175,7 +185,7 @@ def runGDR(adata,
expressed_pct=0.1,
remove_lowly_expressed=True,
n_genes_user=n_gene,
groupby=groupby
groupby=groupby_i
)

marker_gene=pd.DataFrame(adata_i.uns['cosg']['names'])
Expand Down

0 comments on commit dd7deb1

Please sign in to comment.