From 5ef29f4ef0b69ae438599c4c7f84eaedfb6f5268 Mon Sep 17 00:00:00 2001 From: Nigel Michki Date: Mon, 19 Sep 2022 15:14:08 -0400 Subject: [PATCH 1/2] Updated MARK to include pts, pts_rest keys in table for fraction of cells expressing gene. Also updated MARK to allow for minimum of 2 groups for comparison. --- VIPInterface.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/VIPInterface.py b/VIPInterface.py index e683f17..b3ef960 100644 --- a/VIPInterface.py +++ b/VIPInterface.py @@ -1001,21 +1001,21 @@ def MARK(data): keepG = [key for key,val in vCount.items() if val>2] adata = adata[adata.obs[data["grp"][0]].isin(keepG),:] - if len(adata.obs[data['grp'][0]].unique())<3: - return 'ERROR @server: {}'.format('Less than 3 groups in selected cells! Please use DEG for 2 groups') + if len(adata.obs[data['grp'][0]].unique())<2: + return 'ERROR @server: {}'.format('Less than 2 groups in selected cells! Please use DEG for 2 groups') #return json.dumps([[['name','scores'],['None','0']],Msg('Less than 3 groups in selected cells!Please use DEG for 2 groups')]) - sc.tl.rank_genes_groups(adata,groupby=data["grp"][0],n_genes=int(data['geneN']),method=data['markMethod'])# + sc.tl.rank_genes_groups(adata,groupby=data["grp"][0],n_genes=int(data['geneN']),method=data['markMethod'],pts=True)# ppr.pprint(int(data['geneN'])) - sc.pl.rank_genes_groups(adata,n_genes=int(data['geneN']),ncols=min([3,len(adata.obs[data['grp'][0]].unique())]),show=False) + sc.pl.rank_genes_groups(adata,n_genes=int(data['geneN']),ncols=min([2,len(adata.obs[data['grp'][0]].unique())]),show=False) fig =plt.gcf() gScore = adata.uns['rank_genes_groups'] #ppr.pprint(gScore) - pKeys = [i for i in ['names','scores','logfoldchanges','pvals','pvals_adj'] if i in gScore.keys()] + pKeys = [i for i in ['names','scores','logfoldchanges','pvals','pvals_adj','pts','pts_rest'] if i in gScore.keys()] scoreM = [pKeys+['Group']] - for i in gScore['scores'].dtype.names: - for j in range(len(gScore['scores'][i])): + for i in gScore['scores'].dtype.names: # iterate over groups + for j in range(len(gScore['scores'][i])): # iterate over gene index (int) one = [] for k in pKeys: if k=='logfoldchanges': @@ -1024,6 +1024,8 @@ def MARK(data): one += ['%.4E' % gScore[k][i][j]] elif k=='scores': one += ['%.4f' % gScore[k][i][j]] + elif k in ['pts', 'pts_rest']: + one += ['%.2f' % gScore[k].at[gScore['names'][i][j], i]] else: one += [gScore[k][i][j]] scoreM += [one+[i]] From 1be435b5e28c193696bced3541ea9fae28c1255f Mon Sep 17 00:00:00 2001 From: nigeil Date: Tue, 20 Sep 2022 15:05:41 -0400 Subject: [PATCH 2/2] Corrected logic for using minimum 2 groups in MARK function. Updated MARK error text. --- VIPInterface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VIPInterface.py b/VIPInterface.py index b3ef960..5e92c2f 100644 --- a/VIPInterface.py +++ b/VIPInterface.py @@ -1001,13 +1001,13 @@ def MARK(data): keepG = [key for key,val in vCount.items() if val>2] adata = adata[adata.obs[data["grp"][0]].isin(keepG),:] - if len(adata.obs[data['grp'][0]].unique())<2: - return 'ERROR @server: {}'.format('Less than 2 groups in selected cells! Please use DEG for 2 groups') + if (len(adata.obs[data['grp'][0]].unique())<2) and (data['markMethod']=="logreg"): + return 'ERROR @server: {}'.format('Less than 2 groups in selected cells! Please select a different method or use the DEG interface for 2 groups') #return json.dumps([[['name','scores'],['None','0']],Msg('Less than 3 groups in selected cells!Please use DEG for 2 groups')]) sc.tl.rank_genes_groups(adata,groupby=data["grp"][0],n_genes=int(data['geneN']),method=data['markMethod'],pts=True)# ppr.pprint(int(data['geneN'])) - sc.pl.rank_genes_groups(adata,n_genes=int(data['geneN']),ncols=min([2,len(adata.obs[data['grp'][0]].unique())]),show=False) + sc.pl.rank_genes_groups(adata,n_genes=int(data['geneN']),ncols=min([3,len(adata.obs[data['grp'][0]].unique())]),show=False) fig =plt.gcf() gScore = adata.uns['rank_genes_groups']