ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/benchmarkGraphAlgorithm.java
Revision: 254
Committed: Thu Aug 9 13:28:02 2007 UTC (17 years, 1 month ago) by duarte
File size: 3421 byte(s)
Log Message:
Also writing graph to file
Line User Rev File contents
1 duarte 254 import java.io.IOException;
2 duarte 253 import java.sql.ResultSet;
3     import java.sql.SQLException;
4     import java.sql.Statement;
5    
6 duarte 254 import proteinstructure.Graph;
7 duarte 253 import proteinstructure.Pdb;
8     import proteinstructure.PdbChainCodeNotFoundError;
9     import proteinstructure.PdbCodeNotFoundError;
10     import proteinstructure.PdbaseInconsistencyError;
11     import proteinstructure.PdbasePdb;
12     import tools.MySQLConnection;
13    
14    
15     public class benchmarkGraphAlgorithm {
16     /*------------------------------ constants ------------------------------*/
17    
18     // database with a list of pdb codes and chain codes to process
19     public static String DB_NAME = "pdb_reps";
20     public static String DB_TABLE = "reps";
21     public static String DB_COL_PDB = "accession_code";
22     public static String DB_COL_CHAIN = "chain_pdb_code";
23    
24     public static String PDB_DB = "pdbase_test";
25     public static String DB_HOST = "white";
26     public static String DB_USER = getUserName();
27     public static String DB_PWD = "nieve";
28    
29     public static String PDB_CODE = "1tdr";
30     public static String CHAIN_CODE = "B";
31     public static double cutoff = 4.2;
32     public static String edgeType = "ALL";
33    
34     /*---------------------------- private methods --------------------------*/
35     /**
36     * Get user name from operating system (for use as database username).
37     * */
38     private static String getUserName() {
39     String user = null;
40     user = System.getProperty("user.name");
41     if(user == null) {
42     System.err.println("Could not get user name from operating system.");
43     }
44     return user;
45     }
46    
47 duarte 254 public static void main(String[] args) throws IOException {
48 duarte 253 MySQLConnection conn = null;
49     String pdbCode, chainCode;
50     int numPdbs = 0;
51    
52     // read command line parameters
53    
54     // read structures from database
55     try{
56     conn = new MySQLConnection(DB_HOST, DB_USER, DB_PWD);
57     } catch (Exception e) {
58     System.err.println("Error opening database connection");
59     }
60     String query = "SELECT DISTINCT " + DB_COL_PDB + "," + DB_COL_CHAIN + " FROM " + DB_NAME + "." + DB_TABLE + " LIMIT 1000;" ;
61     Statement stmt;
62     try {
63     stmt = conn.createStatement();
64     ResultSet rs = stmt.executeQuery(query);
65     while(rs.next()) {
66     pdbCode = rs.getString(1);
67     chainCode = rs.getString(2);
68    
69     if(chainCode == null) {
70     chainCode = "NULL";
71     }
72    
73     numPdbs++;
74     // get graphs
75    
76     Pdb pdb = null;
77     try {
78     pdb = new PdbasePdb(pdbCode, chainCode, PDB_DB, conn);
79     int length = pdb.get_length();
80     int atoms = pdb.getNumAtoms();
81 duarte 254
82     // get graph
83     long start = System.currentTimeMillis();
84     Graph graph = pdb.get_graph(edgeType, cutoff);
85     long end = System.currentTimeMillis();
86    
87     graph.write_graph_to_file(pdbCode+chainCode+"_"+edgeType+"_"+cutoff);
88 duarte 253
89 duarte 254 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 duarte 253 } catch (PdbaseInconsistencyError e) {
96     System.out.println("Inconsistency in " + pdbCode + chainCode);
97     } catch (PdbCodeNotFoundError e) {
98     e.printStackTrace();
99     } catch (SQLException e) {
100     e.printStackTrace();
101     } catch (PdbChainCodeNotFoundError e) {
102     e.printStackTrace();
103     }
104    
105    
106    
107    
108    
109     }
110     System.out.println();
111    
112     } catch (SQLException e) {
113     e.printStackTrace();
114     }
115    
116     // output results
117     System.out.println("Number of structures: " + numPdbs);
118    
119    
120     }
121    
122     }