javadoc
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index 6f22947..5a2c46e 100755 (executable)
@@ -29,11 +29,6 @@ public class AlignmentAnnotation
 {\r
     public SequenceI sequenceRef;\r
 \r
-    /** This annotation is the original loaded annotation\r
-     *  without any gaps. It is necessary to adjust the annotation\r
-     *  if sequences are updated */\r
-    public AlignmentAnnotation datasetAnnotation;\r
-\r
     /** DOCUMENT ME!! */\r
     public String label;\r
 \r
@@ -43,6 +38,7 @@ public class AlignmentAnnotation
     /** DOCUMENT ME!! */\r
     public Annotation[] annotations;\r
 \r
+    public java.util.Hashtable sequenceMapping;\r
 \r
     /** DOCUMENT ME!! */\r
     public float graphMin;\r
@@ -143,6 +139,8 @@ public class AlignmentAnnotation
         this.annotations = annotations;\r
         graph = graphType;\r
 \r
+        boolean drawValues = true;\r
+\r
         if (min == max)\r
         {\r
             min = 999999999;\r
@@ -153,6 +151,11 @@ public class AlignmentAnnotation
                     continue;\r
                 }\r
 \r
+                if(drawValues && annotations[i].displayCharacter.length() > 1 )\r
+                {\r
+                  drawValues = false;\r
+                }\r
+\r
                 if (annotations[i].value > max)\r
                 {\r
                     max = annotations[i].value;\r
@@ -170,19 +173,30 @@ public class AlignmentAnnotation
 \r
         for (int i = 0; i < annotations.length; i++)\r
         {\r
-            if ((annotations[i] != null) &&\r
-                    ((annotations[i].secondaryStructure == 'H') ||\r
+            if (!hasIcons\r
+                && annotations[i] != null\r
+                && ((annotations[i].secondaryStructure == 'H') ||\r
                     (annotations[i].secondaryStructure == 'E')))\r
             {\r
                 hasIcons = true;\r
             }\r
 \r
-            if ((annotations[i] != null) &&\r
-                    (annotations[i].displayCharacter.length() > 0))\r
+            if (!hasText\r
+                && annotations[i]!=null\r
+                && annotations[i].displayCharacter.length() > 0)\r
             {\r
                 hasText = true;\r
             }\r
         }\r
+\r
+        if(!drawValues && graphType!=NO_GRAPH)\r
+        {\r
+          for (int i = 0; i < annotations.length; i++)\r
+          {\r
+            if (annotations[i] != null)\r
+              annotations[i].displayCharacter = "";\r
+          }\r
+        }\r
     }\r
 \r
     /**\r
@@ -238,26 +252,74 @@ public class AlignmentAnnotation
         threshold = line;\r
       }\r
 \r
-      public GraphLine getTrheshold()\r
+      public GraphLine getThreshold()\r
       {\r
           return threshold;\r
       }\r
 \r
+      /**\r
+       * This\r
+       */\r
+      public void createSequenceMapping(SequenceI seqRef, int startRes)\r
+      {\r
+        if(seqRef == null)\r
+          return;\r
+\r
+        sequenceMapping = new java.util.Hashtable();\r
+\r
+        sequenceRef = seqRef;\r
+\r
+        if(startRes < sequenceRef.getStart())\r
+          startRes = sequenceRef.getStart();\r
+\r
+        int seqPos;\r
+\r
+        int fileOffset = 0;\r
+        if(startRes > sequenceRef.getStart())\r
+        {\r
+          fileOffset = startRes - sequenceRef.getStart();\r
+        }\r
+\r
+        for(int i = 0; i < annotations.length; i++)\r
+        {\r
+            seqPos = sequenceRef.findPosition(i + fileOffset);\r
+            if(seqPos<annotations.length)\r
+            {\r
+              if (annotations[i] != null)\r
+              {\r
+                  sequenceMapping.put(new Integer(seqPos),\r
+                                      annotations[i]);\r
+              }\r
+            }\r
+         }\r
+\r
+        adjustForAlignment();\r
+\r
+      }\r
+\r
       public void adjustForAlignment()\r
       {\r
           int a=0, aSize = sequenceRef.getLength();\r
 \r
-          int index = 0;\r
+          if(aSize == 0)\r
+          {\r
+            //Its been deleted\r
+            return;\r
+          }\r
+\r
+          int position;\r
           Annotation[] temp = new Annotation[aSize];\r
+          Integer index;\r
 \r
-          for (a = 0; a < aSize; a++)\r
+          for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)\r
           {\r
-            if (!jalview.util.Comparison.isGap(sequenceRef.getCharAt(a)))\r
-            {\r
-              index = sequenceRef.findPosition(a);\r
-              if(datasetAnnotation.annotations.length>index)\r
-                temp[a] = datasetAnnotation.annotations[index];\r
-            }\r
+              index = new Integer(a);\r
+              if(sequenceMapping.containsKey(index))\r
+              {\r
+                position = sequenceRef.findIndex(a)-1;\r
+\r
+                temp[position] = (Annotation)sequenceMapping.get(index);\r
+              }\r
           }\r
 \r
           annotations = temp;\r