JAL-1078 - removed 'Load Score File' menu item and extended annotation file loader...
[jalview.git] / src / jalview / gui / AlignFrame.java
index 51a119e..bfcab9e 100755 (executable)
@@ -55,6 +55,7 @@ import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.io.JnetAnnotationMaker;
 import jalview.io.NewickFile;
+import jalview.io.TCoffeeScoreFile;
 import jalview.jbgui.GAlignFrame;
 import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.BuriedColourScheme;
@@ -69,13 +70,14 @@ import jalview.schemes.PurinePyrimidineColourScheme;
 import jalview.schemes.RNAHelicesColourChooser;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TCoffeeColourScheme;
 import jalview.schemes.TaylorColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.schemes.UserColourScheme;
 import jalview.schemes.ZappoColourScheme;
-import jalview.ws.WSMenuEntryProviderI;
 import jalview.ws.jws1.Discoverer;
 import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -106,6 +108,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JButton;
@@ -143,7 +146,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   AlignViewport viewport;
 
   Vector alignPanels = new Vector();
-
+  
   /**
    * Last format used to load or save alignments in this window
    */
@@ -284,7 +287,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   void init()
   {
-    if (viewport.getAlignmentConservationAnnotation()== null)
+    if (viewport.getAlignmentConservationAnnotation() == null)
     {
       BLOSUM62Colour.setEnabled(false);
       conservationMenuItem.setEnabled(false);
@@ -403,21 +406,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     || evt.isShiftDown() || evt.isAltDown());
           }
           break;
-          
-        //case KeyEvent.VK_A:
-       //      if (viewport.cursorMode)
-       //     {
-       //              alignPanel.seqPanel.insertNucAtCursor(false,"A");
-       //              //System.out.println("A");
-       //     }
-       //      break;
-        /*     
-        case KeyEvent.VK_CLOSE_BRACKET:
-               if (viewport.cursorMode)
-            {
-                       System.out.println("closing bracket");
-            }
-               break;
+
+        // case KeyEvent.VK_A:
+        // if (viewport.cursorMode)
+        // {
+        // alignPanel.seqPanel.insertNucAtCursor(false,"A");
+        // //System.out.println("A");
+        // }
+        // break;
+        /*
+         * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
+         * System.out.println("closing bracket"); } break;
          */
         case KeyEvent.VK_DELETE:
         case KeyEvent.VK_BACK_SPACE:
@@ -666,11 +665,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     rnahelicesColour.setEnabled(nucleotide);
     purinePyrimidineColour.setEnabled(nucleotide);
     // Remember AlignFrame always starts as protein
-    //if (!nucleotide)
-   // {
-   //   showTr
-   //   calculateMenu.remove(calculateMenu.getItemCount() - 2);
-   // }
+    // if (!nucleotide)
+    // {
+    // showTr
+    // calculateMenu.remove(calculateMenu.getItemCount() - 2);
+    // }
   }
 
   /**
@@ -713,7 +712,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
     showSequenceLogo.setSelected(av.isShowSequenceLogo());
     normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
-    
+
     setColourSelected(ColourSchemeProperty.getColourName(av
             .getGlobalColourScheme()));
 
@@ -726,7 +725,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     sortByTree.setSelected(av.sortByTree);
     listenToViewSelections.setSelected(av.followSelection);
     rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
-    rnahelicesColour.setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
+    rnahelicesColour
+            .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
     setShowProductsEnabled();
 
     updateEditMenuBar();
@@ -856,6 +856,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     if (fileName != null)
     {
+      // TODO: JAL-1108 - ensure all associated frames are closed regardless of originating file's format
       // TODO: work out how to recover feature settings for correct view(s) when
       // file is reloaded.
       if (currentFileFormat.equals("Jalview"))
@@ -1036,10 +1037,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         }
       }
       FormatAdapter f = new FormatAdapter();
-      String output = f.formatSequences(format,
+      String output = f.formatSequences(
+              format,
               (Alignment) viewport.getAlignment(), // class cast exceptions will
               // occur in the distant future
-              omitHidden, f.getCacheSuffixDefault(format), viewport.getColumnSelection());
+              omitHidden, f.getCacheSuffixDefault(format),
+              viewport.getColumnSelection());
 
       if (output == null)
       {
@@ -1122,7 +1125,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     try
     {
       cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
-              viewport.getAlignment(), omitHidden, viewport.getColumnSelection()));
+              viewport.getAlignment(), omitHidden,
+              viewport.getColumnSelection()));
       Desktop.addInternalFrame(cap,
               "Alignment output - " + e.getActionCommand(), 600, 500);
     } catch (OutOfMemoryError oom)
@@ -1199,12 +1203,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   public void exportAnnotations_actionPerformed(ActionEvent e)
   {
-    new AnnotationExporter().exportAnnotations(
-            alignPanel,
+    new AnnotationExporter().exportAnnotations(alignPanel,
             viewport.showAnnotation ? viewport.getAlignment()
-                    .getAlignmentAnnotation() : null, viewport.getAlignment()
-                    .getGroups(),
-            ((Alignment) viewport.getAlignment()).alignmentProperties);
+                    .getAlignmentAnnotation() : null, viewport
+                    .getAlignment().getGroups(), ((Alignment) viewport
+                    .getAlignment()).alignmentProperties);
   }
 
   public void associatedData_actionPerformed(ActionEvent e)
@@ -1343,9 +1346,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       viewport.redoList.clear();
       updateEditMenuBar();
       viewport.updateHiddenColumns();
-//      viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
-//              && viewport.getColumnSelection().getHiddenColumns() != null && viewport.getColumnSelection()
-//              .getHiddenColumns().size() > 0);
+      // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
+      // && viewport.getColumnSelection().getHiddenColumns() != null &&
+      // viewport.getColumnSelection()
+      // .getHiddenColumns().size() > 0);
     }
   }
 
@@ -1392,16 +1396,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     if (originalSource != null)
     {
-      if (originalSource!=viewport)
+      if (originalSource != viewport)
       {
-        Cache.log.warn("Implementation worry: mismatch of viewport origin for undo");
+        Cache.log
+                .warn("Implementation worry: mismatch of viewport origin for undo");
       }
       originalSource.updateHiddenColumns();
-//      originalSource.hasHiddenColumns = (viewport.getColumnSelection() != null
-//              && viewport.getColumnSelection().getHiddenColumns() != null && viewport.getColumnSelection()
-//              .getHiddenColumns().size() > 0);
-      originalSource.firePropertyChange("alignment", null,
-              originalSource.getAlignment().getSequences());
+      // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
+      // null
+      // && viewport.getColumnSelection().getHiddenColumns() != null &&
+      // viewport.getColumnSelection()
+      // .getHiddenColumns().size() > 0);
+      originalSource.firePropertyChange("alignment", null, originalSource
+              .getAlignment().getSequences());
     }
   }
 
@@ -1428,16 +1435,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (originalSource != null)
     {
 
-      if (originalSource!=viewport)
+      if (originalSource != viewport)
       {
-        Cache.log.warn("Implementation worry: mismatch of viewport origin for redo");
+        Cache.log
+                .warn("Implementation worry: mismatch of viewport origin for redo");
       }
       originalSource.updateHiddenColumns();
-      //originalSource.hasHiddenColumns = (viewport.getColumnSelection() != null
-      //        && viewport.getColumnSelection().getHiddenColumns() != null && viewport.getColumnSelection()
-      //        .getHiddenColumns().size() > 0);
-      originalSource.firePropertyChange("alignment", null,
-              originalSource.getAlignment().getSequences());
+      // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
+      // null
+      // && viewport.getColumnSelection().getHiddenColumns() != null &&
+      // viewport.getColumnSelection()
+      // .getHiddenColumns().size() > 0);
+      originalSource.firePropertyChange("alignment", null, originalSource
+              .getAlignment().getSequences());
     }
   }
 
@@ -1551,12 +1561,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     Vector sg = new Vector();
     if (viewport.cursorMode)
     {
-      sg.addElement(viewport.getAlignment()
-              .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
+      sg.addElement(viewport.getAlignment().getSequenceAt(
+              alignPanel.seqPanel.seqCanvas.cursorY));
     }
     else if (viewport.getSelectionGroup() != null
-            && viewport.getSelectionGroup().getSize() != viewport.getAlignment()
-                    .getHeight())
+            && viewport.getSelectionGroup().getSize() != viewport
+                    .getAlignment().getHeight())
     {
       sg = viewport.getSelectionGroup().getSequences(
               viewport.getHiddenRepSequences());
@@ -2268,7 +2278,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
-            "Remove Gapped Columns", seqs, start, end, viewport.getAlignment());
+            "Remove Gapped Columns", seqs, start, end,
+            viewport.getAlignment());
 
     addHistoryItem(removeGapCols);
 
@@ -2594,8 +2605,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // Hide everything by the current selection - this is a hack - we do the
       // invert and then hide
       // first check that there will be visible columns after the invert.
-      if ((viewport.getColumnSelection() != null && viewport.getColumnSelection().getSelected() != null && viewport.getColumnSelection()
-              .getSelected().size() > 0)
+      if ((viewport.getColumnSelection() != null
+              && viewport.getColumnSelection().getSelected() != null && viewport
+              .getColumnSelection().getSelected().size() > 0)
               || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
                       .getEndRes()))
       {
@@ -2623,7 +2635,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         hideSelSequences_actionPerformed(null);
         hide = true;
       }
-      else if (!(toggleCols && viewport.getColumnSelection().getSelected().size() > 0))
+      else if (!(toggleCols && viewport.getColumnSelection().getSelected()
+              .size() > 0))
       {
         showAllSeqs_actionPerformed(null);
       }
@@ -2911,9 +2924,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   public void clustalColour_actionPerformed(ActionEvent e)
   {
-    changeColour(new ClustalxColourScheme(
-            viewport.getAlignment().getSequences(),
-            viewport.getAlignment().getWidth()));
+    changeColour(new ClustalxColourScheme(viewport.getAlignment()
+            .getSequences(), viewport.getAlignment().getWidth()));
   }
 
   /**
@@ -3008,17 +3020,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     changeColour(new PurinePyrimidineColourScheme());
   }
+
   /*
-  public void covariationColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation()[0]));
-  }
-  */
+   * public void covariationColour_actionPerformed(ActionEvent e) {
+   * changeColour(new
+   * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
+   * ()[0])); }
+   */
   public void annotationColour_actionPerformed(ActionEvent e)
   {
     new AnnotationColourChooser(viewport, alignPanel);
   }
-  
+
   public void rnahelicesColour_actionPerformed(ActionEvent e)
   {
     new RNAHelicesColourChooser(viewport, alignPanel);
@@ -3043,6 +3056,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   public void changeColour(ColourSchemeI cs)
   {
+    // TODO: compare with applet and pull up to model method
     int threshold = 0;
 
     if (cs != null)
@@ -3103,9 +3117,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
         if (cs instanceof ClustalxColourScheme)
         {
-          sg.cs = new ClustalxColourScheme(
-                  sg.getSequences(viewport.getHiddenRepSequences()),
-                  sg.getWidth());
+          sg.cs = new ClustalxColourScheme(sg.getSequences(viewport
+                  .getHiddenRepSequences()), sg.getWidth());
         }
         else if (cs instanceof UserColourScheme)
         {
@@ -3115,7 +3128,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
           try
           {
-            sg.cs = (ColourSchemeI) cs.getClass().newInstance();
+            sg.cs = cs.getClass().newInstance();
           } catch (Exception ex)
           {
           }
@@ -3139,9 +3152,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         if (viewport.getConservationSelected())
         {
           Conservation c = new Conservation("Group",
-                  ResidueProperties.propHash, 3,
-                  sg.getSequences(viewport.getHiddenRepSequences()),
-                  sg.getStartRes(), sg.getEndRes() + 1);
+                  ResidueProperties.propHash, 3, sg.getSequences(viewport
+                          .getHiddenRepSequences()), sg.getStartRes(),
+                  sg.getEndRes() + 1);
           c.calculate();
           c.verdict(false, viewport.getConsPercGaps());
           sg.cs.setConservation(c);
@@ -3187,7 +3200,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void modifyConservation_actionPerformed(ActionEvent e)
   {
     if (viewport.getConservationSelected()
-            && viewport.getGlobalColourScheme()!= null)
+            && viewport.getGlobalColourScheme() != null)
     {
       SliderPanel.setConservationSlider(alignPanel,
               viewport.getGlobalColourScheme(), "Background");
@@ -3371,7 +3384,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
     AlignmentSorter.sortByID(viewport.getAlignment());
-    addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
+    addHistoryItem(new OrderCommand("ID Sort", oldOrder,
+            viewport.getAlignment()));
     alignPanel.paintAlignment(true);
   }
 
@@ -3474,6 +3488,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               .getAlignment().getSequences());
     }
   }
+
   public void sortByTreeOption_actionPerformed(ActionEvent e)
   {
     viewport.sortByTree = sortByTree.isSelected();
@@ -3484,6 +3499,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     viewport.followSelection = listenToViewSelections.isSelected();
   }
+
   /**
    * DOCUMENT ME!
    * 
@@ -3639,8 +3655,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         // pointers
         AlignmentSorter.sortBy(viewport.getAlignment(), order);
 
-        addHistoryItem(new OrderCommand(order.getName(), oldOrder,
-                viewport.getAlignment()));
+        addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
+                .getAlignment()));
 
         alignPanel.paintAlignment(true);
       }
@@ -3775,7 +3791,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
           tp.sortByTree_actionPerformed(null);
           addHistoryItem(tp.sortAlignmentIn(alignPanel));
-          
+
         }
       });
 
@@ -3911,6 +3927,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
+  @Override
+  protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
+  {
+    changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
+  }
+
   public TreePanel ShowNewickTree(NewickFile nf, String title)
   {
     return ShowNewickTree(nf, title, 600, 500, 4, 5);
@@ -4017,20 +4039,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           // TODO: group services by location as well as function and/or
           // introduce
           // object broker mechanism.
-          final Vector wsmenu = new Vector();
+          final Vector<JMenu> wsmenu = new Vector<JMenu>();
           final IProgressIndicator af = me;
           final JMenu msawsmenu = new JMenu("Alignment");
           final JMenu secstrmenu = new JMenu(
                   "Secondary Structure Prediction");
-          final JMenu seqsrchmenu = new JMenu(
-                  "Sequence Database Search");
-          final JMenu analymenu = new JMenu(
-                  "Analysis");
-          // JAL-940 - only show secondary structure prediction services from the legacy server
+          final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
+          final JMenu analymenu = new JMenu("Analysis");
+          final JMenu dismenu = new JMenu("Disorder");
+          // JAL-940 - only show secondary structure prediction services from
+          // the legacy server
           if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
-                  // && 
-                  Discoverer.services != null
-                  && (Discoverer.services.size() > 0))
+              // &&
+          Discoverer.services != null && (Discoverer.services.size() > 0))
           {
             // TODO: refactor to allow list of AbstractName/Handler bindings to
             // be
@@ -4038,7 +4059,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
             Vector secstrpr = (Vector) Discoverer.services
                     .get("SecStrPred");
-            Vector seqsrch = null; // (Vector) Discoverer.services.get("SeqSearch");
+            Vector seqsrch = null; // (Vector)
+                                   // Discoverer.services.get("SeqSearch");
             // TODO: move GUI generation code onto service implementation - so a
             // client instance attaches itself to the GUI with method call like
             // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
@@ -4082,13 +4104,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             }
           }
 
-          
-          // Add all submenus in the order they should appear on the web services menu
+          // Add all submenus in the order they should appear on the web
+          // services menu
           wsmenu.add(msawsmenu);
           wsmenu.add(secstrmenu);
-          wsmenu.add(new JMenu("Disorder"));
+          wsmenu.add(dismenu);
           wsmenu.add(analymenu);
-          
+          // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
+          // submens.add(msawsmenu);
+          // submens.add(secstrmenu);
+          // submens.add(dismenu);
+          // submens.add(analymenu);
+
           // No search services yet
           // wsmenu.add(seqsrchmenu);
 
@@ -4121,11 +4148,29 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     {
                       jws2servs.attachWSMenuEntry(webService, me);
                     }
+                    if (jws2servs.isRunning())
+                    {
+                      JMenuItem tm = new JMenuItem(
+                              "Still discovering JABA Services");
+                      tm.setEnabled(false);
+                      webService.add(tm);
+                    }
                   }
                 }
 
                 build_urlServiceMenu(me.webService);
                 build_fetchdbmenu(webService);
+                for (JMenu item : wsmenu)
+                {
+                  if (item.getItemCount() == 0)
+                  {
+                    item.setEnabled(false);
+                  }
+                  else
+                  {
+                    item.setEnabled(true);
+                  }
+                }
               } catch (Exception e)
               {
               }
@@ -4143,7 +4188,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   }
 
-
   /**
    * construct any groupURL type service menu entries.
    * 
@@ -4158,7 +4202,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
      * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
      * 
      * @Override public void actionPerformed(ActionEvent e) {
-     * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.getAlignment(),
+     * jalview.datamodel.AlignmentView
+     * .testSelectionViews(af.viewport.getAlignment(),
      * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
      * 
      * }); webService.add(testAlView);
@@ -4167,9 +4212,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // rest-style services with other types of analysis/calculation service
     // SHmmr test client - still being implemented.
     // DEBUG - alignmentView
-    
-    for (jalview.ws.rest.RestClient client: jalview.ws.rest.RestClient.getRestClients()) {
-      client.attachWSMenuEntry(JvSwingUtils.findOrCreateMenu(webService, client.getAction()), this);
+
+    for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
+            .getRestClients())
+    {
+      client.attachWSMenuEntry(
+              JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
+              this);
     }
 
     if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
@@ -4445,11 +4494,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     boolean featuresFile = false;
     try
     {
-      featuresFile = new FeaturesFile(file, type)
-              .parse(viewport.getAlignment().getDataset(),
-                      alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
-                      false, jalview.bin.Cache.getDefault(
-                              "RELAXEDSEQIDMATCHING", false));
+      featuresFile = new FeaturesFile(file, type).parse(viewport
+              .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
+              .getFeatureRenderer().featureColours, false,
+              jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
     } catch (Exception ex)
     {
       ex.printStackTrace();
@@ -4575,7 +4623,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             int l = 0, c = pdbfn.indexOf(".");
             while (mtch == null && c != -1)
             {
-              do 
+              do
               {
                 l = c;
               } while ((c = pdbfn.indexOf(".", l)) > l);
@@ -4628,18 +4676,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               // try and associate
               // TODO: may want to set a standard ID naming formalism for
               // associating PDB files which have no IDs.
-              for (SequenceI toassoc: (SequenceI[])fm[2]) {
-              PDBEntry pe = new AssociatePdbFileWithSeq()
-                      .associatePdbWithSeq((String) fm[0], (String) fm[1],
-                              toassoc, false);
-              if (pe != null)
+              for (SequenceI toassoc : (SequenceI[]) fm[2])
               {
-                System.err
-                        .println("Associated file : " + ((String) fm[0])
-                                + " with "
-                                + toassoc.getDisplayId(true));
-                assocfiles++;
-              }
+                PDBEntry pe = new AssociatePdbFileWithSeq()
+                        .associatePdbWithSeq((String) fm[0],
+                                (String) fm[1], toassoc, false);
+                if (pe != null)
+                {
+                  System.err.println("Associated file : "
+                          + ((String) fm[0]) + " with "
+                          + toassoc.getDisplayId(true));
+                  assocfiles++;
+                }
               }
               alignPanel.paintAlignment(true);
             }
@@ -4701,54 +4749,92 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
       if (!isAnnotation)
       {
-        // try to see if its a JNet 'concise' style annotation file *before* we
-        // try to parse it as a features file
-        if (format == null)
+        // first see if its a T-COFFEE score file
+        TCoffeeScoreFile tcf = null;
+        try
         {
-          format = new IdentifyFile().Identify(file, protocol);
-        }
-        if (format.equalsIgnoreCase("JnetFile"))
+          tcf = new TCoffeeScoreFile(file, protocol);
+          if (tcf.isValid())
+          {
+            if (tcf.annotateAlignment(viewport.getAlignment(), true))
+            {
+              tcoffeeColour.setEnabled(true);
+              tcoffeeColour.setSelected(true);
+              changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
+              isAnnotation = true;
+              statusBar
+                      .setText("Successfully pasted T-Coffee scores to alignment.");
+            }
+            else
+            {
+              // some problem - if no warning its probable that the ID matching process didn't work
+              JOptionPane.showMessageDialog(Desktop.desktop,
+                      tcf.getWarningMessage()==null ? "Check that the file matches sequence IDs in the alignment." : tcf.getWarningMessage(),
+                      "Problem reading T-COFFEE score file",
+                      JOptionPane.WARNING_MESSAGE);
+            }
+          }
+          else
+          {
+            tcf = null;
+          }
+        } catch (Exception x)
         {
-          jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
-                  protocol);
-          new JnetAnnotationMaker().add_annotation(predictions,
-                  viewport.getAlignment(), 0, false);
-          isAnnotation = true;
+          Cache.log.debug("Exception when processing data source as T-COFFEE score file",x);
+          tcf = null;
         }
-        else
+        if (tcf == null)
         {
-          /*
-           * if (format.equalsIgnoreCase("PDB")) {
-           * 
-           * String pdbfn = ""; // try to match up filename with sequence id try
-           * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
-           * File(file); pdbfn = fl.getName(); } else if (protocol ==
-           * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
-           * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
-           * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
-           * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
-           * attempt to find a match in the alignment SequenceI mtch =
-           * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
-           * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
-           * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
-           * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
-           * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
-           * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
-           * System.err.println("Associated file : " + file + " with " +
-           * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
-           * TODO: maybe need to load as normal otherwise return; } }
-           */
+          // try to see if its a JNet 'concise' style annotation file *before*
+          // we
           // try to parse it as a features file
-          boolean isGroupsFile = parseFeaturesFile(file, protocol);
-          // if it wasn't a features file then we just treat it as a general
-          // alignment file to load into the current view.
-          if (!isGroupsFile)
+          if (format == null)
+          {
+            format = new IdentifyFile().Identify(file, protocol);
+          }
+          if (format.equalsIgnoreCase("JnetFile"))
           {
-            new FileLoader().LoadFile(viewport, file, protocol, format);
+            jalview.io.JPredFile predictions = new jalview.io.JPredFile(
+                    file, protocol);
+            new JnetAnnotationMaker().add_annotation(predictions,
+                    viewport.getAlignment(), 0, false);
+            isAnnotation = true;
           }
           else
           {
-            alignPanel.paintAlignment(true);
+            /*
+             * if (format.equalsIgnoreCase("PDB")) {
+             * 
+             * String pdbfn = ""; // try to match up filename with sequence id
+             * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
+             * new File(file); pdbfn = fl.getName(); } else if (protocol ==
+             * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
+             * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
+             * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
+             * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
+             * // attempt to find a match in the alignment SequenceI mtch =
+             * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
+             * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
+             * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
+             * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
+             * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
+             * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
+             * { System.err.println("Associated file : " + file + " with " +
+             * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
+             * TODO: maybe need to load as normal otherwise return; } }
+             */
+            // try to parse it as a features file
+            boolean isGroupsFile = parseFeaturesFile(file, protocol);
+            // if it wasn't a features file then we just treat it as a general
+            // alignment file to load into the current view.
+            if (!isGroupsFile)
+            {
+              new FileLoader().LoadFile(viewport, file, protocol, format);
+            }
+            else
+            {
+              alignPanel.paintAlignment(true);
+            }
           }
         }
       }
@@ -4906,31 +4992,45 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         final jalview.ws.SequenceFetcher sf = SequenceFetcher
                 .getSequenceFetcherSingleton(me);
-        final String[] otherdb = sf.getOrderedSupportedSources();
-        // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
-        // jalview.util.QuickSort.sort(otherdb, otherdb);
         javax.swing.SwingUtilities.invokeLater(new Runnable()
         {
           public void run()
           {
-
+            String[] dbclasses = sf.getOrderedSupportedSources();
+            // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
+            // jalview.util.QuickSort.sort(otherdb, otherdb);
+            List<DbSourceProxy> otherdb;
             JMenu dfetch = new JMenu();
-            JMenuItem fetchr;
-            rfetch.add(dfetch);
-            int comp = 0, mcomp = 15;
+            JMenu ifetch = new JMenu();
+            JMenuItem fetchr = null;
+            int comp = 0, icomp = 0, mcomp = 15;
             String mname = null;
-            if (otherdb != null && otherdb.length > 0)
+            int dbi = 0;
+            for (String dbclass : dbclasses)
             {
-              for (int i = 0; i < otherdb.length; i++)
+              otherdb = sf.getSourceProxy(dbclass);
+              // add a single entry for this class, or submenu allowing 'fetch
+              // all' or pick one
+              if (otherdb == null || otherdb.size() < 1)
               {
-                String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
-                if (mname == null)
-                {
-                  mname = "from '" + dbname + "'";
-                }
-                fetchr = new JMenuItem(otherdb[i]);
-                final String[] dassource = new String[]
-                { otherdb[i] };
+                continue;
+              }
+              // List<DbSourceProxy> dbs=otherdb;
+              // otherdb=new ArrayList<DbSourceProxy>();
+              // for (DbSourceProxy db:dbs)
+              // {
+              // if (!db.isA(DBRefSource.ALIGNMENTDB)
+              // }
+              if (mname == null)
+              {
+                mname = "From " + dbclass;
+              }
+              if (otherdb.size() == 1)
+              {
+                final DbSourceProxy[] dassource = otherdb
+                        .toArray(new DbSourceProxy[0]);
+                DbSourceProxy src = otherdb.get(0);
+                fetchr = new JMenuItem(src.getDbSource());
                 fetchr.addActionListener(new ActionListener()
                 {
 
@@ -4950,17 +5050,108 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   }
 
                 });
-                fetchr.setToolTipText("Retrieve from " + dbname);
+                fetchr.setToolTipText("<html>"
+                        + JvSwingUtils.wrapTooltip("Retrieve from "
+                                + src.getDbName()) + "<html>");
                 dfetch.add(fetchr);
-                if (comp++ == mcomp || i == (otherdb.length - 1))
+                comp++;
+              }
+              else
+              {
+                final DbSourceProxy[] dassource = otherdb
+                        .toArray(new DbSourceProxy[0]);
+                // fetch all entry
+                DbSourceProxy src = otherdb.get(0);
+                fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
+                        + "'");
+                fetchr.addActionListener(new ActionListener()
                 {
-                  dfetch.setText(mname + " to '" + dbname + "'");
-                  rfetch.add(dfetch);
-                  dfetch = new JMenu();
-                  mname = null;
-                  comp = 0;
+                  public void actionPerformed(ActionEvent e)
+                  {
+                    new Thread(new Runnable()
+                    {
+
+                      public void run()
+                      {
+                        new jalview.ws.DBRefFetcher(alignPanel.av
+                                .getSequenceSelection(),
+                                alignPanel.alignFrame, dassource)
+                                .fetchDBRefs(false);
+                      }
+                    }).start();
+                  }
+                });
+
+                fetchr.setToolTipText("<html>"
+                        + JvSwingUtils.wrapTooltip("Retrieve from all "
+                                + otherdb.size() + " sources in "
+                                + src.getDbSource() + "<br>First is :"
+                                + src.getDbName()) + "<html>");
+                dfetch.add(fetchr);
+                comp++;
+                // and then build the rest of the individual menus
+                ifetch = new JMenu("Sources from " + src.getDbSource());
+                icomp = 0;
+                String imname = null;
+                int i = 0;
+                for (DbSourceProxy sproxy : otherdb)
+                {
+                  String dbname = sproxy.getDbName();
+                  String sname = dbname.length() > 5 ? dbname.substring(0,
+                          5) + "..." : dbname;
+                  String msname = dbname.length() > 10 ? dbname.substring(
+                          0, 10) + "..." : dbname;
+                  if (imname == null)
+                  {
+                    imname = "from '" + sname + "'";
+                  }
+                  fetchr = new JMenuItem(msname);
+                  final DbSourceProxy[] dassrc =
+                  { sproxy };
+                  fetchr.addActionListener(new ActionListener()
+                  {
+
+                    public void actionPerformed(ActionEvent e)
+                    {
+                      new Thread(new Runnable()
+                      {
+
+                        public void run()
+                        {
+                          new jalview.ws.DBRefFetcher(alignPanel.av
+                                  .getSequenceSelection(),
+                                  alignPanel.alignFrame, dassrc)
+                                  .fetchDBRefs(false);
+                        }
+                      }).start();
+                    }
+
+                  });
+                  fetchr.setToolTipText("<html>"
+                          + JvSwingUtils.wrapTooltip("Retrieve from "
+                                  + dbname) + "</html>");
+                  ifetch.add(fetchr);
+                  ++i;
+                  if (++icomp >= mcomp || i == (otherdb.size()))
+                  {
+                    ifetch.setText(imname + " to '" + sname + "'");
+                    dfetch.add(ifetch);
+                    ifetch = new JMenu();
+                    imname = null;
+                    icomp = 0;
+                    comp++;
+                  }
                 }
               }
+              ++dbi;
+              if (comp >= mcomp || dbi >= (dbclasses.length))
+              {
+                dfetch.setText(mname + " to '" + dbclass + "'");
+                rfetch.add(dfetch);
+                dfetch = new JMenu();
+                mname = null;
+                comp = 0;
+              }
             }
           }
         });
@@ -5060,11 +5251,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.setShowSequenceLogo(showSequenceLogo.getState());
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
   }
+
   protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
   {
     viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
   }
+
   protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
   {
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
@@ -5084,8 +5277,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
               viewport.getSequenceSelection(),
               viewport.getAlignmentView(true).getSequenceStrings(
-                      viewport.getGapCharacter()),
-              viewport.getAlignment().getGroups());
+                      viewport.getGapCharacter()), viewport.getAlignment()
+                      .getGroups());
       viewport.getAlignment().deleteAllGroups();
       viewport.sequenceColours = null;
       viewport.setSelectionGroup(null);
@@ -5123,7 +5316,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               "Implementation error: cannot show a view from another alignment in an AlignFrame.");
     }
     if (tabbedPane != null
-            & alignPanels.indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
+            & alignPanels.indexOf(alignmentPanel) != tabbedPane
+                    .getSelectedIndex())
     {
       tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
     }