Skip to content

Commit

Permalink
Fixed the error of log_init in gsea_obj.enrichment (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlitnightly committed Oct 9, 2024
1 parent 985583e commit bb2c694
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
12 changes: 8 additions & 4 deletions omicverse/externel/gseapy/gsea.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def __init__(self, data, gene_sets, classes, outdir='GSEA_output',
self._noplot=no_plot
# init logger
logfile = self.prepare_outdir()
self._logger = log_init(outlog=logfile,
self._logger = log_init(name='gseapy',
filename=logfile,
log_level=logging.INFO if self.verbose else logging.WARNING)

def load_data(self, cls_vec):
Expand Down Expand Up @@ -481,7 +482,8 @@ def __init__(self, rnk, gene_sets, outdir='GSEA_prerank',
self._noplot=no_plot
# init logger
logfile = self.prepare_outdir()
self._logger = log_init(outlog=logfile,
self._logger = log_init(name='gseapy',
filename=logfile,
log_level=logging.INFO if self.verbose else logging.WARNING)


Expand Down Expand Up @@ -558,7 +560,8 @@ def __init__(self, data, gene_sets, outdir="GSEA_SingleSample", sample_norm_meth
# init logger

logfile = self.prepare_outdir()
self._logger = log_init(outlog=logfile,
self._logger = log_init(name='gseapy',
filename=logfile,
log_level=logging.INFO if self.verbose else logging.WARNING)

def corplot(self):
Expand Down Expand Up @@ -814,7 +817,8 @@ def __init__(self, indir, outdir='GSEApy_Replot', weighted_score_type=1,
# init logger
mkdirs(self.outdir)
outlog = os.path.join(self.outdir,"gseapy.%s.%s.log"%(self.module,"run"))
self._logger = log_init(outlog=outlog,
self._logger = log_init(name='gseapy',
filename=logfile,
log_level=logging.INFO if self.verbose else logging.WARNING)
def run(self):
"""main replot function"""
Expand Down
1 change: 1 addition & 0 deletions omicverse/single/_SCSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ def get_cell_matrix_detail(self,exps,ltitle,fid,gcol,ccol,usertag,abs_tag):
#print(rownames)
#print(colnames)
#print(cell_matrix)


if self.noprint == False:
if usertag:
Expand Down
34 changes: 34 additions & 0 deletions omicverse/space/_cast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from scipy.sparse import csr_matrix,issparse
import numpy as np
import os
from tqdm import tqdm
import pandas as pd

def CAST(adata,sample_key=None,basis='spatial',layer='norm_1e4',
output_path = 'output/CAST_Mark',gpu_t=0,device='cuda:0',**kwargs):
if issparse(adata.obsm[basis]):
adata.obsm[basis]=adata.obsm[basis].toarray()
adata.obs['x'] = adata.obsm[basis][:,0]
adata.obs['y'] = adata.obsm[basis][:,1]


# Get the coordinates and expression data for each sample
samples = np.unique(adata.obs[sample_key]) # used samples in adata
coords_raw = {sample_t: np.array(adata.obs[['x','y']])[adata.obs[sample_key] == sample_t] for sample_t in samples}
exp_dict = {sample_t: adata[adata.obs[sample_key] == sample_t].layers['norm_1e4'] for sample_t in samples}


os.makedirs(output_path, exist_ok=True)

from ..externel.CAST import CAST_MARK
embed_dict = CAST_MARK(coords_raw,exp_dict,output_path,gpu_t=gpu_t,device=device,**kwargs)


adata.obsm['X_cast']=np.zeros((adata.shape[0],512))

adata.obsm['X_cast']=pd.DataFrame(adata.obsm['X_cast'],index=adata.obs.index)
for key in tqdm(embed_dict.keys()):
adata.obsm['X_cast'].loc[adata.obs[sample_key]==key]+=embed_dict[key].cpu().numpy()
adata.obsm['X_cast']=adata.obsm['X_cast'].values
print('CAST embedding is saved in adata.obsm[\'X_cast\']')
#adata.obs['cast_clusters']=adata.obs['cast_clusters'].astype('category')
8 changes: 7 additions & 1 deletion omicverse_guide/docs/Release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,10 @@ Support Raw Windows platform
### PP Module

- Fixed a return bugs in `pp.regress_and_scale` (#156)
- Fixed a scanpy version error when using `ov.pp.pca` (#154)
- Fixed a scanpy version error when using `ov.pp.pca` (#154)

## v 1.6.8

### Bulk Module

- Fixed the error of log_init in gsea_obj.enrichment (#184)

0 comments on commit bb2c694

Please sign in to comment.