1 |
duarte |
420 |
import java.io.FileNotFoundException; |
2 |
|
|
import java.io.IOException; |
3 |
|
|
import java.sql.SQLException; |
4 |
|
|
import java.util.HashMap; |
5 |
|
|
import java.util.HashSet; |
6 |
|
|
import java.util.Set; |
7 |
|
|
|
8 |
|
|
|
9 |
|
|
import edu.uci.ics.jung.graph.util.EdgeType; |
10 |
|
|
import edu.uci.ics.jung.graph.util.Pair; |
11 |
|
|
|
12 |
|
|
import proteinstructure.*; |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
public class testJUNGframework { |
16 |
|
|
|
17 |
|
|
public static void main(String[] args) throws FileNotFoundException, IOException, GraphFileFormatError, PdbaseInconsistencyError, PdbCodeNotFoundError, SQLException, PdbChainCodeNotFoundError, GraphIdNotFoundError { |
18 |
|
|
Pdb pdb = new PdbasePdb("7adh", "A"); |
19 |
|
|
|
20 |
|
|
RIGraph graph = pdb.get_graph("Ca", 8.0); |
21 |
|
|
RIGraph graph2 = pdb.get_graph("Ca/Cb", 8.0); |
22 |
|
|
//RIGraph graph = new FileRIGraph("/scratch/local/temp.graph"); |
23 |
|
|
//RIGraph graph = new DbRIGraph("casp_decoys",9); |
24 |
|
|
//System.out.println(graph); |
25 |
|
|
System.out.println("#pdb code:"+graph.getPdbCode()); |
26 |
|
|
System.out.println("#chain code:"+graph.getChainCode()); |
27 |
|
|
System.out.println("#pdb chain code:"+graph.getPdbChainCode()); |
28 |
|
|
System.out.println("#full length:"+graph.getFullLength()); |
29 |
|
|
System.out.println("#obs length:"+graph.getObsLength()); |
30 |
|
|
System.out.println("#ct:"+graph.getContactType()); |
31 |
|
|
System.out.println("#cutoff:"+graph.getCutoff()); |
32 |
|
|
System.out.println("#edge count:"+graph.getEdgeCount()); |
33 |
|
|
System.out.println("#vertex count:"+graph.getVertexCount()); |
34 |
|
|
|
35 |
|
|
// TEST getting atom weights and weights |
36 |
|
|
for (RIGEdge e:graph.getEdges()) { |
37 |
|
|
Pair<RIGNode> pair = graph.getEndpoints(e); |
38 |
|
|
System.out.println(pair.getFirst()+" "+pair.getSecond()+" atom w: "+e.getAtomWeight()+" w: "+e.getWeight() ); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
// TEST printing node information |
43 |
|
|
System.out.println("TEST printing node information"); |
44 |
|
|
for (int ind:graph.getSerials()){ |
45 |
|
|
RIGNode n = graph.getNodeFromSerial(ind); |
46 |
|
|
SecStrucElement sselem = n.getSecStrucElement(); |
47 |
|
|
char sstype = sselem==null?0:sselem.getType(); |
48 |
|
|
System.out.println("V"+n.getResidueSerial()+" "+n.getResidueType()+" "+sstype); |
49 |
|
|
|
50 |
|
|
} |
51 |
|
|
System.out.println(); |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
// TEST of neighbourhood methods |
55 |
|
|
System.out.println("TEST neighbor methods"); |
56 |
|
|
HashMap<Pair<RIGNode>,Integer> cmNbhSizes = graph.getAllCommonNbhSizes(); |
57 |
|
|
int i = 109; |
58 |
|
|
for (int j=170;j<=180;j++) { |
59 |
|
|
RIGNbhood nbh = graph.getNbhood(graph.getNodeFromSerial(j)); |
60 |
|
|
System.out.println("nbhood of "+j+": "+ nbh); |
61 |
|
|
for (RIGNode nb:nbh.values()) { |
62 |
|
|
System.out.print(" "+nb); |
63 |
|
|
} |
64 |
|
|
System.out.println(); |
65 |
|
|
int size = cmNbhSizes.get(new Pair<RIGNode>(graph.getNodeFromSerial(i),graph.getNodeFromSerial(j))); |
66 |
|
|
System.out.println("common neighbs for edge "+i+", "+j+": "+size); |
67 |
|
|
RIGCommonNbhood cmNbh = graph.getCommonNbhood(graph.getNodeFromSerial(i), graph.getNodeFromSerial(j)); |
68 |
|
|
for (RIGNode nb:cmNbh.values()){ |
69 |
|
|
System.out.print(" "+nb); |
70 |
|
|
} |
71 |
|
|
System.out.println(); |
72 |
|
|
System.out.println(cmNbh); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
// TEST of evaluate prediction |
76 |
|
|
System.out.println("TEST eval prediction"); |
77 |
|
|
PredEval pev = graph.evaluatePrediction(graph2); |
78 |
|
|
pev.print(); |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
// TEST of range restrict methods |
82 |
|
|
System.out.println(); |
83 |
|
|
System.out.println("TEST restrict methods"); |
84 |
|
|
System.out.println("num contacts full range: "+graph.getEdgeCount()); |
85 |
|
|
graph.restrictContactsToMaxRange(10); |
86 |
|
|
System.out.println("num contacts max range 10: "+graph.getEdgeCount()); |
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
// TEST of isDirected() |
91 |
|
|
System.out.println("TEST isDirected"); |
92 |
|
|
if (graph.isDirected()) { |
93 |
|
|
System.out.println("directed"); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
// TEST of Pair<Integer>, does it respect equals |
97 |
|
|
System.out.println("TEST Pair<Integer>"); |
98 |
|
|
Pair<Integer> p1 = new Pair<Integer>(1,2); |
99 |
|
|
Pair<Integer> p2 = new Pair<Integer>(1,2); |
100 |
|
|
Set<Pair<Integer>> set = new HashSet<Pair<Integer>>(); |
101 |
|
|
set.add(p1); |
102 |
|
|
set.add(p2); |
103 |
|
|
if (p1.equals(p2)) { |
104 |
|
|
System.out.println("2 pairs are equal"); |
105 |
|
|
} |
106 |
|
|
System.out.println(set); |
107 |
|
|
|
108 |
|
|
// TEST of getSuccessorCount, getPredecessorCount, getNeighborCount |
109 |
|
|
System.out.println("TEST degree methods: getNeighborCount, getSuccessorCount, getPredecessorCount"); |
110 |
|
|
// graph is undirected, graph2 is directed |
111 |
|
|
System.out.println("undirected graph: "); |
112 |
|
|
for (int serial=1;serial<=10;serial++){ |
113 |
|
|
RIGNode node = graph.getNodeFromSerial(serial); |
114 |
|
|
System.out.println("degree for node "+serial+": "+graph.getNeighborCount(node)+", indegree: "+graph.getPredecessorCount(node)+", outdegree: "+graph.getSuccessorCount(node)); |
115 |
|
|
} |
116 |
|
|
System.out.println("directed graph: "); |
117 |
|
|
for (int serial=1;serial<=10;serial++){ |
118 |
|
|
RIGNode node = graph2.getNodeFromSerial(serial); |
119 |
|
|
System.out.println("degree for node "+serial+": "+graph2.getNeighborCount(node)+", indegree: "+graph2.getPredecessorCount(node)+", outdegree: "+graph2.getSuccessorCount(node)); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
// TEST adding and getting undirected edges |
123 |
|
|
System.out.println("TEST adding and getting undirected edges: "); |
124 |
|
|
RIGraph g = new RIGraph("ABCD"); |
125 |
|
|
EdgeType edgeType = EdgeType.DIRECTED; |
126 |
|
|
RIGNode n1 = g.getNodeFromSerial(1); |
127 |
|
|
RIGNode n2 = g.getNodeFromSerial(2); |
128 |
|
|
g.addEdge(new RIGEdge(1), n1, n2, edgeType); |
129 |
|
|
g.addEdge(new RIGEdge(2), n2, n1, edgeType); |
130 |
|
|
g.addEdge(new RIGEdge(3), n1, n2, edgeType); |
131 |
|
|
for (RIGEdge e:g.getEdges()) { |
132 |
|
|
System.out.println(g.getEndpoints(e).getFirst()+" "+g.getEndpoints(e).getSecond()+", w "+e.getAtomWeight()); |
133 |
|
|
} |
134 |
|
|
System.out.println("vertex count: "+g.getVertexCount()); |
135 |
|
|
System.out.println("edge count: "+g.getEdgeCount()); |
136 |
|
|
System.out.println("edge w "+ g.findEdge(n1, n2).getAtomWeight()); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
|
140 |
|
|
} |