JAL-1114 - refactor methods handling Vectors and Hashtables to Lists and Maps, and...
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index d2b04f9..6ce68c3 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)\r
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle\r
  * \r
  * This file is part of Jalview.\r
  * \r
  */\r
 package jalview.appletgui;\r
 \r
-import java.net.*;\r
-import java.util.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import jalview.analysis.*;\r
+import jalview.analysis.AAFrequency;\r
+import jalview.analysis.AlignmentSorter;\r
+import jalview.analysis.Conservation;\r
 import jalview.api.SequenceStructureBinding;\r
 import jalview.bin.JalviewLite;\r
-import jalview.commands.*;\r
-import jalview.datamodel.*;\r
-import jalview.io.*;\r
-import jalview.schemes.*;\r
+import jalview.commands.CommandI;\r
+import jalview.commands.EditCommand;\r
+import jalview.commands.OrderCommand;\r
+import jalview.commands.RemoveGapColCommand;\r
+import jalview.commands.RemoveGapsCommand;\r
+import jalview.commands.SlideSequencesCommand;\r
+import jalview.commands.TrimRegionCommand;\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.AlignmentOrder;\r
+import jalview.datamodel.ColumnSelection;\r
+import jalview.datamodel.PDBEntry;\r
+import jalview.datamodel.Sequence;\r
+import jalview.datamodel.SequenceGroup;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.io.AnnotationFile;\r
+import jalview.io.AppletFormatAdapter;\r
+import jalview.io.FeaturesFile;\r
+import jalview.io.TCoffeeScoreFile;\r
+import jalview.schemes.Blosum62ColourScheme;\r
+import jalview.schemes.BuriedColourScheme;\r
+import jalview.schemes.ClustalxColourScheme;\r
+import jalview.schemes.ColourSchemeI;\r
+import jalview.schemes.HelixColourScheme;\r
+import jalview.schemes.HydrophobicColourScheme;\r
+import jalview.schemes.NucleotideColourScheme;\r
+import jalview.schemes.PIDColourScheme;\r
+import jalview.schemes.PurinePyrimidineColourScheme;\r
+import jalview.schemes.RNAHelicesColourChooser;\r
+import jalview.schemes.ResidueProperties;\r
+import jalview.schemes.StrandColourScheme;\r
+import jalview.schemes.TCoffeeColourScheme;\r
+import jalview.schemes.TaylorColourScheme;\r
+import jalview.schemes.TurnColourScheme;\r
+import jalview.schemes.ZappoColourScheme;\r
 import jalview.structure.StructureSelectionManager;\r
 \r
-public class AlignFrame extends EmbmenuFrame implements ActionListener,\r
-        ItemListener, KeyListener\r
+import java.awt.BorderLayout;\r
+import java.awt.Canvas;\r
+import java.awt.CheckboxMenuItem;\r
+import java.awt.Color;\r
+import java.awt.Font;\r
+import java.awt.FontMetrics;\r
+import java.awt.Frame;\r
+import java.awt.Graphics;\r
+import java.awt.Label;\r
+import java.awt.Menu;\r
+import java.awt.MenuBar;\r
+import java.awt.MenuItem;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.FocusEvent;\r
+import java.awt.event.FocusListener;\r
+import java.awt.event.ItemEvent;\r
+import java.awt.event.ItemListener;\r
+import java.awt.event.KeyEvent;\r
+import java.awt.event.KeyListener;\r
+import java.awt.event.WindowAdapter;\r
+import java.awt.event.WindowEvent;\r
+import java.io.IOException;\r
+import java.io.InputStreamReader;\r
+import java.net.URL;\r
+import java.net.URLEncoder;\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+import java.util.List;\r
+import java.util.StringTokenizer;\r
+import java.util.Vector;\r
+\r
+public class AlignFrame extends EmbmenuFrame implements ActionListener,  ItemListener, KeyListener\r
 {\r
   public AlignmentPanel alignPanel;\r
 \r
@@ -44,11 +102,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   int DEFAULT_HEIGHT = 500;\r
 \r
   String jalviewServletURL;\r
+  \r
 \r
-  public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet,\r
-          String title, boolean embedded)\r
+  public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet, String title, boolean embedded)\r
   {\r
-\r
     if (applet != null)\r
     {\r
       jalviewServletURL = applet.getParameter("APPLICATION_URL");\r
@@ -69,12 +126,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.updateConsensus(alignPanel);\r
 \r
     annotationPanelMenuItem.setState(viewport.showAnnotation);\r
-    displayNonconservedMenuItem.setState(viewport.getShowunconserved());\r
+    displayNonconservedMenuItem.setState(viewport.getShowUnconserved());\r
     followMouseOverFlag.setState(viewport.getFollowHighlight());\r
-    showGroupConsensus.setState(viewport.showGroupConsensus);\r
-    showGroupConservation.setState(viewport.showGroupConservation);\r
-    showConsensusHistogram.setState(viewport.showConsensusHistogram);\r
-    showSequenceLogo.setState(viewport.showSequenceLogo);\r
+    showGroupConsensus.setState(viewport.isShowGroupConsensus());\r
+    showGroupConservation.setState(viewport.isShowGroupConservation());\r
+    showConsensusHistogram.setState(viewport.isShowConsensusHistogram());\r
+    showSequenceLogo.setState(viewport.isShowSequenceLogo());\r
 \r
     seqLimits.setState(viewport.showJVSuffix);\r
 \r
@@ -131,7 +188,20 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       }\r
 \r
     }\r
-\r
+    if (viewport.getAlignment().isNucleotide())\r
+    {\r
+      viewport.updateStrucConsensus(alignPanel);\r
+      if (viewport.getAlignment().hasRNAStructure())\r
+      {\r
+        RNAHelixColour.setEnabled(true);\r
+      }\r
+      else {\r
+        RNAHelixColour.setEnabled(false);\r
+      }\r
+    } else {\r
+      RNAHelixColour.setEnabled(false);\r
+      purinePyrimidineColour.setEnabled(false);\r
+    }\r
     // Some JVMS send keyevents to Top frame or lowest panel,\r
     // Havent worked out why yet. So add to both this frame and seqCanvas for\r
     // now\r
@@ -161,20 +231,35 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
-   * DOCUMENT ME!\r
+   * Load a features file onto the alignment\r
    * \r
-   * @param String\r
-   *          DOCUMENT ME!\r
+   * @param file file URL, content, or other resolvable path\r
+   * @param type is protocol for accessing data referred to by file\r
    */\r
 \r
-  public void parseFeaturesFile(String file, String type)\r
+  public boolean parseFeaturesFile(String file, String type)\r
   {\r
+    return parseFeaturesFile(file, type, true);\r
+  }\r
+  \r
+  /**\r
+   * Load a features file onto the alignment\r
+   * \r
+   * @param file file URL, content, or other resolvable path\r
+   * @param type is protocol for accessing data referred to by file\r
+   * @param autoenabledisplay when true, display features flag will be automatically enabled if features are loaded\r
+   * @return true if data parsed as a features file\r
+   */\r
+  public boolean parseFeaturesFile(String file, String type, boolean autoenabledisplay)\r
+  {    \r
+    // TODO: test if importing a features file onto an alignment which already has features with links overwrites the original links.\r
+    \r
     Hashtable featureLinks = new Hashtable();\r
     boolean featuresFile = false;\r
     try\r
     {\r
       featuresFile = new jalview.io.FeaturesFile(file, type)\r
-              .parse(viewport.alignment,\r
+              .parse(viewport.getAlignment(),\r
                       alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,\r
                       featureLinks, true, viewport.applet.getDefaultParameter("relaxedidmatch", false));\r
     } catch (Exception ex)\r
@@ -188,15 +273,19 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {\r
         alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureLinks = featureLinks;\r
       }\r
-      viewport.showSequenceFeatures = true;\r
-      sequenceFeatures.setState(true);\r
+      if (autoenabledisplay)\r
+      {\r
+        viewport.showSequenceFeatures = true;\r
+        sequenceFeatures.setState(true);\r
+      }\r
       if (viewport.featureSettings != null)\r
       {\r
         viewport.featureSettings.refreshTable();\r
       }\r
       alignPanel.paintAlignment(true);\r
+      statusBar.setText("Successfully added features to alignment.");\r
     }\r
-\r
+    return featuresFile;\r
   }\r
 \r
   public void keyPressed(KeyEvent evt)\r
@@ -473,7 +562,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       // Hide everything by the current selection - this is a hack - we do the\r
       // invert and then hide\r
       // first check that there will be visible columns after the invert.\r
-      if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel\r
+      if ((viewport.getColumnSelection() != null && viewport.getColumnSelection().getSelected() != null && viewport.getColumnSelection()\r
               .getSelected().size() > 0)\r
               || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg\r
                       .getEndRes()))\r
@@ -497,12 +586,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
     if (toggleSeqs)\r
     {\r
-      if (sg != null && sg.getSize() != viewport.alignment.getHeight())\r
+      if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())\r
       {\r
         hide = true;\r
         viewport.hideAllSelectedSeqs();\r
       }\r
-      else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))\r
+      else if (!(toggleCols && viewport.getColumnSelection().getSelected().size() > 0))\r
       {\r
         viewport.showAllHiddenSeqs();\r
       }\r
@@ -510,12 +599,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
     if (toggleCols)\r
     {\r
-      if (viewport.colSel.getSelected().size() > 0)\r
+      if (viewport.getColumnSelection().getSelected().size() > 0)\r
       {\r
         viewport.hideSelectedColumns();\r
         if (!toggleSeqs)\r
         {\r
-          viewport.selectionGroup = sg;\r
+          viewport.setSelectionGroup(sg);\r
         }\r
       }\r
       else if (!hide)\r
@@ -599,7 +688,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }\r
     else if (evt.getSource() == autoCalculate)\r
     {\r
-      viewport.autocalculateConsensus = autoCalculate.getState();\r
+      viewport.autoCalculateConsensus = autoCalculate.getState();\r
+    }\r
+    else if (evt.getSource() == sortByTree)\r
+    {\r
+      viewport.sortByTree = sortByTree.getState();\r
     }\r
     else if (evt.getSource() == this.centreColumnLabelFlag)\r
     {\r
@@ -845,7 +938,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     else if (source == alProperties)\r
     {\r
       StringBuffer contents = new jalview.io.AlignmentProperties(\r
-              viewport.alignment).formatAsString();\r
+              viewport.getAlignment()).formatAsString();\r
       CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);\r
       cap.setText(contents.toString());\r
       Frame frame = new Frame();\r
@@ -864,9 +957,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     else if (source == clustalColour)\r
     {\r
       abovePIDThreshold.setState(false);\r
-      changeColour(new ClustalxColourScheme(\r
-              viewport.alignment.getSequences(),\r
-              viewport.alignment.getWidth()));\r
+      changeColour(new ClustalxColourScheme(viewport.getAlignment(),null));\r
     }\r
     else if (source == zappoColour)\r
     {\r
@@ -900,6 +991,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       changeColour(new NucleotideColourScheme());\r
     }\r
+    else if (source == purinePyrimidineColour)\r
+    {\r
+      changeColour(new PurinePyrimidineColourScheme());\r
+    }\r
+    else if (source == RNAHelixColour)\r
+    {\r
+      new RNAHelicesColourChooser(viewport, alignPanel);\r
+    }\r
     else if (source == modifyPID)\r
     {\r
       modifyPID_actionPerformed();\r
@@ -920,6 +1019,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       changeColour(new Blosum62ColourScheme());\r
     }\r
+    else if (source == tcoffeeColour) {\r
+        changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));\r
+    }\r
     else if (source == annotationColour)\r
     {\r
       new AnnotationColourChooser(viewport, alignPanel);\r
@@ -1002,21 +1104,21 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public void loadAnnotations()\r
   {\r
     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);\r
-    cap.setText("Paste your features / annotations file here.");\r
+    cap.setText("Paste your features / annotations / T-coffee score file here.");\r
     cap.setAnnotationImport();\r
     Frame frame = new Frame();\r
     frame.add(cap);\r
     jalview.bin.JalviewLite.addFrame(frame, "Paste Annotations ", 400, 300);\r
 \r
   }\r
-\r
+  \r
   public String outputAnnotations(boolean displayTextbox)\r
   {\r
     String annotation = new AnnotationFile().printAnnotations(\r
-            viewport.showAnnotation ? viewport.alignment\r
-                    .getAlignmentAnnotation() : null, viewport.alignment\r
+            viewport.showAnnotation ? viewport.getAlignment()\r
+                    .getAlignmentAnnotation() : null, viewport.getAlignment()\r
                     .getGroups(),\r
-            ((Alignment) viewport.alignment).alignmentProperties);\r
+            ((Alignment) viewport.getAlignment()).alignmentProperties);\r
 \r
     if (displayTextbox)\r
     {\r
@@ -1032,7 +1134,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   private Hashtable getDisplayedFeatureCols()\r
   {\r
-    if (alignPanel.getFeatureRenderer() != null)\r
+    if (alignPanel.getFeatureRenderer() != null && viewport.featuresDisplayed!=null)\r
     {\r
       FeatureRenderer fr = alignPanel.getFeatureRenderer();\r
       Hashtable fcols = new Hashtable();\r
@@ -1053,24 +1155,37 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     if (format.equalsIgnoreCase("Jalview"))\r
     {\r
       features = new FeaturesFile().printJalviewFormat(\r
-              viewport.alignment.getSequencesArray(),\r
+              viewport.getAlignment().getSequencesArray(),\r
               getDisplayedFeatureCols());\r
     }\r
     else\r
     {\r
       features = new FeaturesFile().printGFFFormat(\r
-              viewport.alignment.getSequencesArray(),\r
+              viewport.getAlignment().getSequencesArray(),\r
               getDisplayedFeatureCols());\r
     }\r
 \r
     if (displayTextbox)\r
     {\r
-      CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);\r
+      boolean frimport=false;\r
+      if (features==null || features.equals("No Features Visible"))\r
+      {\r
+        features = "# No features visible - paste some and import them here.";\r
+        frimport=true;\r
+      }\r
+      \r
+      CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);\r
+      if (frimport)\r
+      {\r
+        cap.setAnnotationImport();\r
+      }\r
       Frame frame = new Frame();\r
       frame.add(cap);\r
       jalview.bin.JalviewLite.addFrame(frame, "Features", 600, 500);\r
-\r
       cap.setText(features);\r
+    } else {\r
+      if (features==null)\r
+        features = "";\r
     }\r
 \r
     return features;\r
@@ -1170,8 +1285,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public void closeMenuItem_actionPerformed()\r
   {\r
     PaintRefresher.RemoveComponent(alignPanel);\r
-    PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);\r
-    PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);\r
+    if (alignPanel.seqPanel!=null && alignPanel.seqPanel.seqCanvas!=null)\r
+    {\r
+      PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);\r
+    }\r
+    if (alignPanel.idPanel!=null && alignPanel.idPanel.idCanvas!=null) {\r
+      PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);\r
+    }\r
 \r
     if (PaintRefresher.components.size() == 0 && viewport.applet == null)\r
     {\r
@@ -1184,7 +1304,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
-   * DOCUMENT ME!\r
+   * TODO: JAL-1104\r
    */\r
   void updateEditMenuBar()\r
   {\r
@@ -1215,6 +1335,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }\r
   }\r
 \r
+  /**\r
+   * TODO: JAL-1104\r
+   */\r
   public void addHistoryItem(CommandI command)\r
   {\r
     if (command.getSize() > 0)\r
@@ -1222,11 +1345,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       viewport.historyList.push(command);\r
       viewport.redoList.removeAllElements();\r
       updateEditMenuBar();\r
-      viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;\r
+      viewport.updateHiddenColumns();\r
     }\r
   }\r
 \r
   /**\r
+   * TODO: JAL-1104\r
    * DOCUMENT ME!\r
    * \r
    * @param e\r
@@ -1244,14 +1368,18 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     command.undoCommand(null);\r
 \r
     AlignViewport originalSource = getOriginatingSource(command);\r
-\r
-    originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;\r
+    // JBPNote Test\r
+    if (originalSource!=viewport) {\r
+      System.err.println("Warning: Viewport object mismatch whilst undoing");\r
+    }\r
+    originalSource.updateHiddenColumns(); //    originalSource.hasHiddenColumns = viewport.getColumnSelection().getHiddenColumns() != null;\r
     updateEditMenuBar();\r
     originalSource.firePropertyChange("alignment", null,\r
-            originalSource.alignment.getSequences());\r
+            originalSource.getAlignment().getSequences());\r
   }\r
 \r
   /**\r
+   * TODO: JAL-1104\r
    * DOCUMENT ME!\r
    * \r
    * @param e\r
@@ -1269,11 +1397,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     command.doCommand(null);\r
 \r
     AlignViewport originalSource = getOriginatingSource(command);\r
-    originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;\r
+    // JBPNote Test\r
+    if (originalSource!=viewport) {\r
+      System.err.println("Warning: Viewport object mismatch whilst re-doing");\r
+    }\r
+    originalSource.updateHiddenColumns(); //sethasHiddenColumns(); = viewport.getColumnSelection().getHiddenColumns() != null;\r
 \r
     updateEditMenuBar();\r
     originalSource.firePropertyChange("alignment", null,\r
-            originalSource.alignment.getSequences());\r
+            originalSource.getAlignment().getSequences());\r
   }\r
 \r
   AlignViewport getOriginatingSource(CommandI command)\r
@@ -1293,7 +1425,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {\r
         if (comps.elementAt(i) instanceof AlignmentPanel)\r
         {\r
-          if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)\r
+          if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())\r
           {\r
             originalSource = ((AlignmentPanel) comps.elementAt(i)).av;\r
             break;\r
@@ -1308,7 +1440,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       // the current view against the closed view first\r
       if (al != null)\r
       {\r
-        PaintRefresher.validateSequences(al, viewport.alignment);\r
+        PaintRefresher.validateSequences(al, viewport.getAlignment());\r
       }\r
 \r
       originalSource = viewport;\r
@@ -1327,42 +1459,42 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
     if (up)\r
     {\r
-      for (int i = 1; i < viewport.alignment.getHeight(); i++)\r
+      for (int i = 1; i < viewport.getAlignment().getHeight(); i++)\r
       {\r
-        SequenceI seq = viewport.alignment.getSequenceAt(i);\r
+        SequenceI seq = viewport.getAlignment().getSequenceAt(i);\r
         if (!sg.getSequences(null).contains(seq))\r
         {\r
           continue;\r
         }\r
 \r
-        SequenceI temp = viewport.alignment.getSequenceAt(i - 1);\r
+        SequenceI temp = viewport.getAlignment().getSequenceAt(i - 1);\r
         if (sg.getSequences(null).contains(temp))\r
         {\r
           continue;\r
         }\r
 \r
-        viewport.alignment.getSequences().setElementAt(temp, i);\r
-        viewport.alignment.getSequences().setElementAt(seq, i - 1);\r
+        viewport.getAlignment().getSequences().setElementAt(temp, i);\r
+        viewport.getAlignment().getSequences().setElementAt(seq, i - 1);\r
       }\r
     }\r
     else\r
     {\r
-      for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)\r
+      for (int i = viewport.getAlignment().getHeight() - 2; i > -1; i--)\r
       {\r
-        SequenceI seq = viewport.alignment.getSequenceAt(i);\r
-        if (!sg.getSequences(viewport.hiddenRepSequences).contains(seq))\r
+        SequenceI seq = viewport.getAlignment().getSequenceAt(i);\r
+        if (!sg.getSequences(viewport.getHiddenRepSequences()).contains(seq))\r
         {\r
           continue;\r
         }\r
 \r
-        SequenceI temp = viewport.alignment.getSequenceAt(i + 1);\r
-        if (sg.getSequences(viewport.hiddenRepSequences).contains(temp))\r
+        SequenceI temp = viewport.getAlignment().getSequenceAt(i + 1);\r
+        if (sg.getSequences(viewport.getHiddenRepSequences()).contains(temp))\r
         {\r
           continue;\r
         }\r
 \r
-        viewport.alignment.getSequences().setElementAt(temp, i);\r
-        viewport.alignment.getSequences().setElementAt(seq, i + 1);\r
+        viewport.getAlignment().getSequences().setElementAt(temp, i);\r
+        viewport.getAlignment().getSequences().setElementAt(seq, i + 1);\r
       }\r
     }\r
 \r
@@ -1371,18 +1503,18 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   synchronized void slideSequences(boolean right, int size)\r
   {\r
-    Vector sg = new Vector();\r
+    List<SequenceI>sg = new Vector<SequenceI>();\r
     if (viewport.cursorMode)\r
     {\r
-      sg.addElement(viewport.alignment\r
+      sg.add(viewport.getAlignment()\r
               .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));\r
     }\r
     else if (viewport.getSelectionGroup() != null\r
-            && viewport.getSelectionGroup().getSize() != viewport.alignment\r
+            && viewport.getSelectionGroup().getSize() != viewport.getAlignment()\r
                     .getHeight())\r
     {\r
       sg = viewport.getSelectionGroup().getSequences(\r
-              viewport.hiddenRepSequences);\r
+              viewport.getHiddenRepSequences());\r
     }\r
 \r
     if (sg.size() < 1)\r
@@ -1390,19 +1522,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       return;\r
     }\r
 \r
-    Vector invertGroup = new Vector();\r
+    Vector<SequenceI> invertGroup = new Vector();\r
 \r
-    for (int i = 0; i < viewport.alignment.getHeight(); i++)\r
+    for (int i = 0; i < viewport.getAlignment().getHeight(); i++)\r
     {\r
-      if (!sg.contains(viewport.alignment.getSequenceAt(i)))\r
-        invertGroup.addElement(viewport.alignment.getSequenceAt(i));\r
+      if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))\r
+        invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));\r
     }\r
 \r
-    SequenceI[] seqs1 = new SequenceI[sg.size()];\r
-    for (int i = 0; i < sg.size(); i++)\r
-      seqs1[i] = (SequenceI) sg.elementAt(i);\r
+    SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);\r
 \r
-    SequenceI[] seqs2 = new SequenceI[invertGroup.size()];\r
+    SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup.size()]);\r
     for (int i = 0; i < invertGroup.size(); i++)\r
       seqs2[i] = (SequenceI) invertGroup.elementAt(i);\r
 \r
@@ -1470,14 +1600,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     for (int i = 0; i < sg.getSize(); i++)\r
     {\r
       SequenceI seq = sg.getSequenceAt(i);\r
-      int index = viewport.alignment.findIndex(seq);\r
+      int index = viewport.getAlignment().findIndex(seq);\r
       orderedSeqs.put(index + "", seq);\r
     }\r
 \r
     int index = 0, startRes, endRes;\r
     char ch;\r
 \r
-    if (viewport.hasHiddenColumns && viewport.getSelectionGroup() != null)\r
+    if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)\r
     {\r
       copiedHiddenColumns = new Vector();\r
       int hiddenOffset = viewport.getSelectionGroup().getStartRes();\r
@@ -1624,17 +1754,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {\r
     for (int i = 0; i < seqs.length; i++)\r
     {\r
-      viewport.alignment.addSequence(seqs[i]);\r
+      viewport.getAlignment().addSequence(seqs[i]);\r
     }\r
 \r
     // !newAlignment\r
     addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,\r
-            seqs, 0, viewport.alignment.getWidth(), viewport.alignment));\r
+            seqs, 0, viewport.getAlignment().getWidth(), viewport.getAlignment()));\r
 \r
-    viewport.setEndSeq(viewport.alignment.getHeight());\r
-    viewport.alignment.getWidth();\r
+    viewport.setEndSeq(viewport.getAlignment().getHeight());\r
+    viewport.getAlignment().getWidth();\r
     viewport.firePropertyChange("alignment", null,\r
-            viewport.alignment.getSequences());\r
+            viewport.getAlignment().getSequences());\r
 \r
   }\r
 \r
@@ -1662,7 +1792,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }\r
 \r
     // If the cut affects all sequences, remove highlighted columns\r
-    if (sg.getSize() == viewport.alignment.getHeight())\r
+    if (sg.getSize() == viewport.getAlignment().getHeight())\r
     {\r
       viewport.getColumnSelection().removeElements(sg.getStartRes(),\r
               sg.getEndRes() + 1);\r
@@ -1679,10 +1809,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
      */\r
     addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,\r
             sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,\r
-            viewport.alignment));\r
+            viewport.getAlignment()));\r
 \r
     viewport.setSelectionGroup(null);\r
-    viewport.alignment.deleteGroup(sg);\r
+    viewport.getAlignment().deleteGroup(sg);\r
 \r
     viewport.firePropertyChange("alignment", null, viewport.getAlignment()\r
             .getSequences());\r
@@ -1752,8 +1882,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
               viewport.getSequenceSelection(),\r
               viewport.getAlignmentView(true).getSequenceStrings(\r
                       viewport.getGapCharacter()),\r
-              viewport.alignment.getGroups());\r
-      viewport.alignment.deleteAllGroups();\r
+              viewport.getAlignment().getGroups());\r
+      viewport.getAlignment().deleteAllGroups();\r
       viewport.sequenceColours = null;\r
       viewport.setSelectionGroup(null);\r
       // set view properties for each group\r
@@ -1761,13 +1891,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {\r
         // gps[g].setShowunconserved(viewport.getShowUnconserved());\r
         gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());\r
-        viewport.alignment.addGroup(gps[g]);\r
+        viewport.getAlignment().addGroup(gps[g]);\r
         Color col = new Color((int) (Math.random() * 255),\r
                 (int) (Math.random() * 255), (int) (Math.random() * 255));\r
         col = col.brighter();\r
-        for (Enumeration sq = gps[g].getSequences(null).elements(); sq\r
-                .hasMoreElements(); viewport.setSequenceColour(\r
-                (SequenceI) sq.nextElement(), col))\r
+        for (SequenceI sq : gps[g].getSequences(null))\r
+          viewport.setSequenceColour(\r
+                sq, col)\r
           ;\r
       }\r
       PaintRefresher.Refresh(this, viewport.getSequenceSetId());\r
@@ -1778,7 +1908,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   protected void deleteGroups_actionPerformed()\r
   {\r
-    viewport.alignment.deleteAllGroups();\r
+    viewport.getAlignment().deleteAllGroups();\r
     viewport.sequenceColours = null;\r
     viewport.setSelectionGroup(null);\r
 \r
@@ -1792,7 +1922,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);\r
     }\r
-    sg.setEndRes(viewport.alignment.getWidth() - 1);\r
+    sg.setEndRes(viewport.getAlignment().getWidth() - 1);\r
     viewport.setSelectionGroup(sg);\r
     alignPanel.paintAlignment(true);\r
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());\r
@@ -1856,11 +1986,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       if (viewport.getSelectionGroup() != null)\r
       {\r
         seqs = viewport.getSelectionGroup().getSequencesAsArray(\r
-                viewport.hiddenRepSequences);\r
+                viewport.getHiddenRepSequences());\r
       }\r
       else\r
       {\r
-        seqs = viewport.alignment.getSequencesArray();\r
+        seqs = viewport.getAlignment().getSequencesArray();\r
       }\r
 \r
       TrimRegionCommand trimRegion;\r
@@ -1868,32 +1998,30 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {\r
         trimRegion = new TrimRegionCommand("Remove Left",\r
                 TrimRegionCommand.TRIM_LEFT, seqs, column,\r
-                viewport.alignment, viewport.colSel,\r
-                viewport.selectionGroup);\r
+                viewport.getAlignment(), viewport.getColumnSelection(),\r
+                viewport.getSelectionGroup());\r
         viewport.setStartRes(0);\r
       }\r
       else\r
       {\r
         trimRegion = new TrimRegionCommand("Remove Right",\r
                 TrimRegionCommand.TRIM_RIGHT, seqs, column,\r
-                viewport.alignment, viewport.colSel,\r
-                viewport.selectionGroup);\r
+                viewport.getAlignment(), viewport.getColumnSelection(),\r
+                viewport.getSelectionGroup());\r
       }\r
 \r
       statusBar.setText("Removed " + trimRegion.getSize() + " columns.");\r
 \r
       addHistoryItem(trimRegion);\r
 \r
-      Vector groups = viewport.alignment.getGroups();\r
 \r
-      for (int i = 0; i < groups.size(); i++)\r
-      {\r
-        SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
 \r
+      for (SequenceGroup sg:viewport.getAlignment().getGroups())\r
+      {\r
         if ((trimLeft && !sg.adjustForRemoveLeft(column))\r
                 || (!trimLeft && !sg.adjustForRemoveRight(column)))\r
         {\r
-          viewport.alignment.deleteGroup(sg);\r
+          viewport.getAlignment().deleteGroup(sg);\r
         }\r
       }\r
 \r
@@ -1904,23 +2032,23 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   public void removeGappedColumnMenuItem_actionPerformed()\r
   {\r
-    int start = 0, end = viewport.alignment.getWidth() - 1;\r
+    int start = 0, end = viewport.getAlignment().getWidth() - 1;\r
 \r
     SequenceI[] seqs;\r
     if (viewport.getSelectionGroup() != null)\r
     {\r
       seqs = viewport.getSelectionGroup().getSequencesAsArray(\r
-              viewport.hiddenRepSequences);\r
+              viewport.getHiddenRepSequences());\r
       start = viewport.getSelectionGroup().getStartRes();\r
       end = viewport.getSelectionGroup().getEndRes();\r
     }\r
     else\r
     {\r
-      seqs = viewport.alignment.getSequencesArray();\r
+      seqs = viewport.getAlignment().getSequencesArray();\r
     }\r
 \r
     RemoveGapColCommand removeGapCols = new RemoveGapColCommand(\r
-            "Remove Gapped Columns", seqs, start, end, viewport.alignment);\r
+            "Remove Gapped Columns", seqs, start, end, viewport.getAlignment());\r
 \r
     addHistoryItem(removeGapCols);\r
 \r
@@ -1929,7 +2057,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
     // This is to maintain viewport position on first residue\r
     // of first sequence\r
-    SequenceI seq = viewport.alignment.getSequenceAt(0);\r
+    SequenceI seq = viewport.getAlignment().getSequenceAt(0);\r
     int startRes = seq.findPosition(viewport.startRes);\r
     // ShiftList shifts;\r
     // viewport.getAlignment().removeGaps(shifts=new ShiftList());\r
@@ -1944,28 +2072,28 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   public void removeAllGapsMenuItem_actionPerformed()\r
   {\r
-    int start = 0, end = viewport.alignment.getWidth() - 1;\r
+    int start = 0, end = viewport.getAlignment().getWidth() - 1;\r
 \r
     SequenceI[] seqs;\r
     if (viewport.getSelectionGroup() != null)\r
     {\r
       seqs = viewport.getSelectionGroup().getSequencesAsArray(\r
-              viewport.hiddenRepSequences);\r
+              viewport.getHiddenRepSequences());\r
       start = viewport.getSelectionGroup().getStartRes();\r
       end = viewport.getSelectionGroup().getEndRes();\r
     }\r
     else\r
     {\r
-      seqs = viewport.alignment.getSequencesArray();\r
+      seqs = viewport.getAlignment().getSequencesArray();\r
     }\r
 \r
     // This is to maintain viewport position on first residue\r
     // of first sequence\r
-    SequenceI seq = viewport.alignment.getSequenceAt(0);\r
+    SequenceI seq = viewport.getAlignment().getSequenceAt(0);\r
     int startRes = seq.findPosition(viewport.startRes);\r
 \r
     addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,\r
-            viewport.alignment));\r
+            viewport.getAlignment()));\r
 \r
     viewport.setStartRes(seq.findIndex(startRes) - 1);\r
 \r
@@ -1988,30 +2116,30 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public AlignFrame newView(String viewtitle)\r
   {\r
     AlignmentI newal;\r
-    if (viewport.hasHiddenRows)\r
+    if (viewport.hasHiddenRows())\r
     {\r
       newal = new Alignment(viewport.getAlignment().getHiddenSequences()\r
               .getFullAlignment().getSequencesArray());\r
     }\r
     else\r
     {\r
-      newal = new Alignment(viewport.alignment.getSequencesArray());\r
+      newal = new Alignment(viewport.getAlignment().getSequencesArray());\r
     }\r
 \r
-    if (viewport.alignment.getAlignmentAnnotation() != null)\r
+    if (viewport.getAlignment().getAlignmentAnnotation() != null)\r
     {\r
-      for (int i = 0; i < viewport.alignment.getAlignmentAnnotation().length; i++)\r
+      for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)\r
       {\r
-        if (!viewport.alignment.getAlignmentAnnotation()[i].autoCalculated)\r
+        if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)\r
         {\r
-          newal.addAnnotation(viewport.alignment.getAlignmentAnnotation()[i]);\r
+          newal.addAnnotation(viewport.getAlignment().getAlignmentAnnotation()[i]);\r
         }\r
       }\r
     }\r
 \r
     AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);\r
 \r
-    newaf.viewport.sequenceSetID = alignPanel.av.getSequenceSetId();\r
+    newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());\r
     PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());\r
     PaintRefresher.Register(newaf.alignPanel,\r
             newaf.alignPanel.av.getSequenceSetId());\r
@@ -2156,11 +2284,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             overview.getPreferredSize().height + 50);\r
 \r
     frame.pack();\r
+    final AlignmentPanel ap=alignPanel;\r
     frame.addWindowListener(new WindowAdapter()\r
     {\r
       public void windowClosing(WindowEvent e)\r
       {\r
-        alignPanel.setOverviewPanel(null);\r
+        if (ap!=null) {\r
+          ap.setOverviewPanel(null);\r
+        }\r
       };\r
     });\r
 \r
@@ -2191,13 +2322,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       if (viewport.getConservationSelected())\r
       {\r
 \r
-        Alignment al = (Alignment) viewport.alignment;\r
+        Alignment al = (Alignment) viewport.getAlignment();\r
         Conservation c = new Conservation("All",\r
                 ResidueProperties.propHash, 3, al.getSequences(), 0,\r
                 al.getWidth() - 1);\r
 \r
         c.calculate();\r
-        c.verdict(false, viewport.ConsPercGaps);\r
+        c.verdict(false, viewport.getConsPercGaps());\r
 \r
         cs.setConservation(c);\r
 \r
@@ -2210,14 +2341,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         cs.setConservation(null);\r
       }\r
 \r
-      cs.setConsensus(viewport.hconsensus);\r
+      cs.setConsensus(viewport.getSequenceConsensusHash());\r
 \r
-    }\r
+    }             \r
     viewport.setGlobalColourScheme(cs);\r
 \r
     if (viewport.getColourAppliesToAllGroups())\r
     {\r
-      Vector groups = viewport.alignment.getGroups();\r
+      Vector groups = viewport.getAlignment().getGroups();\r
       for (int i = 0; i < groups.size(); i++)\r
       {\r
         SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
@@ -2230,14 +2361,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         if (cs instanceof ClustalxColourScheme)\r
         {\r
           sg.cs = new ClustalxColourScheme(\r
-                  sg.getSequences(viewport.hiddenRepSequences),\r
+                  sg.getSequences(viewport.getHiddenRepSequences()),\r
                   sg.getWidth());\r
         }\r
         else\r
         {\r
           try\r
           {\r
-            sg.cs = (ColourSchemeI) cs.getClass().newInstance();\r
+            sg.cs = cs.getClass().newInstance();\r
           } catch (Exception ex)\r
           {\r
             ex.printStackTrace();\r
@@ -2251,7 +2382,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         {\r
           sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());\r
           sg.cs.setConsensus(AAFrequency.calculate(\r
-                  sg.getSequences(viewport.hiddenRepSequences), 0,\r
+                  sg.getSequences(viewport.getHiddenRepSequences()), 0,\r
                   sg.getWidth()));\r
         }\r
         else\r
@@ -2263,10 +2394,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         {\r
           Conservation c = new Conservation("Group",\r
                   ResidueProperties.propHash, 3,\r
-                  sg.getSequences(viewport.hiddenRepSequences), 0,\r
-                  viewport.alignment.getWidth() - 1);\r
+                  sg.getSequences(viewport.getHiddenRepSequences()), 0,\r
+                  viewport.getAlignment().getWidth() - 1);\r
           c.calculate();\r
-          c.verdict(false, viewport.ConsPercGaps);\r
+          c.verdict(false, viewport.getConsPercGaps());\r
           sg.cs.setConservation(c);\r
         }\r
         else\r
@@ -2293,7 +2424,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   protected void modifyPID_actionPerformed()\r
   {\r
     if (viewport.getAbovePIDThreshold()\r
-            && viewport.globalColourScheme != null)\r
+            && viewport.getGlobalColourScheme() != null)\r
     {\r
       SliderPanel.setPIDSliderSource(alignPanel,\r
               viewport.getGlobalColourScheme(), "Background");\r
@@ -2304,10 +2435,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   protected void modifyConservation_actionPerformed()\r
   {\r
     if (viewport.getConservationSelected()\r
-            && viewport.globalColourScheme != null)\r
+            && viewport.getGlobalColourScheme() != null)\r
     {\r
       SliderPanel.setConservationSlider(alignPanel,\r
-              viewport.globalColourScheme, "Background");\r
+              viewport.getGlobalColourScheme(), "Background");\r
       SliderPanel.showConservationSlider();\r
     }\r
   }\r
@@ -2343,7 +2474,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             .getAlignment().getSequenceAt(0), null);\r
 \r
     addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,\r
-            viewport.alignment));\r
+            viewport.getAlignment()));\r
     alignPanel.paintAlignment(true);\r
   }\r
 \r
@@ -2351,7 +2482,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {\r
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();\r
     AlignmentSorter.sortByID(viewport.getAlignment());\r
-    addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));\r
+    addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));\r
     alignPanel.paintAlignment(true);\r
   }\r
 \r
@@ -2360,7 +2491,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();\r
     AlignmentSorter.sortByLength(viewport.getAlignment());\r
     addHistoryItem(new OrderCommand("Length Sort", oldOrder,\r
-            viewport.alignment));\r
+            viewport.getAlignment()));\r
     alignPanel.paintAlignment(true);\r
   }\r
 \r
@@ -2369,7 +2500,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();\r
     AlignmentSorter.sortByGroup(viewport.getAlignment());\r
     addHistoryItem(new OrderCommand("Group Sort", oldOrder,\r
-            viewport.alignment));\r
+            viewport.getAlignment()));\r
     alignPanel.paintAlignment(true);\r
 \r
   }\r
@@ -2394,7 +2525,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public void PCAMenuItem_actionPerformed()\r
   {\r
     // are the sequences aligned?\r
-    if (!viewport.alignment.isAligned(false))\r
+    if (!viewport.getAlignment().isAligned(false))\r
     {\r
       SequenceI current;\r
       int Width = viewport.getAlignment().getWidth();\r
@@ -2451,7 +2582,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   void NewTreePanel(String type, String pwType, String title)\r
   {\r
     // are the sequences aligned?\r
-    if (!viewport.alignment.isAligned(false))\r
+    if (!viewport.getAlignment().isAligned(false))\r
     {\r
       SequenceI current;\r
       int Width = viewport.getAlignment().getWidth();\r
@@ -2471,7 +2602,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
     if ((viewport.getSelectionGroup() != null && viewport\r
             .getSelectionGroup().getSize() > 1)\r
-            || (viewport.getSelectionGroup() == null && viewport.alignment\r
+            || (viewport.getSelectionGroup() == null && viewport.getAlignment()\r
                     .getHeight() > 1))\r
     {\r
       final TreePanel tp = new TreePanel(alignPanel, type, pwType);\r
@@ -2515,7 +2646,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // addHistoryItem(new HistoryItem("Sort", viewport.alignment,\r
     // HistoryItem.SORT));\r
     addHistoryItem(new OrderCommand("Order by " + title, oldOrder,\r
-            viewport.alignment));\r
+            viewport.getAlignment()));\r
     alignPanel.paintAlignment(true);\r
   }\r
 \r
@@ -2538,7 +2669,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         sortByTree(treePanel, title); // treePanel.getTitle());\r
       }\r
     });\r
-\r
+    \r
     treePanel.addWindowListener(new WindowAdapter()\r
     {\r
       public void windowOpened(WindowEvent e)\r
@@ -2567,11 +2698,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     AlignmentSorter.sortBy(viewport.getAlignment(), alorder);\r
     if (undoname!=null)\r
     {\r
-      addHistoryItem(new OrderCommand(undoname, oldOrder, viewport.alignment));\r
+      addHistoryItem(new OrderCommand(undoname, oldOrder, viewport.getAlignment()));\r
     }\r
     alignPanel.paintAlignment(true);\r
     return true;\r
   }\r
+\r
   protected void documentation_actionPerformed()\r
   {\r
     alignPanel.av.applet.openJalviewHelpUrl();\r
@@ -2661,7 +2793,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   MenuItem loadTree = new MenuItem("Load Associated Tree ...");\r
 \r
   MenuItem loadAnnotations = new MenuItem("Load Features/Annotations ...");\r
-\r
+  \r
   MenuItem outputFeatures = new MenuItem("Export Features ...");\r
 \r
   MenuItem outputAnnotations = new MenuItem("Export Annotations ...");\r
@@ -2734,11 +2866,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   MenuItem buriedColour = new MenuItem();\r
 \r
+  MenuItem purinePyrimidineColour = new MenuItem();\r
+  MenuItem RNAHelixColour = new MenuItem();\r
+  \r
   MenuItem userDefinedColour = new MenuItem();\r
 \r
   MenuItem PIDColour = new MenuItem();\r
 \r
   MenuItem BLOSUM62Colour = new MenuItem();\r
+  \r
+  MenuItem tcoffeeColour = new MenuItem();\r
 \r
   MenuItem njTreeBlosumMenuItem = new MenuItem();\r
 \r
@@ -2805,6 +2942,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   CheckboxMenuItem autoCalculate = new CheckboxMenuItem(\r
           "Autocalculate Consensus", true);\r
 \r
+  CheckboxMenuItem sortByTree = new CheckboxMenuItem(\r
+          "Sort Alignment With New Tree", true);\r
+\r
   Menu sortByTreeMenu = new Menu();\r
 \r
   Menu sort = new Menu();\r
@@ -2919,14 +3059,20 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     turnColour.addActionListener(this);\r
     buriedColour.setLabel("Buried Index");\r
     buriedColour.addActionListener(this);\r
+    purinePyrimidineColour.setLabel("Purine/Pyrimidine");\r
+    purinePyrimidineColour.addActionListener(this);\r
+    RNAHelixColour.setLabel("by RNA Helices");\r
+    RNAHelixColour.addActionListener(this);\r
     userDefinedColour.setLabel("User Defined...");\r
     userDefinedColour.addActionListener(this);\r
     PIDColour.setLabel("Percentage Identity");\r
     PIDColour.addActionListener(this);\r
     BLOSUM62Colour.setLabel("BLOSUM62 Score");\r
     BLOSUM62Colour.addActionListener(this);\r
-    avDistanceTreeBlosumMenuItem\r
-            .setLabel("Average Distance Using BLOSUM62");\r
+    tcoffeeColour.setLabel("T-Coffee Scores");\r
+    tcoffeeColour.setEnabled(false);   // it will enabled only if a score file is provided\r
+    tcoffeeColour.addActionListener(this);\r
+    avDistanceTreeBlosumMenuItem .setLabel("Average Distance Using BLOSUM62");\r
     avDistanceTreeBlosumMenuItem.addActionListener(this);\r
     njTreeBlosumMenuItem.setLabel("Neighbour Joining Using BLOSUM62");\r
     njTreeBlosumMenuItem.addActionListener(this);\r
@@ -3000,6 +3146,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     sort.setLabel("Sort");\r
     calculate.setLabel("Calculate Tree");\r
     autoCalculate.addItemListener(this);\r
+    sortByTree.addItemListener(this);\r
     inputText.setLabel("Input from textbox");\r
     inputText.addActionListener(this);\r
     centreColumnLabelFlag.setLabel("Centre column labels");\r
@@ -3070,7 +3217,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     fileMenu.add(inputText);\r
     fileMenu.add(loadTree);\r
     fileMenu.add(loadAnnotations);\r
-\r
+    \r
     fileMenu.addSeparator();\r
     fileMenu.add(outputTextboxMenu);\r
     fileMenu.add(outputFeatures);\r
@@ -3131,6 +3278,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     colourMenu.add(turnColour);\r
     colourMenu.add(buriedColour);\r
     colourMenu.add(nucleotideColour);\r
+    colourMenu.add(purinePyrimidineColour);\r
+    colourMenu.add(tcoffeeColour);\r
     colourMenu.add(userDefinedColour);\r
     colourMenu.addSeparator();\r
     colourMenu.add(conservationMenuItem);\r
@@ -3138,12 +3287,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     colourMenu.add(abovePIDThreshold);\r
     colourMenu.add(modifyPID);\r
     colourMenu.add(annotationColour);\r
+    colourMenu.add(RNAHelixColour);\r
     calculateMenu.add(sort);\r
     calculateMenu.add(calculate);\r
     calculateMenu.addSeparator();\r
     calculateMenu.add(pairwiseAlignmentMenuItem);\r
     calculateMenu.add(PCAMenuItem);\r
     calculateMenu.add(autoCalculate);\r
+    calculateMenu.add(sortByTree);\r
     this.add(statusBar, BorderLayout.SOUTH);\r
     pasteMenu.add(pasteNew);\r
     pasteMenu.add(pasteThis);\r
@@ -3557,4 +3708,51 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public String getSequenceSetId() {\r
     return viewport.getSequenceSetId();\r
   }\r
+  \r
+  \r
+  /**\r
+   * Load the (T-Coffee) score file from the specified url \r
+   * \r
+   * @param source File/URL/T-COFFEE score file contents\r
+   * @throws IOException \r
+   * @return true if alignment was annotated with data from source\r
+   */\r
+  public boolean loadScoreFile( String source ) throws IOException {\r
+\r
+    TCoffeeScoreFile file = new TCoffeeScoreFile(source, AppletFormatAdapter.checkProtocol(source));\r
+         if( !file.isValid()) {\r
+           // TODO: raise dialog for gui\r
+           System.err.println("Problems parsing T-Coffee scores: "+file.getWarningMessage());\r
+           System.err.println("Origin was:\n"+source);\r
+           return false;\r
+         }\r
+         \r
+         /*\r
+          * check that the score matrix matches the alignment dimensions\r
+          */\r
+         AlignmentI aln; \r
+         if( (aln=viewport.getAlignment()) != null && (aln.getHeight() != file.getHeight() || aln.getWidth() != file.getWidth()) ) {\r
+           // TODO: raise a dialog box here rather than bomb out.\r
+           System.err.println("The scores matrix does not match the alignment dimensions");\r
+                 \r
+         }\r
+         \r
+          // TODO add parameter to indicate if matching should be done\r
+         if (file.annotateAlignment(alignPanel.getAlignment(), false))\r
+         {\r
+           alignPanel.fontChanged();\r
+           tcoffeeColour.setEnabled(true);\r
+                 // switch to this color\r
+                 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));\r
+                 return true;\r
+          } else {\r
+            System.err.println("Problems resolving T-Coffee scores:");\r
+            if (file.getWarningMessage()!=null) {\r
+              System.err.println(file.getWarningMessage());\r
+            }\r
+          }\r
+         return false;\r
+  }\r
+  \r
+  \r
 }\r