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

Line File contents
1 import java.io.IOException;
2 import java.sql.ResultSet;
3 import java.sql.SQLException;
4 import java.sql.Statement;
5
6 import proteinstructure.PdbLoadError;
7 import proteinstructure.RIGraph;
8 import proteinstructure.Pdb;
9 import proteinstructure.PdbCodeNotFoundError;
10 import proteinstructure.PdbasePdb;
11 import tools.MySQLConnection;
12
13
14 public class benchmarkGraphAlgorithm {
15 /*------------------------------ constants ------------------------------*/
16
17 // database with a list of pdb codes and chain codes to process
18 public static String DB_NAME = "pdb_reps";
19 public static String DB_TABLE = "reps";
20 public static String DB_COL_PDB = "accession_code";
21 public static String DB_COL_CHAIN = "chain_pdb_code";
22
23 public static String PDB_DB = "pdbase_test";
24 public static String DB_HOST = "white";
25 public static String DB_USER = getUserName();
26 public static String DB_PWD = "nieve";
27
28 public static String PDB_CODE = "1tdr";
29 public static String CHAIN_CODE = "B";
30 public static double cutoff = 4.2;
31 public static String edgeType = "ALL";
32
33 /*---------------------------- private methods --------------------------*/
34 /**
35 * Get user name from operating system (for use as database username).
36 * */
37 private static String getUserName() {
38 String user = null;
39 user = System.getProperty("user.name");
40 if(user == null) {
41 System.err.println("Could not get user name from operating system.");
42 }
43 return user;
44 }
45
46 public static void main(String[] args) throws IOException {
47 MySQLConnection conn = null;
48 String pdbCode, chainCode;
49 int numPdbs = 0;
50
51 // read command line parameters
52
53 // read structures from database
54 try{
55 conn = new MySQLConnection(DB_HOST, DB_USER, DB_PWD);
56 } catch (Exception e) {
57 System.err.println("Error opening database connection");
58 }
59 String query = "SELECT DISTINCT " + DB_COL_PDB + "," + DB_COL_CHAIN + " FROM " + DB_NAME + "." + DB_TABLE + " LIMIT 1000;" ;
60 Statement stmt;
61 try {
62 stmt = conn.createStatement();
63 ResultSet rs = stmt.executeQuery(query);
64 while(rs.next()) {
65 pdbCode = rs.getString(1);
66 chainCode = rs.getString(2);
67
68 if(chainCode == null) {
69 chainCode = "NULL";
70 }
71
72 numPdbs++;
73 // get graphs
74
75 Pdb pdb = null;
76 try {
77 pdb = new PdbasePdb(pdbCode, PDB_DB, conn);
78 pdb.load(chainCode);
79 int length = pdb.get_length();
80 int atoms = pdb.getNumAtoms();
81
82 // get graph
83 long start = System.currentTimeMillis();
84 RIGraph graph = pdb.get_graph(edgeType, cutoff);
85 long end = System.currentTimeMillis();
86
87 graph.write_graph_to_file(pdbCode+chainCode+"_"+edgeType+"_"+cutoff);
88
89 System.out.print(pdbCode+"_"+chainCode);
90 System.out.print("\t"+length+"\t"+atoms);
91 System.out.printf("\t%4.3f",(double) (end-start)/1000);
92 System.out.println();
93
94
95 } catch (PdbLoadError e) {
96 System.out.println("pdb load error in " + pdbCode + chainCode+", specific error: "+e.getMessage());
97 } catch (PdbCodeNotFoundError e) {
98 e.printStackTrace();
99 } catch (SQLException e) {
100 e.printStackTrace();
101 }
102
103
104
105
106 }
107 System.out.println();
108
109 } catch (SQLException e) {
110 e.printStackTrace();
111 }
112
113 // output results
114 System.out.println("Number of structures: " + numPdbs);
115
116
117 }
118
119 }