You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Additional function parameters / changed functionality / changed defaults?
Please describe your wishes
Hi scanpy and thank you for your work :-) ,
I created a small function to export rank_gene_groups genes to panda Dataframes, so I'm proposing it:
Here is the code:
def get_df_of_rank_gene_groups(adata, key):
"""Returns a dictionnary containing the differentially expressed genes in "key" in dataframes."""
rgg=adata.uns[key].copy()
if "params" in rgg :
params=rgg.pop("params")
groups=list(rgg["names"].dtype.names)
d_return={}
for g in groups :
df_g = pd.DataFrame({key:rgg.get(key)[g]for key in rgg.keys() if key not in ["pts", "pts_rest"]},
columns= rgg.keys())
df_g.index=df_g.pop("names")
if "pts" in rgg.keys():
df_g.pop("pts")
if "pts_rest" in rgg.keys():
df_g.pop("pts_rest")
pts_df=pd.DataFrame({"pts":rgg.get("pts")[g],"pts_rest":rgg.get("pts_rest")[g]}, index=adata.var_names )
else:
pts_ref=rgg.get("pts")[rgg.get("pts").columns.difference(rgg["names"].dtype.names)]
pts_df=pd.DataFrame({"pts":rgg.get("pts")[g], "pts_rest":pts_ref.iloc[:,0]}, index=adata.var_names )
df_g=pd.concat([df_g,pts_df], axis=1)
d_return[g]=df_g
if len(groups) > 1:
return d_return
else :
return d_return[groups[0]]
Depending on the number of groups, it returns a dictionnary, or a single dataframe, with genes names, pvalues and proportions of cells expressing.
I'm sure it needs improvments but it can really be useful to export DEGs for publication or sharing.
Best
The text was updated successfully, but these errors were encountered:
Hi, I'm not a maintainer of scanpy, just happened to see this. Are you aware of sc.get.rank_genes_groups_df? What additional functionality does your code add and could this be implemented as a change to the existing function?
Hi,
Thank you Malte! No I was not aware of that one in the get module ! And I believe it does everything we need as it seems to also incluse pts.
So all good !
What kind of feature would you like to request?
Additional function parameters / changed functionality / changed defaults?
Please describe your wishes
Hi scanpy and thank you for your work :-) ,
I created a small function to export rank_gene_groups genes to panda Dataframes, so I'm proposing it:
Here is the code:
Depending on the number of groups, it returns a dictionnary, or a single dataframe, with genes names, pvalues and proportions of cells expressing.
I'm sure it needs improvments but it can really be useful to export DEGs for publication or sharing.
Best
The text was updated successfully, but these errors were encountered: