JAL-1066 - per-sequence colouring with sequence associated alignment annotation
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 28 Aug 2012 13:46:56 +0000 (14:46 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 28 Aug 2012 13:46:56 +0000 (14:46 +0100)
src/jalview/schemes/AnnotationColourGradient.java

index 6c46d0e..78e850b 100755 (executable)
 package jalview.schemes;
 
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.GraphLine;
+import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
+import java.util.IdentityHashMap;
+import java.util.Map;
 
 public class AnnotationColourGradient extends ResidueColourScheme
 {
@@ -45,6 +49,10 @@ public class AnnotationColourGradient extends ResidueColourScheme
 
   public boolean predefinedColours = false;
 
+  public boolean seqAssociated = false;
+
+  IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
+
   /**
    * Creates a new AnnotationColourGradient object.
    */
@@ -94,6 +102,33 @@ public class AnnotationColourGradient extends ResidueColourScheme
     bb = maxColour.getBlue() - b1;
   }
 
+  @Override
+  public void alignmentChanged(AnnotatedCollectionI alignment,
+          Map<SequenceI, SequenceCollectionI> hiddenReps)
+  {
+    // TODO Auto-generated method stub
+    super.alignmentChanged(alignment, hiddenReps);
+    
+    if (seqAssociated && annotation.getCalcId() != null)
+    {
+      if (seqannot!=null) {
+        seqannot.clear();
+      } else {
+        seqannot=new IdentityHashMap<SequenceI, AlignmentAnnotation>();
+      }
+      for (AlignmentAnnotation alan : alignment.findAnnotation(annotation
+              .getCalcId()))
+      {
+        if (alan.sequenceRef != null
+                && (alan.label != null && annotation != null && alan.label
+                        .equals(annotation.label)))
+        {
+          seqannot.put(alan.sequenceRef, alan);
+        }
+      }
+    }
+  }
+
   public String getAnnotation()
   {
     return annotation.label;
@@ -158,7 +193,11 @@ public class AnnotationColourGradient extends ResidueColourScheme
   public Color findColour(char c, int j, SequenceI seq)
   {
     Color currentColour = Color.white;
-
+    AlignmentAnnotation annotation=(seqAssociated ? seqannot.get(seq):this.annotation);
+    if (annotation==null)
+    {
+      return currentColour;
+    }
     if ((threshold == 0) || aboveThreshold(c, j))
     {
       if (j < annotation.annotations.length
@@ -226,4 +265,14 @@ public class AnnotationColourGradient extends ResidueColourScheme
 
     return currentColour;
   }
+
+  public boolean isSeqAssociated()
+  {
+    return seqAssociated;
+  }
+
+  public void setSeqAssociated(boolean sassoc)
+  {
+    seqAssociated = sassoc;
+  }
 }