Hypergraphs

For hypergrapph related functions

source

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*


source

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*


source

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

from parag.core import get_net_data
import scanpy as sc
nodes,edges=get_net_data(sc.datasets.pbmc68k_reduced())
nodes.head(1)
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
edges.head(1)
cell id1 cell id2 distance
0 CAGACAACAAAACG-7 GTGATGACTGGGAG-4 1.298669

Degrees by subsets

cfg_bars=plot_degreeby_subset(
    nodes.sort_values('bulk_labels',ascending=True),
    edges,
    col_node_id='cell id',
    col_source='cell id1',
    col_target='cell id2',
    col_subset_id='bulk_labels',    
    config_base_path=None,
    cmap_subsets=None,  
    # defaults=dict(
    #     innerRadius=170,
    #     outerRadius=200,
    #     innerPadding=0.15,
    # ),
    )

Integrate with graph

cfg,df_=to_net(
    nodes,
    edges,
    col_node_id='cell id',
    col_source='cell id1',
    col_target='cell id2',
    col_subset_id='bulk_labels',
    show_node_names=False,
    defaults=dict(
            textSize=8,
            textOffset=3,
    ),
)