[jgrapht-users] Getting all connected sets of a graph as graphs
Brought to you by:
barak_naveh,
perfecthash
From: Tim J. <ts...@rc...> - 2011-04-25 14:47:23
|
Hi list, I'm new to jgrapht and I'm using it to model protein graphs. What I need to do is split a graph G into multiple graphs, each of which should represent a connected set of G. I have found the ConnectivityInspector class and its connectedSets() method, but I'm not sure on how to turn the edge set it returns into a new graph. Can anybody tell me how to do that? Some more details on what I've done so far follow: I have written a ProteinGraph class that extends SimpleGraph<V, E> and implements UndirectedGraph<V, E>. I have also written a LabeledEdge class that extends DefaultEdge. Both of this shouldn't make much of a difference I guess. Here is my code so far: // Creates a ProteinGraph from the connectivity matrix of all super-secondary structures of a protein chain ProteinGraph<SSE, LabeledEdge> g = chainCM.toJGraph(); // Get all connected sets ConnectivityInspector<SSE, LabeledEdge> ci = new ConnectivityInspector<SSE, LabeledEdge>(g); List<Set<SSE>> conSets = ci.connectedSets(); // Create graphs out of the connected sets for(Integer j = 0; j < conSets.size(); j++) { // I can do this... UndirectedSubgraph<SSE, LabeledEdge> subGraph = new UndirectedSubgraph<SSE, LabeledEdge>(g, conSets.get(j), null); // ... but I would like to do something like this: ProteinGraph<SSE, LabeledEdge> psg = new UndirectedSubgraph<SSE, LabeledEdge>(g, conSets.get(j), null); // or ProteinGraph<SSE, LabeledEdge> psg = subGraph.toGraph(); } Using that code, my question could also be formulated as 'How can I turn a UndirectedSubgraph into a new Graph of a certain type (my ProteinGraph class, in this case). Is there any way to do this? Or should I write a new constructor for ProteinGraph that uses the SubGraph to construct the ProteinGraph based on the vertix set and edge set in the subgraph? Thanks for any hints, -- Tim |