JAL-2629 storage and lifecycle of alignment/group HMM annotations revised
[jalview.git] / src / jalview / hmmer / HMMSearch.java
similarity index 91%
rename from src/jalview/hmmer/HMMSearchThread.java
rename to src/jalview/hmmer/HMMSearch.java
index d974b49..caf0b37 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Scanner;
 
 import javax.swing.JOptionPane;
 
-public class HMMSearchThread extends HmmerCommand implements Runnable
+public class HMMSearch extends HmmerCommand
 {
   static final String HMMSEARCH = "hmmsearch";
 
@@ -43,7 +43,7 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
    * 
    * @param af
    */
-  public HMMSearchThread(AlignFrame af, List<ArgumentI> args)
+  public HMMSearch(AlignFrame af, List<ArgumentI> args)
   {
     super(af, args);
   }
@@ -51,7 +51,8 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
   /**
    * Runs the HMMSearchThread: the data on the alignment or group is exported,
    * then the command is executed in the command line and then the data is
-   * imported and displayed in a new frame
+   * imported and displayed in a new frame. Call this method directly to execute
+   * synchronously, or via start() in a new Thread for asynchronously.
    */
   @Override
   public void run()
@@ -194,10 +195,10 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
     {
       AlignmentI alignment = af.getViewport().getAlignment();
       AlignmentI copy = new Alignment(alignment);
-      List<SequenceI> hmms = copy.getHMMConsensusSequences();
-      for (SequenceI seq : hmms)
+      SequenceI hmms = copy.getHmmConsensus();
+      if (hmms != null)
       {
-        copy.deleteSequence(seq);
+        copy.deleteSequence(hmms);
       }
       StockholmFile stoFile = new StockholmFile(copy);
       stoFile.setSeqs(copy.getSequencesArray());
@@ -256,8 +257,8 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
                 MessageManager.getString("label.trim_termini_desc"), true,
                 true, true, null));
       }
-      HMMAlignThread hmmalign = new HMMAlignThread(frame, alignArgs);
-      hmmalign.hmmalignWaitTillComplete();
+      HMMAlign hmmalign = new HMMAlign(frame, alignArgs);
+      hmmalign.run();
       frame = null;
       hmmTemp.delete();
       inputAlignmentTemp.delete();
@@ -271,26 +272,6 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
     }
   }
 
-  /**
-   * Runs hmmsearch, and waits for the results to be imported before continuing
-   */
-  public void hmmsearchWaitTillComplete()
-  {
-    Thread loader = new Thread(this);
-    loader.start();
-
-    while (loader.isAlive())
-    {
-      try
-      {
-        Thread.sleep(500);
-      } catch (Exception ex)
-      {
-      }
-    }
-
-  }
-
   void readTable(File inputTableTemp) throws IOException
   {
     BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));