scPPIN Class¶
- class scppin.scPPIN(network=None, node_weights=None, edge_weights=None)[source]¶
Bases:
objectscPPIN analyzer for detecting functional modules in protein-protein interaction networks.
This class manages network, node weights (p-values), edge weights, and analysis results as object attributes, ensuring data consistency and providing a clean workflow.
- network¶
Protein-protein interaction network filtered to genes with weights
- Type:
Optional[ig.Graph]
- module¶
Detected functional module
- Type:
Optional[ig.Graph]
Examples
>>> import scppin >>> >>> # Create analyzer >>> analyzer = scppin.scPPIN() >>> >>> # Load network with weights from CSV column >>> analyzer.load_network('edges.csv', weight_column='confidence') >>> >>> # Set node weights (p-values) >>> analyzer.set_node_weights({'TP53': 0.0001, 'MDM2': 0.001}) >>> >>> # Detect module >>> module = analyzer.detect_module(fdr=0.01)
- load_network(source, weight_column=None, fmt='auto')[source]¶
Load network from file, list, DataFrame, or igraph graph.
- Parameters:
source (Union[str, List[Tuple], pd.DataFrame, ig.Graph]) – Network source: - String: Path to CSV/TXT/GraphML file - List: List of edge tuples - DataFrame: Edge list DataFrame - ig.Graph: Existing igraph graph
weight_column (Optional[str]) – Column name in CSV/DataFrame to use as edge weights. If provided and source is file/DataFrame, loads weights from that column. Sets edge weights as ‘weight’ attribute on network edges.
fmt (str, optional) – File format hint (‘auto’, ‘csv’, ‘graphml’, ‘gml’) (default: ‘auto’)
- Returns:
self (for method chaining)
- Return type:
Examples
>>> analyzer = scppin.scPPIN() >>> analyzer.load_network('edges.csv') >>> analyzer.load_network('edges.csv', weight_column='confidence') >>> analyzer.load_network([('A', 'B'), ('B', 'C')])
- set_node_weights(weights, groupby=None, group=None)[source]¶
Set node weights (p-values) and filter network to genes with weights.
- Parameters:
weights (Union[Dict[str, float], AnnData]) – Node weights: - Dict: Dictionary mapping gene names to weights (p-values) - AnnData: Extract from rank_genes_groups (requires groupby/group)
groupby (Optional[str]) – Key in adata.obs for grouping labels (required if weights is AnnData)
group (Optional[str]) – Specific group to extract (required if weights is AnnData)
- Returns:
self (for method chaining)
- Return type:
Examples
>>> analyzer.set_node_weights({'TP53': 0.0001, 'MDM2': 0.001}) >>> analyzer.set_node_weights(adata, groupby='louvain', group='0')
Note
This method automatically: - Normalizes gene names for matching - Filters network to only include genes with weights
- set_edge_weights(weights, attr_name='weight')[source]¶
Set edge weights from user-provided dictionary.
- Parameters:
- Returns:
self (for method chaining)
- Return type:
Examples
>>> # From dictionary >>> weights = {('TP53', 'MDM2'): 0.9, ('TP53', 'CDKN1A'): 0.8} >>> analyzer.set_edge_weights(weights=weights)
- detect_module(fdr=0.01, edge_weight_attr=None, c0=0.01, normalization='minmax', simplify=True, validate=True, use_max_prize_root=False)[source]¶
Detect functional module using PCST optimization.
- Parameters:
fdr (float, optional) – False discovery rate threshold (default: 0.01)
edge_weight_attr (Optional[str], optional) – Edge attribute name for weights (default: None = uniform costs). If None, uses uniform edge costs matching R implementation.
c0 (Optional[float], optional) – Minimum edge cost (default: 0.01)
normalization (Optional[str], optional) – Normalization method for edge weights: ‘minmax’, ‘log1p’, ‘power’, or None (default: ‘minmax’). If None, uses weights directly without normalization (assumes weights are already in [0, 1] range). Only used when edge_weight_attr is provided.
simplify (bool, optional) – Simplify network (default: True)
validate (bool, optional) – Validate network (default: True)
use_max_prize_root (bool, optional) – If True, use the node with highest prize as root (default: False)
- Returns:
Detected functional module (also stored on
self.module)- Return type:
ig.Graph
Examples
>>> # Default PCST >>> module = analyzer.detect_module(fdr=0.01) >>> >>> # PCST with edge weights >>> module = analyzer.detect_module(fdr=0.01, edge_weight_attr='weight') >>> >>> # PCST with max prize root (more deterministic) >>> module = analyzer.detect_module( ... fdr=0.01, use_max_prize_root=True ... )
- plot_module(fdr=0.01, **kwargs)[source]¶
Visualize detected module.
- Parameters:
fdr (float, optional) – FDR threshold for visualization (default: 0.01)
**kwargs – Additional plotting arguments passed to plot_functional_module
- Returns:
Figure object
- Return type:
- network_statistics(graph=None)[source]¶
Compute comprehensive network statistics.
- Parameters:
graph (Optional[ig.Graph], optional) – Network to analyze. If None, uses self.module if available, otherwise uses self.network (default: None)
- Returns:
Dictionary with network statistics including: - Basic stats: num_nodes, num_edges, density, num_components - Degree statistics: avg_degree, max_degree, min_degree - Clustering: avg_clustering_coefficient - Path metrics: avg_shortest_path_length, diameter (if connected) - Centrality: avg_degree_centrality, avg_betweenness_centrality
- Return type:
Dict
Examples
>>> analyzer.detect_module(fdr=0.01) >>> stats = analyzer.network_statistics() # Statistics for module >>> print(f"Density: {stats['density']:.4f}") >>> print(f"Avg clustering: {stats['avg_clustering_coefficient']:.4f}")