JAL-1031 allow empty selections to pass through to tree builder, which will ignore...
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index 3ebc083..bcb518f 100644 (file)
@@ -1,39 +1,98 @@
 /*\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
+ *\r
  * This file is part of Jalview.\r
- * \r
+ *\r
  * Jalview is free software: you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License \r
+ * modify it under the terms of the GNU General Public License\r
  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
- * \r
- * Jalview is distributed in the hope that it will be useful, but \r
- * WITHOUT ANY WARRANTY; without even the implied warranty \r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ *\r
+ * Jalview is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty\r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
  * PURPOSE.  See the GNU General Public License for more details.\r
- * \r
+ *\r
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\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.SequenceCollectionI;\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
@@ -45,10 +104,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   String jalviewServletURL;\r
 \r
-  public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet,\r
-          String title, boolean embedded)\r
-  {\r
 \r
+  public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet, String title, boolean embedded)\r
+  {\r
     if (applet != null)\r
     {\r
       jalviewServletURL = applet.getParameter("APPLICATION_URL");\r
@@ -75,6 +133,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     showGroupConservation.setState(viewport.isShowGroupConservation());\r
     showConsensusHistogram.setState(viewport.isShowConsensusHistogram());\r
     showSequenceLogo.setState(viewport.isShowSequenceLogo());\r
+    normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());\r
 \r
     seqLimits.setState(viewport.showJVSuffix);\r
 \r
@@ -131,7 +190,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
@@ -162,25 +234,28 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * Load a features file onto the alignment\r
-   * \r
+   *\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
-    parseFeaturesFile(file, type, true);\r
+    return parseFeaturesFile(file, type, true);\r
   }\r
-  \r
+\r
   /**\r
    * Load a features file onto the alignment\r
-   * \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 void parseFeaturesFile(String file, String type, boolean autoenabledisplay)\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
@@ -210,10 +285,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         viewport.featureSettings.refreshTable();\r
       }\r
       alignPanel.paintAlignment(true);\r
+      statusBar.setText("Successfully added features to alignment.");\r
     }\r
-\r
+    return featuresFile;\r
   }\r
 \r
+  @Override\r
   public void keyPressed(KeyEvent evt)\r
   {\r
     if (viewport.cursorMode\r
@@ -227,8 +304,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
     case 27: // escape key\r
       deselectAllSequenceMenuItem_actionPerformed();\r
-      \r
-      alignPanel.alabels.cancelDrag(); \r
+\r
+      alignPanel.alabels.cancelDrag();\r
       break;\r
     case KeyEvent.VK_X:\r
       if (evt.isControlDown() || evt.isMetaDown())\r
@@ -475,7 +552,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * called by key handler and the hide all/show all menu items\r
-   * \r
+   *\r
    * @param toggleSeqs\r
    * @param toggleCols\r
    */\r
@@ -540,14 +617,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }\r
   }\r
 \r
+  @Override\r
   public void keyReleased(KeyEvent evt)\r
   {\r
   }\r
 \r
+  @Override\r
   public void keyTyped(KeyEvent evt)\r
   {\r
   }\r
 \r
+  @Override\r
   public void itemStateChanged(ItemEvent evt)\r
   {\r
     if (evt.getSource() == displayNonconservedMenuItem)\r
@@ -640,6 +720,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       showSequenceLogo_actionPerformed();\r
     }\r
+    else if (evt.getSource() == normSequenceLogo)\r
+    {\r
+      normSequenceLogo_actionPerformed();\r
+    }\r
     else if (evt.getSource() == showConsensusHistogram)\r
     {\r
       showConsensusHistogram_actionPerformed();\r
@@ -664,6 +748,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     this.alignPanel.annotationPanel.repaint();\r
   }\r
 \r
+  @Override\r
   public void actionPerformed(ActionEvent evt)\r
   {\r
     Object source = evt.getSource();\r
@@ -849,6 +934,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       showSequenceLogo_actionPerformed();\r
     }\r
+    else if (source == normSequenceLogo)\r
+    {\r
+      normSequenceLogo_actionPerformed();\r
+    }\r
     else if (source == showConsensusHistogram)\r
     {\r
       showConsensusHistogram_actionPerformed();\r
@@ -883,9 +972,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     else if (source == clustalColour)\r
     {\r
       abovePIDThreshold.setState(false);\r
-      changeColour(new ClustalxColourScheme(\r
-              viewport.getAlignment().getSequences(),\r
-              viewport.getAlignment().getWidth()));\r
+      changeColour(new ClustalxColourScheme(viewport.getAlignment(),null));\r
     }\r
     else if (source == zappoColour)\r
     {\r
@@ -919,6 +1006,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
@@ -939,6 +1034,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
@@ -1021,7 +1119,7 @@ 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
@@ -1090,7 +1188,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         features = "# No features visible - paste some and import them here.";\r
         frimport=true;\r
       }\r
-      \r
+\r
       CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);\r
       if (frimport)\r
       {\r
@@ -1202,8 +1300,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
@@ -1216,7 +1319,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
-   * DOCUMENT ME!\r
+   * TODO: JAL-1104\r
    */\r
   void updateEditMenuBar()\r
   {\r
@@ -1247,6 +1350,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
@@ -1259,8 +1365,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
+   * TODO: JAL-1104\r
    * DOCUMENT ME!\r
-   * \r
+   *\r
    * @param e\r
    *          DOCUMENT ME!\r
    */\r
@@ -1287,8 +1394,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
+   * TODO: JAL-1104\r
    * DOCUMENT ME!\r
-   * \r
+   *\r
    * @param e\r
    *          DOCUMENT ME!\r
    */\r
@@ -1363,57 +1471,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       return;\r
     }\r
-\r
-    if (up)\r
-    {\r
-      for (int i = 1; i < viewport.getAlignment().getHeight(); i++)\r
-      {\r
-        SequenceI seq = viewport.getAlignment().getSequenceAt(i);\r
-        if (!sg.getSequences(null).contains(seq))\r
-        {\r
-          continue;\r
-        }\r
-\r
-        SequenceI temp = viewport.getAlignment().getSequenceAt(i - 1);\r
-        if (sg.getSequences(null).contains(temp))\r
-        {\r
-          continue;\r
-        }\r
-\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.getAlignment().getHeight() - 2; i > -1; i--)\r
-      {\r
-        SequenceI seq = viewport.getAlignment().getSequenceAt(i);\r
-        if (!sg.getSequences(viewport.getHiddenRepSequences()).contains(seq))\r
-        {\r
-          continue;\r
-        }\r
-\r
-        SequenceI temp = viewport.getAlignment().getSequenceAt(i + 1);\r
-        if (sg.getSequences(viewport.getHiddenRepSequences()).contains(temp))\r
-        {\r
-          continue;\r
-        }\r
-\r
-        viewport.getAlignment().getSequences().setElementAt(temp, i);\r
-        viewport.getAlignment().getSequences().setElementAt(seq, i + 1);\r
-      }\r
-    }\r
-\r
+    viewport.getAlignment().moveSelectedSequencesByOne(sg, up ? null : viewport.getHiddenRepSequences(), up);\r
     alignPanel.paintAlignment(true);\r
   }\r
 \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.getAlignment()\r
+      sg.add(viewport.getAlignment()\r
               .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));\r
     }\r
     else if (viewport.getSelectionGroup() != null\r
@@ -1429,7 +1496,7 @@ 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.getAlignment().getHeight(); i++)\r
     {\r
@@ -1437,13 +1504,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         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
+      seqs2[i] = invertGroup.elementAt(i);\r
 \r
     SlideSequencesCommand ssc;\r
     if (right)\r
@@ -1735,7 +1800,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * group consensus toggled\r
-   * \r
+   *\r
    */\r
   protected void showGroupConsensus_actionPerformed()\r
   {\r
@@ -1755,7 +1820,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /*\r
    * (non-Javadoc)\r
-   * \r
+   *\r
    * @see\r
    * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt\r
    * .event.ActionEvent)\r
@@ -1767,7 +1832,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
   /*\r
    * (non-Javadoc)\r
-   * \r
+   *\r
    * @see\r
    * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt\r
    * .event.ActionEvent)\r
@@ -1777,6 +1842,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.setShowSequenceLogo(showSequenceLogo.getState());\r
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());\r
   }\r
+  protected void normSequenceLogo_actionPerformed()\r
+  {\r
+    showSequenceLogo.setState(true);\r
+    viewport.setShowSequenceLogo(true);\r
+    viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());\r
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());\r
+  }\r
 \r
   protected void applyAutoAnnotationSettings_actionPerformed()\r
   {\r
@@ -1804,9 +1876,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         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
@@ -1923,12 +1995,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
       addHistoryItem(trimRegion);\r
 \r
-      Vector groups = viewport.getAlignment().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
@@ -2020,7 +2090,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * create a new view derived from the current view\r
-   * \r
+   *\r
    * @param viewtitle\r
    * @return frame for the new view\r
    */\r
@@ -2093,7 +2163,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
-   * \r
+   *\r
    * @return list of feature groups on the view\r
    */\r
   public String[] getFeatureGroups()\r
@@ -2109,7 +2179,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * get sequence feature groups that are hidden or shown\r
-   * \r
+   *\r
    * @param visible\r
    *          true is visible\r
    * @return list\r
@@ -2127,7 +2197,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * Change the display state for the given feature groups\r
-   * \r
+   *\r
    * @param groups\r
    *          list of group strings\r
    * @param state\r
@@ -2195,11 +2265,15 @@ 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
+      @Override\r
       public void windowClosing(WindowEvent e)\r
       {\r
-        alignPanel.setOverviewPanel(null);\r
+        if (ap!=null) {\r
+          ap.setOverviewPanel(null);\r
+        }\r
       };\r
     });\r
 \r
@@ -2254,68 +2328,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }\r
     viewport.setGlobalColourScheme(cs);\r
 \r
-    if (viewport.getColourAppliesToAllGroups())\r
-    {\r
-      Vector groups = viewport.getAlignment().getGroups();\r
-      for (int i = 0; i < groups.size(); i++)\r
-      {\r
-        SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
-\r
-        if (cs == null)\r
-        {\r
-          sg.cs = null;\r
-          continue;\r
-        }\r
-        if (cs instanceof ClustalxColourScheme)\r
-        {\r
-          sg.cs = new ClustalxColourScheme(\r
-                  sg.getSequences(viewport.getHiddenRepSequences()),\r
-                  sg.getWidth());\r
-        }\r
-        else\r
-        {\r
-          try\r
-          {\r
-            sg.cs = (ColourSchemeI) cs.getClass().newInstance();\r
-          } catch (Exception ex)\r
-          {\r
-            ex.printStackTrace();\r
-            sg.cs = cs;\r
-          }\r
-        }\r
-\r
-        if (viewport.getAbovePIDThreshold()\r
-                || cs instanceof PIDColourScheme\r
-                || cs instanceof Blosum62ColourScheme)\r
-        {\r
-          sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());\r
-          sg.cs.setConsensus(AAFrequency.calculate(\r
-                  sg.getSequences(viewport.getHiddenRepSequences()), 0,\r
-                  sg.getWidth()));\r
-        }\r
-        else\r
-        {\r
-          sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
-        }\r
-\r
-        if (viewport.getConservationSelected())\r
-        {\r
-          Conservation c = new Conservation("Group",\r
-                  ResidueProperties.propHash, 3,\r
-                  sg.getSequences(viewport.getHiddenRepSequences()), 0,\r
-                  viewport.getAlignment().getWidth() - 1);\r
-          c.calculate();\r
-          c.verdict(false, viewport.getConsPercGaps());\r
-          sg.cs.setConservation(c);\r
-        }\r
-        else\r
-        {\r
-          sg.cs.setConservation(null);\r
-          sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
-        }\r
-\r
-      }\r
-    }\r
 \r
     if (alignPanel.getOverviewPanel() != null)\r
     {\r
@@ -2510,7 +2522,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
     if ((viewport.getSelectionGroup() != null && viewport\r
             .getSelectionGroup().getSize() > 1)\r
-            || (viewport.getSelectionGroup() == null && viewport.getAlignment()\r
+            || (viewport.getAlignment()\r
                     .getHeight() > 1))\r
     {\r
       final TreePanel tp = new TreePanel(alignPanel, type, pwType);\r
@@ -2540,7 +2552,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * sort the alignment using the given treePanel\r
-   * \r
+   *\r
    * @param treePanel\r
    *          tree used to sort view\r
    * @param title\r
@@ -2561,7 +2573,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   /**\r
    * Do any automatic reordering of the alignment and add the necessary bits to\r
    * the menu structure for the new tree\r
-   * \r
+   *\r
    * @param treePanel\r
    * @param title\r
    */\r
@@ -2572,14 +2584,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     sortByTreeMenu.add(item);\r
     item.addActionListener(new java.awt.event.ActionListener()\r
     {\r
+      @Override\r
       public void actionPerformed(ActionEvent evt)\r
       {\r
         sortByTree(treePanel, title); // treePanel.getTitle());\r
       }\r
     });\r
-    \r
+\r
     treePanel.addWindowListener(new WindowAdapter()\r
     {\r
+      @Override\r
       public void windowOpened(WindowEvent e)\r
       {\r
         if (viewport.sortByTree)\r
@@ -2589,6 +2603,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         super.windowOpened(e);\r
       }\r
 \r
+      @Override\r
       public void windowClosing(WindowEvent e)\r
       {\r
         sortByTreeMenu.remove(item);\r
@@ -2632,6 +2647,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         this.builddate = builddate;\r
       }\r
 \r
+      @Override\r
       public void paint(Graphics g)\r
       {\r
         g.setColor(Color.white);\r
@@ -2774,12 +2790,17 @@ 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
   MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();\r
@@ -2865,7 +2886,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   CheckboxMenuItem seqLimits = new CheckboxMenuItem();\r
 \r
   CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();\r
-  \r
+\r
   CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();\r
   Menu autoAnnMenu=new Menu();\r
   CheckboxMenuItem showSequenceLogo= new CheckboxMenuItem();\r
@@ -2873,6 +2894,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();\r
   CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();\r
   CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();\r
+  CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();\r
 \r
   private void jbInit() throws Exception\r
   {\r
@@ -2890,6 +2912,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
       item.addActionListener(new java.awt.event.ActionListener()\r
       {\r
+        @Override\r
         public void actionPerformed(ActionEvent e)\r
         {\r
           outputText_actionPerformed(e);\r
@@ -2962,14 +2985,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
@@ -3081,10 +3110,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     showGroupConservation.setLabel("Group Conservation");\r
     showConsensusHistogram.setLabel("Show Consensus Histogram");\r
     showSequenceLogo.setLabel("Show Consensus Logo");\r
+    normSequenceLogo.setLabel("Normalise Consensus Logo");\r
     applyAutoAnnotationSettings.setLabel("Apply to all groups");\r
     applyAutoAnnotationSettings.setState(true);\r
     autoAnnMenu.setLabel("Autocalculated Annotation");\r
-    \r
+\r
     invertColSel.addActionListener(this);\r
     showColumns.addActionListener(this);\r
     showSeqs.addActionListener(this);\r
@@ -3097,6 +3127,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     showGroupConservation.addItemListener(this);\r
     showConsensusHistogram.addItemListener(this);\r
     showSequenceLogo.addItemListener(this);\r
+    normSequenceLogo.addItemListener(this);\r
+    \r
     applyAutoAnnotationSettings.addItemListener(this);\r
     formatMenu.setLabel("Format");\r
     selectMenu.setLabel("Select");\r
@@ -3150,6 +3182,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     autoAnnMenu.add(applyAutoAnnotationSettings);\r
     autoAnnMenu.add(showConsensusHistogram);\r
     autoAnnMenu.add(showSequenceLogo);\r
+    autoAnnMenu.add(normSequenceLogo);\r
     autoAnnMenu.addSeparator();\r
     autoAnnMenu.add(showGroupConservation);\r
     autoAnnMenu.add(showGroupConsensus);\r
@@ -3175,6 +3208,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
@@ -3182,6 +3217,7 @@ 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
@@ -3269,7 +3305,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * Attach the alignFrame panels after embedding menus, if necessary. This used\r
    * to be called setEmbedded, but is now creates the dropdown menus in a\r
    * platform independent manner to avoid OSX/Mac menu appendage daftness.\r
-   * \r
+   *\r
    * @param reallyEmbedded\r
    *          true to attach the view to the applet area on the page rather than\r
    *          in a new window\r
@@ -3297,14 +3333,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       final AlignFrame me = this;\r
       viewport.applet.addFocusListener(new FocusListener()\r
       {\r
-        \r
+\r
         @Override\r
         public void focusLost(FocusEvent e)\r
         {\r
           if (me.viewport.applet.currentAlignFrame==me) {\r
                   me.viewport.applet.currentAlignFrame = null;\r
         }}\r
-        \r
+\r
         @Override\r
         public void focusGained(FocusEvent e)\r
         {\r
@@ -3339,7 +3375,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * structures in the original jmol window. Note This method doesn't work\r
    * without an additional javascript library to exchange messages between the\r
    * distinct applets. See http://issues.jalview.org/browse/JAL-621\r
-   * \r
+   *\r
    * @param viewer\r
    *          JmolViewer instance\r
    * @param sequenceIds\r
@@ -3404,7 +3440,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
   /**\r
    * bind a pdb file to a sequence in the current view\r
-   * \r
+   *\r
    * @param sequenceId\r
    *          - sequenceId within the dataset.\r
    * @param pdbEntryString\r
@@ -3576,7 +3612,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   /**\r
    * modify the current selection, providing the user has not made a selection already.\r
-   * @param sel - sequences from this alignment \r
+   * @param sel - sequences from this alignment\r
    * @param csel - columns to be selected on the alignment\r
    */\r
   public void select(SequenceGroup sel, ColumnSelection csel)\r
@@ -3586,15 +3622,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 \r
   public void scrollTo(int row, int column)\r
   {\r
-    alignPanel.seqPanel.scrollTo(row, column);    \r
+    alignPanel.seqPanel.scrollTo(row, column);\r
   }\r
   public void scrollToRow(int row)\r
   {\r
-    alignPanel.seqPanel.scrollToRow(row);    \r
+    alignPanel.seqPanel.scrollToRow(row);\r
   }\r
   public void scrollToColumn(int column)\r
   {\r
-    alignPanel.seqPanel.scrollToColumn(column);    \r
+    alignPanel.seqPanel.scrollToColumn(column);\r
   }\r
   /**\r
    * @return the alignments unique ID.\r
@@ -3602,4 +3638,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