JAL-2629 add basic parameter adjustment to hmmsearch/align
[jalview.git] / src / jalview / gui / AlignFrame.java
index abecd10..85e3db5 100644 (file)
@@ -65,6 +65,9 @@ import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.hmmer.HMMAlignThread;
 import jalview.hmmer.HMMBuildThread;
+import jalview.hmmer.HMMERParamStore;
+import jalview.hmmer.HMMERPreset;
+import jalview.hmmer.HMMSearchThread;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
 import jalview.io.BioJsHTMLOutput;
@@ -97,6 +100,9 @@ import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
 import jalview.ws.jws1.Discoverer;
 import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.WsParamSetI;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.awt.BorderLayout;
@@ -141,6 +147,7 @@ import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JEditorPane;
+import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
@@ -1029,36 +1036,132 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
-  public void hmmBuild_actionPerformed(ActionEvent e)
+  public void hmmBuildSettings_actionPerformed(ActionEvent e)
           throws IOException, InterruptedException
   {
-    new Thread(new HMMBuildThread(this)).start();
+    if (!(alignmentIsSufficient(1)))
+    {
+      return;
+    }
+    WsParamSetI set = new HMMERPreset();
+    List<ArgumentI> args = new ArrayList<>();
+    ParamDatastoreI store = new HMMERParamStore("hmmalign");
+    WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+            args);
+    params.showRunDialog();
+    new Thread(new HMMBuildThread(this, params.getJobParams())).start();
     alignPanel.repaint();
 
   }
 
   @Override
-  public void hmmAlign_actionPerformed(ActionEvent e)
+  public void hmmAlignSettings_actionPerformed(ActionEvent e)
           throws IOException, InterruptedException
   {
-    new Thread(new HMMAlignThread(this, true)).start();
+    if (!(checkForHMM() && alignmentIsSufficient(2)))
+    {
+      return;
+    }
+    WsParamSetI set = new HMMERPreset();
+    List<ArgumentI> args = new ArrayList<>();
+    ParamDatastoreI store = new HMMERParamStore("hmmalign");
+    WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+            args);
+    params.showRunDialog();
+    new Thread(new HMMAlignThread(this, true, params.getJobParams()))
+            .start();
     alignPanel.repaint();
   }
 
   @Override
-  public void changeHMMERLocation_actionPerformed(ActionEvent e)
+  public void hmmSearchSettings_actionPerformed(ActionEvent e)
   {
-    String location = JOptionPane.showInputDialog(
-            MessageManager.getString("label.enter_location"));
-    Cache.setProperty(Preferences.HMMER_PATH, location);
+    if (!checkForHMM())
+    {
+      return;
+    }
+    WsParamSetI set = new HMMERPreset();
+    List<ArgumentI> args = new ArrayList<>();
+    ParamDatastoreI store = new HMMERParamStore("hmmsearch");
+    WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+            args);
+    params.showRunDialog();
+    new Thread(new HMMSearchThread(this, true, params.getJobParams()))
+            .start();
+    alignPanel.repaint();
+  }
+
+  @Override
+  public void hmmBuildRun_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
+  {
+    if (!alignmentIsSufficient(1))
+    {
+      return;
+    }
+    new Thread(new HMMBuildThread(this, null)).start();
+    alignPanel.repaint();
+
+  }
+
+  @Override
+  public void hmmAlignRun_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
+  {
+    if (!(checkForHMM() && alignmentIsSufficient(2)))
+    {
+      return;
+    }
+    new Thread(new HMMAlignThread(this, true, null))
+            .start();
+    alignPanel.repaint();
   }
 
   @Override
-  public void hmmSearch_actionPerformed(ActionEvent e)
+  public void hmmSearchRun_actionPerformed(ActionEvent e)
   {
+    if (!checkForHMM())
+    {
+      return;
+    }
+    new Thread(new HMMSearchThread(this, true, null))
+            .start();
     alignPanel.repaint();
   }
 
+  /**
+   * Checks if the frame has a selected hidden Markov model
+   * 
+   * @return
+   */
+  private boolean checkForHMM()
+  {
+    if (getSelectedHMM() == null)
+    {
+      JOptionPane.showMessageDialog(this,
+              MessageManager.getString("warn.no_selected_hmm"));
+      return false;
+    }
+    return true;
+  }
+
+  /**
+   * Checks if the alignment contains the required number of sequences.
+   * 
+   * @param required
+   * @return
+   */
+  public boolean alignmentIsSufficient(int required)
+  {
+    if (getViewport().getAlignment().getSequences().size() < required)
+    {
+      JOptionPane.showMessageDialog(this,
+              MessageManager.getString("warn.not_enough_sequences"));
+      return false;
+    }
+    return true;
+  }
+
   @Override
   public void reload_actionPerformed(ActionEvent e)
   {