JAL-2629 choice of hmm profile now a parameter not a selection, apis simplified
[jalview.git] / src / jalview / hmmer / HMMSearch.java
index 6f73f2f..7738cb5 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.hmmer;
 
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -15,12 +16,14 @@ import jalview.util.FileUtils;
 import jalview.util.MessageManager;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.simple.BooleanOption;
+import jalview.ws.params.simple.Option;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Scanner;
 
@@ -28,6 +31,8 @@ import javax.swing.JOptionPane;
 
 public class HMMSearch extends HmmerCommand
 {
+  private static final String PARAMNAME_NO_OF_RESULTS = MessageManager.getString("label.number_of_results");
+
   static final String HMMSEARCH = "hmmsearch";
 
   boolean realign = false;
@@ -57,15 +62,15 @@ public class HMMSearch extends HmmerCommand
   @Override
   public void run()
   {
-    HiddenMarkovModel hmm = af.getSelectedHMM();
+    HiddenMarkovModel hmm = getHmmProfile();
     if (hmm == null)
     {
-      JOptionPane.showMessageDialog(af,
-              MessageManager.getString("warn.no_selected_hmm"));
+      // shouldn't happen if we got this far
+      Cache.log.error("Error: no hmm for hmmsearch");
       return;
     }
 
-    SequenceI hmmSeq = af.getSelectedHMMSequence();
+    SequenceI hmmSeq = hmm.getConsensusSequence();// af.getSelectedHMMSequence();
     long msgId = System.currentTimeMillis();
     af.setProgressBar(MessageManager.getString("status.running_hmmsearch"),
             msgId);
@@ -83,8 +88,8 @@ public class HMMSearch extends HmmerCommand
       boolean ran = runCommand(searchOutputFile, hitsAlignmentFile, hmmFile);
       if (!ran)
       {
-        JvOptionPane.showInternalMessageDialog(af,
-                MessageManager.getString("warn.hmmsearch_failed"));
+        JvOptionPane.showInternalMessageDialog(af, MessageManager
+                .formatMessage("warn.command_failed", "hmmsearch"));
         return;
       }
 
@@ -197,15 +202,16 @@ public class HMMSearch extends HmmerCommand
     {
       /*
        * no external database specified for search, so
-       * export current alignment as 'database' to search
+       * export current alignment as 'database' to search,
+       * excluding any HMM consensus sequences it contains
        */
       databaseFile = FileUtils.createTempFile("database", ".sto");
       AlignmentI al = af.getViewport().getAlignment();
       AlignmentI copy = new Alignment(al);
-      SequenceI hmms = copy.getHmmConsensus();
-      if (hmms != null)
+      List<SequenceI> hmms = copy.getHmmSequences();
+      for (SequenceI hmmSeq : hmms)
       {
-        copy.deleteSequence(hmms);
+        copy.deleteSequence(hmmSeq);
       }
       exportStockholm(copy.getSequencesArray(), databaseFile, null);
       // StockholmFile stoFile = new StockholmFile(copy);
@@ -253,10 +259,17 @@ public class HMMSearch extends HmmerCommand
       hmmAndSeqs[0] = hmmSeq;
       System.arraycopy(seqs, 0, hmmAndSeqs, 1, seqCount);
 
-      AlignmentI alignment = new Alignment(hmmAndSeqs);
-      AlignFrame frame = new AlignFrame(alignment, 1, 1);
-      frame.setSelectedHMMSequence(hmmSeq);
+      /*
+       * and align the search results to the HMM profile
+       */
+      AlignmentI al = new Alignment(hmmAndSeqs);
+      AlignFrame frame = new AlignFrame(al, 1, 1);
       List<ArgumentI> alignArgs = new ArrayList<>();
+      String defSeq = hmmSeq.getName();
+      List<String> options = Collections.singletonList(defSeq);
+      Option option = new Option(MessageManager.getString("label.use_hmm"),
+              "", true, defSeq, defSeq, options, null);
+      alignArgs.add(option);
       if (trim)
       {
         alignArgs.add(new BooleanOption(
@@ -264,7 +277,7 @@ public class HMMSearch extends HmmerCommand
                 MessageManager.getString("label.trim_termini_desc"), true,
                 true, true, null));
       }
-      HMMAlign hmmalign = new HMMAlign(frame, alignArgs);
+      HmmerCommand hmmalign = new HMMAlign(frame, alignArgs);
       hmmalign.run();
       frame = null;
       hmmTemp.delete();