Skip to content

Commit

Permalink
Added ForbiddenCity color system
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlitnightly committed Oct 27, 2024
1 parent 65047b1 commit 4506f02
Show file tree
Hide file tree
Showing 13 changed files with 4,658 additions and 19 deletions.
7 changes: 4 additions & 3 deletions omicverse/bulk/_Enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def geneset_plot(enrich_res,num:int=10,node_size:list=[5,10,15],
figsize:tuple=(2,4),cmap:str='YlGnBu',
text_knock:int=5,text_maxsize:int=20,
bbox_to_anchor_used:tuple=(-0.45, -13),node_diameter:int=10,
custom_ticks:list=[5,10])->matplotlib.axes._axes.Axes:
custom_ticks:list=[5,10],ax=None)->matplotlib.axes._axes.Axes:
"""
Plot the gene set enrichment result.
Expand All @@ -247,7 +247,8 @@ def geneset_plot(enrich_res,num:int=10,node_size:list=[5,10,15],
A matplotlib.axes.Axes object.
"""
fig, ax = plt.subplots(figsize=figsize)
if ax is None:
fig, ax = plt.subplots(figsize=figsize)
plot_data2=enrich_res.sort_values('P-value')[:num].sort_values('logc')
st=ax.scatter(plot_data2['fraction'],range(len(plot_data2['logc'])),
s=plot_data2['num']*node_diameter,linewidths=1,edgecolors='black',c=plot_data2['logp'],cmap=cmap)
Expand All @@ -258,7 +259,7 @@ def geneset_plot(enrich_res,num:int=10,node_size:list=[5,10,15],
plt.title(fig_title,fontsize=12)
plt.xlabel(fig_xlabel,fontsize=12)

#fig = plt.gcf()
fig = plt.gcf()
cax = fig.add_axes(cax_loc)
cb=fig.colorbar(st,shrink=0.25,cax=cax,orientation='horizontal')
cb.set_label(r'$−Log_{10}(P_{adjusted})$',fontdict={'size':cax_fontsize})
Expand Down
9 changes: 5 additions & 4 deletions omicverse/pl/_cpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ def cpdb_chord(adata:anndata.AnnData,interaction_edges:pd.DataFrame,
def cpdb_heatmap(adata:anndata.AnnData,interaction_edges:pd.DataFrame,
celltype_key:str,nodecolor_dict=None,ax=None,
source_cells=None,target_cells=None,
figsize=(3,3),fontsize=11,rotate=False,
legend_kws={'fontsize':8,'bbox_to_anchor':(5, -0.5),'loc':'center left',},return_table=False,**kwargs):
figsize=(3,3),fontsize=11,rotate=False,legend=True,
legend_kws={'fontsize':8,'bbox_to_anchor':(5, -0.5),'loc':'center left',},
return_table=False,**kwargs):

if nodecolor_dict!=None:
type_color_all=nodecolor_dict
Expand Down Expand Up @@ -297,7 +298,7 @@ def cpdb_heatmap(adata:anndata.AnnData,interaction_edges:pd.DataFrame,
show_colnames=False,
row_dendrogram=False,
col_names_side='left',
legend=True,
legend=legend,
**kwargs
#cmap_legend_kws={'font':12},
)
Expand All @@ -319,7 +320,7 @@ def cpdb_heatmap(adata:anndata.AnnData,interaction_edges:pd.DataFrame,
show_colnames=False,
row_dendrogram=False,
col_names_side='top',
legend=True,
legend=legend,
**kwargs
#cmap_legend_kws={'font':12},
)
Expand Down
29 changes: 25 additions & 4 deletions omicverse/pl/_flowsig.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def plot_curve_network(G: nx.Graph, G_type_dict: dict, G_color_dict: dict, pos_t
label_verticalalignment: str = 'center_baseline', label_fontsize: int = 12,
label_fontfamily: str = 'Arial', label_fontweight: str = 'bold', label_bbox=None,
legend_bbox: tuple = (0.7, 0.05), legend_ncol: int = 3, legend_fontsize: int = 12,
legend_fontweight: str = 'bold', curve_awarg=None,ylim=(-0.5,0.5),xlim=(-3,3)):
legend_fontweight: str = 'bold', curve_awarg=None,ylim=(-0.5,0.5),xlim=(-3,3),ax=None):
"""
Plot network graph.
Expand Down Expand Up @@ -91,7 +91,10 @@ def plot_curve_network(G: nx.Graph, G_type_dict: dict, G_color_dict: dict, pos_t
curve_awarg: dict, arguments for curved graph
"""
from adjustText import adjust_text
fig, ax = plt.subplots(figsize=figsize)
if ax is None:
fig, ax = plt.subplots(figsize=figsize)
else:
fig = ax.figure

# Determine node positions
if pos_type == 'spring':
Expand Down Expand Up @@ -202,6 +205,12 @@ def plot_flowsig_network(flow_network,
gem_li=[i for i in flow_network.nodes if 'GEM' in i]
receptor_li=[i for i,j in flow_network.edges if ('GEM' in j)and('GEM' not in i)]
sender_li=[j for i,j in flow_network.edges if ('GEM' in i)and('GEM' not in j)]
for g in gem_li:
flow_network.nodes[g]['type']='module'
for g in receptor_li:
flow_network.nodes[g]['type']='inflow'
for g in sender_li:
flow_network.nodes[g]['type']='outflow'
#gene_li=[i for i in flow_network.nodes if 'GEM' not in i]
G_type_dict=dict(zip(gem_li+receptor_li+sender_li,
['GEM' for i in range(len(gem_li))]+\
Expand All @@ -213,7 +222,10 @@ def plot_flowsig_network(flow_network,
sender_li=[j for i,j in flow_network.edges if ('GEM' in i)and('GEM' not in j)]
#gene_li=[i for i in flow_network.nodes if 'GEM' not in i]
if len(gem_li)<28:
from ._palette import sc_color
sc_color=['#7CBB5F','#368650','#A499CC','#5E4D9A','#78C2ED','#866017', '#9F987F','#E0DFED',
'#EF7B77', '#279AD7','#F0EEF0', '#1F577B', '#A56BA7', '#E0A7C8', '#E069A6', '#941456', '#FCBC10',
'#EAEFC5', '#01A0A7', '#75C8CC', '#F0D7BC', '#D5B26C', '#D5DA48', '#B6B812', '#9DC3C3', '#A89C92', '#FEE00C', '#FEF2A1']

G_color_dict=dict(zip(gem_li+receptor_li+sender_li,
[sc_color[i] for i in range(len(gem_li))]+\
['#c2c2c2' for i in range(len(receptor_li))]+\
Expand All @@ -227,7 +239,16 @@ def plot_flowsig_network(flow_network,

#G = nx.Graph([(0, 1), (1, 2), (1, 3), (3, 4)])
import networkx as nx
layers = {"layer1": list(set(sender_li)), "layer3": list(set(receptor_li)),"layer2": list(set(gem_li)),}
if len(sender_li)==0 and len(receptor_li)>0:
layers = { "layer3": list(set(receptor_li)),
"layer2": list(set(gem_li)),}
elif len(sender_li)>0 and len(receptor_li)==0:
layers = {"layer1": list(set(sender_li)),
"layer3": list(set(gem_li))}
else:
layers = {"layer1": list(set(sender_li)),
"layer3": list(set(receptor_li)),
"layer2": list(set(gem_li)),}
pos = nx.multipartite_layout(flow_network, subset_key=layers,align='horizontal',scale=2.0)

#fig, ax = plt.subplots(figsize=(8,8))
Expand Down
Loading

0 comments on commit 4506f02

Please sign in to comment.