formatting
[jalview.git] / src / jalview / gui / SequenceFetcher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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     database.setEnabled(false);
410     textArea.setEnabled(false);
411     ok.setEnabled(false);
412     close.setEnabled(false);
413
414     Thread worker = new Thread(this);
415     worker.start();
416   }
417
418   private void resetDialog()
419   {
420     database.setEnabled(true);
421     textArea.setEnabled(true);
422     ok.setEnabled(true);
423     close.setEnabled(true);
424   }
425
426   @Override
427   public void run()
428   {
429     String error = "";
430     if (!database.hasSelection())
431     {
432       error += "Please select the source database\n";
433     }
434     // TODO: make this transformation more configurable
435     com.stevesoft.pat.Regex empty;
436     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
437     {
438       empty = new com.stevesoft.pat.Regex(
439       // replace commas and spaces with a semicolon
440               "(\\s|[,; ])+", ";");
441     }
442     else
443     {
444       // just turn spaces and semicolons into single semicolons
445       empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
446     }
447     textArea.setText(empty.replaceAll(textArea.getText()));
448     // see if there's anthing to search with
449     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
450             .getText()))
451     {
452       error += "Please enter a (semi-colon separated list of) database id(s)";
453     }
454     if (error.length() > 0)
455     {
456       showErrorMessage(error);
457       resetDialog();
458       return;
459     }
460     // indicate if successive sources should be merged into one alignment.
461     boolean addToLast = false;
462     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
463     ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
464     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
465             .iterator();
466     String[] qries;
467     List<String> nextfetch = Arrays.asList(qries = textArea.getText()
468             .split(";"));
469     Iterator<String> en = Arrays.asList(new String[0]).iterator();
470     int nqueries = qries.length;
471     while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
472     {
473       if (!en.hasNext() && nextfetch.size() > 0)
474       {
475         en = nextfetch.iterator();
476         nqueries = nextfetch.size();
477         // save the remaining queries in the original array
478         qries = nextfetch.toArray(new String[nqueries]);
479         nextfetch = new ArrayList<String>();
480       }
481
482       DbSourceProxy proxy = proxies.next();
483       boolean isAliSource = false;
484       try
485       {
486         // update status
487         guiWindow.setProgressBar("Fetching " + nqueries
488                 + " sequence queries from " + proxy.getDbName(), Thread
489                 .currentThread().hashCode());
490         isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
491         if (proxy.getAccessionSeparator() == null)
492         {
493           while (en.hasNext())
494           {
495             String item = en.next();
496             try
497             {
498               if (aresult != null)
499               {
500                 try
501                 {
502                   // give the server a chance to breathe
503                   Thread.sleep(5);
504                 } catch (Exception e)
505                 {
506                   //
507                 }
508
509               }
510
511               AlignmentI indres = null;
512               try
513               {
514                 indres = proxy.getSequenceRecords(item);
515               } catch (OutOfMemoryError oome)
516               {
517                 new OOMWarning("fetching " + item + " from "
518                         + proxy.getDbName(), oome, this);
519               }
520               if (indres != null)
521               {
522                 aresultq.add(item);
523                 aresult.add(indres);
524               }
525               else
526               {
527                 nextfetch.add(item);
528               }
529             } catch (Exception e)
530             {
531               jalview.bin.Cache.log.info("Error retrieving " + item
532                       + " from " + proxy.getDbName(), e);
533               nextfetch.add(item);
534             }
535           }
536         }
537         else
538         {
539           StringBuffer multiacc = new StringBuffer();
540           ArrayList<String> tosend = new ArrayList<String>();
541           while (en.hasNext())
542           {
543             String nel = en.next();
544             tosend.add(nel);
545             multiacc.append(nel);
546             if (en.hasNext())
547             {
548               multiacc.append(proxy.getAccessionSeparator());
549             }
550           }
551           try
552           {
553             AlignmentI rslt;
554             SequenceI[] rs;
555             List<String> nores = new ArrayList<String>();
556             rslt = proxy.getSequenceRecords(multiacc.toString());
557             if (rslt == null || rslt.getHeight() == 0)
558             {
559               // no results - pass on all queries to next source
560               nextfetch.addAll(tosend);
561             }
562             else
563             {
564               aresultq.add(multiacc.toString());
565               aresult.add(rslt);
566
567               rs = rslt.getSequencesArray();
568               // search for each query in the dbrefs associated with each
569               // sequence
570               // returned.
571               // ones we do not find will be used to query next source (if any)
572               for (String q : tosend)
573               {
574                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
575                 dbr.setSource(proxy.getDbSource());
576                 dbr.setVersion(null);
577                 if (proxy.getAccessionValidator() != null)
578                 {
579                   Regex vgr = proxy.getAccessionValidator();
580                   vgr.search(q);
581                   if (vgr.numSubs() > 0)
582                   {
583                     dbr.setAccessionId(vgr.stringMatched(1));
584                   }
585                   else
586                   {
587                     dbr.setAccessionId(vgr.stringMatched());
588                   }
589                 }
590                 else
591                 {
592                   dbr.setAccessionId(q);
593                 }
594                 boolean rfound = false;
595                 for (int r = 0; r < rs.length; r++)
596                 {
597                   if (rs[r] != null
598                           && (found = DBRefUtils.searchRefs(
599                                   rs[r].getDBRef(), dbr)) != null
600                           && found.length > 0)
601                   {
602                     rfound = true;
603                     rs[r] = null;
604                     continue;
605                   }
606                 }
607                 if (!rfound)
608                 {
609                   nextfetch.add(q);
610                 }
611               }
612             }
613           } catch (OutOfMemoryError oome)
614           {
615             new OOMWarning("fetching " + multiacc + " from "
616                     + database.getSelectedItem(), oome, this);
617           }
618         }
619
620       } catch (Exception e)
621       {
622         showErrorMessage("Error retrieving " + textArea.getText()
623                 + " from " + database.getSelectedItem());
624         // error
625         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
626         System.err.println("Retrieval failed for source ='"
627                 + database.getSelectedItem() + "' and query\n'"
628                 + textArea.getText() + "'\n");
629         e.printStackTrace();
630       } catch (OutOfMemoryError e)
631       {
632         // resets dialog box - so we don't use OOMwarning here.
633         showErrorMessage("Out of Memory when retrieving "
634                 + textArea.getText()
635                 + " from "
636                 + database.getSelectedItem()
637                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
638         e.printStackTrace();
639       } catch (Error e)
640       {
641         showErrorMessage("Serious Error retrieving " + textArea.getText()
642                 + " from " + database.getSelectedItem());
643         e.printStackTrace();
644       }
645       // Stack results ready for opening in alignment windows
646       if (aresult != null && aresult.size() > 0)
647       {
648         AlignmentI ar = null;
649         if (isAliSource)
650         {
651           addToLast = false;
652           // new window for each result
653           while (aresult.size() > 0)
654           {
655             presult.add(aresult.remove(0));
656             presultTitle.add(aresultq.remove(0) + " "
657                     + getDefaultRetrievalTitle());
658           }
659         }
660         else
661         {
662           String titl = null;
663           if (addToLast && presult.size() > 0)
664           {
665             ar = presult.remove(presult.size() - 1);
666             titl = presultTitle.remove(presultTitle.size() - 1);
667           }
668           // concatenate all results in one window
669           while (aresult.size() > 0)
670           {
671             if (ar == null)
672             {
673               ar = aresult.remove(0);
674             }
675             else
676             {
677               ar.append(aresult.remove(0));
678             }
679             ;
680           }
681           addToLast = true;
682           presult.add(ar);
683           presultTitle.add(titl);
684         }
685       }
686       guiWindow.setProgressBar("Finished querying", Thread.currentThread()
687               .hashCode());
688     }
689     guiWindow.setProgressBar((presult.size() > 0) ? "Parsing results."
690             : "Processing ..", Thread.currentThread().hashCode());
691     // process results
692     while (presult.size() > 0)
693     {
694       parseResult(presult.remove(0), presultTitle.remove(0), null);
695     }
696     // only remove visual delay after we finished parsing.
697     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
698     if (nextfetch.size() > 0)
699     {
700       StringBuffer sb = new StringBuffer();
701       sb.append("Didn't retrieve the following "
702               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
703                       + " queries") + ": \n");
704       int l = sb.length(), lr = 0;
705       for (String s : nextfetch)
706       {
707         if (l != sb.length())
708         {
709           sb.append("; ");
710         }
711         if (lr - sb.length() > 40)
712         {
713           sb.append("\n");
714         }
715         sb.append(s);
716       }
717       showErrorMessage(sb.toString());
718     }
719     resetDialog();
720   }
721
722   AlignmentI parseResult(String result, String title)
723   {
724     String format = new IdentifyFile().Identify(result, "Paste");
725     Alignment sequences = null;
726     if (FormatAdapter.isValidFormat(format))
727     {
728       sequences = null;
729       try
730       {
731         sequences = new FormatAdapter().readFile(result.toString(),
732                 "Paste", format);
733       } catch (Exception ex)
734       {
735       }
736
737       if (sequences != null)
738       {
739         return parseResult(sequences, title, format);
740       }
741     }
742     else
743     {
744       showErrorMessage("Error retrieving " + textArea.getText() + " from "
745               + database.getSelectedItem());
746     }
747
748     return null;
749   }
750
751   /**
752    * 
753    * @return a standard title for any results retrieved using the currently
754    *         selected source and settings
755    */
756   public String getDefaultRetrievalTitle()
757   {
758     return "Retrieved from " + database.getSelectedItem();
759   }
760
761   AlignmentI parseResult(AlignmentI al, String title,
762           String currentFileFormat)
763   {
764
765     if (al != null && al.getHeight() > 0)
766     {
767       if (alignFrame == null)
768       {
769         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
770                 AlignFrame.DEFAULT_HEIGHT);
771         if (currentFileFormat != null)
772         {
773           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
774           // FORMAT FOR
775           // NON-FormatAdapter Sourced
776           // Alignments?
777         }
778
779         if (title == null)
780         {
781           title = getDefaultRetrievalTitle();
782         }
783         SequenceFeature[] sfs = null;
784         List<SequenceI> alsqs;
785         synchronized (alsqs = al.getSequences())
786         {
787           for (SequenceI sq : alsqs)
788           {
789             if ((sfs = (sq).getDatasetSequence().getSequenceFeatures()) != null)
790             {
791               if (sfs.length > 0)
792               {
793                 af.setShowSeqFeatures(true);
794                 break;
795               }
796             }
797
798           }
799         }
800         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
801                 AlignFrame.DEFAULT_HEIGHT);
802
803         af.statusBar.setText("Successfully pasted alignment file");
804
805         try
806         {
807           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
808                   false));
809         } catch (Exception ex)
810         {
811         }
812       }
813       else
814       {
815         for (int i = 0; i < al.getHeight(); i++)
816         {
817           alignFrame.viewport.getAlignment().addSequence(
818                   al.getSequenceAt(i)); // this
819           // also
820           // creates
821           // dataset
822           // sequence
823           // entries
824         }
825         alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
826                 .getHeight());
827         alignFrame.viewport.getAlignment().getWidth();
828         alignFrame.viewport.firePropertyChange("alignment", null,
829                 alignFrame.viewport.getAlignment().getSequences());
830       }
831     }
832     return al;
833   }
834
835   void showErrorMessage(final String error)
836   {
837     resetDialog();
838     javax.swing.SwingUtilities.invokeLater(new Runnable()
839     {
840       @Override
841       public void run()
842       {
843         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
844                 "Error Retrieving Data", JOptionPane.WARNING_MESSAGE);
845       }
846     });
847   }
848 }