ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/testJUNGframework.java
Revision: 492
Committed: Wed Jan 2 13:18:57 2008 UTC (16 years, 8 months ago) by duarte
File size: 6767 byte(s)
Log Message:
Copied the aglappe-jung branch into trunk.

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