JAL-976 clean out associated annotation
[jalview.git] / src / jalview / ws / jws2 / AAConsClient.java
index 289d49b..d1bf303 100644 (file)
@@ -4,6 +4,8 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.gui.AlignFrame;
+import jalview.gui.AlignmentPanel;
+import jalview.ws.jws2.dm.AAConsSettings;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.WsParamSetI;
 
@@ -23,12 +25,23 @@ public class AAConsClient extends JabawsAlignCalcWorker
           WsParamSetI preset, List<Argument> paramset)
   {
     super(service, alignFrame, preset, paramset);
-    submitGaps=true;
-    alignedSeqs=true;
-    nucleotidesAllowed=false;
-    proteinAllowed=true;
+    submitGaps = true;
+    alignedSeqs = true;
+    nucleotidesAllowed = false;
+    proteinAllowed = true;
+    gapMap=new boolean[0];
+    initViewportParams();
   }
 
+  protected void initViewportParams()
+  {
+    ((jalview.gui.AlignViewport) alignViewport).setCalcIdSettingsFor(getCalcId(), new AAConsSettings(true, service, this.preset, (arguments!=null) ?  JabaParamStore.getJwsArgsfromJaba(arguments) : null), true);
+  }
+  @Override
+  public void updateParameters(WsParamSetI newpreset, java.util.List<Argument> newarguments) {
+    super.updateParameters(newpreset, newarguments);
+    initViewportParams();
+  };
   public String getServiceActionText()
   {
     return "calculating Amino acid consensus using AACons service";
@@ -41,11 +54,9 @@ public class AAConsClient extends JabawsAlignCalcWorker
 
   public void updateResultAnnotation(boolean immediate)
   {
-
     if (immediate || !calcMan.isWorking(this) && scoremanager != null)
     {
       AlignmentAnnotation annotation;
-      ;
       Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
       int alWidth = alignViewport.getAlignment().getWidth();
       AlignmentI alignment;
@@ -72,9 +83,12 @@ public class AAConsClient extends JabawsAlignCalcWorker
           else
           {
             // simple annotation row
-            annotation = findOrCreate(scr.getMethod(), true, null, null);
+            annotation = alignViewport.getAlignment()
+                    .findOrCreateAnnotation(scr.getMethod(), getCalcId(), true,
+                            null, null);
+
             Annotation[] elm = new Annotation[alWidth];
-            if (alWidth == scr.getScores().size())
+            if (alWidth == gapMap.length) // scr.getScores().size())
             {
               Iterator<Float> vals = scr.getScores().iterator();
               float m = 0f, x = 0f;
@@ -98,6 +112,14 @@ public class AAConsClient extends JabawsAlignCalcWorker
                     x = val;
                   }
                 }
+                // if we're at a gapped column then skip to next ungapped position
+                if (gapMap != null && gapMap.length > 0)
+                {
+                  while (!gapMap[i])
+                  {
+                    elm[i++]=new Annotation("", "" , ' ', Float.NaN);
+                  }
+                }
                 elm[i] = new Annotation("", "" + val, ' ', val);
               }
 
@@ -147,4 +169,20 @@ public class AAConsClient extends JabawsAlignCalcWorker
     }
   }
 
+  public String getCalcId()
+  {
+    return SequenceAnnotationWSClient.AAConsCalcId;
+  }
+
+  public static void removeAAConsAnnotation(AlignmentPanel alignPanel)
+  {
+    for (AlignmentAnnotation aa: alignPanel.getAlignment().findAnnotation(SequenceAnnotationWSClient.AAConsCalcId))
+    {
+      alignPanel.getAlignment().deleteAnnotation(aa);
+    }
+    // List<AlignmentAnnotation>
+    // ourannots=alignPanel.getAlignment().findAnnotation(Screen3D.)
+    // TODO Auto-generated method stub
+
+  }
 }