JAL-2051 better checking of retrieved / duplicated accession ids
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index fb94c05..812bf76 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  */
 package jalview.gui;
 
-import jalview.datamodel.Alignment;
+import jalview.api.FeatureSettingsModelI;
+import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
-import jalview.io.FormatAdapter;
-import jalview.io.IdentifyFile;
+import jalview.fts.service.pdb.PDBFTSPanel;
+import jalview.fts.service.uniprot.UniprotFTSPanel;
+import jalview.io.gff.SequenceOntologyI;
 import jalview.util.DBRefUtils;
 import jalview.util.MessageManager;
 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
@@ -55,8 +56,6 @@ import javax.swing.JTextArea;
 import javax.swing.SwingConstants;
 import javax.swing.tree.DefaultMutableTreeNode;
 
-import com.stevesoft.pat.Regex;
-
 public class SequenceFetcher extends JPanel implements Runnable
 {
   JLabel dbeg = new JLabel();
@@ -115,7 +114,13 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   private static Thread initingThread = null;
 
-  int x = 0;
+  int debounceTrap = 0;
+
+  public JTextArea getTextArea()
+  {
+    return textArea;
+  }
+
   /**
    * Blocking method that initialises and returns the shared instance of the
    * SequenceFetcher client
@@ -131,9 +136,11 @@ public class SequenceFetcher extends JPanel implements Runnable
     {
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar(
-                MessageManager.getString("status.waiting_sequence_database_fetchers_init"),
-                Thread.currentThread().hashCode());
+        guiWindow
+                .setProgressBar(
+                        MessageManager
+                                .getString("status.waiting_sequence_database_fetchers_init"),
+                        Thread.currentThread().hashCode());
       }
       // initting happening on another thread - so wait around to see if it
       // finishes.
@@ -150,15 +157,17 @@ public class SequenceFetcher extends JPanel implements Runnable
       }
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar(
-                       MessageManager.getString("status.waiting_sequence_database_fetchers_init"),
-                Thread.currentThread().hashCode());
+        guiWindow
+                .setProgressBar(
+                        MessageManager
+                                .getString("status.waiting_sequence_database_fetchers_init"),
+                        Thread.currentThread().hashCode());
       }
     }
     if (sfetch == null
-            || dasRegistry != jalview.bin.Cache.getDasSourceRegistry()
-            || lastDasSourceRegistry != (jalview.bin.Cache
-                    .getDasSourceRegistry().getDasRegistryURL() + jalview.bin.Cache
+            || dasRegistry != Cache.getDasSourceRegistry()
+            || lastDasSourceRegistry != (Cache.getDasSourceRegistry()
+                    .getDasRegistryURL() + Cache
                     .getDasSourceRegistry().getLocalSourceString())
                     .hashCode())
     {
@@ -169,17 +178,17 @@ public class SequenceFetcher extends JPanel implements Runnable
        */
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar(MessageManager.getString("status.init_sequence_database_fetchers"),
+        guiWindow.setProgressBar(MessageManager
+                .getString("status.init_sequence_database_fetchers"),
                 Thread.currentThread().hashCode());
       }
-      dasRegistry = jalview.bin.Cache.getDasSourceRegistry();
+      dasRegistry = Cache.getDasSourceRegistry();
       dasRegistry.refreshSources();
 
       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
       if (guiWindow != null)
       {
-        guiWindow.setProgressBar(MessageManager.getString("status.init_sequence_database_fetchers"),
-                Thread.currentThread().hashCode());
+        guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
       }
       lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
               .getLocalSourceString()).hashCode();
@@ -190,9 +199,11 @@ public class SequenceFetcher extends JPanel implements Runnable
     return sfetch;
   }
 
+  private IProgressIndicator progressIndicator;
+
   public SequenceFetcher(IProgressIndicator guiIndic)
   {
-    final IProgressIndicator guiWindow = guiIndic;
+    this.progressIndicator = guiIndic;
     final SequenceFetcher us = this;
     // launch initialiser thread
     Thread sf = new Thread(new Runnable()
@@ -201,9 +212,9 @@ public class SequenceFetcher extends JPanel implements Runnable
       @Override
       public void run()
       {
-        if (getSequenceFetcherSingleton(guiWindow) != null)
+        if (getSequenceFetcherSingleton(progressIndicator) != null)
         {
-          us.initGui(guiWindow);
+          us.initGui(progressIndicator);
         }
         else
         {
@@ -215,8 +226,10 @@ public class SequenceFetcher extends JPanel implements Runnable
               JOptionPane
                       .showInternalMessageDialog(
                               Desktop.desktop,
-                              MessageManager.getString("warn.couldnt_create_sequence_fetcher_client"),
-                              MessageManager.getString("label.couldnt_create_sequence_fetcher"),
+                              MessageManager
+                                      .getString("warn.couldnt_create_sequence_fetcher_client"),
+                              MessageManager
+                                      .getString("label.couldnt_create_sequence_fetcher"),
                               JOptionPane.ERROR_MESSAGE);
             }
           });
@@ -273,7 +286,9 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   private String getFrameTitle()
   {
-    return ((alignFrame == null) ? MessageManager.getString("label.new_sequence_fetcher") : MessageManager.getString("label.additional_sequence_fetcher"));
+    return ((alignFrame == null) ? MessageManager
+            .getString("label.new_sequence_fetcher") : MessageManager
+            .getString("label.additional_sequence_fetcher"));
   }
 
   private void jbInit() throws Exception
@@ -357,21 +372,28 @@ public class SequenceFetcher extends JPanel implements Runnable
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        x++;
+        debounceTrap++;
         String currentSelection = database.getSelectedItem();
 
-        if (!currentSelection.equalsIgnoreCase("pdb"))
+        if (currentSelection.equalsIgnoreCase("pdb")
+                && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0)))
         {
-            otherSourceAction();
+          pdbSourceAction();
         }
-        if (currentSelection.equalsIgnoreCase("pdb") && ((x % 2) == 0))
+        // else if (currentSelection.equalsIgnoreCase("uniprot")
+        // && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) ==
+        // 0)))
+        // {
+        // uniprotSourceAction();
+        // }
+        else
         {
-          frame.dispose();
-          new EBIFetchPanel();
+          otherSourceAction();
         }
-
+        database.action = -1;
       }
     });
+
     dbeg.setText("");
     jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
@@ -388,9 +410,18 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   }
 
-  private void hideX()
+  private void pdbSourceAction()
   {
-    this.setVisible(false);
+    databaseButt.setText(database.getSelectedItem());
+    new PDBFTSPanel(this);
+    frame.dispose();
+  }
+
+  private void uniprotSourceAction()
+  {
+    databaseButt.setText(database.getSelectedItem());
+    new UniprotFTSPanel(this);
+    frame.dispose();
   }
   private void otherSourceAction()
   {
@@ -402,8 +433,7 @@ public class SequenceFetcher extends JPanel implements Runnable
                       : ""));
       String eq = database.getExampleQueries();
       dbeg.setText(MessageManager.formatMessage(
-              "label.example_query_param", new String[]
-              { eq }));
+              "label.example_query_param", new String[] { eq }));
       boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
       for (DbSourceProxy dbs : database.getSelectedSources())
       {
@@ -441,8 +471,6 @@ public class SequenceFetcher extends JPanel implements Runnable
     jPanel3.repaint();
   }
 
-
-
   public void close_actionPerformed(ActionEvent e)
   {
     try
@@ -508,165 +536,65 @@ public class SequenceFetcher extends JPanel implements Runnable
       resetDialog();
       return;
     }
+    // TODO: Refactor to GUI independent code and write tests.
     // indicate if successive sources should be merged into one alignment.
     boolean addToLast = false;
-    ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
-    ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
+    List<String> aresultq = new ArrayList<String>();
+    List<String> presultTitle = new ArrayList<String>();
+    List<AlignmentI> presult = new ArrayList<AlignmentI>();
+    List<AlignmentI> aresult = new ArrayList<AlignmentI>();
     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
             .iterator();
     String[] qries;
-    List<String> nextfetch = Arrays.asList(qries = textArea.getText()
+    List<String> nextFetch = Arrays.asList(qries = textArea.getText()
             .split(";"));
     Iterator<String> en = Arrays.asList(new String[0]).iterator();
     int nqueries = qries.length;
-    while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
+
+    FeatureSettingsModelI preferredFeatureColours = null;
+    while (proxies.hasNext() && (en.hasNext() || nextFetch.size() > 0))
     {
-      if (!en.hasNext() && nextfetch.size() > 0)
+      if (!en.hasNext() && nextFetch.size() > 0)
       {
-        en = nextfetch.iterator();
-        nqueries = nextfetch.size();
+        en = nextFetch.iterator();
+        nqueries = nextFetch.size();
         // save the remaining queries in the original array
-        qries = nextfetch.toArray(new String[nqueries]);
-        nextfetch = new ArrayList<String>();
+        qries = nextFetch.toArray(new String[nqueries]);
+        nextFetch = new ArrayList<String>();
       }
 
       DbSourceProxy proxy = proxies.next();
-      boolean isAliSource = false;
       try
       {
         // update status
-        guiWindow.setProgressBar(MessageManager.formatMessage("status.fetching_sequence_queries_from", new String[]{Integer.valueOf(nqueries).toString(),proxy.getDbName()}), Thread
-                .currentThread().hashCode());
-        isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
-        if (proxy.getAccessionSeparator() == null)
+        guiWindow
+                .setProgressBar(MessageManager.formatMessage(
+                        "status.fetching_sequence_queries_from",
+                        new String[] {
+                            Integer.valueOf(nqueries).toString(),
+                            proxy.getDbName() }), Thread.currentThread()
+                        .hashCode());
+        if (proxy.getMaximumQueryCount() == 1)
         {
+          /*
+           * proxy only handles one accession id at a time
+           */
           while (en.hasNext())
           {
-            String item = en.next();
-            try
-            {
-              if (aresult != null)
-              {
-                try
-                {
-                  // give the server a chance to breathe
-                  Thread.sleep(5);
-                } catch (Exception e)
-                {
-                  //
-                }
-
-              }
-
-              AlignmentI indres = null;
-              try
-              {
-                indres = proxy.getSequenceRecords(item);
-              } catch (OutOfMemoryError oome)
-              {
-                new OOMWarning("fetching " + item + " from "
-                        + proxy.getDbName(), oome, this);
-              }
-              if (indres != null)
-              {
-                aresultq.add(item);
-                aresult.add(indres);
-              }
-              else
-              {
-                nextfetch.add(item);
-              }
-            } catch (Exception e)
+            String acc = en.next();
+            if (!fetchSingleAccession(proxy, acc, aresultq, aresult))
             {
-              jalview.bin.Cache.log.info("Error retrieving " + item
-                      + " from " + proxy.getDbName(), e);
-              nextfetch.add(item);
+              nextFetch.add(acc);
             }
           }
         }
         else
         {
-          StringBuffer multiacc = new StringBuffer();
-          ArrayList<String> tosend = new ArrayList<String>();
-          while (en.hasNext())
-          {
-            String nel = en.next();
-            tosend.add(nel);
-            multiacc.append(nel);
-            if (en.hasNext())
-            {
-              multiacc.append(proxy.getAccessionSeparator());
-            }
-          }
-          try
-          {
-            AlignmentI rslt;
-            SequenceI[] rs;
-            List<String> nores = new ArrayList<String>();
-            rslt = proxy.getSequenceRecords(multiacc.toString());
-            if (rslt == null || rslt.getHeight() == 0)
-            {
-              // no results - pass on all queries to next source
-              nextfetch.addAll(tosend);
-            }
-            else
-            {
-              aresultq.add(multiacc.toString());
-              aresult.add(rslt);
-
-              rs = rslt.getSequencesArray();
-              // search for each query in the dbrefs associated with each
-              // sequence
-              // returned.
-              // ones we do not find will be used to query next source (if any)
-              for (String q : tosend)
-              {
-                DBRefEntry dbr = new DBRefEntry(), found[] = null;
-                dbr.setSource(proxy.getDbSource());
-                dbr.setVersion(null);
-                if (proxy.getAccessionValidator() != null)
-                {
-                  Regex vgr = proxy.getAccessionValidator();
-                  vgr.search(q);
-                  if (vgr.numSubs() > 0)
-                  {
-                    dbr.setAccessionId(vgr.stringMatched(1));
-                  }
-                  else
-                  {
-                    dbr.setAccessionId(vgr.stringMatched());
-                  }
-                }
-                else
-                {
-                  dbr.setAccessionId(q);
-                }
-                boolean rfound = false;
-                for (int r = 0; r < rs.length; r++)
-                {
-                  if (rs[r] != null
-                          && (found = DBRefUtils.searchRefs(
-                                  rs[r].getDBRef(), dbr)) != null
-                          && found.length > 0)
-                  {
-                    rfound = true;
-                    rs[r] = null;
-                    continue;
-                  }
-                }
-                if (!rfound)
-                {
-                  nextfetch.add(q);
-                }
-              }
-            }
-          } catch (OutOfMemoryError oome)
-          {
-            new OOMWarning("fetching " + multiacc + " from "
-                    + database.getSelectedItem(), oome, this);
-          }
+          /*
+           * proxy can fetch multiple accessions at one time
+           */
+          fetchMultipleAccessions(proxy, en, aresultq, aresult, nextFetch);
         }
-
       } catch (Exception e)
       {
         showErrorMessage("Error retrieving " + textArea.getText()
@@ -679,7 +607,6 @@ public class SequenceFetcher extends JPanel implements Runnable
         e.printStackTrace();
       } catch (OutOfMemoryError e)
       {
-        // resets dialog box - so we don't use OOMwarning here.
         showErrorMessage("Out of Memory when retrieving "
                 + textArea.getText()
                 + " from "
@@ -692,11 +619,19 @@ public class SequenceFetcher extends JPanel implements Runnable
                 + " from " + database.getSelectedItem());
         e.printStackTrace();
       }
+
       // Stack results ready for opening in alignment windows
       if (aresult != null && aresult.size() > 0)
       {
+        FeatureSettingsModelI proxyColourScheme = proxy
+                .getFeatureColourScheme();
+        if (proxyColourScheme != null)
+        {
+          preferredFeatureColours = proxyColourScheme;
+        }
+
         AlignmentI ar = null;
-        if (isAliSource)
+        if (proxy.isAlignmentSource())
         {
           addToLast = false;
           // new window for each result
@@ -726,33 +661,37 @@ public class SequenceFetcher extends JPanel implements Runnable
             {
               ar.append(aresult.remove(0));
             }
-            ;
           }
           addToLast = true;
           presult.add(ar);
           presultTitle.add(titl);
         }
       }
-      guiWindow.setProgressBar(MessageManager.getString("status.finshed_querying"), Thread.currentThread()
+      guiWindow.setProgressBar(MessageManager
+              .getString("status.finshed_querying"), Thread.currentThread()
               .hashCode());
     }
-    guiWindow.setProgressBar((presult.size() > 0) ? MessageManager.getString("status.parsing_results")
-            : MessageManager.getString("status.processing"), Thread.currentThread().hashCode());
+    guiWindow.setProgressBar(
+            (presult.size() > 0) ? MessageManager
+                    .getString("status.parsing_results") : MessageManager
+                    .getString("status.processing"), Thread.currentThread()
+                    .hashCode());
     // process results
     while (presult.size() > 0)
     {
-      parseResult(presult.remove(0), presultTitle.remove(0), null);
+      parseResult(presult.remove(0), presultTitle.remove(0), null,
+              preferredFeatureColours);
     }
     // only remove visual delay after we finished parsing.
     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
-    if (nextfetch.size() > 0)
+    if (nextFetch.size() > 0)
     {
       StringBuffer sb = new StringBuffer();
       sb.append("Didn't retrieve the following "
-              + (nextfetch.size() == 1 ? "query" : nextfetch.size()
+              + (nextFetch.size() == 1 ? "query" : nextFetch.size()
                       + " queries") + ": \n");
       int l = sb.length(), lr = 0;
-      for (String s : nextfetch)
+      for (String s : nextFetch)
       {
         if (l != sb.length())
         {
@@ -769,33 +708,159 @@ public class SequenceFetcher extends JPanel implements Runnable
     resetDialog();
   }
 
-  AlignmentI parseResult(String result, String title)
+  /**
+   * Tries to fetch one or more accession ids from the database proxy
+   * 
+   * @param proxy
+   * @param accessions
+   *          the queries to fetch
+   * @param aresultq
+   *          a successful queries list to add to
+   * @param aresult
+   *          a list of retrieved alignments to add to
+   * @param nextFetch
+   *          failed queries are added to this list
+   * @throws Exception
+   */
+  void fetchMultipleAccessions(DbSourceProxy proxy,
+          Iterator<String> accessions, List<String> aresultq,
+          List<AlignmentI> aresult, List<String> nextFetch)
+          throws Exception
   {
-    String format = new IdentifyFile().Identify(result, "Paste");
-    Alignment sequences = null;
-    if (FormatAdapter.isValidFormat(format))
+    StringBuilder multiacc = new StringBuilder();
+    List<String> tosend = new ArrayList<String>();
+    while (accessions.hasNext())
+    {
+      String nel = accessions.next();
+      tosend.add(nel);
+      multiacc.append(nel);
+      if (accessions.hasNext())
+      {
+        multiacc.append(proxy.getAccessionSeparator());
+      }
+    }
+
+    try
     {
-      sequences = null;
-      try
+      String query = multiacc.toString();
+      AlignmentI rslt = proxy.getSequenceRecords(query);
+      if (rslt == null || rslt.getHeight() == 0)
       {
-        sequences = new FormatAdapter().readFile(result.toString(),
-                "Paste", format);
-      } catch (Exception ex)
+        // no results - pass on all queries to next source
+        nextFetch.addAll(tosend);
+      }
+      else
+      {
+        aresultq.add(query);
+        aresult.add(rslt);
+        if (tosend.size() > 1)
+        {
+          checkResultForQueries(rslt, tosend, nextFetch, proxy);
+        }
+      }
+    } catch (OutOfMemoryError oome)
+    {
+      new OOMWarning("fetching " + multiacc + " from "
+              + database.getSelectedItem(), oome, this);
+    }
+  }
+
+  /**
+   * Query for a single accession id via the database proxy
+   * 
+   * @param proxy
+   * @param accession
+   * @param aresultq
+   *          a list of successful queries to add to
+   * @param aresult
+   *          a list of retrieved alignments to add to
+   * @return true if the fetch was successful, else false
+   */
+  boolean fetchSingleAccession(DbSourceProxy proxy, String accession,
+          List<String> aresultq, List<AlignmentI> aresult)
+  {
+    boolean success = false;
+    try
+    {
+      if (aresult != null)
       {
+        try
+        {
+          // give the server a chance to breathe
+          Thread.sleep(5);
+        } catch (Exception e)
+        {
+          //
+        }
       }
 
-      if (sequences != null)
+      AlignmentI indres = null;
+      try
       {
-        return parseResult(sequences, title, format);
+        indres = proxy.getSequenceRecords(accession);
+      } catch (OutOfMemoryError oome)
+      {
+        new OOMWarning("fetching " + accession + " from "
+                + proxy.getDbName(), oome, this);
       }
-    }
-    else
+      if (indres != null)
+      {
+        aresultq.add(accession);
+        aresult.add(indres);
+        success = true;
+      }
+    } catch (Exception e)
+    {
+      Cache.log.info(
+              "Error retrieving " + accession
+              + " from " + proxy.getDbName(), e);
+    } finally
     {
-      showErrorMessage("Error retrieving " + textArea.getText() + " from "
-              + database.getSelectedItem());
+      return success;
     }
+  }
 
-    return null;
+  /**
+   * Checks which of the queries were successfully retrieved by searching the
+   * DBRefs of the retrieved sequences for a match. Any not found are added to
+   * the 'nextFetch' list.
+   * 
+   * @param rslt
+   * @param queries
+   * @param nextFetch
+   * @param proxy
+   */
+  void checkResultForQueries(AlignmentI rslt, List<String> queries,
+          List<String> nextFetch, DbSourceProxy proxy)
+  {
+    SequenceI[] rs = rslt.getSequencesArray();
+
+    for (String q : queries)
+    {
+      DBRefEntry[] found = null;
+      DBRefEntry dbr = new DBRefEntry();
+      dbr.setSource(proxy.getDbSource());
+      dbr.setVersion(null);
+      String accId = proxy.getAccessionIdFromQuery(q);
+      dbr.setAccessionId(accId);
+      boolean rfound = false;
+      for (int r = 0; r < rs.length; r++)
+      {
+        if (rs[r] != null)
+        {
+          found = DBRefUtils.searchRefs(rs[r].getDBRefs(), accId);
+          if (found != null && found.length > 0)
+          {
+            rfound = true;
+            break;
+          }
+        }
+      }
+      if (!rfound)
+      {
+        nextFetch.add(q);
+      }
+    }
   }
 
   /**
@@ -809,11 +874,16 @@ public class SequenceFetcher extends JPanel implements Runnable
   }
 
   AlignmentI parseResult(AlignmentI al, String title,
-          String currentFileFormat)
+          String currentFileFormat,
+          FeatureSettingsModelI preferredFeatureColours)
   {
 
     if (al != null && al.getHeight() > 0)
     {
+      if (title == null)
+      {
+        title = getDefaultRetrievalTitle();
+      }
       if (alignFrame == null)
       {
         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
@@ -826,10 +896,6 @@ public class SequenceFetcher extends JPanel implements Runnable
           // Alignments?
         }
 
-        if (title == null)
-        {
-          title = getDefaultRetrievalTitle();
-        }
         SequenceFeature[] sfs = null;
         List<SequenceI> alsqs;
         synchronized (alsqs = al.getSequences())
@@ -847,6 +913,16 @@ public class SequenceFetcher extends JPanel implements Runnable
 
           }
         }
+
+        if (preferredFeatureColours != null)
+        {
+          af.getViewport().applyFeaturesStyle(preferredFeatureColours);
+        }
+        if (Cache.getDefault("HIDE_INTRONS", true))
+        {
+          hideIntronsIfPresent(af);
+        }
+
         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);
 
@@ -855,7 +931,7 @@ public class SequenceFetcher extends JPanel implements Runnable
 
         try
         {
-          af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
+          af.setMaximum(Cache.getDefault("SHOW_FULLSCREEN",
                   false));
         } catch (Exception ex)
         {
@@ -863,26 +939,31 @@ public class SequenceFetcher extends JPanel implements Runnable
       }
       else
       {
-        for (int i = 0; i < al.getHeight(); i++)
-        {
-          alignFrame.viewport.getAlignment().addSequence(
-                  al.getSequenceAt(i)); // this
-          // also
-          // creates
-          // dataset
-          // sequence
-          // entries
-        }
-        alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
-                .getHeight());
-        alignFrame.viewport.getAlignment().getWidth();
-        alignFrame.viewport.firePropertyChange("alignment", null,
-                alignFrame.viewport.getAlignment().getSequences());
+        alignFrame.viewport.addAlignment(al, title);
       }
     }
     return al;
   }
 
+  /**
+   * Hide columns not containing 'exon' features, provided there are exon
+   * features on the alignment
+   * 
+   * @param af
+   */
+  public void hideIntronsIfPresent(AlignFrame af)
+  {
+    boolean hasExons = af.avc.markColumnsContainingFeatures(false, false,
+            false,
+            SequenceOntologyI.EXON);
+    if (hasExons)
+    {
+      af.avc.markColumnsContainingFeatures(true, false, true,
+              SequenceOntologyI.EXON);
+      af.getViewport().hideSelectedColumns();
+    }
+  }
+
   void showErrorMessage(final String error)
   {
     resetDialog();
@@ -897,4 +978,14 @@ public class SequenceFetcher extends JPanel implements Runnable
       }
     });
   }
+
+  public IProgressIndicator getProgressIndicator()
+  {
+    return progressIndicator;
+  }
+
+  public void setProgressIndicator(IProgressIndicator progressIndicator)
+  {
+    this.progressIndicator = progressIndicator;
+  }
 }