normalised logo rendering (JAL-958)
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index cc71e4a..6bee416 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
- * 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.
  * 
@@ -91,6 +91,11 @@ public class SequenceGroup
    * consensus calculation property
    */
   private boolean showSequenceLogo = false;
+  /**
+   * flag indicating if logo should be rendered normalised
+   */
+  private boolean normaliseSequenceLogo;
+
 
   /**
    * @return the includeAllConsSymbols
@@ -226,8 +231,8 @@ public class SequenceGroup
               if (!found)
                 continue;
             }
-            AlignmentAnnotation newannot = new AlignmentAnnotation(seq
-                    .getAnnotation()[a]);
+            AlignmentAnnotation newannot = new AlignmentAnnotation(
+                    seq.getAnnotation()[a]);
             newannot.restrict(startRes, endRes);
             newannot.setSequenceRef(seqs[ipos]);
             newannot.adjustForAlignment();
@@ -440,7 +445,9 @@ public class SequenceGroup
   }
 
   /**
-   * Add s to this sequence group
+   * Add s to this sequence group. If aligment sequence is already contained in
+   * group, it will not be added again, but recalculation may happen if the flag
+   * is set.
    * 
    * @param s
    *          alignment sequence to be added
@@ -508,12 +515,15 @@ public class SequenceGroup
         }
         if (cs != null)
         {
-          cs.setConservation(c);
-
-          if (cs instanceof ClustalxColourScheme)
+          if (cs.conservationApplied())
           {
-            ((ClustalxColourScheme) cs)
-                    .resetClustalX(sequences, getWidth());
+            cs.setConservation(c);
+
+            if (cs instanceof ClustalxColourScheme)
+            {
+              ((ClustalxColourScheme) cs).resetClustalX(sequences,
+                      getWidth());
+            }
           }
         }
       }
@@ -627,10 +637,9 @@ public class SequenceGroup
   }
 
   /**
-   * DOCUMENT ME!
+   * Set the first column selected by this group. Runs from 0<=i<N_cols
    * 
    * @param i
-   *          DOCUMENT ME!
    */
   public void setStartRes(int i)
   {
@@ -638,10 +647,9 @@ public class SequenceGroup
   }
 
   /**
-   * DOCUMENT ME!
+   * Set the groups last selected column. Runs from 0<=i<N_cols
    * 
    * @param i
-   *          DOCUMENT ME!
    */
   public void setEndRes(int i)
   {
@@ -794,23 +802,42 @@ public class SequenceGroup
    */
   public SequenceI[] getSequencesInOrder(AlignmentI al)
   {
+    return getSequencesInOrder(al, true);
+  }
+
+  /**
+   * return an array representing the intersection of the group with al,
+   * optionally returning an array the size of al.getHeight() where nulls mark
+   * the non-intersected sequences
+   * 
+   * @param al
+   * @param trim
+   * @return null or array
+   */
+  public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
+  {
     int sSize = sequences.size();
     int alHeight = al.getHeight();
 
-    SequenceI[] seqs = new SequenceI[sSize];
+    SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
 
     int index = 0;
     for (int i = 0; i < alHeight && index < sSize; i++)
     {
       if (sequences.contains(al.getSequenceAt(i)))
       {
-        seqs[index++] = al.getSequenceAt(i);
+        seqs[(trim) ? index : i] = al.getSequenceAt(i);
+        index++;
       }
     }
     if (index == 0)
     {
       return null;
     }
+    if (!trim)
+    {
+      return seqs;
+    }
     if (index < seqs.length)
     {
       SequenceI[] dummy = seqs;
@@ -979,6 +1006,20 @@ public class SequenceGroup
   private boolean showConsensusHistogram;
 
   /**
+   * set this alignmentAnnotation object as the one used to render consensus
+   * annotation
+   * 
+   * @param aan
+   */
+  public void setConsensus(AlignmentAnnotation aan)
+  {
+    if (consensus == null)
+    {
+      consensus = aan;
+    }
+  }
+
+  /**
    * 
    * @return automatically calculated consensus row
    */
@@ -1007,6 +1048,20 @@ public class SequenceGroup
   }
 
   /**
+   * set this alignmentAnnotation object as the one used to render consensus
+   * annotation
+   * 
+   * @param aan
+   */
+  public void setConservationRow(AlignmentAnnotation aan)
+  {
+    if (conservation == null)
+    {
+      conservation = aan;
+    }
+  }
+
+  /**
    * get the conservation annotation row for this group
    * 
    * @return autoCalculated annotation row
@@ -1056,8 +1111,8 @@ public class SequenceGroup
       }
     }
 
-    SequenceI sq = new Sequence("Group" + getName() + " Consensus", seqs
-            .toString());
+    SequenceI sq = new Sequence("Group" + getName() + " Consensus",
+            seqs.toString());
     sq.setDescription("Percentage Identity Consensus "
             + ((ignoreGapsInConsensus) ? " without gaps" : ""));
     return sq;
@@ -1079,17 +1134,18 @@ public class SequenceGroup
   }
 
   /**
-   * @param includeAllConsSymbols
-   *          the includeAllConsSymbols to set
+   * @param showSequenceLogo
+   *          indicates if a sequence logo is shown for consensus annotation
    */
-  public void setIncludeAllConsSymbols(boolean includeAllConsSymbols)
+  public void setshowSequenceLogo(boolean showSequenceLogo)
   {
-    if (this.showSequenceLogo != includeAllConsSymbols && consensus != null)
+    // TODO: decouple calculation from settings update
+    if (this.showSequenceLogo != showSequenceLogo && consensus != null)
     {
-      this.showSequenceLogo = includeAllConsSymbols;
+      this.showSequenceLogo = showSequenceLogo;
       recalcConservation();
     }
-    this.showSequenceLogo = includeAllConsSymbols;
+    this.showSequenceLogo = showSequenceLogo;
   }
 
   /**
@@ -1116,4 +1172,17 @@ public class SequenceGroup
   {
     return showConsensusHistogram;
   }
+
+  /**
+   * set flag indicating if logo should be normalised when rendered
+   * @param norm
+   */
+  public void setNormaliseSequenceLogo(boolean norm)
+  {
+    normaliseSequenceLogo=norm;
+  }
+  public boolean isNormaliseSequenceLogo()
+  {
+    return normaliseSequenceLogo;
+  }
 }