from parag.core import get_net_data
import scanpy as sc
=get_net_data(sc.datasets.pbmc68k_reduced()) nodes,edges
Hypergraphs
to_net
to_net (nodes:pandas.core.frame.DataFrame, edges:pandas.core.frame.DataFrame, col_node_id:str, col_source:str, col_target:str, col_subset_id:str, show_node_names:bool=True, defaults:dict=None, dbug:bool=False)
*Plot interactive hypergraph ‘representation’.
Args: nodes (pd.DataFrame): nodes edges (pd.DataFrame): edges col_node_id (str): column with node ids col_source (str): column with sources col_target (str): column with targets col_subset_id (str): column with subset ids show_node_names (bool, optional): show node names. Defaults to True. defaults (dict, optional): defaults provided to the vega config. Defaults to None. dbug (bool, optional): debug mode. Defaults to False.
Returns: tuple: vega config, degrees*
plot_degreeby_subset
plot_degreeby_subset (nodes:pandas.core.frame.DataFrame, edges:pandas.core.frame.DataFrame, col_node_id:str, col_source:str, col_target:str, col_subset_id:str, order:list=None, hue_order:list=None, config_base_path:str=None, cmap_subsets:str=None, show_text:bool=True, plot:bool=True, **kws_display_plot)
*Plot bar plot of degrees by subsets
Args: nodes (pd.DataFrame): nodes edges (pd.DataFrame): edges col_node_id (str): column with node ids col_source (str): column with sources col_target (str): column with targets col_subset_id (str): column with subset ids order (list, optional): order of subsets. Defaults to None. hue_order (list, optional): order of colors. Defaults to None. config_base_path (str, optional): base vega config. Defaults to None. cmap_subsets (str, optional): colormap. Defaults to None. show_text (bool, optional): show text. Defaults to True. plot (bool, optional): plot or not. Defaults to True.
Returns: tuple: vega config, degrees*
get_degreeby_subset
get_degreeby_subset (nodes:pandas.core.frame.DataFrame, edges:pandas.core.frame.DataFrame, col_node_id:str, col_source:str, col_target:str, col_subset_id:str)
*Get degrees by subsets (groups) of the source nodes
Args: nodes (pd.DataFrame): nodes edges (pd.DataFrame): edges col_node_id (str): column with node ids col_source (str): column with source ids col_target (str): column with target ids col_subset_id (str): column with subset ids
Returns: pd.DataFrame: table*
Demo data
1) nodes.head(
cell id | bulk_labels | n_genes | percent_mito | n_counts | S_score | G2M_score | phase | louvain | x | y | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | CAGACAACAAAACG-7 | CD4+/CD25 T Reg | 1109 | 0.012702 | 3779.0 | -0.054589 | -1.267457 | G1 | 0 | -7.174749 | -6.994063 |
1) edges.head(
cell id1 | cell id2 | distance | |
---|---|---|---|
0 | CAGACAACAAAACG-7 | GTGATGACTGGGAG-4 | 1.298669 |
Degrees by subsets
=plot_degreeby_subset(
cfg_bars'bulk_labels',ascending=True),
nodes.sort_values(
edges,='cell id',
col_node_id='cell id1',
col_source='cell id2',
col_target='bulk_labels',
col_subset_id=None,
config_base_path=None,
cmap_subsets# defaults=dict(
# innerRadius=170,
# outerRadius=200,
# innerPadding=0.15,
# ),
)
Integrate with graph
=to_net(
cfg,df_
nodes,
edges,='cell id',
col_node_id='cell id1',
col_source='cell id2',
col_target='bulk_labels',
col_subset_id=False,
show_node_names=dict(
defaults=8,
textSize=3,
textOffset
), )