qbiocode.apps.quvine.data.prepare module#

Summary#

Classes:

PrepareGraphConfig

PrepareGraphConfig(subsample_nodes: 'bool' = False, max_nodes: 'int' = 3000, radius: 'int' = 2, sparsify_edges: 'bool' = True, retain_ratio: 'float' = 0.7, max_degree: 'int' = 40, scoring: "Literal['common_neighbors', 'prefer_low_degree']" = 'common_neighbors', verbose: 'bool' = False)

Functions:

keep_largest_connected_component

Return a connected component while preserving required nodes when possible.

prepare_graph

Step-by-step graph preparation:

Reference#

keep_largest_connected_component(G, *, required_nodes=None)[source]#

Return a connected component while preserving required nodes when possible.

If required_nodes are supplied and they all lie in the same connected component, that component is preferred over the global largest component. Otherwise, fall back to the largest connected component.

Return type:

Graph

class PrepareGraphConfig(subsample_nodes=False, max_nodes=3000, radius=2, sparsify_edges=True, retain_ratio=0.7, max_degree=40, scoring='common_neighbors', verbose=False)[source]#

Bases: object

subsample_nodes: bool = False#
max_nodes: int = 3000#
radius: int = 2#
sparsify_edges: bool = True#
retain_ratio: float = 0.7#
max_degree: int = 40#
scoring: Literal['common_neighbors', 'prefer_low_degree'] = 'common_neighbors'#
verbose: bool = False#
prepare_graph(cfg, graph, seed, *, seeds=None, targets=None)[source]#

Step-by-step graph preparation:

  1. Materialize a clean undirected simple graph (no views).

  2. If cfg.subsample_nodes: subsample nodes while protecting seeds+targets,

    expand neighborhood (radius hops), fill remaining budget.

  3. If cfg.sparsify_edges: degree-capped, biology-aware edge sparsification

    (triangle support or low-degree preference).

  4. Return a clean nx.Graph.

Designed to avoid the KeyError / _succ / neighbor traversal issues you saw: - no subgraph views - no nx.is_connected / connected_components - no G.neighbors() calls - only adjacency dict access (G.adj[u])

Return type:

Graph