RNAalifoldClient updated to be more like AAConClient and now (attempts) to support...
[jalview.git] / src / jalview / ws / jws2 / SequenceAnnotationWSClient.java
index dbb789b..eecefd9 100644 (file)
@@ -1,5 +1,19 @@
-/**
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
  * 
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  */
 package jalview.ws.jws2;
 
@@ -24,10 +38,10 @@ import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
 /**
- * @author jprocter 
+ * @author jprocter
  * 
  */
-public class SequenceAnnotationWSClient extends Jws2Client 
+public class SequenceAnnotationWSClient extends Jws2Client
 {
 
   public static final String AAConCalcId = "jabaws2.AACon";
@@ -47,17 +61,20 @@ public class SequenceAnnotationWSClient extends Jws2Client
     initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams);
   }
 
+  // dan think. Do I need to change this method to run RNAalifold through the GUI
+  
   public void initSequenceAnnotationWSClient(final Jws2Instance sh,
           AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
   {
-    if (alignFrame.getViewport().getAlignment().isNucleotide())
-    {
-      JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
-              + " can only be used\nfor amino acid alignments.",
-              "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
-      return;
-
-    }
+       // dan changed! dan test. comment out if conditional
+//    if (alignFrame.getViewport().getAlignment().isNucleotide())
+//    {
+//      JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType
+//              + " can only be used\nfor amino acid alignments.",
+//              "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE);
+//      return;
+//
+//    }
     if (sh.action.toLowerCase().contains("conservation"))
     {
       // Build an AACon style client - take alignment, return annotation for
@@ -117,7 +134,51 @@ public class SequenceAnnotationWSClient extends Jws2Client
               .startWorker(
                       new AADisorderClient(sh, alignFrame, preset, paramset));
     }
+    
+    
+    // dan test dan changed!
+    if (sh.action.toLowerCase().contains("rna structure prediction"))
+    {
 
+       List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
+                       .getCalcManager()
+                       .getRegisteredWorkersOfClass(RNAalifoldClient.class);
+       if (clnts == null || clnts.size() == 0)
+       {
+               if (!processParams(sh, editParams))
+               {
+                       return;
+               }
+               RNAalifoldClient worker;
+               alignFrame
+                                               .getViewport()
+                                               .getCalcManager()
+                                               .registerWorker(
+                                                                       worker = new RNAalifoldClient(sh, alignFrame,
+                                                                                                       this.preset, paramset));
+               alignFrame.getViewport().getCalcManager().startWorker(worker);
+       }
+       else 
+       {
+               RNAalifoldClient worker = (RNAalifoldClient) clnts.get(0);
+               if (editParams)
+               {
+                       paramset = worker.getArguments();
+                       preset = worker.getPreset();
+               }
+               
+               if (!processParams(sh, editParams, true))
+        {
+          return;
+        }
+               
+               // reinstate worker if it was blacklisted (might have happened due to
+        // invalid parameters)
+        alignFrame.getViewport().getCalcManager().workerMayRun(worker);
+        worker.updateParameters(this.preset, paramset);
+       }
+       
+    }
   }
 
   public SequenceAnnotationWSClient(AAConSettings fave,
@@ -164,7 +225,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
       // only add these menu options if the service has user-modifiable
       // arguments
       annotservice = new JMenuItem("Edit settings and run ...");
-      annotservice.setToolTipText("View and change parameters before running calculation");
+      annotservice
+              .setToolTipText("View and change parameters before running calculation");
 
       annotservice.addActionListener(new ActionListener()
       {
@@ -201,20 +263,25 @@ public class SequenceAnnotationWSClient extends Jws2Client
         wsmenu.add(presetlist);
       }
 
-    } else {
+    }
+    else
+    {
       annotservice = new JMenuItem("View documentation");
-      if (service.docUrl!=null)
+      if (service.docUrl != null)
       {
         annotservice.addActionListener(new ActionListener()
         {
-          
+
           @Override
           public void actionPerformed(ActionEvent arg0)
           {
             Desktop.instance.showUrl(service.docUrl);
           }
         });
-        annotservice.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("View <a href=\""+service.docUrl+"\">"+service.docUrl+"</a>")+"</html>");
+        annotservice.setToolTipText("<html>"
+                + JvSwingUtils.wrapTooltip("View <a href=\""
+                        + service.docUrl + "\">" + service.docUrl + "</a>")
+                + "</html>");
         wsmenu.add(annotservice);
       }
     }
@@ -250,15 +317,15 @@ public class SequenceAnnotationWSClient extends Jws2Client
         AAConClient worker = (AAConClient) aaconClient.get(0);
         if (!worker.service.hosturl.equals(service.hosturl))
         {
-         // javax.swing.SwingUtilities.invokeLater(new Runnable()
+          // javax.swing.SwingUtilities.invokeLater(new Runnable()
           {
-         //   @Override
-         //   public void run()
+            // @Override
+            // public void run()
             {
               removeCurrentAAConWorkerFor(alignFrame);
               buildCurrentAAConWorkerFor(alignFrame, service);
             }
-          }//);
+          }// );
         }
       }
     }