diff --git a/gssnng/score_cells.py b/gssnng/score_cells.py index 3fbd376..69eae1e 100644 --- a/gssnng/score_cells.py +++ b/gssnng/score_cells.py @@ -81,7 +81,7 @@ def run_gssnng( samp_neighbors = None error_checking(mat, samp_neighbors, recompute_neighbors, - gs_obj, score_method, ranked, method_params) + gs_obj, score_method, ranked, method_params, 0) if method_params == None: method_params = dict() @@ -154,7 +154,7 @@ def with_gene_sets( samp_neighbors = None error_checking(adata, samp_neighbors, recompute_neighbors, - gs_obj, score_method, ranked, method_params) + gs_obj, score_method, ranked, method_params, 0) if method_params == None: method_params = dict() diff --git a/gssnng/smooth_anndatas.py b/gssnng/smooth_anndatas.py index 6f10803..f76f34e 100644 --- a/gssnng/smooth_anndatas.py +++ b/gssnng/smooth_anndatas.py @@ -1,6 +1,6 @@ import anndata from gssnng.score_cells import _proc_data -#from gssnng.util import error_checking +from gssnng.util import error_checking from typing import Union def smooth_anndata( @@ -34,16 +34,18 @@ def smooth_anndata( return_data = 1 noise_trials = 0 ### not used currently - samp_neighbors = None + samp_neighbors = None ### also not used + just_smoothing=1 - #error_checking2(adata, recompute_neighbors, method_params) # UPDATE + error_checking(adata, samp_neighbors, recompute_neighbors, + None, None, None, method_params, just_smoothing) if method_params == None: method_params = dict() # score each cell with the list of gene sets data_list = _proc_data(adata, None, groupby, smooth_mode, recompute_neighbors, - None, method_params, None, + None, method_params, samp_neighbors, noise_trials, None, cores, return_data) print("**done**") diff --git a/gssnng/util.py b/gssnng/util.py index b155e89..5a2a104 100644 --- a/gssnng/util.py +++ b/gssnng/util.py @@ -14,7 +14,8 @@ def error_checking( gs_obj, score_method, ranked, - method_params + method_params, + just_smoothing ): """ QC on the adata. Need to make sure there's enough neighbors available given the sampling size. @@ -23,30 +24,33 @@ def error_checking( :param samp_neighbors: integer, number of neighbors to sample """ - if type(method_params) != type(dict()): - raise Exception('ERROR: please use a dictionary to pass method params') - - if any([xi in adata.obs.columns for xi in gs_obj.get_gs_names()]): - #raise Exception('ERROR: gene set names in columns of adata.obs, please drop.') - print("Warning! Dropping gene set names from obs!") - genesetlist = [x.name for x in gs_obj.set_list] - for gsi in genesetlist: - print('dropping: ' + gsi) - adata.obs.drop(columns=[gsi], inplace=True) - if 'gssnng_groupby' in adata.obs.columns: adata.obs.drop(columns='gssnng_groupby', inplace=True) #raise Exception("Error: please drop 'gssnng_groupby' as a column name.") print('... and dropping gssnng_groupby column...') - if ranked == False and score_method == 'singscore': - raise Exception('ERROR: singscore requires ranked data, set ranked parameter to True') - if (recompute_neighbors == None) or (recompute_neighbors == 0): n_neighbors = adata.uns['neighbors']['params']['n_neighbors'] #[0]# in older AnnData versions need this?? else: n_neighbors = recompute_neighbors + if just_smoothing == 0: + # then do all other checks + if type(method_params) != type(dict()): + raise Exception('ERROR: please use a dictionary to pass method params') + + if any([xi in adata.obs.columns for xi in gs_obj.get_gs_names()]): + #raise Exception('ERROR: gene set names in columns of adata.obs, please drop.') + print("Warning! Dropping gene set names from obs!") + genesetlist = [x.name for x in gs_obj.set_list] + for gsi in genesetlist: + print('dropping: ' + gsi) + adata.obs.drop(columns=[gsi], inplace=True) + + if ranked == False and score_method == 'singscore': + raise Exception('ERROR: singscore requires ranked data, set ranked parameter to True') + + #if n_neighbors < samp_neighbors: # print('*******') # print('WARNING: Number of neighbors too low for sampling parameter!')