Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MARK to include pts, pts_rest keys in marker gene table #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions VIPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,21 +1139,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) 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'])#
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)
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':
Expand All @@ -1162,6 +1162,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]]
Expand Down