(JAL-958) - normalised sequence logo for applet
[jalview.git] / src / jalview / gui / AlignViewport.java
index 1dbcf56..1c6a94e 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
@@ -40,7 +40,7 @@ import java.util.*;
 import java.awt.*;
 
 import jalview.analysis.*;
-import jalview.api.StructureSelectionManagerProvider;
+import jalview.api.AlignViewportI;
 
 import jalview.bin.*;
 
@@ -57,7 +57,7 @@ import jalview.structure.VamsasSource;
  * @author $author$
  * @version $Revision: 1.141 $
  */
-public class AlignViewport implements SelectionSource, VamsasSource
+public class AlignViewport implements SelectionSource, VamsasSource, AlignViewportI
 {
   private static final int RIGHT_JUSTIFY = 1;
 
@@ -404,6 +404,7 @@ public class AlignViewport implements SelectionSource, VamsasSource
       showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
               true);
       showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
+      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO", false);
       showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
       // TODO: add menu option action that nulls or creates consensus object
       // depending on if the user wants to see the annotation or not in a
@@ -413,17 +414,22 @@ public class AlignViewport implements SelectionSource, VamsasSource
       consensus.hasText = true;
       consensus.autoCalculated = true;
 
-      // TODO check if this can done accordingly
-      strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
-              new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
-      strucConsensus.hasText = true;
-      strucConsensus.autoCalculated = true;
-
+      if (alignment.isNucleotide() && alignment.hasRNAStructure())
+      {
+        strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
+                new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+        strucConsensus.hasText = true;
+        strucConsensus.autoCalculated = true;
+      }
+      
       if (Cache.getDefault("SHOW_IDENTITY", true))
       {
         alignment.addAnnotation(consensus);
         // TODO: Make own if for structure
-        alignment.addAnnotation(strucConsensus);
+        if (alignment.isNucleotide() && alignment.hasRNAStructure())
+        {
+          alignment.addAnnotation(strucConsensus);
+        }
       }
 
     }
@@ -2297,7 +2303,10 @@ public class AlignViewport implements SelectionSource, VamsasSource
    * should consensus profile be rendered by default
    */
   public boolean showSequenceLogo = false;
-
+  /**
+   * should consensus profile be rendered normalised to row height
+   */
+  public  boolean normaliseSequenceLogo = false;
   /**
    * should consensus histograms be rendered by default
    */
@@ -2461,4 +2470,57 @@ public class AlignViewport implements SelectionSource, VamsasSource
     }
     return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
   }
+
+  
+  public boolean isNormaliseSequenceLogo()
+  {
+    return normaliseSequenceLogo;
+  }
+
+  public void setNormaliseSequenceLogo(boolean state)
+  {
+    normaliseSequenceLogo = state;
+  }
+
+  public boolean isCalcInProgress()
+  {
+    // TODO generalise to iterate over all calculators associated with av
+    return updatingConsensus || updatingConservation || updatingStrucConsensus;
+  }
+
+  public boolean isCalculationInProgress(
+          AlignmentAnnotation alignmentAnnotation)
+  {
+    if (!alignmentAnnotation.autoCalculated)
+      return false;
+    if ((updatingConsensus && consensus==alignmentAnnotation)
+            || (updatingConservation && (conservation==alignmentAnnotation || quality==alignmentAnnotation))
+            || (updatingStrucConsensus && strucConsensus==alignmentAnnotation)
+            )
+    {
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * 
+   * @return true if alignment characters should be displayed 
+   */
+  public boolean isValidCharWidth()
+  {
+    return validCharWidth;
+  }
+
+  @Override
+  public Hashtable[] getSequenceConsensusHash()
+  {
+    return hconsensus;
+  }
+
+  @Override
+  public Hashtable[] getRnaStructureConsensusHash()
+  {
+    return hStrucConsensus;
+  }
 }