JAL-3070 JAL-3066 JAL-3067 refactor annotation web service so client is passed sequen...
[jalview.git] / src / jalview / ws / jws2 / jabaws2 / JabawsAnnotationInstance.java
index e7f3022..a52b515 100644 (file)
@@ -1,22 +1,24 @@
 package jalview.ws.jws2.jabaws2;
 
-import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
+import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.util.MessageManager;
 import jalview.ws.api.JobId;
 import jalview.ws.api.SequenceAnnotationServiceI;
-import jalview.ws.gui.AnnotationWsJob;
 import jalview.ws.jws2.JabaParamStore;
 import jalview.ws.jws2.JabaPreset;
-import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.WsParamSetI;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import compbio.data.msa.SequenceAnnotation;
 import compbio.data.sequence.FastaSequence;
@@ -106,37 +108,47 @@ public abstract class JabawsAnnotationInstance
     return new JobId(our.getServiceType(), our.getName(), rslt);
   }
 
+
   @Override
-  public List<AlignmentAnnotation> getAlignmentAnnotation(
-          AnnotationWsJob running,
-          SeqAnnotationServiceCalcWorker abstractJabaCalcWorker) throws Throwable
+  public
+  List<AlignmentAnnotation> getAnnotationResult(JobId job,
+          List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
+          Map<String, FeatureMatcherSetI> featureFilters) throws Throwable
   {
     if (scoremanager == null)
     {
       // TODO: raise annotation unavailable exception ?
-      scoremanager = service.getAnnotation(running.getJobId());
+      scoremanager = service.getAnnotation(job.getJobId());
     }
     if (scoremanager == null)
     {
       return List.of();
     }
-
-    return annotationFromScoreManager(running,
-            abstractJabaCalcWorker.getAlignViewport(),
-            abstractJabaCalcWorker.getGapMap());
+    /**
+     * dummy alignment to perform annotation on
+     */
+    AlignmentI newal = new Alignment(seqs.toArray(new SequenceI[0]));
+    List<AlignmentAnnotation> ourAnnot = annotationFromScoreManager(newal,
+            featureColours, featureFilters);
+    return ourAnnot;
   }
 
   /**
    * service specific annotation creation method
    * 
-   * @param running
-   * @param alignViewport
-   * @param gapMap
+   * @param seqs
+   *          - sequences to be annotated with results
+   * @param featureColours
+   *          - - updated with any colours imported during result processing
+   * @param featureFilters
+   *          - updated with any filters imported during result processing
+   * 
    * @return
    */
   abstract List<AlignmentAnnotation> annotationFromScoreManager(
-          AnnotationWsJob running,
-          AlignViewportI alignViewport, boolean[] gapMap);
+          AlignmentI seqs, Map<String, FeatureColourI> featureColours,
+          Map<String, FeatureMatcherSetI> featureFilters);
+
 
   /**
    * create and complete an annotation row from a JABAWS score object
@@ -149,16 +161,16 @@ public abstract class JabawsAnnotationInstance
    * @param scr
    */
 
-  protected void createAnnotationRowsForScores(AlignViewportI alignViewport,
+  protected void createAnnotationRowsForScores(AlignmentI al_result,
           boolean[] gapMap, List<AlignmentAnnotation> ourAnnot,
           String calcId,
           int alWidth, Score scr)
   {
     // simple annotation row
-    AlignmentAnnotation annotation = alignViewport.getAlignment()
+    AlignmentAnnotation annotation = al_result
             .findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
                     null);
-    if (alWidth == gapMap.length) // scr.getScores().size())
+    if (gapMap == null || alWidth == gapMap.length) // scr.getScores().size())
     {
       constructAnnotationFromScore(gapMap, annotation, 0,
               alWidth, scr);
@@ -180,7 +192,7 @@ public abstract class JabawsAnnotationInstance
    * @return
    */
   protected AlignmentAnnotation createAnnotationRowsForScores(
-          AlignViewportI alignViewport, boolean[] gapMap,
+          AlignmentI alignment, boolean[] gapMap,
           List<AlignmentAnnotation> ourAnnot, String typeName,
           String calcId, SequenceI dseq, int base, Score scr)
   {
@@ -191,7 +203,7 @@ public abstract class JabawsAnnotationInstance
     // scr.getMethod(), typeName, new Annotation[]
     // {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
     // annotation.setCalcId(calcId);
-    AlignmentAnnotation annotation = alignViewport.getAlignment()
+    AlignmentAnnotation annotation = alignment
             .findOrCreateAnnotation(typeName, calcId, false, dseq, null);
     constructAnnotationFromScore(gapMap, annotation, 0, dseq.getLength(),
             scr);
@@ -203,44 +215,6 @@ public abstract class JabawsAnnotationInstance
   }
 
   /**
-   * replace an existing sequence associated annotation with another, creating
-   * association as necessary
-   * 
-   * @param newAnnot
-   *          - annotation row used to create an instance on the dataset
-   *          sequence.
-   * @param typeName
-   *          - label used to match existing row
-   * @param calcId
-   *          - calcId for existing row
-   * @param aSeq
-   *          - alignment sequence with reference to destination dataet sequence
-   */
-  protected void replaceAnnotationOnAlignmentWith(
-          AlignmentAnnotation newAnnot, String typeName, String calcId,
-          SequenceI aSeq)
-  {
-    SequenceI dsseq = aSeq.getDatasetSequence();
-    while (dsseq.getDatasetSequence() != null)
-    {
-      dsseq = dsseq.getDatasetSequence();
-    }
-    // look for same annotation on dataset and lift this one over
-    List<AlignmentAnnotation> dsan = dsseq.getAlignmentAnnotations(calcId,
-            typeName);
-    if (dsan != null && dsan.size() > 0)
-    {
-      for (AlignmentAnnotation dssan : dsan)
-      {
-        dsseq.removeAlignmentAnnotation(dssan);
-      }
-    }
-    AlignmentAnnotation dssan = new AlignmentAnnotation(newAnnot);
-    dsseq.addAlignmentAnnotation(dssan);
-    dssan.adjustForAlignment();
-  }
-
-  /**
    * create column annotation elements from Jabaws score object
    * 
    * @param gapMap