Create sequence mapping for annotations
authoramwaterhouse <Andrew Waterhouse>
Wed, 10 May 2006 12:56:30 +0000 (12:56 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 10 May 2006 12:56:30 +0000 (12:56 +0000)
src/jalview/datamodel/AlignmentAnnotation.java

index c3ccb0b..d75683c 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
@@ -243,21 +239,65 @@ public class AlignmentAnnotation
           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, seqIndex;\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)-1;\r
+            if(seqPos<annotations.length)\r
+            {\r
+              if (annotations[seqPos] != null)\r
+              {\r
+                seqIndex = sequenceRef.findIndex(i) + 1;\r
+\r
+                if(seqIndex>=startRes)\r
+                sequenceMapping.put(new Integer(seqIndex),\r
+                                    annotations[seqPos]);\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
+          int position;\r
           Annotation[] temp = new Annotation[aSize];\r
-\r
-          for (a = 0; a < aSize; a++)\r
+          Integer index;\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