JAL-4199 Remove viewport reference from AnnotationTask
[jalview.git] / src / jalview / ws2 / actions / annotation / AnnotationTask.java
index 0aaff23..866f862 100644 (file)
@@ -31,7 +31,9 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
 
   private final AnnotationAction action;
 
-  private final AlignViewportI viewport;
+  private final AlignmentI alignment;
+
+  private final AnnotatedCollectionI selectionGroup;
 
   public AnnotationTask(AnnotationWebServiceClientI client,
       AnnotationAction action, List<ArgumentI> args, Credentials credentials,
@@ -40,7 +42,8 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
     super(client, args, credentials);
     this.client = client;
     this.action = action;
-    this.viewport = viewport;
+    this.alignment = viewport.getAlignment();
+    this.selectionGroup = viewport.getSelectionGroup();
   }
 
   /**
@@ -55,7 +58,6 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
   @Override
   public List<AnnotationJob> prepareJobs() throws ServiceInputInvalidException
   {
-    AlignmentI alignment = viewport.getAlignment();
     if (alignment == null || alignment.getWidth() <= 0 ||
         alignment.getSequences() == null)
       throw new ServiceInputInvalidException("Alignment does not contain sequences");
@@ -66,7 +68,7 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
       throw new ServiceInputInvalidException(
           action.getFullName() + " does not allow protein sequences");
     boolean bySequence = !action.isAlignmentAnalysis();
-    AnnotatedCollectionI inputSeqs = bySequence ? viewport.getSelectionGroup() : null;
+    AnnotatedCollectionI inputSeqs = bySequence ? selectionGroup : null;
     if (inputSeqs == null || inputSeqs.getWidth() <= 0 ||
         inputSeqs.getSequences() == null || inputSeqs.getSequences().size() < 1)
       inputSeqs = alignment;
@@ -100,30 +102,17 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
      * visibility */
 
     udpateCalcId(returnedAnnot);
-    int graphGroup = viewport.getAlignment().getLastGraphGroup();
-    shiftGraphGroup(returnedAnnot, graphGroup);
-    List<AlignmentAnnotation> annotations = new ArrayList<>();
     for (AlignmentAnnotation ala : returnedAnnot)
     {
       SequenceI aseq = null;
-      if (ala.sequenceRef != null) {
+      if (ala.sequenceRef != null)
+      {
         SequenceI seq = job.seqNames.get(ala.sequenceRef.getName());
         aseq = seq.getRootDatasetSequence();
       }
       ala.sequenceRef = aseq;
       Annotation[] gappedAnnots = createGappedAnnotations(ala.annotations, job.start, job.gapMap);
       ala.annotations = gappedAnnots;
-
-      AlignmentAnnotation newAnnot = viewport.getAlignment()
-          .updateFromOrCopyAnnotation(ala);
-      if (aseq != null)
-      {
-        aseq.addAlignmentAnnotation(newAnnot);
-        newAnnot.adjustForAlignment();
-        AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(
-            newAnnot, newAnnot.label, newAnnot.getCalcId());
-      }
-      annotations.add(newAnnot);
     }
 
     boolean hasFeatures = false;
@@ -142,7 +131,7 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
       datasetSeq.transferAnnotation(sq, mp);
     }
 
-    return new AnnotationResult(annotations, hasFeatures, featureColours, featureFilters);
+    return new AnnotationResult(returnedAnnot, hasFeatures, featureColours, featureFilters);
   }
 
   /**
@@ -161,20 +150,9 @@ public class AnnotationTask extends BaseTask<AnnotationJob, AnnotationResult>
     }
   }
 
-  private static void shiftGraphGroup(Iterable<AlignmentAnnotation> annotations, int shift)
-  {
-    for (AlignmentAnnotation ala : annotations)
-    {
-      if (ala.graphGroup > 0)
-      {
-        ala.graphGroup += shift;
-      }
-    }
-  }
-
   private Annotation[] createGappedAnnotations(Annotation[] annotations, int start, boolean[] gapMap)
   {
-    var size = Math.max(viewport.getAlignment().getWidth(), gapMap.length);
+    var size = Math.max(alignment.getWidth(), gapMap.length);
     Annotation[] gappedAnnotations = new Annotation[size];
     for (int p = 0, ap = start; ap < size; ap++)
     {