ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/testJUNGframework.java
Revision: 430
Committed: Mon Nov 26 18:20:04 2007 UTC (16 years, 11 months ago) by duarte
Original Path: branches/aglappe-jung/testJUNGframework.java
File size: 6852 byte(s)
Log Message:
Fixed tester after changes in getAllCommonNnhSizes
Line User Rev File contents
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 duarte 430 HashMap<Pair<Integer>,Integer> cmNbhSizes = graph.getAllCommonNbhSizes();
57    
58     for (Pair<Integer> pair:cmNbhSizes.keySet()) {
59     //for (int j=170;j<=180;j++) {
60     if (pair.getFirst()==109 && pair.getSecond()>=170 && pair.getSecond()<=180) {
61     RIGNbhood nbh = graph.getNbhood(graph.getNodeFromSerial(pair.getSecond()));
62     System.out.println("nbhood of "+pair.getSecond()+": "+ nbh);
63     for (RIGNode nb:nbh.values()) {
64     System.out.print(" "+nb);
65     }
66     System.out.println();
67    
68     int size = cmNbhSizes.get(pair);
69     System.out.println("common neighbs for edge "+pair.getFirst()+", "+pair.getSecond()+": "+size);
70     RIGCommonNbhood cmNbh = graph.getCommonNbhood(graph.getNodeFromSerial(pair.getFirst()), graph.getNodeFromSerial(pair.getSecond()));
71     for (RIGNode nb:cmNbh.values()){
72     System.out.print(" "+nb);
73     }
74     System.out.println();
75     System.out.println(cmNbh);
76 duarte 420 }
77     }
78    
79     // TEST of evaluate prediction
80     System.out.println("TEST eval prediction");
81     PredEval pev = graph.evaluatePrediction(graph2);
82     pev.print();
83    
84     // TEST of isDirected()
85     System.out.println("TEST isDirected");
86     if (graph.isDirected()) {
87     System.out.println("directed");
88     }
89    
90     // TEST of Pair<Integer>, does it respect equals
91     System.out.println("TEST Pair<Integer>");
92     Pair<Integer> p1 = new Pair<Integer>(1,2);
93     Pair<Integer> p2 = new Pair<Integer>(1,2);
94     Set<Pair<Integer>> set = new HashSet<Pair<Integer>>();
95     set.add(p1);
96     set.add(p2);
97     if (p1.equals(p2)) {
98     System.out.println("2 pairs are equal");
99     }
100     System.out.println(set);
101    
102 duarte 424 // TEST of degree methods and getSuccessorCount, getPredecessorCount, getNeighborCount
103     // degree and neighbor counts are different when the graph has parallel edges (our graphs shouldn't have them anyway)
104     System.out.println("TEST degree and neighbor count methods");
105 duarte 420 // graph is undirected, graph2 is directed
106     System.out.println("undirected graph: ");
107     for (int serial=1;serial<=10;serial++){
108     RIGNode node = graph.getNodeFromSerial(serial);
109 duarte 424 System.out.println("node "+serial+": nbr count "+graph.getNeighborCount(node)+", predec count: "+graph.getPredecessorCount(node)+", successor count: "+graph.getSuccessorCount(node));
110     System.out.println("node "+serial+": degree "+graph.degree(node)+", in degree: "+graph.inDegree(node)+", out degree: "+graph.outDegree(node));
111 duarte 420 }
112     System.out.println("directed graph: ");
113     for (int serial=1;serial<=10;serial++){
114     RIGNode node = graph2.getNodeFromSerial(serial);
115 duarte 424 System.out.println("node "+serial+": nbr count "+graph2.getNeighborCount(node)+", predec count: "+graph2.getPredecessorCount(node)+", successor count: "+graph2.getSuccessorCount(node));
116     System.out.println("node "+serial+": degree "+graph2.degree(node)+", in degree: "+graph2.inDegree(node)+", out degree: "+graph2.outDegree(node));
117 duarte 420 }
118    
119 duarte 423 // TEST adding and getting directed/undirected edges
120     System.out.println("TEST adding and getting directed/undirected edges: ");
121 duarte 420 RIGraph g = new RIGraph("ABCD");
122 duarte 421 EdgeType edgeType = EdgeType.UNDIRECTED;
123 duarte 420 RIGNode n1 = g.getNodeFromSerial(1);
124     RIGNode n2 = g.getNodeFromSerial(2);
125 duarte 421 RIGNode n3 = g.getNodeFromSerial(3);
126 duarte 420 g.addEdge(new RIGEdge(1), n1, n2, edgeType);
127     g.addEdge(new RIGEdge(2), n2, n1, edgeType);
128     g.addEdge(new RIGEdge(3), n1, n2, edgeType);
129 duarte 421 g.addEdge(new RIGEdge(4), n1, n3, edgeType);
130 duarte 420 for (RIGEdge e:g.getEdges()) {
131     System.out.println(g.getEndpoints(e).getFirst()+" "+g.getEndpoints(e).getSecond()+", w "+e.getAtomWeight());
132     }
133     System.out.println("vertex count: "+g.getVertexCount());
134     System.out.println("edge count: "+g.getEdgeCount());
135 duarte 421 System.out.println("edge w "+ g.findEdge(n3, n1).getAtomWeight());
136 duarte 423
137     // TEST copying of RIGraph objects and restrictRange methods
138     System.out.println("TEST copying of RIGraph objects");
139     RIGraph g1 = new PdbasePdb("1bxy","A").get_graph("Ca", 8);
140     RIGraph g2 = new PdbasePdb("1sha","A").get_graph("Ca", 8);
141     System.out.println("g1: "+g1.getPdbCode()+" nodes: "+g1.getVertexCount()+" edges: "+g1.getEdgeCount());
142     System.out.println("g2: "+g2.getPdbCode()+" nodes: "+g2.getVertexCount()+" edges: "+g2.getEdgeCount());
143     RIGraph newgraph = g1.copy();
144     System.out.println("new g: "+newgraph.getPdbCode()+" nodes: "+newgraph.getVertexCount()+" edges: "+newgraph.getEdgeCount());
145     newgraph = g2;
146     System.out.println("new g reassigned to g2: "+newgraph.getPdbCode()+" nodes: "+newgraph.getVertexCount()+" edges: "+newgraph.getEdgeCount());
147     newgraph.restrictContactsToMaxRange(10);
148     System.out.println("new g reassigned to g2, max range 10: "+newgraph.getPdbCode()+" nodes: "+newgraph.getVertexCount()+" edges: "+newgraph.getEdgeCount());
149     System.out.println("g1: "+g1.getPdbCode()+" nodes: "+g1.getVertexCount()+" edges: "+g1.getEdgeCount());
150    
151 duarte 420 }
152    
153    
154     }