JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / ws / jws2 / AADisorderClient.java
index c5fbf49..d955db5 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -40,6 +40,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import compbio.data.sequence.FastaSequence;
 import compbio.data.sequence.Range;
 import compbio.data.sequence.Score;
 import compbio.data.sequence.ScoreManager.ScoreHolder;
@@ -50,6 +51,7 @@ public class AADisorderClient extends JabawsCalcWorker implements
 {
 
   private static final String THRESHOLD = "THRESHOLD";
+
   private static final String RANGE = "RANGE";
 
   String typeName;
@@ -81,6 +83,12 @@ public class AADisorderClient extends JabawsCalcWorker implements
     return "Submitting amino acid sequences for disorder prediction.";
   }
 
+  @Override
+  boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
+  {
+    return (seqs.size() > 0);
+  }
+
   private static Map<String, Map<String, String[]>> featureMap;
 
   private static Map<String, Map<String, Map<String, Object>>> annotMap;
@@ -96,34 +104,29 @@ public class AADisorderClient extends JabawsCalcWorker implements
     Map<String, String[]> fmap;
     featureMap.put(compbio.ws.client.Services.IUPredWS.toString(),
             fmap = new HashMap<String, String[]>());
-    fmap.put("Glob", new String[]
-    { "Globular Domain", "Predicted globular domain" });
+    fmap.put("Glob", new String[] { "Globular Domain",
+        "Predicted globular domain" });
     featureMap.put(compbio.ws.client.Services.JronnWS.toString(),
             fmap = new HashMap<String, String[]>());
     featureMap.put(compbio.ws.client.Services.DisemblWS.toString(),
             fmap = new HashMap<String, String[]>());
-    fmap.put("REM465", new String[]
-    { "REM465", "Missing density" });
-    fmap.put("HOTLOOPS", new String[]
-    { "HOTLOOPS", "Flexible loops" });
-    fmap.put("COILS", new String[]
-    { "COILS", "Random coil" });
+    fmap.put("REM465", new String[] { "REM465", "Missing density" });
+    fmap.put("HOTLOOPS", new String[] { "HOTLOOPS", "Flexible loops" });
+    fmap.put("COILS", new String[] { "COILS", "Random coil" });
     featureMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
             fmap = new HashMap<String, String[]>());
-    fmap.put("GlobDoms", new String[]
-    { "Globular Domain", "Predicted globular domain" });
-    fmap.put("Disorder", new String[]
-    { "Protein Disorder", "Probable unstructured peptide region" });
+    fmap.put("GlobDoms", new String[] { "Globular Domain",
+        "Predicted globular domain" });
+    fmap.put("Disorder", new String[] { "Protein Disorder",
+        "Probable unstructured peptide region" });
     Map<String, Map<String, Object>> amap;
     annotMap = new HashMap<String, Map<String, Map<String, Object>>>();
     annotMap.put(compbio.ws.client.Services.GlobPlotWS.toString(),
             amap = new HashMap<String, Map<String, Object>>());
     amap.put("Dydx", new HashMap<String, Object>());
     amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
-    amap.get("Dydx").put(THRESHOLD, new double[]
-    { 1, 0 });
-    amap.get("Dydx").put(RANGE, new float[]
-            { -1, +1 });
+    amap.get("Dydx").put(THRESHOLD, new double[] { 1, 0 });
+    amap.get("Dydx").put(RANGE, new float[] { -1, +1 });
 
     amap.put("SmoothedScore", new HashMap<String, Object>());
     amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
@@ -134,40 +137,27 @@ public class AADisorderClient extends JabawsCalcWorker implements
     amap.put("COILS", new HashMap<String, Object>());
     amap.put("HOTLOOPS", new HashMap<String, Object>());
     amap.put("REM465", new HashMap<String, Object>());
-    amap.get("COILS").put(THRESHOLD, new double[]
-    { 1, 0.516 });
-    amap.get("COILS").put(RANGE, new float[]
-            { 0, 1 });
-
-    amap.get("HOTLOOPS").put(THRESHOLD, new double[]
-    { 1, 0.6 });
-    amap.get("HOTLOOPS").put(RANGE, new float[]
-            { 0, 1 });
-    amap.get("REM465").put(THRESHOLD, new double[]
-    { 1, 0.1204 });
-    amap.get("REM465").put(RANGE, new float[]
-            { 0, 1 });
+    amap.get("COILS").put(THRESHOLD, new double[] { 1, 0.516 });
+    amap.get("COILS").put(RANGE, new float[] { 0, 1 });
 
+    amap.get("HOTLOOPS").put(THRESHOLD, new double[] { 1, 0.6 });
+    amap.get("HOTLOOPS").put(RANGE, new float[] { 0, 1 });
+    amap.get("REM465").put(THRESHOLD, new double[] { 1, 0.1204 });
+    amap.get("REM465").put(RANGE, new float[] { 0, 1 });
 
     annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
             amap = new HashMap<String, Map<String, Object>>());
     amap.put("Long", new HashMap<String, Object>());
     amap.put("Short", new HashMap<String, Object>());
-    amap.get("Long").put(THRESHOLD, new double[]
-    { 1, 0.5 });
-    amap.get("Long").put(RANGE, new float[]
-            { 0, 1 });
-    amap.get("Short").put(THRESHOLD, new double[]
-    { 1, 0.5 });
-    amap.get("Short").put(RANGE, new float[]
-            { 0, 1 });
+    amap.get("Long").put(THRESHOLD, new double[] { 1, 0.5 });
+    amap.get("Long").put(RANGE, new float[] { 0, 1 });
+    amap.get("Short").put(THRESHOLD, new double[] { 1, 0.5 });
+    amap.get("Short").put(RANGE, new float[] { 0, 1 });
     annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
             amap = new HashMap<String, Map<String, Object>>());
     amap.put("JRonn", new HashMap<String, Object>());
-    amap.get("JRonn").put(THRESHOLD, new double[]
-    { 1, 0.5 });
-    amap.get("JRonn").put(RANGE, new float[]
-            { 0, 1 });
+    amap.get("JRonn").put(THRESHOLD, new double[] { 1, 0.5 });
+    amap.get("JRonn").put(RANGE, new float[] { 0, 1 });
   }
 
   @Override
@@ -203,14 +193,15 @@ public class AADisorderClient extends JabawsCalcWorker implements
       {
         boolean sameGroup = false;
         SequenceI dseq, aseq, seq = seqNames.get(seqId);
-        int base = seq.findPosition(start)-1;
+        int base = seq.findPosition(start) - 1;
         aseq = seq;
         while ((dseq = seq).getDatasetSequence() != null)
         {
           seq = seq.getDatasetSequence();
         }
         ScoreHolder scores = null;
-        try {
+        try
+        {
           scores = scoremanager.getAnnotationForSequence(seqId);
         } catch (Exception q)
         {
@@ -218,12 +209,14 @@ public class AADisorderClient extends JabawsCalcWorker implements
                   .info("Couldn't recover disorder prediction for sequence "
                           + seq.getName()
                           + "(Prediction name was "
-                          + seqId+")"
+                          + seqId
+                          + ")"
                           + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
         }
         float last = Float.NaN, val = Float.NaN;
         int lastAnnot = ourAnnot.size();
-        if (scores!=null && scores.scores!=null) {
+        if (scores != null && scores.scores != null)
+        {
           for (Score scr : scores.scores)
           {
 
@@ -239,8 +232,8 @@ public class AADisorderClient extends JabawsCalcWorker implements
                 if (type == null)
                 {
                   // create a default type for this feature
-                  type = new String[]
-                  { typeName + " (" + scr.getMethod() + ")",
+                  type = new String[] {
+                      typeName + " (" + scr.getMethod() + ")",
                       service.getActionText() };
                 }
                 if (vals.hasNext())
@@ -255,7 +248,7 @@ public class AADisorderClient extends JabawsCalcWorker implements
                           + rn.from, base + rn.to, methodName);
                 }
                 dseq.addSequenceFeature(sf);
-                if (last != val && last != Float.NaN)
+                if (last != val && !Float.isNaN(last))
                 {
                   fc.put(sf.getType(), sf);
                 }
@@ -269,27 +262,29 @@ public class AADisorderClient extends JabawsCalcWorker implements
               {
                 continue;
               }
+              String typename, calcName;
               AlignmentAnnotation annot = createAnnotationRowsForScores(
                       ourAnnot,
-                      service.serviceType + " (" + scr.getMethod() + ")",
-                      service.getServiceTypeURI() + "/" + scr.getMethod(),
-                      aseq, base + 1, scr);
+                      typename = service.serviceType + " ("
+                              + scr.getMethod() + ")",
+                      calcName = service.getServiceTypeURI() + "/"
+                              + scr.getMethod(), aseq, base + 1, scr);
               annot.graph = AlignmentAnnotation.LINE_GRAPH;
-              
-              Map<String,Object> styleMap = (annotTypeMap == null) ? null : annotTypeMap.get(scr.getMethod());
-              
+
+              Map<String, Object> styleMap = (annotTypeMap == null) ? null
+                      : annotTypeMap.get(scr.getMethod());
+
               annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
-              double[] thrsh = (styleMap==null) ? null
-                      : (double[]) styleMap.get(
-                              THRESHOLD);
-              float[] range = (styleMap==null) ? null : (float[]) styleMap.get(
-                      RANGE);
-              if (range!=null)
+              double[] thrsh = (styleMap == null) ? null
+                      : (double[]) styleMap.get(THRESHOLD);
+              float[] range = (styleMap == null) ? null
+                      : (float[]) styleMap.get(RANGE);
+              if (range != null)
               {
                 annot.graphMin = range[0];
                 annot.graphMax = range[1];
               }
-              if (styleMap==null || styleMap.get(DONTCOMBINE) == null)
+              if (styleMap == null || styleMap.get(DONTCOMBINE) == null)
               {
                 {
                   if (!sameGroup)
@@ -323,6 +318,9 @@ public class AADisorderClient extends JabawsCalcWorker implements
                 }
               }
               annot._linecolour = col;
+              // finally, update any dataset annotation
+              replaceAnnotationOnAlignmentWith(annot, typename, calcName,
+                      aseq);
             }
           }
         }
@@ -335,7 +333,7 @@ public class AADisorderClient extends JabawsCalcWorker implements
       {
         if (dispFeatures)
         {
-          jalview.gui.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
+          jalview.api.FeatureRenderer fr = ((jalview.gui.AlignmentPanel) ap)
                   .cloneFeatureRenderer();
           for (String ft : fc.keySet())
           {
@@ -371,4 +369,11 @@ public class AADisorderClient extends JabawsCalcWorker implements
     }
   }
 
+  @Override
+  public String getCalcId()
+  {
+    // Disorder predictions are not dynamically updated so we return null
+    return null;
+  }
+
 }