JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / ws / jws2 / RNAalifoldClient.java
index 126266b..769100e 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.
  * 
@@ -24,7 +24,7 @@ import jalview.api.AlignCalcWorkerI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.gui.AlignFrame;
-import jalview.ws.jws2.dm.AAConSettings;
+import jalview.util.MessageManager;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.WsParamSetI;
 import jalview.ws.uimodel.AlignAnalysisUIText;
@@ -36,6 +36,7 @@ import java.util.List;
 import java.util.TreeSet;
 import java.util.regex.Pattern;
 
+import compbio.data.sequence.FastaSequence;
 import compbio.data.sequence.RNAStructReader.AlifoldResult;
 import compbio.data.sequence.RNAStructScoreManager;
 import compbio.data.sequence.Range;
@@ -44,11 +45,12 @@ import compbio.metadata.Argument;
 
 /**
  * Client for the JABA RNA Alifold Service
+ * 
  * @author daluke - Daniel Barton
- *
+ * 
  */
 
-public class RNAalifoldClient extends JabawsAlignCalcWorker implements
+public class RNAalifoldClient extends JabawsCalcWorker implements
         AlignCalcWorkerI
 {
 
@@ -64,39 +66,31 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
           WsParamSetI preset, List<Argument> paramset)
   {
     super(sh, alignFrame, preset, paramset);
-
-    //if (arguments == null)
-    //  arguments = new ArrayList<Argument>();
-
     af = alignFrame;
     methodName = sh.serviceType;
-    alignedSeqs=true;
-    submitGaps=true;
+    alignedSeqs = true;
+    submitGaps = true;
     nucleotidesAllowed = true;
     proteinAllowed = false;
     initViewportParams();
   }
-  
+
   public String getCalcId()
   {
     return CALC_ID;
   }
-  private static String CALC_ID="jalview.ws.jws2.RNAalifoldClient";
+
+  private static String CALC_ID = "jalview.ws.jws2.RNAalifoldClient";
 
   public static AlignAnalysisUIText getAlignAnalysisUITest()
   {
     return new AlignAnalysisUIText(
             compbio.ws.client.Services.RNAalifoldWS.toString(),
-            jalview.ws.jws2.RNAalifoldClient.class,
-            CALC_ID,
-            true,
-            false,
-            true,
-            "RNAAliFold Prediction",
-            "When checked, RNA secondary structure predictions will be calculated for the alignment, and updated when edits are made.",
-            "Change RNAAliFold settings...",
-            "Modify settings for the RNAAliFold prediction. Use this to hide or show different results of the RNA calculation, and change RNA folding parameters");
-
+            jalview.ws.jws2.RNAalifoldClient.class, CALC_ID, true, false,
+            true, MessageManager.getString("label.rnalifold_calculations"),
+            MessageManager.getString("tooltip.rnalifold_calculations"),
+            MessageManager.getString("label.rnalifold_settings"),
+            MessageManager.getString("tooltip.rnalifold_settings"));
   }
 
   @Override
@@ -107,6 +101,12 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
   }
 
   @Override
+  boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
+  {
+    return (seqs.size() > 1);
+  }
+
+  @Override
   public void updateResultAnnotation(boolean immediate)
   {
 
@@ -180,11 +180,15 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
      * same data object as was overwritten with the contact probabilites data.
      */
     if (data == null)
+    {
       data = compbio.data.sequence.RNAStructReader
               .newEmptyScore(AlifoldResult.consensusAlignment);
+    }
 
     if (descriptionData == null)
+    {
       descriptionData = data;
+    }
 
     String[] typenameAndDescription = constructTypenameAndDescription(descriptionData
             .first());
@@ -218,7 +222,8 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
   private AlignmentAnnotation constructAnnotationFromScoreHolder(
           AlignmentAnnotation annotation, String struct, TreeSet<Score> data)
   {
-    Annotation[] anns = new Annotation[gapMap!= null ? gapMap.length+1 : struct.length()];
+    Annotation[] anns = new Annotation[gapMap != null ? gapMap.length + 1
+            : struct.length()];
 
     if (data != null
             && data.size() > 1
@@ -236,10 +241,10 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
         basePairs.put(score.getRanges().first(), new Float(score
                 .getScores().get(0)));
       }
-      
-      for (int i = 0,ri=0,iEnd=struct.length();i<iEnd; i++,ri++)
+
+      for (int i = 0, ri = 0, iEnd = struct.length(); i < iEnd; i++, ri++)
       {
-        if (gapMap!=null)
+        if (gapMap != null)
         {
           // skip any gapped columns in the input data
           while (!gapMap[ri])
@@ -263,7 +268,9 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
           {
             float t = contacts.get(contact);
             if (t > prob)
+            {
               prob = t;
+            }
             description += Integer.toString(contact.from) + "->"
                     + Integer.toString(contact.to) + ": "
                     + Float.toString(t) + "%  |  ";
@@ -276,16 +283,16 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
     }
     else if (data == null || data.size() == 1)
     {
-      for (int i = 0,ri=0,iEnd=struct.length();i<iEnd; i++,ri++)
+      for (int i = 0, ri = 0, iEnd = struct.length(); i < iEnd; i++, ri++)
       {
-        if (gapMap!=null)
+        if (gapMap != null)
         {
           // skip any gapped columns in the input data
-          while (!gapMap[ri] && ri<gapMap.length)
+          while (!gapMap[ri] && ri < gapMap.length)
           {
             ri++;
           }
-          if (ri==gapMap.length)
+          if (ri == gapMap.length)
           {
             break;
           }
@@ -343,7 +350,9 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
                 score.getScores().get(0), score.getScores().get(1));
       }
       else
+      {
         description = "Stochastic Backtrack Structure";
+      }
     }
     else if (datatype.equals(AlifoldResult.MEAStucture.toString()))
     {
@@ -363,8 +372,7 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
       description = typename;
     }
 
-    return new String[]
-    { typename, description };
+    return new String[] { typename, description };
   }
 
   // Check whether, at position i there is a base contact and return all the
@@ -380,7 +388,9 @@ public class RNAalifoldClient extends JabawsAlignCalcWorker implements
       // ordering of the Scores TreeSet in ScoreManager which is, descending
       // probability
       if (contact.from == i || contact.to == i)
+      {
         contacts.put(contact, basePairs.get(contact));
+      }
     }
 
     return contacts;