Sequence label colour stored for each sequence group
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index acd0b51..6ded8bd 100755 (executable)
@@ -26,8 +26,7 @@ import jalview.analysis.*;
 import jalview.schemes.*;
 
 /**
- * DOCUMENT ME!
- *
+ * Collects a set contiguous ranges on a set of sequences
  * @author $author$
  * @version $Revision$
  */
@@ -39,7 +38,7 @@ public class SequenceGroup
   Vector aaFrequency;
   boolean displayBoxes = true;
   boolean displayText = true;
-  boolean colourText = true;
+  boolean colourText = false;
   private Vector sequences = new Vector();
   int width = -1;
 
@@ -47,7 +46,8 @@ public class SequenceGroup
   public ColourSchemeI cs;
   int startRes = 0;
   int endRes = 0;
-  Color outlineColour = Color.black;
+  public Color outlineColour = Color.black;
+  public Color idColour = null; 
   public int thresholdTextColour = 0;
   public Color textColour = Color.black;
   public Color textColour2 = Color.white;
@@ -63,14 +63,14 @@ public class SequenceGroup
   /**
    * Creates a new SequenceGroup object.
    *
-   * @param sequences DOCUMENT ME!
-   * @param groupName DOCUMENT ME!
-   * @param scheme DOCUMENT ME!
-   * @param displayBoxes DOCUMENT ME!
-   * @param displayText DOCUMENT ME!
-   * @param colourText DOCUMENT ME!
-   * @param start DOCUMENT ME!
-   * @param end DOCUMENT ME!
+   * @param sequences 
+   * @param groupName 
+   * @param scheme 
+   * @param displayBoxes 
+   * @param displayText 
+   * @param colourText 
+   * @param start first column of group
+   * @param end last column of group
    */
   public SequenceGroup(Vector sequences, String groupName,
                        ColourSchemeI scheme, boolean displayBoxes,
@@ -93,34 +93,62 @@ public class SequenceGroup
     int iSize = sequences.size();
     SequenceI[] seqs = new SequenceI[iSize];
     SequenceI[] inorder = getSequencesInOrder(align);
-
-    for (int i = 0; i < iSize; i++)
+    
+    for (int i = 0,ipos=0; i < inorder.length; i++)
     {
       SequenceI seq = inorder[i];
 
-      seqs[i] = seq.getSubSequence(startRes, endRes+1);
-
-      seqs[i].setDescription(seq.getDescription());
-      seqs[i].setDBRef(seq.getDBRef());
-      seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
-      if (seq.getDatasetSequence() != null)
+      seqs[ipos] = seq.getSubSequence(startRes, endRes+1);
+      if (seqs[ipos]!=null)
       {
-        seqs[i].setDatasetSequence(seq.getDatasetSequence());
-      }
+        seqs[ipos].setDescription(seq.getDescription());
+        seqs[ipos].setDBRef(seq.getDBRef());
+        seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
+        if (seq.getDatasetSequence() != null)
+        {
+          seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
+        }
 
-      if (seq.getAnnotation() != null)
-      {
-        for (int a = 0; a < seq.getAnnotation().length; a++)
+        if (seq.getAnnotation() != null)
         {
-          AlignmentAnnotation newannot = new AlignmentAnnotation(seq.getAnnotation()[a]);
-          newannot.restrict(startRes, endRes);
-          newannot.setSequenceRef(seqs[i]);
-          newannot.adjustForAlignment();
-          seqs[i].addAlignmentAnnotation(newannot);
+          AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
+          // Only copy annotation that is either a score or referenced by the alignment's annotation vector
+          for (int a = 0; a < seq.getAnnotation().length; a++)
+          {
+            AlignmentAnnotation tocopy = seq.getAnnotation()[a];
+            if (alann!=null)
+            {
+              boolean found=false;
+              for (int pos=0;pos<alann.length; pos++)
+              {
+                if (alann[pos]==tocopy)
+                { 
+                  found=true;
+                  break;
+                }
+              }
+              if (!found)
+                continue;
+            }
+            AlignmentAnnotation newannot = new AlignmentAnnotation(seq
+                    .getAnnotation()[a]);
+            newannot.restrict(startRes, endRes);
+            newannot.setSequenceRef(seqs[ipos]);
+            newannot.adjustForAlignment();
+            seqs[ipos].addAlignmentAnnotation(newannot);
+          }
         }
+        ipos++;
+      } else {
+        iSize--;
       }
     }
-
+    if (iSize!=inorder.length)
+    {
+      SequenceI[] nseqs = new SequenceI[iSize];
+      System.arraycopy(seqs, 0, nseqs, 0, iSize);
+      seqs = nseqs;
+    }
     return seqs;
 
   }
@@ -309,10 +337,10 @@ public class SequenceGroup
   }
 
   /**
-   * DOCUMENT ME!
+   * Add s to this sequence group
    *
-   * @param s DOCUMENT ME!
-   * @param recalc DOCUMENT ME!
+   * @param s alignment sequence to be added
+   * @param recalc true means Group's conservation should be recalculated
    */
   public void addSequence(SequenceI s, boolean recalc)
   {
@@ -328,7 +356,7 @@ public class SequenceGroup
   }
 
   /**
-   * DOCUMENT ME!
+   * calculate residue conservation for group
    */
   public void recalcConservation()
   {
@@ -598,4 +626,20 @@ public class SequenceGroup
 
     return seqs;
   }
+
+  /**
+   * @return the idColour
+   */
+  public Color getIdColour()
+  {
+    return idColour;
+  }
+
+  /**
+   * @param idColour the idColour to set
+   */
+  public void setIdColour(Color idColour)
+  {
+    this.idColour = idColour;
+  }
 }