Merge branch 'docs/2_8_1_Release' into Release_2_8_1_Branch
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index 693291f..a01c0a5 100755 (executable)
@@ -1,19 +1,20 @@
 /*
- * 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
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- * 
+ *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.datamodel;
 
@@ -469,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()
@@ -483,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)
@@ -518,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
@@ -552,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)
     {
@@ -569,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);
   }
@@ -612,9 +627,9 @@ public class SequenceGroup implements AnnotatedCollectionI
   }
 
   /**
-   * DOCUMENT ME!
    * 
-   * @return DOCUMENT ME!
+   * 
+   * @return the first column selected by this group. Runs from 0<=i<N_cols
    */
   public int getStartRes()
   {
@@ -622,9 +637,8 @@ public class SequenceGroup implements AnnotatedCollectionI
   }
 
   /**
-   * DOCUMENT ME!
    * 
-   * @return DOCUMENT ME!
+   * @return the groups last selected column. Runs from 0<=i<N_cols
    */
   public int getEndRes()
   {
@@ -1034,12 +1048,12 @@ public class SequenceGroup implements AnnotatedCollectionI
     {
       consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
               100f, AlignmentAnnotation.BAR_GRAPH);
+      consensus.hasText = true;
+      consensus.autoCalculated = true;
+      consensus.groupRef = this;
+      consensus.label = "Consensus for " + getName();
+      consensus.description = "Percent Identity";
     }
-    consensus.hasText = true;
-    consensus.autoCalculated = true;
-    consensus.groupRef = this;
-    consensus.label = "Consensus for " + getName();
-    consensus.description = "Percent Identity";
     return consensus;
   }
 
@@ -1195,11 +1209,15 @@ public class SequenceGroup implements AnnotatedCollectionI
     ArrayList<AlignmentAnnotation> annot = new ArrayList<AlignmentAnnotation>();
     for (SequenceI seq : (Vector<SequenceI>) sequences)
     {
-      for (AlignmentAnnotation al : seq.getAnnotation())
+      AlignmentAnnotation[] aa = seq.getAnnotation();
+      if (aa != null)
       {
-        if (al.groupRef == this)
+        for (AlignmentAnnotation al : aa)
         {
-          annot.add(al);
+          if (al.groupRef == this)
+          {
+            annot.add(al);
+          }
         }
       }
     }
@@ -1232,4 +1250,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;
+  }
 }