Annotation adjustment moved to EditCommand
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index 62de696..6803e9f 100755 (executable)
@@ -27,6 +27,12 @@ package jalview.datamodel;
  */
 public class AlignmentAnnotation
 {
+  /** If true, this annotations is calculated every edit,
+   * eg consensus, quality or conservation graphs */
+  public boolean autoCalculated = false;
+
+  public String annotationId = Math.random() +"";
+
     public SequenceI sequenceRef;
 
     /** DOCUMENT ME!! */
@@ -103,21 +109,57 @@ public class AlignmentAnnotation
         this.description = description;
         this.annotations = annotations;
 
-        for (int i = 0; i < annotations.length; i++)
+       areLabelsSecondaryStructure();
+    }
+
+    void areLabelsSecondaryStructure()
+    {
+      boolean nonSSLabel = false;
+      for (int i = 0; i < annotations.length; i++)
+      {
+        if(annotations[i]==null)
+          continue;
+
+        if (annotations[i].secondaryStructure == 'H' ||
+            annotations[i].secondaryStructure == 'E')
         {
-            if ((annotations[i] != null) &&
-                    ((annotations[i].secondaryStructure == 'H') ||
-                    (annotations[i].secondaryStructure == 'E')))
-            {
-                hasIcons = true;
-            }
+          hasIcons = true;
+        }
 
-            if ((annotations[i] != null) &&
-                    (annotations[i].displayCharacter.length() > 0))
-            {
-                hasText = true;
-            }
+        if (annotations[i].displayCharacter.length()==1
+            && !annotations[i].displayCharacter.equals("H")
+            && !annotations[i].displayCharacter.equals("E")
+            && !annotations[i].displayCharacter.equals("-"))
+        {
+          if(jalview.schemes.ResidueProperties.aaIndex
+             [annotations[i].displayCharacter.charAt(0)]>0)
+          {
+            nonSSLabel = true;
+          }
         }
+
+        if (annotations[i].displayCharacter.length() > 0)
+        {
+          hasText = true;
+        }
+      }
+
+      if(nonSSLabel)
+      {
+        hasIcons = false;
+        for (int j = 0; j < annotations.length; j++)
+        {
+          if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
+          {
+            annotations[j].displayCharacter
+                =String.valueOf(annotations[j].secondaryStructure);
+            annotations[j].secondaryStructure = ' ';
+          }
+
+        }
+
+      }
+
     }
 
     /**
@@ -171,23 +213,7 @@ public class AlignmentAnnotation
         graphMin = min;
         graphMax = max;
 
-        for (int i = 0; i < annotations.length; i++)
-        {
-            if (!hasIcons
-                && annotations[i] != null
-                && ((annotations[i].secondaryStructure == 'H') ||
-                    (annotations[i].secondaryStructure == 'E')))
-            {
-                hasIcons = true;
-            }
-
-            if (!hasText
-                && annotations[i]!=null
-                && annotations[i].displayCharacter.length() > 0)
-            {
-                hasText = true;
-            }
-        }
+        areLabelsSecondaryStructure();
 
         if(!drawValues && graphType!=NO_GRAPH)
         {
@@ -258,11 +284,14 @@ public class AlignmentAnnotation
       }
 
       /**
-       * Attach the annotation to seqRef, starting from startRes position.
+       * Attach the annotation to seqRef, starting from startRes position. If alreadyMapped is true then the indices of the annotation[] array are sequence positions rather than alignment column positions.
        * @param seqRef
        * @param startRes
+       * @param alreadyMapped
        */
-      public void createSequenceMapping(SequenceI seqRef, int startRes)
+      public void createSequenceMapping(SequenceI seqRef,
+                                        int startRes,
+                                        boolean alreadyMapped)
       {
         if(seqRef == null)
           return;
@@ -270,30 +299,22 @@ public class AlignmentAnnotation
         sequenceMapping = new java.util.Hashtable();
 
         sequenceRef = seqRef;
-
-        if(startRes < sequenceRef.getStart())
-          startRes = sequenceRef.getStart();
-
         int seqPos;
 
-        int fileOffset = 0;
-        if(startRes > sequenceRef.getStart())
-        {
-          fileOffset = startRes - sequenceRef.getStart();
-        }
-
         for(int i = 0; i < annotations.length; i++)
         {
-            seqPos = sequenceRef.findPosition(i + fileOffset);
             if (annotations[i] != null)
             {
-              sequenceMapping.put(new Integer(seqPos),
-                  annotations[i]);
+              if(alreadyMapped)
+                seqPos = seqRef.findPosition(i);
+              else
+                seqPos = i+startRes;
+
+              sequenceMapping.put(new Integer(seqPos), annotations[i]);
             }
          }
 
         adjustForAlignment();
-
       }
 
       public void adjustForAlignment()