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