Skip to content

Commit 52f41f4

Browse files
committed
Merge pull request #352 from lafita/graph
Include jgrapht dependency to biojava-structure
2 parents f2b0346 + a9eeced commit 52f41f4

12 files changed

Lines changed: 86 additions & 566 deletions

File tree

biojava-structure/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
<artifactId>vecmath</artifactId>
3131
<version>1.3.1</version>
3232
</dependency>
33-
33+
34+
<dependency>
35+
<groupId>org.jgrapht</groupId>
36+
<artifactId>jgrapht-core</artifactId>
37+
<version>0.9.1</version>
38+
</dependency>
3439

3540
<!-- logging dependencies (managed by parent pom, don't set versions or scopes here) -->
3641
<dependency>

biojava-structure/src/main/java/org/biojava/nbio/structure/SeqMisMatchImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88
public class SeqMisMatchImpl implements SeqMisMatch, Serializable{
99

10-
Integer seqNum;
10+
private static final long serialVersionUID = -3699285122925652562L;
11+
12+
Integer seqNum;
1113
String origGroup;
1214
String pdbGroup;
1315
String details;

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/core/QuatSymmetryDetector.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424

2525
import org.biojava.nbio.structure.Structure;
2626
import org.biojava.nbio.structure.symmetry.utils.CombinationGenerator;
27-
import org.biojava.nbio.structure.symmetry.utils.ComponentFinder;
28-
import org.biojava.nbio.structure.symmetry.utils.Graph;
27+
import org.jgrapht.UndirectedGraph;
28+
import org.jgrapht.alg.ConnectivityInspector;
29+
import org.jgrapht.graph.DefaultEdge;
30+
import org.jgrapht.graph.UndirectedSubgraph;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
2933

3034
import javax.vecmath.Point3d;
35+
3136
import java.math.BigInteger;
3237
import java.util.*;
3338

@@ -40,6 +45,10 @@
4045
*
4146
*/
4247
public class QuatSymmetryDetector {
48+
49+
private static final Logger logger = LoggerFactory
50+
.getLogger(QuatSymmetryDetector.class);
51+
4352
private Structure structure = null;
4453
private QuatSymmetryParameters parameters = null;
4554

@@ -136,8 +145,8 @@ private void run() {
136145

137146
double time = (System.nanoTime()- start)/1000000000;
138147
if (time > parameters.getLocalTimeLimit()) {
139-
System.out.println("Warning: QuatSymmetryDetector: Exceeded time limit for local symmetry calculations: " + time +
140-
" seconds. Results may be incomplete");
148+
logger.warn("Exceeded time limit for local symmetry calculations: " + time +
149+
" seconds. Quat symmetry results may be incomplete");
141150
break;
142151
}
143152
}
@@ -387,8 +396,8 @@ private List<List<Integer>> decomposeClusters(List<Point3d[]> caCoords, List<Int
387396
}
388397

389398
SubunitGraph subunitGraph = new SubunitGraph(subList);
390-
Graph<Integer> graph = subunitGraph.getProteinGraph();
391-
// System.out.println("Graph: " + graph);
399+
UndirectedGraph<Integer, DefaultEdge> graph = subunitGraph.getProteinGraph();
400+
logger.debug("Graph: {}", graph.toString());
392401

393402
for (int i = last; i > 1; i--) {
394403
CombinationGenerator generator = new CombinationGenerator(last, i);
@@ -397,8 +406,9 @@ private List<List<Integer>> decomposeClusters(List<Point3d[]> caCoords, List<Int
397406

398407
// avoid combinatorial explosion, i.e. for 1FNT
399408
BigInteger maxCombinations = BigInteger.valueOf(parameters.getMaximumLocalCombinations());
400-
// System.out.println("maxCombinations: " + generator.getTotal());
409+
logger.debug("Number of combinations: {}", generator.getTotal());
401410
if (generator.getTotal().compareTo(maxCombinations) > 0) {
411+
logger.warn("Number of combinations exceeds limit for biounit with {} subunits in groups of {} subunits. Will not check local symmetry for them", last, i);
402412
continue;
403413
}
404414

@@ -424,8 +434,8 @@ private List<List<Integer>> decomposeClusters(List<Point3d[]> caCoords, List<Int
424434
}
425435

426436
// check if this subset of subunits interact with each other
427-
Graph<Integer> subGraph = graph.extractSubGraph(subSet);
428-
if (isConnectedGraph(subGraph)) {
437+
UndirectedGraph<Integer, DefaultEdge> subGraph = new UndirectedSubgraph<Integer, DefaultEdge>(graph, new HashSet<Integer>(subSet), null);
438+
if (isConnectedGraph(subGraph)) {
429439
subClusters.add(subSet);
430440
if (subClusters.size() > parameters.getMaximumLocalResults()) {
431441
return subClusters;
@@ -454,10 +464,9 @@ private static int getLastMultiSubunit(List<Integer> clusterIds) {
454464
return clusterIds.size();
455465
}
456466

457-
private static boolean isConnectedGraph(Graph<Integer> graph) {
458-
ComponentFinder<Integer> finder = new ComponentFinder<Integer>();
459-
finder.setGraph(graph);
460-
return finder.getComponentCount() == 1;
467+
private static boolean isConnectedGraph(UndirectedGraph<Integer, DefaultEdge> graph) {
468+
ConnectivityInspector<Integer, DefaultEdge> inspector = new ConnectivityInspector<Integer, DefaultEdge>(graph);
469+
return inspector.isGraphConnected();
461470
}
462471

463472
private static List<Integer> getFolds(Integer[] subCluster, int size) {

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/core/SubunitGraph.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,44 @@
2020
*/
2121
package org.biojava.nbio.structure.symmetry.core;
2222

23-
import org.biojava.nbio.structure.symmetry.utils.Graph;
24-
import org.biojava.nbio.structure.symmetry.utils.SimpleGraph;
25-
2623
import javax.vecmath.Point3d;
24+
25+
import org.jgrapht.UndirectedGraph;
26+
import org.jgrapht.graph.DefaultEdge;
27+
import org.jgrapht.graph.SimpleGraph;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
2731
import java.util.List;
2832

2933
public class SubunitGraph {
30-
private static double DISTANCE_CUTOFF = 8;
31-
private static int MIN_CONTACTS = 10;
34+
35+
private static final Logger logger = LoggerFactory
36+
.getLogger(SubunitGraph.class);
37+
38+
private static final double DISTANCE_CUTOFF = 8;
39+
private static final int MIN_CONTACTS = 10;
3240
private List<Point3d[]> caCoords = null;
3341

3442
public SubunitGraph(List<Point3d[]> caCoords) {
3543
this.caCoords = caCoords;
3644
}
3745

38-
public Graph<Integer> getProteinGraph() {
46+
public UndirectedGraph<Integer, DefaultEdge> getProteinGraph() {
3947
int n = caCoords.size();
4048

4149
// add vertex for each chain center
42-
Graph<Integer> graph = new SimpleGraph<Integer>();
50+
UndirectedGraph<Integer, DefaultEdge> graph = new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
4351
for (int i = 0; i < n; i++) {
4452
graph.addVertex(i);
4553
}
46-
54+
4755
// add edges if there are 10 or more contact of Calpha atoms
4856
for (int i = 0; i < n - 1; i++) {
4957
for (int j = i + 1; j < n; j++) {
50-
// System.out.println("contacts: " + calcContactNumber(caCoords.get(i), caCoords.get(j)));
51-
if (calcContactNumber(caCoords.get(i), caCoords.get(j)) >= MIN_CONTACTS) {
58+
int numContacts = calcContactNumber(caCoords.get(i), caCoords.get(j));
59+
logger.debug("Calpha contacts between subunits {},{}: {}", i, j, numContacts);
60+
if (numContacts >= MIN_CONTACTS) {
5261
graph.addEdge(i, j);
5362
}
5463
}

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/utils/ComponentFinder.java

Lines changed: 0 additions & 169 deletions
This file was deleted.

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/utils/Edge.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)