faebb1a76d2cd34b395337a7caec5ca52889c63c
[jalview.git] / src / jalview / gui / SequenceFetcher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.gui;
19
20 import java.util.*;
21 import java.util.List;
22
23 import java.awt.*;
24 import java.awt.event.*;
25
26 import javax.swing.*;
27 import javax.swing.tree.DefaultMutableTreeNode;
28
29 import com.stevesoft.pat.Regex;
30
31 import jalview.datamodel.*;
32 import jalview.io.*;
33 import jalview.util.DBRefUtils;
34 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
35 import jalview.ws.seqfetcher.DbSourceProxy;
36 import java.awt.BorderLayout;
37
38 public class SequenceFetcher extends JPanel implements Runnable
39 {
40   // ASequenceFetcher sfetch;
41   JInternalFrame frame;
42
43   IProgressIndicator guiWindow;
44
45   AlignFrame alignFrame;
46
47   StringBuffer result;
48
49   final String noDbSelected = "-- Select Database --";
50
51   private static jalview.ws.SequenceFetcher sfetch = null;
52
53   private static long lastDasSourceRegistry = -3;
54
55   private static DasSourceRegistryI dasRegistry = null;
56
57   private static boolean _initingFetcher = false;
58
59   private static Thread initingThread = null;
60
61   /**
62    * Blocking method that initialises and returns the shared instance of the
63    * SequenceFetcher client
64    * 
65    * @param guiWindow
66    *          - where the initialisation delay message should be shown
67    * @return the singleton instance of the sequence fetcher client
68    */
69   public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
70           final IProgressIndicator guiWindow)
71   {
72     if (_initingFetcher && initingThread != null && initingThread.isAlive())
73     {
74       if (guiWindow != null)
75       {
76         guiWindow.setProgressBar(
77                 "Waiting for Sequence Database Fetchers to initialise",
78                 Thread.currentThread().hashCode());
79       }
80       // initting happening on another thread - so wait around to see if it
81       // finishes.
82       while (_initingFetcher && initingThread != null
83               && initingThread.isAlive())
84       {
85         try
86         {
87           Thread.sleep(10);
88         } catch (Exception e)
89         {
90         }
91         ;
92       }
93       if (guiWindow != null)
94       {
95         guiWindow.setProgressBar(
96                 "Waiting for Sequence Database Fetchers to initialise",
97                 Thread.currentThread().hashCode());
98       }
99     }
100     if (sfetch == null
101             || dasRegistry != jalview.bin.Cache.getDasSourceRegistry()
102             || lastDasSourceRegistry != (jalview.bin.Cache
103                     .getDasSourceRegistry().getDasRegistryURL() + jalview.bin.Cache
104                     .getDasSourceRegistry().getLocalSourceString())
105                     .hashCode())
106     {
107       _initingFetcher = true;
108       initingThread = Thread.currentThread();
109       /**
110        * give a visual indication that sequence fetcher construction is occuring
111        */
112       if (guiWindow != null)
113       {
114         guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
115                 Thread.currentThread().hashCode());
116       }
117       dasRegistry = jalview.bin.Cache.getDasSourceRegistry();
118       dasRegistry.refreshSources();
119
120       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
121       if (guiWindow != null)
122       {
123         guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
124                 Thread.currentThread().hashCode());
125       }
126       lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
127               .getLocalSourceString()).hashCode();
128       sfetch = sf;
129       _initingFetcher = false;
130       initingThread = null;
131     }
132     return sfetch;
133   }
134
135   public SequenceFetcher(IProgressIndicator guiIndic)
136   {
137     final IProgressIndicator guiWindow = guiIndic;
138     final SequenceFetcher us = this;
139     // launch initialiser thread
140     Thread sf = new Thread(new Runnable()
141     {
142
143       @Override
144       public void run()
145       {
146         if (getSequenceFetcherSingleton(guiWindow) != null)
147         {
148           us.initGui(guiWindow);
149         }
150         else
151         {
152           javax.swing.SwingUtilities.invokeLater(new Runnable()
153           {
154             @Override
155             public void run()
156             {
157               JOptionPane
158                       .showInternalMessageDialog(
159                               Desktop.desktop,
160                               "Could not create the sequence fetcher client. Check error logs for details.",
161                               "Couldn't create SequenceFetcher",
162                               JOptionPane.ERROR_MESSAGE);
163             }
164           });
165
166           // raise warning dialog
167         }
168       }
169     });
170     sf.start();
171   }
172
173   private class DatabaseAuthority extends DefaultMutableTreeNode
174   {
175
176   };
177
178   private class DatabaseSource extends DefaultMutableTreeNode
179   {
180
181   };
182
183   /**
184    * called by thread spawned by constructor
185    * 
186    * @param guiWindow
187    */
188   private void initGui(IProgressIndicator guiWindow)
189   {
190     this.guiWindow = guiWindow;
191     if (guiWindow instanceof AlignFrame)
192     {
193       alignFrame = (AlignFrame) guiWindow;
194     }
195     database = new JDatabaseTree(sfetch);
196     try
197     {
198       jbInit();
199     } catch (Exception ex)
200     {
201       ex.printStackTrace();
202     }
203
204     frame = new JInternalFrame();
205     frame.setContentPane(this);
206     if (new jalview.util.Platform().isAMac())
207     {
208       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 240);
209     }
210     else
211     {
212       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
213     }
214   }
215
216   private String getFrameTitle()
217   {
218     return ((alignFrame == null) ? "New " : "Additional ")
219             + "Sequence Fetcher";
220   }
221
222   private void jbInit() throws Exception
223   {
224     this.setLayout(borderLayout2);
225
226     database.setFont(JvSwingUtils.getLabelFont());
227     dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
228     jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
229     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
230     jLabel1.setText("Separate multiple accession ids with semi colon \";\"");
231
232     replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
233     replacePunctuation
234             .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
235     replacePunctuation.setText("Replace commas with semi-colons");
236     ok.setText("OK");
237     ok.addActionListener(new ActionListener()
238     {
239       @Override
240       public void actionPerformed(ActionEvent e)
241       {
242         ok_actionPerformed();
243       }
244     });
245     clear.setText("Clear");
246     clear.addActionListener(new ActionListener()
247     {
248       @Override
249       public void actionPerformed(ActionEvent e)
250       {
251         clear_actionPerformed();
252       }
253     });
254
255     example.setText("Example");
256     example.addActionListener(new ActionListener()
257     {
258       @Override
259       public void actionPerformed(ActionEvent e)
260       {
261         example_actionPerformed();
262       }
263     });
264     close.setText("Close");
265     close.addActionListener(new ActionListener()
266     {
267       @Override
268       public void actionPerformed(ActionEvent e)
269       {
270         close_actionPerformed(e);
271       }
272     });
273     textArea.setFont(JvSwingUtils.getLabelFont());
274     textArea.setLineWrap(true);
275     textArea.addKeyListener(new KeyAdapter()
276     {
277       @Override
278       public void keyPressed(KeyEvent e)
279       {
280         if (e.getKeyCode() == KeyEvent.VK_ENTER)
281           ok_actionPerformed();
282       }
283     });
284     jPanel3.setLayout(borderLayout1);
285     borderLayout1.setVgap(5);
286     jPanel1.add(ok);
287     jPanel1.add(example);
288     jPanel1.add(clear);
289     jPanel1.add(close);
290     jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
291     jPanel2.setLayout(borderLayout3);
292     databaseButt = database.getDatabaseSelectorButton();
293     databaseButt.setFont(JvSwingUtils.getLabelFont());
294     database.addActionListener(new ActionListener()
295     {
296
297       @Override
298       public void actionPerformed(ActionEvent e)
299       {
300         try
301         {
302           databaseButt.setText(database.getSelectedItem()
303                   + (database.getSelectedSources().size() > 1 ? " (and "
304                           + database.getSelectedSources().size()
305                           + " others)" : ""));
306           String eq = database.getExampleQueries();
307           dbeg.setText("Example query: " + eq);
308           boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
309           for (DbSourceProxy dbs : database.getSelectedSources())
310           {
311             if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
312             {
313               enablePunct = false;
314               break;
315             }
316           }
317           replacePunctuation.setEnabled(enablePunct);
318
319         } catch (Exception ex)
320         {
321           dbeg.setText("");
322           replacePunctuation.setEnabled(true);
323         }
324         jPanel2.repaint();
325       }
326     });
327     dbeg.setText("");
328     jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
329     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
330     JPanel jPanel2a = new JPanel(new BorderLayout());
331     jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
332     jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
333     jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
334     // jPanel2.setPreferredSize(new Dimension())
335     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
336     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
337     this.add(jPanel3, java.awt.BorderLayout.CENTER);
338     this.add(jPanel2, java.awt.BorderLayout.NORTH);
339     jScrollPane1.getViewport().add(textArea);
340
341   }
342
343   protected void example_actionPerformed()
344   {
345     DbSourceProxy db = null;
346     try
347     {
348       textArea.setText(database.getExampleQueries());
349     } catch (Exception ex)
350     {
351     }
352     jPanel3.repaint();
353   }
354
355   protected void clear_actionPerformed()
356   {
357     textArea.setText("");
358     jPanel3.repaint();
359   }
360
361   JLabel dbeg = new JLabel();
362
363   JDatabaseTree database;
364
365   JButton databaseButt;
366
367   JLabel jLabel1 = new JLabel();
368
369   JCheckBox replacePunctuation = new JCheckBox();
370
371   JButton ok = new JButton();
372
373   JButton clear = new JButton();
374
375   JButton example = new JButton();
376
377   JButton close = new JButton();
378
379   JPanel jPanel1 = new JPanel();
380
381   JTextArea textArea = new JTextArea();
382
383   JScrollPane jScrollPane1 = new JScrollPane();
384
385   JPanel jPanel2 = new JPanel();
386
387   JPanel jPanel3 = new JPanel();
388
389   JPanel jPanel4 = new JPanel();
390
391   BorderLayout borderLayout1 = new BorderLayout();
392
393   BorderLayout borderLayout2 = new BorderLayout();
394
395   BorderLayout borderLayout3 = new BorderLayout();
396
397   public void close_actionPerformed(ActionEvent e)
398   {
399     try
400     {
401       frame.setClosed(true);
402     } catch (Exception ex)
403     {
404     }
405   }
406
407   public void ok_actionPerformed()
408   {
409     databaseButt.setEnabled(false);
410     example.setEnabled(false);
411     textArea.setEnabled(false);
412     ok.setEnabled(false);
413     close.setEnabled(false);
414
415     Thread worker = new Thread(this);
416     worker.start();
417   }
418
419   private void resetDialog()
420   {
421     databaseButt.setEnabled(true);
422     example.setEnabled(true);
423     textArea.setEnabled(true);
424     ok.setEnabled(true);
425     close.setEnabled(true);
426   }
427
428   @Override
429   public void run()
430   {
431     String error = "";
432     if (!database.hasSelection())
433     {
434       error += "Please select the source database\n";
435     }
436     // TODO: make this transformation more configurable
437     com.stevesoft.pat.Regex empty;
438     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
439     {
440       empty = new com.stevesoft.pat.Regex(
441       // replace commas and spaces with a semicolon
442               "(\\s|[,; ])+", ";");
443     }
444     else
445     {
446       // just turn spaces and semicolons into single semicolons
447       empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
448     }
449     textArea.setText(empty.replaceAll(textArea.getText()));
450     // see if there's anthing to search with
451     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
452             .getText()))
453     {
454       error += "Please enter a (semi-colon separated list of) database id(s)";
455     }
456     if (error.length() > 0)
457     {
458       showErrorMessage(error);
459       resetDialog();
460       return;
461     }
462     // indicate if successive sources should be merged into one alignment.
463     boolean addToLast = false;
464     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
465     ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
466     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
467             .iterator();
468     String[] qries;
469     List<String> nextfetch = Arrays.asList(qries = textArea.getText()
470             .split(";"));
471     Iterator<String> en = Arrays.asList(new String[0]).iterator();
472     int nqueries = qries.length;
473     while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
474     {
475       if (!en.hasNext() && nextfetch.size() > 0)
476       {
477         en = nextfetch.iterator();
478         nqueries = nextfetch.size();
479         // save the remaining queries in the original array
480         qries = nextfetch.toArray(new String[nqueries]);
481         nextfetch = new ArrayList<String>();
482       }
483
484       DbSourceProxy proxy = proxies.next();
485       boolean isAliSource = false;
486       try
487       {
488         // update status
489         guiWindow.setProgressBar("Fetching " + nqueries
490                 + " sequence queries from " + proxy.getDbName(), Thread
491                 .currentThread().hashCode());
492         isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
493         if (proxy.getAccessionSeparator() == null)
494         {
495           while (en.hasNext())
496           {
497             String item = en.next();
498             try
499             {
500               if (aresult != null)
501               {
502                 try
503                 {
504                   // give the server a chance to breathe
505                   Thread.sleep(5);
506                 } catch (Exception e)
507                 {
508                   //
509                 }
510
511               }
512
513               AlignmentI indres = null;
514               try
515               {
516                 indres = proxy.getSequenceRecords(item);
517               } catch (OutOfMemoryError oome)
518               {
519                 new OOMWarning("fetching " + item + " from "
520                         + proxy.getDbName(), oome, this);
521               }
522               if (indres != null)
523               {
524                 aresultq.add(item);
525                 aresult.add(indres);
526               }
527               else
528               {
529                 nextfetch.add(item);
530               }
531             } catch (Exception e)
532             {
533               jalview.bin.Cache.log.info("Error retrieving " + item
534                       + " from " + proxy.getDbName(), e);
535               nextfetch.add(item);
536             }
537           }
538         }
539         else
540         {
541           StringBuffer multiacc = new StringBuffer();
542           ArrayList<String> tosend = new ArrayList<String>();
543           while (en.hasNext())
544           {
545             String nel = en.next();
546             tosend.add(nel);
547             multiacc.append(nel);
548             if (en.hasNext())
549             {
550               multiacc.append(proxy.getAccessionSeparator());
551             }
552           }
553           try
554           {
555             AlignmentI rslt;
556             SequenceI[] rs;
557             List<String> nores = new ArrayList<String>();
558             rslt = proxy.getSequenceRecords(multiacc.toString());
559             if (rslt == null || rslt.getHeight() == 0)
560             {
561               // no results - pass on all queries to next source
562               nextfetch.addAll(tosend);
563             }
564             else
565             {
566               aresultq.add(multiacc.toString());
567               aresult.add(rslt);
568
569               rs = rslt.getSequencesArray();
570               // search for each query in the dbrefs associated with each
571               // sequence
572               // returned.
573               // ones we do not find will be used to query next source (if any)
574               for (String q : tosend)
575               {
576                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
577                 dbr.setSource(proxy.getDbSource());
578                 dbr.setVersion(null);
579                 if (proxy.getAccessionValidator() != null)
580                 {
581                   Regex vgr = proxy.getAccessionValidator();
582                   vgr.search(q);
583                   if (vgr.numSubs() > 0)
584                   {
585                     dbr.setAccessionId(vgr.stringMatched(1));
586                   }
587                   else
588                   {
589                     dbr.setAccessionId(vgr.stringMatched());
590                   }
591                 }
592                 else
593                 {
594                   dbr.setAccessionId(q);
595                 }
596                 boolean rfound = false;
597                 for (int r = 0; r < rs.length; r++)
598                 {
599                   if (rs[r] != null
600                           && (found = DBRefUtils.searchRefs(
601                                   rs[r].getDBRef(), dbr)) != null
602                           && found.length > 0)
603                   {
604                     rfound = true;
605                     rs[r] = null;
606                     continue;
607                   }
608                 }
609                 if (!rfound)
610                 {
611                   nextfetch.add(q);
612                 }
613               }
614             }
615           } catch (OutOfMemoryError oome)
616           {
617             new OOMWarning("fetching " + multiacc + " from "
618                     + database.getSelectedItem(), oome, this);
619           }
620         }
621
622       } catch (Exception e)
623       {
624         showErrorMessage("Error retrieving " + textArea.getText()
625                 + " from " + database.getSelectedItem());
626         // error
627         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
628         System.err.println("Retrieval failed for source ='"
629                 + database.getSelectedItem() + "' and query\n'"
630                 + textArea.getText() + "'\n");
631         e.printStackTrace();
632       } catch (OutOfMemoryError e)
633       {
634         // resets dialog box - so we don't use OOMwarning here.
635         showErrorMessage("Out of Memory when retrieving "
636                 + textArea.getText()
637                 + " from "
638                 + database.getSelectedItem()
639                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
640         e.printStackTrace();
641       } catch (Error e)
642       {
643         showErrorMessage("Serious Error retrieving " + textArea.getText()
644                 + " from " + database.getSelectedItem());
645         e.printStackTrace();
646       }
647       // Stack results ready for opening in alignment windows
648       if (aresult != null && aresult.size() > 0)
649       {
650         AlignmentI ar = null;
651         if (isAliSource)
652         {
653           addToLast = false;
654           // new window for each result
655           while (aresult.size() > 0)
656           {
657             presult.add(aresult.remove(0));
658             presultTitle.add(aresultq.remove(0) + " "
659                     + getDefaultRetrievalTitle());
660           }
661         }
662         else
663         {
664           String titl = null;
665           if (addToLast && presult.size() > 0)
666           {
667             ar = presult.remove(presult.size() - 1);
668             titl = presultTitle.remove(presultTitle.size() - 1);
669           }
670           // concatenate all results in one window
671           while (aresult.size() > 0)
672           {
673             if (ar == null)
674             {
675               ar = aresult.remove(0);
676             }
677             else
678             {
679               ar.append(aresult.remove(0));
680             }
681             ;
682           }
683           addToLast = true;
684           presult.add(ar);
685           presultTitle.add(titl);
686         }
687       }
688       guiWindow.setProgressBar("Finished querying", Thread.currentThread()
689               .hashCode());
690     }
691     guiWindow.setProgressBar((presult.size() > 0) ? "Parsing results."
692             : "Processing ..", Thread.currentThread().hashCode());
693     // process results
694     while (presult.size() > 0)
695     {
696       parseResult(presult.remove(0), presultTitle.remove(0), null);
697     }
698     // only remove visual delay after we finished parsing.
699     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
700     if (nextfetch.size() > 0)
701     {
702       StringBuffer sb = new StringBuffer();
703       sb.append("Didn't retrieve the following "
704               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
705                       + " queries") + ": \n");
706       int l = sb.length(), lr = 0;
707       for (String s : nextfetch)
708       {
709         if (l != sb.length())
710         {
711           sb.append("; ");
712         }
713         if (lr - sb.length() > 40)
714         {
715           sb.append("\n");
716         }
717         sb.append(s);
718       }
719       showErrorMessage(sb.toString());
720     }
721     resetDialog();
722   }
723
724   AlignmentI parseResult(String result, String title)
725   {
726     String format = new IdentifyFile().Identify(result, "Paste");
727     Alignment sequences = null;
728     if (FormatAdapter.isValidFormat(format))
729     {
730       sequences = null;
731       try
732       {
733         sequences = new FormatAdapter().readFile(result.toString(),
734                 "Paste", format);
735       } catch (Exception ex)
736       {
737       }
738
739       if (sequences != null)
740       {
741         return parseResult(sequences, title, format);
742       }
743     }
744     else
745     {
746       showErrorMessage("Error retrieving " + textArea.getText() + " from "
747               + database.getSelectedItem());
748     }
749
750     return null;
751   }
752
753   /**
754    * 
755    * @return a standard title for any results retrieved using the currently
756    *         selected source and settings
757    */
758   public String getDefaultRetrievalTitle()
759   {
760     return "Retrieved from " + database.getSelectedItem();
761   }
762
763   AlignmentI parseResult(AlignmentI al, String title,
764           String currentFileFormat)
765   {
766
767     if (al != null && al.getHeight() > 0)
768     {
769       if (alignFrame == null)
770       {
771         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
772                 AlignFrame.DEFAULT_HEIGHT);
773         if (currentFileFormat != null)
774         {
775           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
776           // FORMAT FOR
777           // NON-FormatAdapter Sourced
778           // Alignments?
779         }
780
781         if (title == null)
782         {
783           title = getDefaultRetrievalTitle();
784         }
785         SequenceFeature[] sfs = null;
786         List<SequenceI> alsqs;
787         synchronized (alsqs = al.getSequences())
788         {
789           for (SequenceI sq : alsqs)
790           {
791             if ((sfs = (sq).getDatasetSequence().getSequenceFeatures()) != null)
792             {
793               if (sfs.length > 0)
794               {
795                 af.setShowSeqFeatures(true);
796                 break;
797               }
798             }
799
800           }
801         }
802         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
803                 AlignFrame.DEFAULT_HEIGHT);
804
805         af.statusBar.setText("Successfully pasted alignment file");
806
807         try
808         {
809           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
810                   false));
811         } catch (Exception ex)
812         {
813         }
814       }
815       else
816       {
817         for (int i = 0; i < al.getHeight(); i++)
818         {
819           alignFrame.viewport.getAlignment().addSequence(
820                   al.getSequenceAt(i)); // this
821           // also
822           // creates
823           // dataset
824           // sequence
825           // entries
826         }
827         alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
828                 .getHeight());
829         alignFrame.viewport.getAlignment().getWidth();
830         alignFrame.viewport.firePropertyChange("alignment", null,
831                 alignFrame.viewport.getAlignment().getSequences());
832       }
833     }
834     return al;
835   }
836
837   void showErrorMessage(final String error)
838   {
839     resetDialog();
840     javax.swing.SwingUtilities.invokeLater(new Runnable()
841     {
842       @Override
843       public void run()
844       {
845         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
846                 "Error Retrieving Data", JOptionPane.WARNING_MESSAGE);
847       }
848     });
849   }
850 }