JAL-4241 Create sequence mapping before adjusting annotations
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 28 Jul 2023 12:24:16 +0000 (14:24 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 28 Jul 2023 12:24:16 +0000 (14:24 +0200)
src/jalview/ws/jws2/SeqAnnotationServiceCalcWorker.java

index 3253f43..e004bf5 100644 (file)
@@ -702,26 +702,18 @@ public class SeqAnnotationServiceCalcWorker extends AlignCalcWorker
         {
           ala.graphGroup += graphGroup;
         }
-        SequenceI aseq = null;
-
-        /**
+        SequenceI aseq = (ala.sequenceRef == null) ? null
+                : running.getSeqNames().get(ala.sequenceRef.getName());
+        /*
          * transfer sequence refs and adjust gapmap
+         * Prepare an array for annotations and copy returned annotations to it
+         * according to gapMap if present.
          */
-        if (ala.sequenceRef != null)
-        {
-          SequenceI seq = running.getSeqNames()
-                  .get(ala.sequenceRef.getName());
-          aseq = seq;
-          while (seq.getDatasetSequence() != null)
-          {
-            seq = seq.getDatasetSequence();
-          }
-        }
         Annotation[] resAnnot = ala.annotations,
                 gappedAnnot = new Annotation[Math.max(
                         alignViewport.getAlignment().getWidth(),
                         gapMap.length)];
-        for (int p = 0, ap = start; ap < gappedAnnot.length; ap++)
+        for (int p = 0, ap = 0; ap < gappedAnnot.length; ap++)
         {
           if (gapMap != null && gapMap.length > ap && !gapMap[ap])
           {
@@ -733,12 +725,12 @@ public class SeqAnnotationServiceCalcWorker extends AlignCalcWorker
           }
         }
         ala.sequenceRef = aseq;
-        ala.annotations = gappedAnnot;
         AlignmentAnnotation newAnnot = getAlignViewport().getAlignment()
                 .updateFromOrCopyAnnotation(ala);
+        newAnnot.annotations = gappedAnnot;
         if (aseq != null)
         {
-
+          newAnnot.createSequenceMapping(aseq, aseq.findPosition(start), false);
           aseq.addAlignmentAnnotation(newAnnot);
           newAnnot.adjustForAlignment();