1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.awt.BorderLayout; |
24 |
|
import java.awt.Font; |
25 |
|
import java.awt.event.ActionEvent; |
26 |
|
import java.awt.event.ActionListener; |
27 |
|
import java.awt.event.KeyAdapter; |
28 |
|
import java.awt.event.KeyEvent; |
29 |
|
import java.util.ArrayList; |
30 |
|
import java.util.Arrays; |
31 |
|
import java.util.HashSet; |
32 |
|
import java.util.Iterator; |
33 |
|
import java.util.List; |
34 |
|
|
35 |
|
import javax.swing.JButton; |
36 |
|
import javax.swing.JCheckBox; |
37 |
|
import javax.swing.JComboBox; |
38 |
|
import javax.swing.JInternalFrame; |
39 |
|
import javax.swing.JLabel; |
40 |
|
import javax.swing.JPanel; |
41 |
|
import javax.swing.JScrollPane; |
42 |
|
import javax.swing.JTextArea; |
43 |
|
import javax.swing.SwingConstants; |
44 |
|
|
45 |
|
import jalview.api.FeatureSettingsModelI; |
46 |
|
import jalview.bin.Cache; |
47 |
|
import jalview.bin.Console; |
48 |
|
import jalview.datamodel.AlignmentI; |
49 |
|
import jalview.datamodel.DBRefEntry; |
50 |
|
import jalview.datamodel.SequenceI; |
51 |
|
import jalview.fts.core.GFTSPanel; |
52 |
|
import jalview.fts.service.pdb.PDBFTSPanel; |
53 |
|
import jalview.fts.service.threedbeacons.TDBeaconsFTSPanel; |
54 |
|
import jalview.fts.service.uniprot.UniprotFTSPanel; |
55 |
|
import jalview.io.FileFormatI; |
56 |
|
import jalview.io.gff.SequenceOntologyI; |
57 |
|
import jalview.util.DBRefUtils; |
58 |
|
import jalview.util.MessageManager; |
59 |
|
import jalview.util.Platform; |
60 |
|
import jalview.ws.seqfetcher.DbSourceProxy; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
|
|
| 1.3% |
Uncovered Elements: 442 (448) |
Complexity: 108 |
Complexity Density: 0.35 |
|
69 |
|
public class SequenceFetcher extends JPanel implements Runnable |
70 |
|
{ |
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 6 |
Complexity Density: 0.86 |
|
71 |
|
private class StringPair |
72 |
|
{ |
73 |
|
private String key; |
74 |
|
|
75 |
|
private String display; |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
77 |
0 |
public StringPair(String s1, String s2)... |
78 |
|
{ |
79 |
0 |
key = s1; |
80 |
0 |
display = s2; |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
public StringPair(String s)... |
84 |
|
{ |
85 |
0 |
this(s, s); |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
0 |
public String getKey()... |
89 |
|
{ |
90 |
0 |
return key; |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0 |
public String getDisplay()... |
94 |
|
{ |
95 |
0 |
return display; |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
@Override... |
99 |
|
public String toString() |
100 |
|
{ |
101 |
0 |
return display; |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0 |
public boolean equals(StringPair other)... |
105 |
|
{ |
106 |
0 |
return other.key == this.key; |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
private static jalview.ws.SequenceFetcher sfetch = null; |
111 |
|
|
112 |
|
JLabel exampleAccession; |
113 |
|
|
114 |
|
JComboBox<StringPair> database; |
115 |
|
|
116 |
|
JCheckBox replacePunctuation; |
117 |
|
|
118 |
|
JButton okBtn; |
119 |
|
|
120 |
|
JButton exampleBtn; |
121 |
|
|
122 |
|
JButton closeBtn; |
123 |
|
|
124 |
|
JButton backBtn; |
125 |
|
|
126 |
|
JTextArea textArea; |
127 |
|
|
128 |
|
JInternalFrame frame; |
129 |
|
|
130 |
|
IProgressIndicator guiWindow; |
131 |
|
|
132 |
|
AlignFrame alignFrame; |
133 |
|
|
134 |
|
GFTSPanel parentSearchPanel; |
135 |
|
|
136 |
|
IProgressIndicator progressIndicator; |
137 |
|
|
138 |
|
volatile boolean _isConstructing = false; |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@return |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
145 |
3518 |
public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton()... |
146 |
|
{ |
147 |
3517 |
if (sfetch == null) |
148 |
|
{ |
149 |
6 |
sfetch = new jalview.ws.SequenceFetcher(); |
150 |
|
} |
151 |
3518 |
return sfetch; |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
0 |
public SequenceFetcher(IProgressIndicator guiIndic)... |
161 |
|
{ |
162 |
0 |
this(guiIndic, null, null); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
@param |
170 |
|
@param |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
172 |
0 |
public SequenceFetcher(IProgressIndicator guiIndic,... |
173 |
|
final String selectedDb, final String queryString) |
174 |
|
{ |
175 |
0 |
this.progressIndicator = guiIndic; |
176 |
0 |
getSequenceFetcherSingleton(); |
177 |
0 |
this.guiWindow = progressIndicator; |
178 |
|
|
179 |
0 |
if (progressIndicator instanceof AlignFrame) |
180 |
|
{ |
181 |
0 |
alignFrame = (AlignFrame) progressIndicator; |
182 |
|
} |
183 |
|
|
184 |
0 |
jbInit(selectedDb); |
185 |
0 |
textArea.setText(queryString); |
186 |
|
|
187 |
0 |
frame = new JInternalFrame(); |
188 |
0 |
frame.setContentPane(this); |
189 |
0 |
frame.setFrameIcon(null); |
190 |
0 |
Desktop.addInternalFrame(frame, getFrameTitle(), true, 400, |
191 |
0 |
Platform.isAMacAndNotJS() ? 240 : 180); |
192 |
|
} |
193 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
194 |
0 |
private String getFrameTitle()... |
195 |
|
{ |
196 |
0 |
return ((alignFrame == null) |
197 |
|
? MessageManager.getString("label.new_sequence_fetcher") |
198 |
|
: MessageManager |
199 |
|
.getString("label.additional_sequence_fetcher")); |
200 |
|
} |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 67 (67) |
Complexity: 4 |
Complexity Density: 0.06 |
|
202 |
0 |
private void jbInit(String selectedDb)... |
203 |
|
{ |
204 |
0 |
this.setLayout(new BorderLayout()); |
205 |
|
|
206 |
0 |
database = new JComboBox<>(); |
207 |
0 |
database.setFont(JvSwingUtils.getLabelFont()); |
208 |
0 |
StringPair instructionItem = new StringPair( |
209 |
|
MessageManager.getString("action.select_ddbb")); |
210 |
0 |
database.setPrototypeDisplayValue(instructionItem); |
211 |
0 |
String[] sources = new jalview.ws.SequenceFetcher().getSupportedDb(); |
212 |
0 |
Arrays.sort(sources, String.CASE_INSENSITIVE_ORDER); |
213 |
0 |
database.addItem(instructionItem); |
214 |
0 |
for (String source : sources) |
215 |
|
{ |
216 |
0 |
List<DbSourceProxy> slist = sfetch.getSourceProxy(source); |
217 |
0 |
if (slist.size() == 1 && slist.get(0) != null) |
218 |
|
{ |
219 |
0 |
database.addItem(new StringPair(source, slist.get(0).getDbName())); |
220 |
|
} |
221 |
|
else |
222 |
|
{ |
223 |
0 |
database.addItem(new StringPair(source)); |
224 |
|
} |
225 |
|
} |
226 |
0 |
setDatabaseSelectedItem(selectedDb); |
227 |
0 |
if (database.getSelectedIndex() == -1) |
228 |
|
{ |
229 |
0 |
database.setSelectedIndex(0); |
230 |
|
} |
231 |
0 |
database.setMaximumRowCount(database.getItemCount()); |
232 |
0 |
database.addActionListener(new ActionListener() |
233 |
|
{ |
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
234 |
0 |
@Override... |
235 |
|
public void actionPerformed(ActionEvent e) |
236 |
|
{ |
237 |
0 |
String currentSelection = ((StringPair) database.getSelectedItem()) |
238 |
|
.getKey(); |
239 |
0 |
updateExampleQuery(currentSelection); |
240 |
|
|
241 |
0 |
if ("pdb".equalsIgnoreCase(currentSelection)) |
242 |
|
{ |
243 |
0 |
frame.dispose(); |
244 |
0 |
new PDBFTSPanel(SequenceFetcher.this); |
245 |
|
} |
246 |
0 |
else if ("uniprot".equalsIgnoreCase(currentSelection)) |
247 |
|
{ |
248 |
0 |
frame.dispose(); |
249 |
0 |
new UniprotFTSPanel(SequenceFetcher.this); |
250 |
|
} |
251 |
0 |
else if ("3d-beacons".equalsIgnoreCase(currentSelection)) |
252 |
|
{ |
253 |
0 |
frame.dispose(); |
254 |
0 |
new TDBeaconsFTSPanel(SequenceFetcher.this); |
255 |
|
} |
256 |
|
else |
257 |
|
{ |
258 |
0 |
otherSourceAction(); |
259 |
|
} |
260 |
|
} |
261 |
|
}); |
262 |
|
|
263 |
0 |
exampleAccession = new JLabel(""); |
264 |
0 |
exampleAccession.setFont(new Font("Verdana", Font.BOLD, 11)); |
265 |
0 |
JLabel jLabel1 = new JLabel(MessageManager |
266 |
|
.getString("label.separate_multiple_accession_ids")); |
267 |
0 |
jLabel1.setFont(new Font("Verdana", Font.ITALIC, 11)); |
268 |
0 |
jLabel1.setHorizontalAlignment(SwingConstants.LEFT); |
269 |
|
|
270 |
0 |
replacePunctuation = new JCheckBox( |
271 |
|
MessageManager.getString("label.replace_commas_semicolons")); |
272 |
0 |
replacePunctuation.setHorizontalAlignment(SwingConstants.LEFT); |
273 |
0 |
replacePunctuation.setFont(new Font("Verdana", Font.ITALIC, 11)); |
274 |
0 |
okBtn = new JButton(MessageManager.getString("action.ok")); |
275 |
0 |
okBtn.addActionListener(new ActionListener() |
276 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
277 |
0 |
@Override... |
278 |
|
public void actionPerformed(ActionEvent e) |
279 |
|
{ |
280 |
0 |
ok_actionPerformed(); |
281 |
|
} |
282 |
|
}); |
283 |
0 |
JButton clear = new JButton(MessageManager.getString("action.clear")); |
284 |
0 |
clear.addActionListener(new ActionListener() |
285 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
286 |
0 |
@Override... |
287 |
|
public void actionPerformed(ActionEvent e) |
288 |
|
{ |
289 |
0 |
clear_actionPerformed(); |
290 |
|
} |
291 |
|
}); |
292 |
|
|
293 |
0 |
exampleBtn = new JButton(MessageManager.getString("label.example")); |
294 |
0 |
exampleBtn.addActionListener(new ActionListener() |
295 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
296 |
0 |
@Override... |
297 |
|
public void actionPerformed(ActionEvent e) |
298 |
|
{ |
299 |
0 |
example_actionPerformed(); |
300 |
|
} |
301 |
|
}); |
302 |
0 |
closeBtn = new JButton(MessageManager.getString("action.cancel")); |
303 |
0 |
closeBtn.addActionListener(new ActionListener() |
304 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
305 |
0 |
@Override... |
306 |
|
public void actionPerformed(ActionEvent e) |
307 |
|
{ |
308 |
0 |
close_actionPerformed(e); |
309 |
|
} |
310 |
|
}); |
311 |
0 |
backBtn = new JButton(MessageManager.getString("action.back")); |
312 |
0 |
backBtn.addActionListener(new ActionListener() |
313 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
314 |
0 |
@Override... |
315 |
|
public void actionPerformed(ActionEvent e) |
316 |
|
{ |
317 |
0 |
parentSearchPanel.btn_back_ActionPerformed(); |
318 |
|
} |
319 |
|
}); |
320 |
|
|
321 |
0 |
backBtn.setVisible(false); |
322 |
|
|
323 |
0 |
textArea = new JTextArea(); |
324 |
0 |
textArea.setFont(JvSwingUtils.getLabelFont()); |
325 |
0 |
textArea.setLineWrap(true); |
326 |
0 |
textArea.addKeyListener(new KeyAdapter() |
327 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
328 |
0 |
@Override... |
329 |
|
public void keyPressed(KeyEvent e) |
330 |
|
{ |
331 |
0 |
if (e.getKeyCode() == KeyEvent.VK_ENTER) |
332 |
|
{ |
333 |
0 |
ok_actionPerformed(); |
334 |
|
} |
335 |
|
} |
336 |
|
}); |
337 |
|
|
338 |
0 |
JPanel actionPanel = new JPanel(); |
339 |
0 |
actionPanel.add(backBtn); |
340 |
0 |
actionPanel.add(exampleBtn); |
341 |
0 |
actionPanel.add(clear); |
342 |
0 |
actionPanel.add(okBtn); |
343 |
0 |
actionPanel.add(closeBtn); |
344 |
|
|
345 |
0 |
JPanel databasePanel = new JPanel(); |
346 |
0 |
databasePanel.setLayout(new BorderLayout()); |
347 |
0 |
databasePanel.add(database, BorderLayout.NORTH); |
348 |
0 |
databasePanel.add(exampleAccession, BorderLayout.CENTER); |
349 |
0 |
JPanel jPanel2a = new JPanel(new BorderLayout()); |
350 |
0 |
jPanel2a.add(jLabel1, BorderLayout.NORTH); |
351 |
0 |
jPanel2a.add(replacePunctuation, BorderLayout.SOUTH); |
352 |
0 |
databasePanel.add(jPanel2a, BorderLayout.SOUTH); |
353 |
|
|
354 |
0 |
JPanel idsPanel = new JPanel(); |
355 |
0 |
idsPanel.setLayout(new BorderLayout(0, 5)); |
356 |
0 |
JScrollPane jScrollPane1 = new JScrollPane(); |
357 |
0 |
jScrollPane1.getViewport().add(textArea); |
358 |
0 |
idsPanel.add(jScrollPane1, BorderLayout.CENTER); |
359 |
|
|
360 |
0 |
this.add(actionPanel, BorderLayout.SOUTH); |
361 |
0 |
this.add(idsPanel, BorderLayout.CENTER); |
362 |
0 |
this.add(databasePanel, BorderLayout.NORTH); |
363 |
|
} |
364 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
365 |
0 |
private void setDatabaseSelectedItem(String db)... |
366 |
|
{ |
367 |
0 |
for (int i = 0; i < database.getItemCount(); i++) |
368 |
|
{ |
369 |
0 |
StringPair sp = database.getItemAt(i); |
370 |
0 |
if (sp != null && db != null && db.equals(sp.getKey())) |
371 |
|
{ |
372 |
0 |
database.setSelectedIndex(i); |
373 |
0 |
return; |
374 |
|
} |
375 |
|
} |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
@param |
383 |
|
@return |
384 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
385 |
0 |
protected String getExampleQueries(String db)... |
386 |
|
{ |
387 |
0 |
StringBuilder sb = new StringBuilder(); |
388 |
0 |
HashSet<String> hs = new HashSet<>(); |
389 |
0 |
for (DbSourceProxy dbs : sfetch.getSourceProxy(db)) |
390 |
|
{ |
391 |
0 |
String tq = dbs.getTestQuery(); |
392 |
0 |
if (hs.add(tq)) |
393 |
|
{ |
394 |
0 |
if (sb.length() > 0) |
395 |
|
{ |
396 |
0 |
sb.append(";"); |
397 |
|
} |
398 |
0 |
sb.append(tq); |
399 |
|
} |
400 |
|
} |
401 |
0 |
return sb.toString(); |
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
408 |
0 |
protected void otherSourceAction()... |
409 |
|
{ |
410 |
0 |
try |
411 |
|
{ |
412 |
0 |
String eq = exampleAccession.getText(); |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
0 |
boolean enablePunct = !(eq != null && eq.indexOf(",") > -1); |
417 |
0 |
replacePunctuation.setEnabled(enablePunct); |
418 |
|
|
419 |
|
} catch (Exception ex) |
420 |
|
{ |
421 |
0 |
exampleAccession.setText(""); |
422 |
0 |
replacePunctuation.setEnabled(true); |
423 |
|
} |
424 |
0 |
repaint(); |
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
@param |
432 |
|
@return |
433 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
434 |
0 |
protected String updateExampleQuery(String selectedDatabase)... |
435 |
|
{ |
436 |
0 |
String eq = getExampleQueries(selectedDatabase); |
437 |
0 |
exampleAccession.setText(MessageManager |
438 |
|
.formatMessage("label.example_query_param", new String[] |
439 |
|
{ eq })); |
440 |
0 |
return eq; |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
447 |
0 |
protected void example_actionPerformed()... |
448 |
|
{ |
449 |
0 |
String eq = getExampleQueries( |
450 |
|
((StringPair) database.getSelectedItem()).getKey()); |
451 |
0 |
textArea.setText(eq); |
452 |
0 |
repaint(); |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
458 |
0 |
protected void clear_actionPerformed()... |
459 |
|
{ |
460 |
0 |
textArea.setText(""); |
461 |
0 |
repaint(); |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
@param |
469 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
470 |
0 |
protected void close_actionPerformed(ActionEvent e)... |
471 |
|
{ |
472 |
0 |
try |
473 |
|
{ |
474 |
0 |
frame.setClosed(true); |
475 |
0 |
if (parentSearchPanel != null) |
476 |
|
{ |
477 |
0 |
parentSearchPanel.btn_cancel_ActionPerformed(); |
478 |
|
} |
479 |
|
} catch (Exception ex) |
480 |
|
{ |
481 |
|
} |
482 |
|
} |
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 6 |
Complexity Density: 0.27 |
|
487 |
0 |
public void ok_actionPerformed()... |
488 |
|
{ |
489 |
|
|
490 |
|
|
491 |
|
|
492 |
0 |
String t0 = textArea.getText(); |
493 |
0 |
String text = t0.trim(); |
494 |
0 |
if (replacePunctuation.isEnabled() && replacePunctuation.isSelected()) |
495 |
|
{ |
496 |
0 |
text = text.replace(",", ";"); |
497 |
|
} |
498 |
0 |
text = text.replaceAll("(\\s|[; ])+", ";"); |
499 |
0 |
if (!t0.equals(text)) |
500 |
|
{ |
501 |
0 |
textArea.setText(text); |
502 |
|
} |
503 |
0 |
if (text.isEmpty()) |
504 |
|
{ |
505 |
|
|
506 |
0 |
showErrorMessage( |
507 |
|
"Please enter a (semi-colon separated list of) database id(s)"); |
508 |
0 |
resetDialog(); |
509 |
0 |
return; |
510 |
|
} |
511 |
0 |
if (database.getSelectedIndex() == 0) |
512 |
|
{ |
513 |
|
|
514 |
0 |
showErrorMessage("Please choose a database"); |
515 |
0 |
resetDialog(); |
516 |
0 |
return; |
517 |
|
} |
518 |
|
|
519 |
0 |
exampleBtn.setEnabled(false); |
520 |
0 |
textArea.setEnabled(false); |
521 |
0 |
okBtn.setEnabled(false); |
522 |
0 |
closeBtn.setEnabled(false); |
523 |
0 |
backBtn.setEnabled(false); |
524 |
|
|
525 |
0 |
Thread worker = new Thread(this); |
526 |
0 |
worker.start(); |
527 |
|
} |
528 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
529 |
0 |
private void resetDialog()... |
530 |
|
{ |
531 |
0 |
exampleBtn.setEnabled(true); |
532 |
0 |
textArea.setEnabled(true); |
533 |
0 |
okBtn.setEnabled(true); |
534 |
0 |
closeBtn.setEnabled(true); |
535 |
0 |
backBtn.setEnabled(parentSearchPanel != null); |
536 |
|
} |
537 |
|
|
|
|
| 0% |
Uncovered Elements: 108 (108) |
Complexity: 27 |
Complexity Density: 0.38 |
|
538 |
0 |
@Override... |
539 |
|
public void run() |
540 |
|
{ |
541 |
0 |
boolean addToLast = false; |
542 |
0 |
List<String> aresultq = new ArrayList<>(); |
543 |
0 |
List<String> presultTitle = new ArrayList<>(); |
544 |
0 |
List<AlignmentI> presult = new ArrayList<>(); |
545 |
0 |
List<AlignmentI> aresult = new ArrayList<>(); |
546 |
0 |
List<DbSourceProxy> sources = sfetch.getSourceProxy( |
547 |
|
((StringPair) database.getSelectedItem()).getKey()); |
548 |
0 |
Iterator<DbSourceProxy> proxies = sources.iterator(); |
549 |
0 |
String[] qries = textArea.getText().trim().split(";"); |
550 |
0 |
List<String> nextFetch = Arrays.asList(qries); |
551 |
0 |
Iterator<String> en = Arrays.asList(new String[0]).iterator(); |
552 |
0 |
int nqueries = qries.length; |
553 |
|
|
554 |
0 |
FeatureSettingsModelI preferredFeatureColours = null; |
555 |
0 |
while (proxies.hasNext() && (en.hasNext() || nextFetch.size() > 0)) |
556 |
|
{ |
557 |
0 |
if (!en.hasNext() && nextFetch.size() > 0) |
558 |
|
{ |
559 |
0 |
en = nextFetch.iterator(); |
560 |
0 |
nqueries = nextFetch.size(); |
561 |
|
|
562 |
0 |
qries = nextFetch.toArray(new String[nqueries]); |
563 |
0 |
nextFetch = new ArrayList<>(); |
564 |
|
} |
565 |
|
|
566 |
0 |
DbSourceProxy proxy = proxies.next(); |
567 |
0 |
try |
568 |
|
{ |
569 |
|
|
570 |
0 |
guiWindow.setProgressBar(MessageManager.formatMessage( |
571 |
|
"status.fetching_sequence_queries_from", new String[] |
572 |
|
{ Integer.valueOf(nqueries).toString(), |
573 |
|
proxy.getDbName() }), |
574 |
|
Thread.currentThread().hashCode()); |
575 |
0 |
if (proxy.getMaximumQueryCount() == 1) |
576 |
|
{ |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
0 |
while (en.hasNext()) |
581 |
|
{ |
582 |
0 |
String acc = en.next(); |
583 |
0 |
if (!fetchSingleAccession(proxy, acc, aresultq, aresult)) |
584 |
|
{ |
585 |
0 |
nextFetch.add(acc); |
586 |
|
} |
587 |
|
} |
588 |
|
} |
589 |
|
else |
590 |
|
{ |
591 |
|
|
592 |
|
|
593 |
|
|
594 |
0 |
fetchMultipleAccessions(proxy, en, aresultq, aresult, nextFetch); |
595 |
|
} |
596 |
|
} catch (Exception e) |
597 |
|
{ |
598 |
0 |
showErrorMessage("Error retrieving " + textArea.getText() + " from " |
599 |
|
+ ((StringPair) database.getSelectedItem()).getDisplay()); |
600 |
|
|
601 |
|
|
602 |
0 |
jalview.bin.Console.errPrintln("Retrieval failed for source ='" |
603 |
|
+ ((StringPair) database.getSelectedItem()).getDisplay() |
604 |
|
+ "' and query\n'" + textArea.getText() + "'\n"); |
605 |
0 |
e.printStackTrace(); |
606 |
|
} catch (OutOfMemoryError e) |
607 |
|
{ |
608 |
0 |
showErrorMessage("Out of Memory when retrieving " |
609 |
|
+ textArea.getText() + " from " |
610 |
|
+ ((StringPair) database.getSelectedItem()).getDisplay() |
611 |
|
+ "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n"); |
612 |
0 |
e.printStackTrace(); |
613 |
|
} catch (Error e) |
614 |
|
{ |
615 |
0 |
showErrorMessage("Serious Error retrieving " + textArea.getText() |
616 |
|
+ " from " |
617 |
|
+ ((StringPair) database.getSelectedItem()).getDisplay()); |
618 |
0 |
e.printStackTrace(); |
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
0 |
if (aresult != null && aresult.size() > 0) |
623 |
|
{ |
624 |
0 |
FeatureSettingsModelI proxyColourScheme = proxy |
625 |
|
.getFeatureColourScheme(); |
626 |
0 |
if (proxyColourScheme != null) |
627 |
|
{ |
628 |
0 |
preferredFeatureColours = proxyColourScheme; |
629 |
|
} |
630 |
|
|
631 |
0 |
AlignmentI ar = null; |
632 |
0 |
if (proxy.isAlignmentSource()) |
633 |
|
{ |
634 |
0 |
addToLast = false; |
635 |
|
|
636 |
0 |
while (aresult.size() > 0) |
637 |
|
{ |
638 |
0 |
presult.add(aresult.remove(0)); |
639 |
0 |
presultTitle.add( |
640 |
|
aresultq.remove(0) + " " + getDefaultRetrievalTitle()); |
641 |
|
} |
642 |
|
} |
643 |
|
else |
644 |
|
{ |
645 |
0 |
String titl = null; |
646 |
0 |
if (addToLast && presult.size() > 0) |
647 |
|
{ |
648 |
0 |
ar = presult.remove(presult.size() - 1); |
649 |
0 |
titl = presultTitle.remove(presultTitle.size() - 1); |
650 |
|
} |
651 |
|
|
652 |
0 |
while (aresult.size() > 0) |
653 |
|
{ |
654 |
0 |
if (ar == null) |
655 |
|
{ |
656 |
0 |
ar = aresult.remove(0); |
657 |
|
} |
658 |
|
else |
659 |
|
{ |
660 |
0 |
ar.append(aresult.remove(0)); |
661 |
|
} |
662 |
|
} |
663 |
0 |
addToLast = true; |
664 |
0 |
presult.add(ar); |
665 |
0 |
presultTitle.add(titl); |
666 |
|
} |
667 |
|
} |
668 |
0 |
guiWindow.setProgressBar( |
669 |
|
MessageManager.getString("status.finshed_querying"), |
670 |
|
Thread.currentThread().hashCode()); |
671 |
|
} |
672 |
0 |
guiWindow |
673 |
|
.setProgressBar( |
674 |
0 |
(presult.size() > 0) |
675 |
|
? MessageManager |
676 |
|
.getString("status.parsing_results") |
677 |
|
: MessageManager.getString("status.processing"), |
678 |
|
Thread.currentThread().hashCode()); |
679 |
|
|
680 |
0 |
while (presult.size() > 0) |
681 |
|
{ |
682 |
0 |
parseResult(presult.remove(0), presultTitle.remove(0), null, |
683 |
|
preferredFeatureColours); |
684 |
|
} |
685 |
|
|
686 |
0 |
guiWindow.setProgressBar(null, Thread.currentThread().hashCode()); |
687 |
0 |
if (nextFetch.size() > 0) |
688 |
|
{ |
689 |
0 |
StringBuffer sb = new StringBuffer(); |
690 |
0 |
sb.append("Didn't retrieve the following " |
691 |
0 |
+ (nextFetch.size() == 1 ? "query" |
692 |
|
: nextFetch.size() + " queries") |
693 |
|
+ ": \n"); |
694 |
0 |
int l = sb.length(), lr = 0; |
695 |
0 |
for (String s : nextFetch) |
696 |
|
{ |
697 |
0 |
if (l != sb.length()) |
698 |
|
{ |
699 |
0 |
sb.append("; "); |
700 |
|
} |
701 |
0 |
if (lr - sb.length() > 40) |
702 |
|
{ |
703 |
0 |
sb.append("\n"); |
704 |
|
} |
705 |
0 |
sb.append(s); |
706 |
|
} |
707 |
0 |
showErrorMessage(sb.toString()); |
708 |
|
} |
709 |
0 |
resetDialog(); |
710 |
|
} |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
@param |
716 |
|
@param |
717 |
|
|
718 |
|
@param |
719 |
|
|
720 |
|
@param |
721 |
|
|
722 |
|
@param |
723 |
|
|
724 |
|
@throws |
725 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 7 |
Complexity Density: 0.39 |
|
726 |
0 |
void fetchMultipleAccessions(DbSourceProxy proxy,... |
727 |
|
Iterator<String> accessions, List<String> aresultq, |
728 |
|
List<AlignmentI> aresult, List<String> nextFetch) throws Exception |
729 |
|
{ |
730 |
0 |
StringBuilder multiacc = new StringBuilder(); |
731 |
0 |
List<String> tosend = new ArrayList<>(); |
732 |
0 |
while (accessions.hasNext()) |
733 |
|
{ |
734 |
0 |
String nel = accessions.next(); |
735 |
0 |
tosend.add(nel); |
736 |
0 |
multiacc.append(nel); |
737 |
0 |
if (accessions.hasNext()) |
738 |
|
{ |
739 |
0 |
multiacc.append(proxy.getAccessionSeparator()); |
740 |
|
} |
741 |
|
} |
742 |
|
|
743 |
0 |
try |
744 |
|
{ |
745 |
0 |
String query = multiacc.toString(); |
746 |
0 |
AlignmentI rslt = proxy.getSequenceRecords(query); |
747 |
0 |
if (rslt == null || rslt.getHeight() == 0) |
748 |
|
{ |
749 |
|
|
750 |
0 |
nextFetch.addAll(tosend); |
751 |
|
} |
752 |
|
else |
753 |
|
{ |
754 |
0 |
aresultq.add(query); |
755 |
0 |
aresult.add(rslt); |
756 |
0 |
if (tosend.size() > 1) |
757 |
|
{ |
758 |
0 |
checkResultForQueries(rslt, tosend, nextFetch, proxy); |
759 |
|
} |
760 |
|
} |
761 |
|
} catch (OutOfMemoryError oome) |
762 |
|
{ |
763 |
0 |
new OOMWarning("fetching " + multiacc + " from " |
764 |
|
+ ((StringPair) database.getSelectedItem()).getDisplay(), |
765 |
|
oome, this); |
766 |
|
} |
767 |
|
} |
768 |
|
|
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
@param |
773 |
|
@param |
774 |
|
@param |
775 |
|
|
776 |
|
@param |
777 |
|
|
778 |
|
@return |
779 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.4 |
|
780 |
0 |
boolean fetchSingleAccession(DbSourceProxy proxy, String accession,... |
781 |
|
List<String> aresultq, List<AlignmentI> aresult) |
782 |
|
{ |
783 |
0 |
boolean success = false; |
784 |
0 |
try |
785 |
|
{ |
786 |
0 |
if (aresult != null) |
787 |
|
{ |
788 |
0 |
try |
789 |
|
{ |
790 |
|
|
791 |
0 |
Thread.sleep(5); |
792 |
|
} catch (Exception e) |
793 |
|
{ |
794 |
|
|
795 |
|
} |
796 |
|
} |
797 |
|
|
798 |
0 |
AlignmentI indres = null; |
799 |
0 |
try |
800 |
|
{ |
801 |
0 |
indres = proxy.getSequenceRecords(accession); |
802 |
|
} catch (OutOfMemoryError oome) |
803 |
|
{ |
804 |
0 |
new OOMWarning( |
805 |
|
"fetching " + accession + " from " + proxy.getDbName(), |
806 |
|
oome, this); |
807 |
|
} |
808 |
0 |
if (indres != null) |
809 |
|
{ |
810 |
0 |
aresultq.add(accession); |
811 |
0 |
aresult.add(indres); |
812 |
0 |
success = true; |
813 |
|
} |
814 |
|
} catch (Exception e) |
815 |
|
{ |
816 |
0 |
Console.info("Error retrieving " + accession + " from " |
817 |
|
+ proxy.getDbName(), e); |
818 |
|
} |
819 |
0 |
return success; |
820 |
|
} |
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
|
826 |
|
|
827 |
|
@param |
828 |
|
@param |
829 |
|
@param |
830 |
|
@param |
831 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
832 |
0 |
void checkResultForQueries(AlignmentI rslt, List<String> queries,... |
833 |
|
List<String> nextFetch, DbSourceProxy proxy) |
834 |
|
{ |
835 |
0 |
SequenceI[] rs = rslt.getSequencesArray(); |
836 |
|
|
837 |
0 |
for (String q : queries) |
838 |
|
{ |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
0 |
String accId = proxy.getAccessionIdFromQuery(q); |
844 |
|
|
845 |
0 |
boolean rfound = false; |
846 |
0 |
for (int r = 0, nr = rs.length; r < nr; r++) |
847 |
|
{ |
848 |
0 |
if (rs[r] != null) |
849 |
|
{ |
850 |
0 |
List<DBRefEntry> found = DBRefUtils.searchRefs(rs[r].getDBRefs(), |
851 |
|
accId); |
852 |
0 |
if (!found.isEmpty()) |
853 |
|
{ |
854 |
0 |
rfound = true; |
855 |
0 |
break; |
856 |
|
} |
857 |
|
} |
858 |
|
} |
859 |
0 |
if (!rfound) |
860 |
|
{ |
861 |
0 |
nextFetch.add(q); |
862 |
|
} |
863 |
|
} |
864 |
|
} |
865 |
|
|
866 |
|
|
867 |
|
|
868 |
|
@return |
869 |
|
|
870 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
871 |
0 |
public String getDefaultRetrievalTitle()... |
872 |
|
{ |
873 |
0 |
return "Retrieved from " |
874 |
|
+ ((StringPair) database.getSelectedItem()).getDisplay(); |
875 |
|
} |
876 |
|
|
877 |
|
|
878 |
|
|
879 |
|
|
880 |
|
@param |
881 |
|
@param |
882 |
|
@param |
883 |
|
@param |
884 |
|
@return |
885 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 9 |
Complexity Density: 0.41 |
|
886 |
0 |
public AlignmentI parseResult(AlignmentI al, String title,... |
887 |
|
FileFormatI currentFileFormat, |
888 |
|
FeatureSettingsModelI preferredFeatureColours) |
889 |
|
{ |
890 |
|
|
891 |
0 |
if (al != null && al.getHeight() > 0) |
892 |
|
{ |
893 |
0 |
if (title == null) |
894 |
|
{ |
895 |
0 |
title = getDefaultRetrievalTitle(); |
896 |
|
} |
897 |
0 |
if (alignFrame == null) |
898 |
|
{ |
899 |
0 |
AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, |
900 |
|
AlignFrame.DEFAULT_HEIGHT); |
901 |
0 |
if (currentFileFormat != null) |
902 |
|
{ |
903 |
0 |
af.currentFileFormat = currentFileFormat; |
904 |
|
} |
905 |
|
|
906 |
0 |
List<SequenceI> alsqs = al.getSequences(); |
907 |
0 |
synchronized (alsqs) |
908 |
|
{ |
909 |
0 |
for (SequenceI sq : alsqs) |
910 |
|
{ |
911 |
0 |
if (sq.getFeatures().hasFeatures()) |
912 |
|
{ |
913 |
0 |
af.setShowSeqFeatures(true); |
914 |
0 |
break; |
915 |
|
} |
916 |
|
} |
917 |
|
} |
918 |
|
|
919 |
0 |
af.getViewport().applyFeaturesStyle(preferredFeatureColours); |
920 |
0 |
if (Cache.getDefault("HIDE_INTRONS", true)) |
921 |
|
{ |
922 |
0 |
af.hideFeatureColumns(SequenceOntologyI.EXON, false); |
923 |
|
} |
924 |
0 |
Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, |
925 |
|
AlignFrame.DEFAULT_HEIGHT); |
926 |
|
|
927 |
0 |
af.setStatus(MessageManager |
928 |
|
.getString("label.successfully_pasted_alignment_file")); |
929 |
|
|
930 |
0 |
try |
931 |
|
{ |
932 |
0 |
af.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false)); |
933 |
|
} catch (Exception ex) |
934 |
|
{ |
935 |
|
} |
936 |
|
} |
937 |
|
else |
938 |
|
{ |
939 |
0 |
alignFrame.viewport.addAlignment(al, title); |
940 |
|
} |
941 |
|
} |
942 |
0 |
return al; |
943 |
|
} |
944 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
945 |
0 |
void showErrorMessage(final String error)... |
946 |
|
{ |
947 |
0 |
resetDialog(); |
948 |
0 |
javax.swing.SwingUtilities.invokeLater(new Runnable() |
949 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
950 |
0 |
@Override... |
951 |
|
public void run() |
952 |
|
{ |
953 |
0 |
JvOptionPane.showInternalMessageDialog(Desktop.desktop, error, |
954 |
|
MessageManager.getString("label.error_retrieving_data"), |
955 |
|
JvOptionPane.WARNING_MESSAGE); |
956 |
|
} |
957 |
|
}); |
958 |
|
} |
959 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
960 |
0 |
public IProgressIndicator getProgressIndicator()... |
961 |
|
{ |
962 |
0 |
return progressIndicator; |
963 |
|
} |
964 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
965 |
0 |
public void setProgressIndicator(IProgressIndicator progressIndicator)... |
966 |
|
{ |
967 |
0 |
this.progressIndicator = progressIndicator; |
968 |
|
} |
969 |
|
|
970 |
|
|
971 |
|
|
972 |
|
|
973 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
974 |
0 |
void hidePanel()... |
975 |
|
{ |
976 |
0 |
frame.setVisible(false); |
977 |
|
} |
978 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
979 |
0 |
public void setQuery(String ids)... |
980 |
|
{ |
981 |
0 |
textArea.setText(ids); |
982 |
|
} |
983 |
|
|
984 |
|
|
985 |
|
|
986 |
|
|
987 |
|
|
988 |
|
|
989 |
|
|
990 |
|
@param |
991 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
992 |
0 |
public void embedIn(GFTSPanel parentPanel)... |
993 |
|
{ |
994 |
0 |
database.setVisible(false); |
995 |
0 |
backBtn.setVisible(true); |
996 |
0 |
parentSearchPanel = parentPanel; |
997 |
|
} |
998 |
|
} |