1 |
duarte |
207 |
package proteinstructure; |
2 |
|
|
|
3 |
|
|
import java.sql.ResultSet; |
4 |
|
|
import java.sql.SQLException; |
5 |
|
|
import java.sql.Statement; |
6 |
|
|
import java.util.ArrayList; |
7 |
|
|
import java.util.HashMap; |
8 |
|
|
|
9 |
|
|
import tools.MySQLConnection; |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* A single chain pdb protein structure loaded from a MSDSD database |
13 |
|
|
* See http://www.ebi.ac.uk/msd-srv/docs/dbdoc/refaindex.html to know what MSDSD is |
14 |
|
|
* |
15 |
|
|
* @author Jose Duarte |
16 |
|
|
* Class: MsdsdPdb |
17 |
|
|
* Package: proteinstructure |
18 |
|
|
*/ |
19 |
|
|
public class MsdsdPdb extends Pdb { |
20 |
|
|
|
21 |
|
|
private final static String MYSQLSERVER="white"; |
22 |
|
|
private final static String MYSQLUSER=MySQLConnection.getUserName(); |
23 |
|
|
private final static String MYSQLPWD="nieve"; |
24 |
|
|
//private final static String DEFAULT_MYMSDSD_DB="my_msdsd_00_07_a"; |
25 |
|
|
private final static String DEFAULT_MSDSD_DB="msdsd_00_07_a"; |
26 |
|
|
|
27 |
|
|
private MySQLConnection conn; |
28 |
|
|
|
29 |
|
|
private int chainid; |
30 |
|
|
private int modelid; |
31 |
|
|
|
32 |
|
|
// TODO for this to be able to be used by other people we need to do things without a myMsdsdDb (or also distribute our fixes database) |
33 |
|
|
private String myMsdsdDb; // our database with add-ons and fixes to msdsd |
34 |
|
|
|
35 |
|
|
/** |
36 |
|
|
* Constructs Pdb object given pdb code and pdb chain code. |
37 |
|
|
* Model will be DEFAULT_MODEL |
38 |
|
|
* MySQLConnection is taken from defaults in MsdsdPdb class: MYSQLSERVER, MYSQLUSER, MYSQLPWD |
39 |
|
|
* Database is taken from default msdsd database in MsdsdPdb class: DEFAULT_MSDSD_DB |
40 |
|
|
* @param pdbCode |
41 |
|
|
* @param pdbChainCode |
42 |
|
|
* @throws MsdsdAcCodeNotFoundError |
43 |
|
|
* @throws MsdsdInconsistentResidueNumbersError |
44 |
|
|
* @throws SQLException |
45 |
|
|
*/ |
46 |
|
|
public MsdsdPdb (String pdbCode, String pdbChainCode) throws MsdsdAcCodeNotFoundError, MsdsdInconsistentResidueNumbersError, SQLException { |
47 |
|
|
this(pdbCode,pdbChainCode,DEFAULT_MODEL,DEFAULT_MSDSD_DB,new MySQLConnection(MYSQLSERVER,MYSQLUSER,MYSQLPWD)); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Constructs Pdb object given pdb code, pdb chain code, db and MySQLConnection |
52 |
|
|
* Model will be DEFAULT_MODEL |
53 |
|
|
* db must be a msdsd database |
54 |
|
|
* @param pdbCode |
55 |
|
|
* @param pdbChainCode |
56 |
|
|
* @param db |
57 |
|
|
* @param conn |
58 |
|
|
* @throws MsdsdAcCodeNotFoundError |
59 |
|
|
* @throws MsdsdInconsistentResidueNumbersError |
60 |
|
|
*/ |
61 |
|
|
public MsdsdPdb (String pdbCode, String pdbChainCode, String db, MySQLConnection conn) throws MsdsdAcCodeNotFoundError, MsdsdInconsistentResidueNumbersError { |
62 |
|
|
this(pdbCode,pdbChainCode,DEFAULT_MODEL,db,conn); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
/** |
66 |
|
|
* Constructs Pdb object given pdb code, pdb chain code and a model serial |
67 |
|
|
* MySQLConnection is taken from defaults in MsdsdPdb class: MYSQLSERVER, MYSQLUSER, MYSQLPWD |
68 |
|
|
* Database is taken from default msdsd database in MsdsdPdb class: DEFAULT_MSDSD_DB |
69 |
|
|
* @param pdbCode |
70 |
|
|
* @param pdbChainCode |
71 |
|
|
* @param model_serial |
72 |
|
|
* @throws MsdsdAcCodeNotFoundError |
73 |
|
|
* @throws MsdsdInconsistentResidueNumbersError |
74 |
|
|
* @throws SQLException |
75 |
|
|
*/ |
76 |
|
|
public MsdsdPdb (String pdbCode, String pdbChainCode, int model_serial) throws MsdsdAcCodeNotFoundError, MsdsdInconsistentResidueNumbersError, SQLException { |
77 |
|
|
this(pdbCode,pdbChainCode,model_serial,DEFAULT_MSDSD_DB,new MySQLConnection(MYSQLSERVER,MYSQLUSER,MYSQLPWD)); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Constructs Pdb object given pdb code, pdb chain code, model serial, a source db and a MySQLConnection. |
82 |
|
|
* db must be a msdsd database |
83 |
|
|
* @param pdbCode |
84 |
|
|
* @param pdbChainCode |
85 |
|
|
* @param model_serial |
86 |
|
|
* @param db |
87 |
|
|
* @param conn |
88 |
|
|
* @throws MsdsdAcCodeNotFoundError |
89 |
|
|
* @throws MsdsdInconsistentResidueNumbersError |
90 |
|
|
*/ |
91 |
|
|
public MsdsdPdb (String pdbCode, String pdbChainCode, int model_serial, String db, MySQLConnection conn) throws MsdsdAcCodeNotFoundError, MsdsdInconsistentResidueNumbersError { |
92 |
|
|
this.pdbCode=pdbCode; |
93 |
|
|
this.pdbChainCode=pdbChainCode; |
94 |
|
|
this.model=model_serial; |
95 |
|
|
this.db=db; |
96 |
|
|
this.myMsdsdDb="my_"+db; // i.e. for db=msdsd_00_07_a then myMsdsdDb=my_msdsd_00_07_a |
97 |
|
|
|
98 |
|
|
this.conn = conn; |
99 |
|
|
|
100 |
|
|
this.getchainid();// initialises chainid, modelid and chainCode |
101 |
|
|
|
102 |
|
|
if (check_inconsistent_res_numbering()){ |
103 |
|
|
throw new MsdsdInconsistentResidueNumbersError("Inconsistent residue numbering in msdsd for accession_code "+this.pdbCode+", chain_pdb_code "+this.pdbChainCode); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
this.sequence = read_seq(); |
107 |
|
|
this.pdbresser2resser = get_ressers_mapping(); |
108 |
|
|
|
109 |
|
|
this.read_atomData(); |
110 |
|
|
|
111 |
|
|
// we initialise resser2pdbresser from the pdbresser2resser HashMap |
112 |
|
|
this.resser2pdbresser = new HashMap<Integer, String>(); |
113 |
|
|
for (String pdbresser:pdbresser2resser.keySet()){ |
114 |
|
|
resser2pdbresser.put(pdbresser2resser.get(pdbresser), pdbresser); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
private void getchainid() throws MsdsdAcCodeNotFoundError { |
119 |
|
|
chainid=0; |
120 |
|
|
String chaincodestr="='"+pdbChainCode+"'"; |
121 |
|
|
if (pdbChainCode.equals("NULL")){ |
122 |
|
|
chaincodestr="IS NULL"; |
123 |
|
|
} |
124 |
|
|
String sql = "SELECT chain_id, model_id, pchain_code " + |
125 |
|
|
" FROM "+myMsdsdDb+".mmol_chain_info " + |
126 |
|
|
" WHERE accession_code='"+pdbCode+"' " + |
127 |
|
|
" AND chain_pdb_code "+chaincodestr + |
128 |
|
|
" AND chain_type='C' " + |
129 |
|
|
" AND asu_chain=1 " + |
130 |
|
|
" AND model_serial="+model; |
131 |
|
|
try { |
132 |
|
|
Statement stmt = conn.createStatement(); |
133 |
|
|
ResultSet rsst = stmt.executeQuery(sql); |
134 |
|
|
if (rsst.next()) { |
135 |
|
|
chainid = rsst.getInt(1); |
136 |
|
|
modelid = rsst.getInt(2); |
137 |
|
|
chainCode=rsst.getString(3); |
138 |
|
|
if (! rsst.isLast()) { |
139 |
|
|
System.err.println("More than 1 chain_id match for accession_code="+pdbCode+", chain_pdb_code="+pdbChainCode); |
140 |
|
|
throw new MsdsdAcCodeNotFoundError("More than 1 chain_id match for accession_code="+pdbCode+", chain_pdb_code="+pdbChainCode); |
141 |
|
|
} |
142 |
|
|
} else { |
143 |
|
|
System.err.println("No chain_id match for accession_code="+pdbCode+", chain_pdb_code="+pdbChainCode); |
144 |
|
|
throw new MsdsdAcCodeNotFoundError("No chain_id could be matched for accession_code "+pdbCode+", chain_pdb_code "+pdbChainCode); |
145 |
|
|
} |
146 |
|
|
rsst.close(); |
147 |
|
|
stmt.close(); |
148 |
|
|
} catch (SQLException e) { |
149 |
|
|
e.printStackTrace(); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
private boolean check_inconsistent_res_numbering(){ |
155 |
|
|
int count=0; |
156 |
|
|
int numserial=0; |
157 |
|
|
try { |
158 |
|
|
String sql="SELECT count(*) " + |
159 |
|
|
" FROM "+myMsdsdDb+".problem_serial_chain " + |
160 |
|
|
" WHERE chain_id="+chainid + |
161 |
|
|
" AND (min_serial!=1 OR num_serial!=num_dist_serial OR num_serial!=max_serial-min_serial+1)"; |
162 |
|
|
Statement stmt = conn.createStatement(); |
163 |
|
|
ResultSet rsst = stmt.executeQuery(sql); |
164 |
|
|
while (rsst.next()) { |
165 |
|
|
count = rsst.getInt(1); |
166 |
|
|
if (count>0){ |
167 |
|
|
return true; |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
sql="SELECT num_serial FROM "+myMsdsdDb+".problem_serial_chain WHERE chain_id="+chainid; |
171 |
|
|
rsst = stmt.executeQuery(sql); |
172 |
|
|
int check = 0; |
173 |
|
|
while (rsst.next()){ |
174 |
|
|
check++; |
175 |
|
|
numserial=rsst.getInt(1); |
176 |
|
|
} |
177 |
|
|
if (check!=1){ |
178 |
|
|
System.err.println("No num_serial match or more than 1 match for accession_code="+pdbCode+", chain_pdb_code="+pdbChainCode); |
179 |
|
|
} |
180 |
|
|
String allresseq = read_seq(); |
181 |
|
|
if (allresseq.length()!=numserial){ |
182 |
|
|
System.err.println("num_serial and length of all_res_seq don't match for accession_code="+pdbCode+", chain_pdb_code="+pdbChainCode); |
183 |
|
|
return true; |
184 |
|
|
} |
185 |
|
|
rsst.close(); |
186 |
|
|
stmt.close(); |
187 |
|
|
} catch (SQLException e) { |
188 |
|
|
e.printStackTrace(); |
189 |
|
|
} |
190 |
|
|
return false; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
private void read_atomData(){ |
194 |
|
|
resser_atom2atomserial = new HashMap<String,Integer>(); |
195 |
|
|
resser2restype = new HashMap<Integer,String>(); |
196 |
|
|
atomser2coord = new HashMap<Integer,Double[]>(); |
197 |
|
|
atomser2resser = new HashMap<Integer,Integer>(); |
198 |
|
|
|
199 |
|
|
String sql = "SELECT serial,chem_atom_name,code_3_letter,residue_serial,x,y,z " + |
200 |
|
|
" FROM "+db+".atom_data " + |
201 |
|
|
" WHERE (model_id = "+modelid+") " + |
202 |
|
|
" AND (chain_id = "+chainid+") " + |
203 |
|
|
" AND (graph_alt_code_used = 1) " + |
204 |
|
|
" AND (graph_standard_aa=1) " + |
205 |
|
|
" AND (pdb_group = 'A')" + |
206 |
|
|
" ORDER BY chain_code, residue_serial, serial"; |
207 |
|
|
try { |
208 |
|
|
Statement stmt = conn.createStatement(); |
209 |
|
|
ResultSet rsst = stmt.executeQuery(sql); |
210 |
|
|
int count=0; |
211 |
|
|
while (rsst.next()){ |
212 |
|
|
count++; |
213 |
|
|
|
214 |
|
|
int atomserial = rsst.getInt(1); // atomserial |
215 |
|
|
String atom = rsst.getString(2).trim(); // atom |
216 |
|
|
String res_type = rsst.getString(3).trim(); // res_type |
217 |
|
|
int res_serial = rsst.getInt(4); // res_serial |
218 |
|
|
double x = rsst.getDouble(5); // x |
219 |
|
|
double y = rsst.getDouble(6); // y |
220 |
|
|
double z = rsst.getDouble(7); // z |
221 |
|
|
Double[] coords = {x, y, z}; |
222 |
|
|
ArrayList<String> aalist=AA.aas(); |
223 |
|
|
if (aalist.contains(res_type)) { |
224 |
|
|
atomser2coord.put(atomserial, coords); |
225 |
|
|
atomser2resser.put(atomserial, res_serial); |
226 |
|
|
resser2restype.put(res_serial, res_type); |
227 |
|
|
ArrayList<String> atomlist = aas2atoms.get(res_type); |
228 |
|
|
if (atomlist.contains(atom)){ |
229 |
|
|
resser_atom2atomserial.put(res_serial+"_"+atom, atomserial); |
230 |
|
|
} |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
|
234 |
|
|
} |
235 |
|
|
if (count==0){ |
236 |
|
|
System.err.println("atom data query returned no data at all for model_id="+modelid+", model_id="+modelid); |
237 |
|
|
} |
238 |
|
|
rsst.close(); |
239 |
|
|
stmt.close(); |
240 |
|
|
} catch (SQLException e) { |
241 |
|
|
e.printStackTrace(); |
242 |
|
|
} |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
private String read_seq(){ |
246 |
|
|
String allresseq=""; |
247 |
|
|
String sql="SELECT all_res_seq FROM "+myMsdsdDb+".chain_seq WHERE chain_id="+chainid; |
248 |
|
|
try { |
249 |
|
|
Statement stmt = conn.createStatement(); |
250 |
|
|
ResultSet rsst = stmt.executeQuery(sql); |
251 |
|
|
int check = 0; |
252 |
|
|
if (rsst.next()) { |
253 |
|
|
check++; |
254 |
|
|
allresseq=rsst.getString(1); |
255 |
|
|
} |
256 |
|
|
if (check!=1) { |
257 |
|
|
System.err.println("No all_res_seq match or more than 1 match for accession_code="+pdbCode+", chain_pdb_code="+pdbChainCode+", chain_id="+chainid); |
258 |
|
|
} |
259 |
|
|
rsst.close(); |
260 |
|
|
stmt.close(); |
261 |
|
|
} catch (SQLException e) { |
262 |
|
|
e.printStackTrace(); |
263 |
|
|
} |
264 |
|
|
|
265 |
|
|
return allresseq; |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
private HashMap<String,Integer> get_ressers_mapping() { |
269 |
|
|
HashMap<String,Integer> map = new HashMap<String, Integer>(); |
270 |
|
|
String sql="SELECT serial, concat(pdb_seq,IF(pdb_insert_code IS NULL,'',pdb_insert_code)) " + |
271 |
|
|
" FROM "+db+".residue " + |
272 |
|
|
" WHERE chain_id="+chainid+ |
273 |
|
|
" AND pdb_seq IS NOT NULL"; |
274 |
|
|
try { |
275 |
|
|
Statement stmt = conn.createStatement(); |
276 |
|
|
ResultSet rsst = stmt.executeQuery(sql); |
277 |
|
|
int count=0; |
278 |
|
|
while (rsst.next()) { |
279 |
|
|
count++; |
280 |
|
|
int resser = rsst.getInt(1); |
281 |
|
|
String pdbresser = rsst.getString(2); |
282 |
|
|
map.put(pdbresser, resser); |
283 |
|
|
} |
284 |
|
|
if (count==0) { |
285 |
|
|
System.err.println("No residue serials mapping data match for chain_id="+chainid); |
286 |
|
|
} |
287 |
|
|
rsst.close(); |
288 |
|
|
stmt.close(); |
289 |
|
|
} catch (SQLException e) { |
290 |
|
|
e.printStackTrace(); |
291 |
|
|
} |
292 |
|
|
|
293 |
|
|
return map; |
294 |
|
|
} |
295 |
|
|
|
296 |
|
|
} |