File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ scaffoldgraph.utils.bipartite
3+
4+ Defines functions for creating bipartite graphs from scaffold graphs.
5+ """
6+
7+ from scaffoldgraph .core import ScaffoldGraph
8+
9+
10+ def make_bipartite_graph (graph ):
11+ """Collapse a scaffold hierarchy into a bipartite representation.
12+
13+ Scaffold --> Molecule
14+
15+ The returned output will inherit the class of the input graph.
16+
17+ Parameters
18+ ----------
19+ graph : sg.core.ScaffoldGraph
20+ A scaffold graph template for producing a bipaertite
21+ graph.
22+
23+ Returns
24+ -------
25+ sg.core.ScaffoldGraph
26+ Bipartite scaffoldgraph where the scaffold hierarchy
27+ has been collapsed.
28+
29+ """
30+ if not issubclass (type (graph ), ScaffoldGraph ):
31+ raise ValueError (f'{ graph } must be a ScaffoldGraph' )
32+ graph_type = type (graph )
33+ B = graph_type (None )
34+ for scf , sdata in graph .get_scaffold_nodes (True ):
35+ B .add_node (scf , ** sdata )
36+ for mol , mdata in graph .get_molecules_for_scaffold (scf , True ):
37+ if not B .molecule_in_graph (mol ):
38+ B .add_node (mol , ** mdata )
39+ B .add_edge (scf , mol )
40+ return B
You can’t perform that action at this time.
0 commit comments