1 |
import java.sql.*; |
2 |
import java.util.*; |
3 |
import proteinstructure.*; |
4 |
import tools.MySQLConnection; |
5 |
|
6 |
|
7 |
public class calculateGridDensity { |
8 |
|
9 |
/*------------------------------ constants ------------------------------*/ |
10 |
|
11 |
// database with a list of pdb codes and chain codes to process |
12 |
public static String DB_NAME = "pdb_reps"; |
13 |
public static String DB_TABLE = "reps"; |
14 |
public static String DB_COL_PDB = "accession_code"; |
15 |
public static String DB_COL_CHAIN = "chain_pdb_code"; |
16 |
|
17 |
public static String PDB_DB = "pdbase"; |
18 |
public static String DB_HOST = "white"; |
19 |
public static String DB_USER = getUserName(); |
20 |
public static String DB_PWD = "nieve"; |
21 |
|
22 |
public static String PDB_CODE = "1tdr"; |
23 |
public static String CHAIN_CODE = "B"; |
24 |
public static double cutoff = 4.0; |
25 |
public static String edgeType = "Ca"; |
26 |
|
27 |
/*---------------------------- private methods --------------------------*/ |
28 |
/** |
29 |
* Get user name from operating system (for use as database username). |
30 |
* */ |
31 |
private static String getUserName() { |
32 |
String user = null; |
33 |
user = System.getProperty("user.name"); |
34 |
if(user == null) { |
35 |
System.err.println("Could not get user name from operating system."); |
36 |
} |
37 |
return user; |
38 |
} |
39 |
|
40 |
private static void calcDensity(String pdbCode, String chainCode, double cutoff, String egdeType, MySQLConnection conn, Map<Integer, Integer> densityCount) { |
41 |
Pdb pdb = null; |
42 |
try { |
43 |
pdb = new PdbasePdb(pdbCode, chainCode, PDB_DB, conn); |
44 |
// add to density count vector |
45 |
pdb.calcGridDensity(edgeType, cutoff, densityCount); |
46 |
|
47 |
} catch (PdbaseInconsistencyError e) { |
48 |
System.out.println("Inconsistency in " + pdbCode + chainCode); |
49 |
} catch (PdbCodeNotFoundError e) { |
50 |
e.printStackTrace(); |
51 |
} catch (SQLException e) { |
52 |
e.printStackTrace(); |
53 |
} catch (PdbChainCodeNotFoundError e) { |
54 |
e.printStackTrace(); |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
public static void printValues(Map<Integer, Integer> v) { |
60 |
int atoms = 0; |
61 |
for(int size:v.keySet()) { |
62 |
System.out.println(size + ": " + v.get(size)); |
63 |
atoms += size*v.get(size); |
64 |
} |
65 |
System.out.println("Atoms: " + atoms); |
66 |
} |
67 |
|
68 |
public static void main(String[] args) { |
69 |
MySQLConnection conn = null; |
70 |
Map<Integer, Integer> densityCount = new TreeMap<Integer,Integer>(); |
71 |
String pdbCode, chainCode; |
72 |
int numPdbs = 0; |
73 |
|
74 |
// read command line parameters |
75 |
|
76 |
// read structures from database |
77 |
try{ |
78 |
conn = new MySQLConnection(DB_HOST, DB_USER, DB_PWD); |
79 |
} catch (Exception e) { |
80 |
System.err.println("Error opening database connection"); |
81 |
} |
82 |
String query = "SELECT DISTINCT " + DB_COL_PDB + "," + DB_COL_CHAIN + " FROM " + DB_NAME + "." + DB_TABLE + ";" ; |
83 |
Statement stmt; |
84 |
try { |
85 |
stmt = conn.createStatement(); |
86 |
ResultSet rs = stmt.executeQuery(query); |
87 |
while(rs.next()) { |
88 |
pdbCode = rs.getString(1); |
89 |
chainCode = rs.getString(2); |
90 |
|
91 |
if(chainCode == null) { |
92 |
chainCode = "NULL"; |
93 |
} |
94 |
|
95 |
numPdbs++; |
96 |
// calculate statistics |
97 |
calcDensity(pdbCode, chainCode, cutoff, edgeType, conn, densityCount); // will add to densityCount |
98 |
System.out.print("."); |
99 |
|
100 |
// for each protein write to db: pdb, chain, num_res, volume, max_density |
101 |
} |
102 |
System.out.println(); |
103 |
|
104 |
} catch (SQLException e) { |
105 |
e.printStackTrace(); |
106 |
} |
107 |
|
108 |
// output results |
109 |
System.out.println("Number of structures: " + numPdbs); |
110 |
printValues(densityCount); |
111 |
|
112 |
} |
113 |
|
114 |
} |