Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / ws / jws2 / jabaws2 / AADisorderClient.java
index 6e65cce..69cd008 100644 (file)
  */
 package jalview.ws.jws2.jabaws2;
 
-import jalview.api.AlignViewportI;
+import jalview.analysis.AlignmentAnnotationUtils;
 import jalview.api.FeatureColourI;
 import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.GraphLine;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.schemes.FeatureColour;
 import jalview.util.ColorUtils;
-import jalview.ws.gui.AnnotationWsJob;
 
 import java.awt.Color;
 import java.util.ArrayList;
@@ -61,41 +63,26 @@ public class AADisorderClient extends JabawsAnnotationInstance
   }
 
   @Override
-  List<AlignmentAnnotation> annotationFromScoreManager(
-          AnnotationWsJob running, AlignViewportI alignViewport,
-          boolean[] gapMap)
+  List<AlignmentAnnotation> annotationFromScoreManager(AlignmentI seqs,
+          Map<String, FeatureColourI> featureColours,
+          Map<String, FeatureMatcherSetI> featureFilters)
   {
 
     Map<String, String[]> featureTypeMap = featureMap.get(our.getName());
     Map<String, Map<String, Object>> annotTypeMap = annotMap
             .get(our.getName());
     boolean dispFeatures = false;
-    Map<String, Object> fc = new Hashtable<>();
+    Map<String, SequenceFeature> fc = new Hashtable<>(),
+            fex = new Hashtable();
     List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
-    /**
-     * grouping for any annotation rows created
-     */
-    int graphGroup = 1;
-    if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
-    {
-      for (AlignmentAnnotation ala : alignViewport.getAlignment()
-              .getAlignmentAnnotation())
-      {
-        if (ala.graphGroup > graphGroup)
-        {
-          graphGroup = ala.graphGroup;
-        }
-      }
-    }
+    int graphGroup = 1, lastAnnot = 0;
 
-    // TODO: downgrade code below so we don't annotate sequences directly
-    Map<String, SequenceI> seqNames = running.getSeqNames();
-    int start = running.getStartPos();
-    for (String seqId : seqNames.keySet())
+    for (SequenceI seq : seqs.getSequences())
     {
+      String seqId = seq.getName();
       boolean sameGroup = false;
-      SequenceI dseq, aseq, seq = seqNames.get(seqId);
-      int base = seq.findPosition(start) - 1;
+      SequenceI dseq, aseq;
+      int base = seq.findPosition(0) - 1;
       aseq = seq;
       while ((dseq = seq).getDatasetSequence() != null)
       {
@@ -107,12 +94,12 @@ public class AADisorderClient extends JabawsAnnotationInstance
         scores = scoremanager.getAnnotationForSequence(seqId);
       } catch (Exception q)
       {
-        Cache.log.info("Couldn't recover disorder prediction for sequence "
+        Console.info("Couldn't recover disorder prediction for sequence "
                 + seq.getName() + "(Prediction name was " + seqId + ")"
-                + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
+                + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.",
+                q);
       }
       float last = Float.NaN, val = Float.NaN;
-      int lastAnnot = ourAnnot.size();
       if (scores != null && scores.scores != null)
       {
         for (Score scr : scores.scores)
@@ -124,7 +111,7 @@ public class AADisorderClient extends JabawsAnnotationInstance
             // make features on sequence
             for (Range rn : scr.getRanges())
             {
-
+              // TODO: Create virtual feature settings
               SequenceFeature sf;
               String[] type = featureTypeMap.get(scr.getMethod());
               if (type == null)
@@ -146,12 +133,16 @@ public class AADisorderClient extends JabawsAnnotationInstance
                         base + rn.to, methodName);
               }
               dseq.addSequenceFeature(sf);
-              if (last != val && !Float.isNaN(last))
+              // mark feature as requiring a graduated colourscheme if has
+              // variable scores
+              if (!Float.isNaN(last) && !Float.isNaN(val) && last != val)
               {
                 fc.put(sf.getType(), sf);
+              } else 
+              {
+                fex.put(sf.getType(), sf);
               }
               last = val;
-              running.setTransferSequenceFeatures(true);
               dispFeatures = true;
             }
           }
@@ -163,7 +154,7 @@ public class AADisorderClient extends JabawsAnnotationInstance
             }
             String typename, calcName;
             AlignmentAnnotation annot = createAnnotationRowsForScores(
-                    alignViewport, gapMap, ourAnnot,
+                    seqs, null, ourAnnot,
                     typename = our.getName() + " (" + scr.getMethod() + ")",
                     calcName = our.getNameURI() + "/" + scr.getMethod(),
                     aseq, base + 1, scr);
@@ -218,8 +209,8 @@ public class AADisorderClient extends JabawsAnnotationInstance
             }
             annot._linecolour = col;
             // finally, update any dataset annotation
-            replaceAnnotationOnAlignmentWith(annot, typename, calcName,
-                    aseq);
+            AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(annot,
+                    typename, calcName);
           }
         }
       }
@@ -232,20 +223,29 @@ public class AADisorderClient extends JabawsAnnotationInstance
     {
       if (dispFeatures)
       {
-        jalview.api.FeatureRenderer fr = running.getFeatureRenderer();
-        for (String ft : fc.keySet())
+        // TODO: virtual feature settings
+        // feature colours need to merged with current viewport's colours
+        // simple feature colours promoted to colour-by-score ranges using
+        // currently assigned or created feature colour
+        for (String ft : fex.keySet())
         {
-          FeatureColourI gc = fr.getFeatureStyle(ft);
-          if (gc.isSimpleColour())
+          Color col = ColorUtils.createColourFromName(ft);
+          // set graduated color as fading to white for minimum, and
+          // autoscaling to values on alignment
+          
+          FeatureColourI ggc;
+          if (fc.get(ft) != null)
           {
-            // set graduated color as fading to white for minimum, and
-            // autoscaling to values on alignment
-            FeatureColourI ggc = new FeatureColour(gc.getColour(),
-                    Color.white, gc.getColour(), Color.white,
-                    Float.MIN_VALUE, Float.MAX_VALUE);
+            ggc = new FeatureColour(col, Color.white, col,
+
+                  Color.white, Float.MIN_VALUE, Float.MAX_VALUE);
             ggc.setAutoScaled(true);
-            fr.setColour(ft, ggc);
           }
+          else
+          {
+            ggc = new FeatureColour(col);
+          }
+          featureColours.put(ft, ggc);
         }
 
       }