--- Adding issue comments
[jalview.git] / src / jalview / ws / jws2 / jabaws2 / JabawsAnnotationInstance.java
index 95abe3c..a52b515 100644 (file)
@@ -1,14 +1,15 @@
 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.AbstractJabaCalcWorker;
 import jalview.ws.jws2.JabaParamStore;
 import jalview.ws.jws2.JabaPreset;
 import jalview.ws.params.ArgumentI;
@@ -17,6 +18,7 @@ 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;
@@ -50,7 +52,8 @@ public abstract class JabawsAnnotationInstance
    */
   public String getCalcId()
   {
-    return our.aaui == null ? null : our.aaui.getCalcId();
+    return our.getAlignAnalysisUI() == null ? null
+            : our.getAlignAnalysisUI().getCalcId();
   }
 
   @Override
@@ -105,42 +108,69 @@ public abstract class JabawsAnnotationInstance
     return new JobId(our.getServiceType(), our.getName(), rslt);
   }
 
+
   @Override
-  public List<AlignmentAnnotation> getAlignmentAnnotation(
-          AnnotationWsJob running,
-          AbstractJabaCalcWorker 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 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);
 
-  // From JabawsCalcWorker
 
-  protected void createAnnotationRowsForScores(AlignViewportI alignViewport,
+  /**
+   * create and complete an annotation row from a JABAWS score object
+   * 
+   * @param alignViewport
+   * @param gapMap
+   * @param ourAnnot
+   * @param calcId
+   * @param alWidth
+   * @param scr
+   */
+
+  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);
@@ -148,8 +178,21 @@ public abstract class JabawsAnnotationInstance
     }
   }
 
+  /**
+   * create a sequence associated annotation row for JABAWS score object scr
+   * 
+   * @param alignViewport
+   * @param gapMap
+   * @param ourAnnot
+   * @param typeName
+   * @param calcId
+   * @param dseq
+   * @param base
+   * @param scr
+   * @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)
   {
@@ -160,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);
@@ -171,30 +214,16 @@ public abstract class JabawsAnnotationInstance
     return annotation;
   }
 
-  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
+   * @param annotation
+   * @param base
+   * @param alWidth
+   * @param scr
+   *          JABAWS score object
+   */
   protected void constructAnnotationFromScore(boolean[] gapMap,
           AlignmentAnnotation annotation,
           int base, int alWidth, Score scr)