JAL-1065 JAL-1066 - use direct object reference rather then index into alignment
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index d253560..94e359a 100755 (executable)
@@ -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, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
@@ -30,7 +30,7 @@ import jalview.schemes.*;
  * @author $author$
  * @version $Revision$
  */
-public class SequenceGroup
+public class SequenceGroup implements AnnotatedCollectionI
 {
   String groupName;
 
@@ -510,12 +510,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());
+            }
           }
         }
       }
@@ -998,17 +1001,19 @@ public class SequenceGroup
   private boolean showConsensusHistogram;
 
   /**
-   * set this alignmentAnnotation object as the one used to render consensus annotation
+   * set this alignmentAnnotation object as the one used to render consensus
+   * annotation
+   * 
    * @param aan
    */
   public void setConsensus(AlignmentAnnotation aan)
   {
-    if (consensus==null)
+    if (consensus == null)
     {
-      consensus=aan;
+      consensus = aan;
     }
   }
-  
+
   /**
    * 
    * @return automatically calculated consensus row
@@ -1038,16 +1043,19 @@ public class SequenceGroup
   }
 
   /**
-   * set this alignmentAnnotation object as the one used to render consensus annotation
+   * set this alignmentAnnotation object as the one used to render consensus
+   * annotation
+   * 
    * @param aan
    */
   public void setConservationRow(AlignmentAnnotation aan)
   {
-    if (conservation==null)
+    if (conservation == null)
     {
-      conservation=aan;
+      conservation = aan;
     }
   }
+
   /**
    * get the conservation annotation row for this group
    * 
@@ -1159,4 +1167,33 @@ public class SequenceGroup
   {
     return showConsensusHistogram;
   }
+
+  @Override
+  /**
+   * returns a new array with all annotation involving this group
+   */
+  public AlignmentAnnotation[] getAlignmentAnnotation()
+  {
+    // TODO add in other methods like 'getAlignmentAnnotation(String label), etc'
+    ArrayList<AlignmentAnnotation> annot = new ArrayList<AlignmentAnnotation>();
+    for (SequenceI seq:(Vector<SequenceI>)sequences)
+    {
+      for (AlignmentAnnotation al: seq.getAnnotation())
+      {
+        if (al.groupRef==this)
+        {
+          annot.add(al);
+        }
+      }
+    }
+    if (consensus!=null)
+    {
+      annot.add(consensus);
+    }
+    if (conservation!=null)
+    {
+      annot.add(conservation);
+    }
+    return annot.toArray(new AlignmentAnnotation[0]);
+  }
 }