2.5.1 release branding
[jalview.git] / src / jalview / gui / SequenceFetcher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, 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.io.*;
21 import java.util.*;
22
23 import java.awt.*;
24 import java.awt.event.*;
25
26 import javax.swing.*;
27
28 import MCview.*;
29 import jalview.datamodel.*;
30 import jalview.datamodel.xdb.embl.*;
31 import java.io.File;
32 import jalview.io.*;
33 import jalview.ws.DBRefFetcher;
34 import jalview.ws.ebi.EBIFetchClient;
35 import jalview.ws.seqfetcher.ASequenceFetcher;
36 import jalview.ws.seqfetcher.DbSourceProxy;
37
38 import java.awt.Rectangle;
39 import java.awt.BorderLayout;
40 import java.awt.Dimension;
41
42 public class SequenceFetcher extends JPanel implements Runnable
43 {
44   // ASequenceFetcher sfetch;
45   JInternalFrame frame;
46
47   IProgressIndicator guiWindow;
48
49   AlignFrame alignFrame;
50
51   StringBuffer result;
52
53   final String noDbSelected = "-- Select Database --";
54
55   Hashtable sources = new Hashtable();
56
57   private static jalview.ws.SequenceFetcher sfetch = null;
58
59   private static String dasRegistry = 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 (sfetch == null
73             || dasRegistry != DasSourceBrowser.getDasRegistryURL())
74     {
75       /**
76        * give a visual indication that sequence fetcher construction is occuring
77        */
78       if (guiWindow != null)
79       {
80         guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
81                 Thread.currentThread().hashCode());
82       }
83       dasRegistry = DasSourceBrowser.getDasRegistryURL();
84       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
85       if (guiWindow != null)
86       {
87         guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
88                 Thread.currentThread().hashCode());
89       }
90       sfetch = sf;
91
92     }
93     return sfetch;
94   }
95
96   public SequenceFetcher(IProgressIndicator guiIndic)
97   {
98     final IProgressIndicator guiWindow = guiIndic;
99     final SequenceFetcher us = this;
100     // launch initialiser thread
101     Thread sf = new Thread(new Runnable()
102     {
103
104       public void run()
105       {
106         if (getSequenceFetcherSingleton(guiWindow) != null)
107         {
108           us.initGui(guiWindow);
109         }
110         else
111         {
112           javax.swing.SwingUtilities.invokeLater(new Runnable()
113           {
114             public void run()
115             {
116               JOptionPane
117                       .showInternalMessageDialog(
118                               Desktop.desktop,
119                               "Could not create the sequence fetcher client. Check error logs for details.",
120                               "Couldn't create SequenceFetcher",
121                               JOptionPane.ERROR_MESSAGE);
122             }
123           });
124
125           // raise warning dialog
126         }
127       }
128     });
129     sf.start();
130   }
131
132   /**
133    * called by thread spawned by constructor
134    * 
135    * @param guiWindow
136    */
137   private void initGui(IProgressIndicator guiWindow)
138   {
139     this.guiWindow = guiWindow;
140     if (guiWindow instanceof AlignFrame)
141     {
142       alignFrame = (AlignFrame) guiWindow;
143     }
144
145     database.addItem(noDbSelected);
146     /*
147      * Dynamically generated database list will need a translation function from
148      * internal source to externally distinct names. UNIPROT and UP_NAME are
149      * identical DB sources, and should be collapsed.
150      */
151
152     String dbs[] = sfetch.getOrderedSupportedSources();
153     for (int i = 0; i < dbs.length; i++)
154     {
155       if (!sources.containsValue(dbs[i]))
156       {
157         String name = sfetch.getSourceProxy(dbs[i]).getDbName();
158         // duplicate source names are thrown away, here.
159         if (!sources.containsKey(name))
160         {
161           database.addItem(name);
162         }
163         // overwrite with latest version of the retriever for this source
164         sources.put(name, dbs[i]);
165       }
166     }
167     try
168     {
169       jbInit();
170     } catch (Exception ex)
171     {
172       ex.printStackTrace();
173     }
174
175     frame = new JInternalFrame();
176     frame.setContentPane(this);
177     if (new jalview.util.Platform().isAMac())
178     {
179       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
180     }
181     else
182     {
183       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 140);
184     }
185   }
186
187   private String getFrameTitle()
188   {
189     return ((alignFrame == null) ? "New " : "Additional ")
190             + "Sequence Fetcher";
191   }
192
193   private void jbInit() throws Exception
194   {
195     this.setLayout(borderLayout2);
196
197     database.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
198     dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
199     jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
200     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
201     jLabel1
202             .setText("Separate multiple accession ids with semi colon \";\"");
203     ok.setText("OK");
204     ok.addActionListener(new ActionListener()
205     {
206       public void actionPerformed(ActionEvent e)
207       {
208         ok_actionPerformed();
209       }
210     });
211     clear.setText("Clear");
212     clear.addActionListener(new ActionListener()
213     {
214       public void actionPerformed(ActionEvent e)
215       {
216         clear_actionPerformed();
217       }
218     });
219
220     example.setText("Example");
221     example.addActionListener(new ActionListener()
222     {
223       public void actionPerformed(ActionEvent e)
224       {
225         example_actionPerformed();
226       }
227     });
228     close.setText("Close");
229     close.addActionListener(new ActionListener()
230     {
231       public void actionPerformed(ActionEvent e)
232       {
233         close_actionPerformed(e);
234       }
235     });
236     textArea.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
237     textArea.setLineWrap(true);
238     textArea.addKeyListener(new KeyAdapter()
239     {
240       public void keyPressed(KeyEvent e)
241       {
242         if (e.getKeyCode() == KeyEvent.VK_ENTER)
243           ok_actionPerformed();
244       }
245     });
246     jPanel3.setLayout(borderLayout1);
247     borderLayout1.setVgap(5);
248     jPanel1.add(ok);
249     jPanel1.add(example);
250     jPanel1.add(clear);
251     jPanel1.add(close);
252     jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
253     jPanel2.setLayout(borderLayout3);
254
255     database.addActionListener(new ActionListener()
256     {
257
258       public void actionPerformed(ActionEvent e)
259       {
260         DbSourceProxy db = null;
261         try
262         {
263           db = sfetch.getSourceProxy((String) sources.get(database
264                   .getSelectedItem()));
265           dbeg.setText("Example query: " + db.getTestQuery());
266         } catch (Exception ex)
267         {
268           dbeg.setText("");
269         }
270         jPanel2.repaint();
271       }
272     });
273     dbeg.setText("");
274     jPanel2.add(database, java.awt.BorderLayout.NORTH);
275     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
276     jPanel2.add(jLabel1, java.awt.BorderLayout.SOUTH);
277     // jPanel2.setPreferredSize(new Dimension())
278     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
279     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
280     this.add(jPanel3, java.awt.BorderLayout.CENTER);
281     this.add(jPanel2, java.awt.BorderLayout.NORTH);
282     jScrollPane1.getViewport().add(textArea);
283
284   }
285
286   protected void example_actionPerformed()
287   {
288     DbSourceProxy db = null;
289     try
290     {
291       db = sfetch.getSourceProxy((String) sources.get(database
292               .getSelectedItem()));
293       textArea.setText(db.getTestQuery());
294     } catch (Exception ex)
295     {
296     }
297     jPanel3.repaint();
298   }
299
300   protected void clear_actionPerformed()
301   {
302     textArea.setText("");
303     jPanel3.repaint();
304   }
305
306   JLabel dbeg = new JLabel();
307
308   JComboBox database = new JComboBox();
309
310   JLabel jLabel1 = new JLabel();
311
312   JButton ok = new JButton();
313
314   JButton clear = new JButton();
315
316   JButton example = new JButton();
317
318   JButton close = new JButton();
319
320   JPanel jPanel1 = new JPanel();
321
322   JTextArea textArea = new JTextArea();
323
324   JScrollPane jScrollPane1 = new JScrollPane();
325
326   JPanel jPanel2 = new JPanel();
327
328   JPanel jPanel3 = new JPanel();
329
330   JPanel jPanel4 = new JPanel();
331
332   BorderLayout borderLayout1 = new BorderLayout();
333
334   BorderLayout borderLayout2 = new BorderLayout();
335
336   BorderLayout borderLayout3 = new BorderLayout();
337
338   public void close_actionPerformed(ActionEvent e)
339   {
340     try
341     {
342       frame.setClosed(true);
343     } catch (Exception ex)
344     {
345     }
346   }
347
348   public void ok_actionPerformed()
349   {
350     database.setEnabled(false);
351     textArea.setEnabled(false);
352     ok.setEnabled(false);
353     close.setEnabled(false);
354
355     Thread worker = new Thread(this);
356     worker.start();
357   }
358
359   private void resetDialog()
360   {
361     database.setEnabled(true);
362     textArea.setEnabled(true);
363     ok.setEnabled(true);
364     close.setEnabled(true);
365   }
366
367   public void run()
368   {
369     String error = "";
370     if (database.getSelectedItem().equals(noDbSelected))
371     {
372       error += "Please select the source database\n";
373     }
374     // TODO: make this transformation optional and configurable
375     com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex(
376             "(\\s|[,; ])+", ";"); // \\s+", "");
377     textArea.setText(empty.replaceAll(textArea.getText()));
378     // see if there's anthing to search with
379     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
380             .getText()))
381     {
382       error += "Please enter a (semi-colon separated list of) database id(s)";
383     }
384     if (error.length() > 0)
385     {
386       showErrorMessage(error);
387       resetDialog();
388       return;
389     }
390     AlignmentI aresult = null;
391     Object source = database.getSelectedItem();
392     Enumeration en = new StringTokenizer(textArea.getText(), ";");
393     try
394     {
395       guiWindow.setProgressBar("Fetching Sequences from "
396               + database.getSelectedItem(), Thread.currentThread()
397               .hashCode());
398       DbSourceProxy proxy = sfetch.getSourceProxy((String) sources
399               .get(source));
400       if (proxy.getAccessionSeparator() == null)
401       {
402         while (en.hasMoreElements())
403         {
404           String item = (String) en.nextElement();
405           try
406           {
407             if (aresult != null)
408             {
409               try
410               {
411                 // give the server a chance to breathe
412                 Thread.sleep(5);
413               } catch (Exception e)
414               {
415                 //
416               }
417
418             }
419             AlignmentI indres = proxy.getSequenceRecords(item);
420             if (indres != null)
421             {
422               if (aresult == null)
423               {
424                 aresult = indres;
425               }
426               else
427               {
428                 aresult.append(indres);
429               }
430             }
431           } catch (Exception e)
432           {
433             jalview.bin.Cache.log.info("Error retrieving " + item
434                     + " from " + source, e);
435           }
436         }
437       }
438       else
439       {
440         StringBuffer multiacc = new StringBuffer();
441         while (en.hasMoreElements())
442         {
443           multiacc.append(en.nextElement());
444           if (en.hasMoreElements())
445           {
446             multiacc.append(proxy.getAccessionSeparator());
447           }
448         }
449         aresult = proxy.getSequenceRecords(multiacc.toString());
450       }
451
452     } catch (Exception e)
453     {
454       showErrorMessage("Error retrieving " + textArea.getText() + " from "
455               + database.getSelectedItem());
456       // error +="Couldn't retrieve sequences from "+database.getSelectedItem();
457       System.err.println("Retrieval failed for source ='"
458               + database.getSelectedItem() + "' and query\n'"
459               + textArea.getText() + "'\n");
460       e.printStackTrace();
461     } catch (OutOfMemoryError e)
462     {
463       // resets dialog box - so we don't use OOMwarning here.
464       showErrorMessage("Out of Memory when retrieving "
465               + textArea.getText()
466               + " from "
467               + database.getSelectedItem()
468               + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
469       e.printStackTrace();
470     } catch (Error e)
471     {
472       showErrorMessage("Serious Error retrieving " + textArea.getText()
473               + " from " + database.getSelectedItem());
474       e.printStackTrace();
475     }
476     if (aresult != null)
477     {
478       parseResult(aresult, null, null);
479     }
480     // only remove visual delay after we finished parsing.
481     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
482     resetDialog();
483   }
484
485   /*
486    * result = new StringBuffer(); if
487    * (database.getSelectedItem().equals("Uniprot")) {
488    * getUniprotFile(textArea.getText()); } else if
489    * (database.getSelectedItem().equals("EMBL") ||
490    * database.getSelectedItem().equals("EMBLCDS")) { String DBRefSource =
491    * database.getSelectedItem().equals("EMBLCDS") ?
492    * jalview.datamodel.DBRefSource.EMBLCDS : jalview.datamodel.DBRefSource.EMBL;
493    * 
494    * StringTokenizer st = new StringTokenizer(textArea.getText(), ";");
495    * SequenceI[] seqs = null; while(st.hasMoreTokens()) { EBIFetchClient dbFetch
496    * = new EBIFetchClient(); String qry =
497    * database.getSelectedItem().toString().toLowerCase( ) + ":" +
498    * st.nextToken(); File reply = dbFetch.fetchDataAsFile( qry, "emblxml",null);
499    * 
500    * jalview.datamodel.xdb.embl.EmblFile efile=null; if (reply != null &&
501    * reply.exists()) { efile =
502    * jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply); } if (efile!=null)
503    * { for (Iterator i=efile.getEntries().iterator(); i.hasNext(); ) { EmblEntry
504    * entry = (EmblEntry) i.next(); SequenceI[] seqparts =
505    * entry.getSequences(false,true, DBRefSource); if (seqparts!=null) {
506    * SequenceI[] newseqs = null; int si=0; if (seqs==null) { newseqs = new
507    * SequenceI[seqparts.length]; } else { newseqs = new
508    * SequenceI[seqs.length+seqparts.length];
509    * 
510    * for (;si<seqs.length; si++) { newseqs[si] = seqs[si]; seqs[si] = null; } }
511    * for (int j=0;j<seqparts.length; si++, j++) { newseqs[si] =
512    * seqparts[j].deriveSequence(); // place DBReferences on dataset and refer }
513    * seqs=newseqs; } } } else { result.append("# no response for "+qry); } } if
514    * (seqs!=null && seqs.length>0) { if (parseResult(new Alignment(seqs), null,
515    * null)!=null) { result.append("# Successfully parsed the
516    * "+database.getSelectedItem()+" Queries into an Alignment"); } } } else if
517    * (database.getSelectedItem().equals("PDB")) { StringTokenizer qset = new
518    * StringTokenizer(textArea.getText(), ";"); String query; SequenceI[] seqs =
519    * null; while (qset.hasMoreTokens() && ((query = qset.nextToken())!=null)) {
520    * SequenceI[] seqparts = getPDBFile(query.toUpperCase()); if (seqparts !=
521    * null) { if (seqs == null) { seqs = seqparts; } else { SequenceI[] newseqs =
522    * new SequenceI[seqs.length+seqparts.length]; int i=0; for (; i <
523    * seqs.length; i++) { newseqs[i] = seqs[i]; seqs[i] = null; } for (int
524    * j=0;j<seqparts.length; i++, j++) { newseqs[i] = seqparts[j]; }
525    * seqs=newseqs; } result.append("# Success for "+query.toUpperCase()+"\n"); }
526    * } if (seqs != null && seqs.length > 0) { if (parseResult(new
527    * Alignment(seqs), null, null)!=null) { result.append( "# Successfully parsed
528    * the PDB File Queries into an
529    * Alignment"); } } } else if( database.getSelectedItem().equals("PFAM")) {
530    * try { result.append(new FastaFile(
531    * "http://www.sanger.ac.uk/cgi-bin/Pfam/getalignment.pl?format=fal&acc=" +
532    * textArea.getText().toUpperCase(), "URL").print() );
533    * 
534    * if(result.length()>0) { parseResult( result.toString(),
535    * textArea.getText().toUpperCase() ); } } catch (java.io.IOException ex) {
536    * result = null; } }
537    * 
538    * if (result == null || result.length() == 0) { showErrorMessage("Error
539    * retrieving " + textArea.getText() + " from " + database.getSelectedItem());
540    * }
541    * 
542    * resetDialog(); return; }
543    * 
544    * void getUniprotFile(String id) { EBIFetchClient ebi = new EBIFetchClient();
545    * File file = ebi.fetchDataAsFile("uniprot:" + id, "xml", null);
546    * 
547    * DBRefFetcher dbref = new DBRefFetcher(); Vector entries =
548    * dbref.getUniprotEntries(file);
549    * 
550    * if (entries != null) { //First, make the new sequences Enumeration en =
551    * entries.elements(); while (en.hasMoreElements()) { UniprotEntry entry =
552    * (UniprotEntry) en.nextElement();
553    * 
554    * StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot"); Enumeration
555    * en2 = entry.getAccession().elements(); while (en2.hasMoreElements()) {
556    * name.append("|"); name.append(en2.nextElement()); } en2 =
557    * entry.getName().elements(); while (en2.hasMoreElements()) {
558    * name.append("|"); name.append(en2.nextElement()); }
559    * 
560    * if (entry.getProtein() != null) { name.append(" " +
561    * entry.getProtein().getName().elementAt(0)); }
562    * 
563    * result.append(name + "\n" + entry.getUniprotSequence().getContent() +
564    * "\n"); }
565    * 
566    * //Then read in the features and apply them to the dataset Alignment al =
567    * parseResult(result.toString(), null); for (int i = 0; i < entries.size();
568    * i++) { UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
569    * Enumeration e = entry.getDbReference().elements(); Vector onlyPdbEntries =
570    * new Vector(); while (e.hasMoreElements()) { PDBEntry pdb = (PDBEntry)
571    * e.nextElement(); if (!pdb.getType().equals("PDB")) { continue; }
572    * 
573    * onlyPdbEntries.addElement(pdb); }
574    * 
575    * Enumeration en2 = entry.getAccession().elements(); while
576    * (en2.hasMoreElements()) {
577    * al.getSequenceAt(i).getDatasetSequence().addDBRef(new DBRefEntry(
578    * DBRefSource.UNIPROT, "0", en2.nextElement().toString())); }
579    * 
580    * 
581    * 
582    * 
583    * al.getSequenceAt(i).getDatasetSequence().setPDBId(onlyPdbEntries); if
584    * (entry.getFeature() != null) { e = entry.getFeature().elements(); while
585    * (e.hasMoreElements()) { SequenceFeature sf = (SequenceFeature)
586    * e.nextElement(); sf.setFeatureGroup("Uniprot");
587    * al.getSequenceAt(i).getDatasetSequence().addSequenceFeature( sf ); } } } }
588    * }
589    * 
590    * SequenceI[] getPDBFile(String id) { Vector result = new Vector(); String
591    * chain = null; if (id.indexOf(":") > -1) { chain =
592    * id.substring(id.indexOf(":") + 1); id = id.substring(0, id.indexOf(":")); }
593    * 
594    * EBIFetchClient ebi = new EBIFetchClient(); String file =
595    * ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw"). getAbsolutePath(); if (file
596    * == null) { return null; } try { PDBfile pdbfile = new PDBfile(file,
597    * jalview.io.AppletFormatAdapter.FILE); for (int i = 0; i <
598    * pdbfile.chains.size(); i++) { if (chain == null || ( (PDBChain)
599    * pdbfile.chains.elementAt(i)).id. toUpperCase().equals(chain)) { PDBChain
600    * pdbchain = (PDBChain) pdbfile.chains.elementAt(i); // Get the Chain's
601    * Sequence - who's dataset includes any special features added from the PDB
602    * file SequenceI sq = pdbchain.sequence; // Specially formatted name for the
603    * PDB chain sequences retrieved from the PDB
604    * sq.setName("PDB|"+id+"|"+sq.getName()); // Might need to add more metadata
605    * to the PDBEntry object // like below /* PDBEntry entry = new PDBEntry(); //
606    * Construct the PDBEntry entry.setId(id); if (entry.getProperty() == null)
607    * entry.setProperty(new Hashtable()); entry.getProperty().put("chains",
608    * pdbchain.id + "=" + sq.getStart() + "-" + sq.getEnd());
609    * sq.getDatasetSequence().addPDBId(entry); // Add PDB DB Refs // We make a
610    * DBRefEtntry because we have obtained the PDB file from a verifiable source
611    * // JBPNote - PDB DBRefEntry should also carry the chain and mapping
612    * information DBRefEntry dbentry = new
613    * DBRefEntry(jalview.datamodel.DBRefSource.PDB, "0", id + pdbchain.id);
614    * sq.addDBRef(dbentry); // and add seuqence to the retrieved set
615    * result.addElement(sq.deriveSequence()); } }
616    * 
617    * if (result.size() < 1) { throw new Exception("WsDBFetch for PDB id resulted
618    * in zero result size"); } } catch (Exception ex) // Problem parsing PDB file
619    * { jalview.bin.Cache.log.warn("Exception when retrieving " +
620    * textArea.getText() + " from " + database.getSelectedItem(), ex); return
621    * null; }
622    * 
623    * 
624    * SequenceI[] results = new SequenceI[result.size()]; for (int i = 0, j =
625    * result.size(); i < j; i++) { results[i] = (SequenceI) result.elementAt(i);
626    * result.setElementAt(null,i); } return results; }
627    */
628   AlignmentI parseResult(String result, String title)
629   {
630     String format = new IdentifyFile().Identify(result, "Paste");
631     Alignment sequences = null;
632     if (FormatAdapter.isValidFormat(format))
633     {
634       sequences = null;
635       try
636       {
637         sequences = new FormatAdapter().readFile(result.toString(),
638                 "Paste", format);
639       } catch (Exception ex)
640       {
641       }
642
643       if (sequences != null)
644       {
645         return parseResult(sequences, title, format);
646       }
647     }
648     else
649     {
650       showErrorMessage("Error retrieving " + textArea.getText() + " from "
651               + database.getSelectedItem());
652     }
653
654     return null;
655   }
656
657   AlignmentI parseResult(AlignmentI al, String title,
658           String currentFileFormat)
659   {
660
661     if (al != null && al.getHeight() > 0)
662     {
663       if (alignFrame == null)
664       {
665         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
666                 AlignFrame.DEFAULT_HEIGHT);
667         if (currentFileFormat != null)
668         {
669           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
670           // FORMAT FOR
671           // NON-FormatAdapter Sourced
672           // Alignments?
673         }
674
675         if (title == null)
676         {
677           title = "Retrieved from " + database.getSelectedItem();
678         }
679         SequenceFeature[] sfs = null;
680         for (Enumeration sq = al.getSequences().elements(); sq
681                 .hasMoreElements();)
682         {
683           if ((sfs = ((SequenceI) sq.nextElement()).getDatasetSequence()
684                   .getSequenceFeatures()) != null)
685           {
686             if (sfs.length > 0)
687             {
688               af.setShowSeqFeatures(true);
689               break;
690             }
691           }
692
693         }
694         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
695                 AlignFrame.DEFAULT_HEIGHT);
696
697         af.statusBar.setText("Successfully pasted alignment file");
698
699         try
700         {
701           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
702                   false));
703         } catch (Exception ex)
704         {
705         }
706       }
707       else
708       {
709         for (int i = 0; i < al.getHeight(); i++)
710         {
711           alignFrame.viewport.alignment.addSequence(al.getSequenceAt(i)); // this
712           // also
713           // creates
714           // dataset
715           // sequence
716           // entries
717         }
718         alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment
719                 .getHeight());
720         alignFrame.viewport.alignment.getWidth();
721         alignFrame.viewport.firePropertyChange("alignment", null,
722                 alignFrame.viewport.getAlignment().getSequences());
723       }
724     }
725     return al;
726   }
727
728   void showErrorMessage(final String error)
729   {
730     resetDialog();
731     javax.swing.SwingUtilities.invokeLater(new Runnable()
732     {
733       public void run()
734       {
735         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
736                 "Error Retrieving Data", JOptionPane.WARNING_MESSAGE);
737       }
738     });
739   }
740 }