JAL-1492 JAL-1397 make AnnotatedCollectionI context aware so groups can be coloured...
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index d406910..1df45a2 100755 (executable)
@@ -470,12 +470,28 @@ public class SequenceGroup implements AnnotatedCollectionI
   }
 
   /**
-   * Max Gaps Threshold for performing a conservation calculation TODO: make
-   * this a configurable property - or global to an alignment view
+   * Max Gaps Threshold (percent) for performing a conservation calculation 
    */
   private int consPercGaps = 25;
 
   /**
+   * @return Max Gaps Threshold for performing a conservation calculation
+   */
+  public int getConsPercGaps()
+  {
+    return consPercGaps;
+  }
+
+  /**
+   * set Max Gaps Threshold (percent) for performing a conservation calculation
+   * @param consPercGaps 
+   */
+  public void setConsPercGaps(int consPercGaps)
+  {
+    this.consPercGaps = consPercGaps;
+  }
+
+  /**
    * calculate residue conservation for group - but only if necessary.
    */
   public void recalcConservation()
@@ -484,22 +500,17 @@ public class SequenceGroup implements AnnotatedCollectionI
     {
       return;
     }
-    if (cs != null)
-    {
-      cs.alignmentChanged(this, null);
-    }
     try
     {
       Hashtable cnsns[] = AAFrequency.calculate(sequences, startRes,
               endRes + 1, showSequenceLogo);
       if (consensus != null)
       {
-        _updateConsensusRow(cnsns);
+        _updateConsensusRow(cnsns, sequences.size());
       }
       if (cs != null)
       {
         cs.setConsensus(cnsns);
-        cs.alignmentChanged(this, null);
       }
 
       if ((conservation != null)
@@ -519,10 +530,13 @@ public class SequenceGroup implements AnnotatedCollectionI
           if (cs.conservationApplied())
           {
             cs.setConservation(c);
-            cs.alignmentChanged(this, null);
           }
         }
       }
+      if (cs != null)
+      {
+        cs.alignmentChanged(context!=null ? context : this, null);
+      }
     } catch (java.lang.OutOfMemoryError err)
     {
       // TODO: catch OOM
@@ -553,7 +567,7 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   public Hashtable[] consensusData = null;
 
-  private void _updateConsensusRow(Hashtable[] cnsns)
+  private void _updateConsensusRow(Hashtable[] cnsns, long nseq)
   {
     if (consensus == null)
     {
@@ -570,7 +584,7 @@ public class SequenceGroup implements AnnotatedCollectionI
     consensus.annotations = new Annotation[aWidth]; // should be alignment width
 
     AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
-            ignoreGapsInConsensus, showSequenceLogo); // TODO: setting container
+            ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting container
                                                       // for
                                                       // ignoreGapsInConsensusCalculation);
   }
@@ -1232,4 +1246,21 @@ public class SequenceGroup implements AnnotatedCollectionI
   {
     sequences.clear();
   }
+  private AnnotatedCollectionI context;
+  /**
+   * set the alignment or group context for this group
+   * @param context
+   */
+  public void setContext(AnnotatedCollectionI context)
+  {
+    this.context = context; 
+  }
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AnnotatedCollectionI#getContext()
+   */
+  @Override
+  public AnnotatedCollectionI getContext()
+  {
+    return context;
+  }
 }