1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package jalview.ws.dbsources; |
23 |
|
|
24 |
|
import jalview.api.FeatureSettingsModelI; |
25 |
|
import jalview.bin.Cache; |
26 |
|
import jalview.datamodel.AlignmentAnnotation; |
27 |
|
import jalview.datamodel.AlignmentI; |
28 |
|
import jalview.datamodel.DBRefEntry; |
29 |
|
import jalview.datamodel.DBRefSource; |
30 |
|
import jalview.datamodel.PDBEntry; |
31 |
|
import jalview.datamodel.PDBEntry.Type; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.io.DataSourceType; |
34 |
|
import jalview.io.FileFormat; |
35 |
|
import jalview.io.FileFormatI; |
36 |
|
import jalview.io.FormatAdapter; |
37 |
|
import jalview.io.PDBFeatureSettings; |
38 |
|
import jalview.structure.StructureImportSettings; |
39 |
|
import jalview.util.MessageManager; |
40 |
|
import jalview.ws.ebi.EBIFetchClient; |
41 |
|
|
42 |
|
import java.io.File; |
43 |
|
import java.util.ArrayList; |
44 |
|
import java.util.List; |
45 |
|
import java.util.Locale; |
46 |
|
|
47 |
|
import com.stevesoft.pat.Regex; |
48 |
|
|
49 |
|
|
50 |
|
@author |
51 |
|
|
52 |
|
|
|
|
| 7.3% |
Uncovered Elements: 102 (110) |
Complexity: 34 |
Complexity Density: 0.49 |
|
53 |
|
public class Pdb extends EbiFileRetrievedProxy |
54 |
|
{ |
55 |
|
private static final String SEPARATOR = "|"; |
56 |
|
|
57 |
|
private static final String COLON = ":"; |
58 |
|
|
59 |
|
private static final int PDB_ID_LENGTH = 4; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
6 |
public Pdb()... |
62 |
|
{ |
63 |
6 |
super(); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@see |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
@Override... |
72 |
|
public String getAccessionSeparator() |
73 |
|
{ |
74 |
0 |
return null; |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
@see |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public Regex getAccessionValidator() |
84 |
|
{ |
85 |
0 |
return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)"); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@see |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
2059 |
@Override... |
94 |
|
public String getDbSource() |
95 |
|
{ |
96 |
2059 |
return DBRefSource.PDB; |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@see |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0 |
@Override... |
105 |
|
public String getDbVersion() |
106 |
|
{ |
107 |
0 |
return "0"; |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@see |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 84 (84) |
Complexity: 23 |
Complexity Density: 0.41 |
|
115 |
0 |
@Override... |
116 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
117 |
|
{ |
118 |
0 |
updateConfiguration(); |
119 |
0 |
AlignmentI pdbAlignment = null; |
120 |
0 |
String chain = null; |
121 |
0 |
String id = null; |
122 |
0 |
if (queries.indexOf(COLON) > -1) |
123 |
|
{ |
124 |
0 |
chain = queries.substring(queries.indexOf(COLON) + 1); |
125 |
0 |
id = queries.substring(0, queries.indexOf(COLON)); |
126 |
|
} |
127 |
|
else |
128 |
|
{ |
129 |
0 |
id = queries; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
0 |
if (queries.length() > PDB_ID_LENGTH && chain == null) |
137 |
|
{ |
138 |
0 |
chain = queries.substring(PDB_ID_LENGTH, PDB_ID_LENGTH + 1); |
139 |
0 |
id = queries.substring(0, PDB_ID_LENGTH); |
140 |
|
} |
141 |
|
|
142 |
0 |
if (!isValidReference(id)) |
143 |
|
{ |
144 |
0 |
jalview.bin.Console |
145 |
|
.errPrintln("Ignoring invalid pdb query: '" + id + "'"); |
146 |
0 |
stopQuery(); |
147 |
0 |
return null; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
0 |
Type pdbFileFormat = StructureImportSettings |
155 |
|
.getDefaultStructureFileFormat(); |
156 |
0 |
String ext = pdbFileFormat.getExtension(); |
157 |
0 |
String fetchFormat = pdbFileFormat.getFormat(); |
158 |
|
|
159 |
0 |
EBIFetchClient ebi = new EBIFetchClient(); |
160 |
0 |
File tmpFile = ebi.fetchDataAsFile("pdb:" + id, fetchFormat, ext); |
161 |
0 |
file = tmpFile.getAbsolutePath(); |
162 |
0 |
stopQuery(); |
163 |
0 |
if (file == null) |
164 |
|
{ |
165 |
0 |
return null; |
166 |
|
} |
167 |
0 |
try |
168 |
|
{ |
169 |
|
|
170 |
0 |
FileFormatI fileFormat = (pdbFileFormat == Type.PDB) ? FileFormat.PDB |
171 |
|
: FileFormat.MMCif; |
172 |
0 |
pdbAlignment = new FormatAdapter().readFile(tmpFile, |
173 |
|
DataSourceType.FILE, fileFormat); |
174 |
0 |
if (pdbAlignment != null) |
175 |
|
{ |
176 |
0 |
List<SequenceI> toremove = new ArrayList<SequenceI>(); |
177 |
0 |
for (SequenceI pdbcs : pdbAlignment.getSequences()) |
178 |
|
{ |
179 |
0 |
String chid = null; |
180 |
|
|
181 |
0 |
for (PDBEntry pid : pdbcs.getAllPDBEntries()) |
182 |
|
{ |
183 |
0 |
if (pid.getFile() == file) |
184 |
|
{ |
185 |
0 |
chid = pid.getChainCode(); |
186 |
|
|
187 |
|
} |
188 |
|
} |
189 |
0 |
if (chain == null || (chid != null && (chid.equals(chain) |
190 |
|
|| chid.trim().equals(chain.trim()) |
191 |
|
|| (chain.trim().length() == 0 && chid.equals("_"))))) |
192 |
|
{ |
193 |
|
|
194 |
|
|
195 |
0 |
if (legacyJalviewPDBeName) |
196 |
|
{ |
197 |
0 |
pdbcs.setName(jalview.datamodel.DBRefSource.PDB + SEPARATOR + id |
198 |
|
+ SEPARATOR + pdbcs.getName()); |
199 |
|
} else { |
200 |
0 |
if (simpleChainName) |
201 |
|
{ |
202 |
0 |
int sep_pos = pdbcs.getName().indexOf(SEPARATOR); |
203 |
0 |
String cid = pdbcs.getName().substring(0,sep_pos); |
204 |
0 |
cid = cid.toLowerCase(Locale.ROOT); |
205 |
0 |
pdbcs.setName(cid+"_"+pdbcs.getName().substring(sep_pos+1)); |
206 |
0 |
}; |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
0 |
DBRefEntry dbentry = new DBRefEntry(getDbSource(), |
225 |
0 |
getDbVersion(), (chid == null ? id : id + chid)); |
226 |
|
|
227 |
0 |
pdbcs.addDBRef(dbentry); |
228 |
|
} |
229 |
|
else |
230 |
|
{ |
231 |
|
|
232 |
|
|
233 |
0 |
toremove.add(pdbcs); |
234 |
|
} |
235 |
|
} |
236 |
|
|
237 |
0 |
for (SequenceI pdbcs : toremove) |
238 |
|
{ |
239 |
0 |
pdbAlignment.deleteSequence(pdbcs); |
240 |
0 |
if (pdbcs.getAnnotation() != null) |
241 |
|
{ |
242 |
0 |
for (AlignmentAnnotation aa : pdbcs.getAnnotation()) |
243 |
|
{ |
244 |
0 |
pdbAlignment.deleteAnnotation(aa); |
245 |
|
} |
246 |
|
} |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
0 |
if (pdbAlignment == null || pdbAlignment.getHeight() < 1) |
251 |
|
{ |
252 |
0 |
throw new Exception(MessageManager.formatMessage( |
253 |
|
"exception.no_pdb_records_for_chain", new String[] |
254 |
0 |
{ id, ((chain == null) ? "' '" : chain) })); |
255 |
|
} |
256 |
|
|
257 |
|
} catch (Exception ex) |
258 |
|
{ |
259 |
0 |
stopQuery(); |
260 |
0 |
throw (ex); |
261 |
|
} |
262 |
0 |
return pdbAlignment; |
263 |
|
} |
264 |
|
|
265 |
|
boolean simpleChainName=false; |
266 |
|
boolean legacyJalviewPDBeName=true; |
267 |
|
|
268 |
|
private static String SIMPLE="SIMPLE"; |
269 |
|
private static String LEGACY="LEGACY"; |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
274 |
0 |
private void updateConfiguration()... |
275 |
|
{ |
276 |
0 |
final String nameConf = Cache.getDefault(Cache.PDB_CHAIN_NAME, "SIMPLE"); |
277 |
0 |
simpleChainName = SIMPLE.equals(nameConf); |
278 |
0 |
legacyJalviewPDBeName = LEGACY.equals(nameConf); |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
@see |
285 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
286 |
0 |
@Override... |
287 |
|
public boolean isValidReference(String accession) |
288 |
|
{ |
289 |
0 |
Regex r = getAccessionValidator(); |
290 |
0 |
return r.search(accession.trim()); |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
296 |
0 |
@Override... |
297 |
|
public String getTestQuery() |
298 |
|
{ |
299 |
0 |
return "1QIP"; |
300 |
|
} |
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
2055 |
@Override... |
303 |
|
public String getDbName() |
304 |
|
{ |
305 |
2055 |
return "PDB"; |
306 |
|
} |
307 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
308 |
0 |
@Override... |
309 |
|
public int getTier() |
310 |
|
{ |
311 |
0 |
return 0; |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
323 |
2 |
@Override... |
324 |
|
public FeatureSettingsModelI getFeatureColourScheme() |
325 |
|
{ |
326 |
2 |
return new PDBFeatureSettings(); |
327 |
|
} |
328 |
|
} |