Merge branch 'develop' into features/mchmmer
[jalview.git] / src / jalview / hmmer / HMMAlignThread.java
index 532271b..fadbdb1 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.hmmer;
 
+import jalview.analysis.AlignmentSorter;
+import jalview.analysis.SeqsetUtils;
 import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
@@ -11,7 +13,6 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
-import jalview.gui.Preferences;
 import jalview.gui.SplitFrame;
 import jalview.io.DataSourceType;
 import jalview.io.StockholmFile;
@@ -23,25 +24,18 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import javax.swing.JInternalFrame;
 
-public class HMMAlignThread implements Runnable
+public class HMMAlignThread extends HmmerCommand implements Runnable
 {
+  static final String HMMALIGN = "hmmalign";
 
-  /**
+  /*
    * feature settings from view that job was associated with
    */
   protected FeatureRendererSettings featureSettings = null;
 
-  /**
-   * Object containing frequently used commands.
-   */
-  HMMERCommands cmds = new HMMERCommands();
-
-  AlignFrame af;
-
   AlignmentI alignment;
 
   AlignmentI dataset;
@@ -58,8 +52,6 @@ public class HMMAlignThread implements Runnable
 
   long barID;
 
-  Map<Integer, SequenceI> hmmSeqs;
-
   File hmmTemp = null;
 
   File outTemp = null;
@@ -106,59 +98,56 @@ public class HMMAlignThread implements Runnable
     barID = System.currentTimeMillis();
     af.setProgressBar(MessageManager.getString("status.running_hmmalign"),
             barID);
-    cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
-      prepareAlignment();
-      SequenceI[][] subAlignments = msa.getVisibleContigs('-');
-      allOrders = new ArrayList<>();
-      allResults = new SequenceI[subAlignments.length][];
-      int job = 0;
-      for (SequenceI[] seqs : subAlignments)
+    prepareAlignment();
+    SequenceI[][] subAlignments = msa.getVisibleContigs('-');
+    allOrders = new ArrayList<>();
+    allResults = new SequenceI[subAlignments.length][];
+    int job = 0;
+    for (SequenceI[] seqs : subAlignments)
+    {
+      uniquifySequences(seqs);
+      try
       {
-        cmds.uniquifySequences(seqs);
-        try
-        {
-          createTemporaryFiles();
-        } catch (IOException e2)
-        {
-          e2.printStackTrace();
-        }
-        try
-        {
-          cmds.exportData(seqs, outTemp.getAbsoluteFile(), hmm,
-                  hmmTemp.getAbsoluteFile());
-        } catch (IOException e1)
-        {
-          e1.printStackTrace();
-        }
-        try
-        {
-          boolean ran = runCommand();
-          if (!ran)
-          {
-            JvOptionPane.showInternalMessageDialog(af,
-                    MessageManager.getString("warn.hmmalign_failed"));
-            return;
-          }
-        } catch (IOException | InterruptedException e)
-        {
-          e.printStackTrace();
-        }
-        try
-        {
-          importData(job);
-        } catch (IOException | InterruptedException e)
+        createTemporaryFiles();
+      } catch (IOException e2)
+      {
+        e2.printStackTrace();
+      }
+      try
+      {
+        exportData(seqs, outTemp.getAbsoluteFile(), hmm,
+                hmmTemp.getAbsoluteFile(), null);
+      } catch (IOException e1)
+      {
+        e1.printStackTrace();
+      }
+      try
+      {
+        boolean ran = runCommand();
+        if (!ran)
         {
-          // TODO Auto-generated catch block
-          e.printStackTrace();
+          JvOptionPane.showInternalMessageDialog(af,
+                  MessageManager.getString("warn.hmmalign_failed"));
+          return;
         }
-        job++;
+      } catch (IOException | InterruptedException e)
+      {
+        e.printStackTrace();
       }
-
+      try
+      {
+        importData(job);
+      } catch (IOException | InterruptedException e)
+      {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+      }
+      job++;
+    }
 
     displayResults(newFrame);
 
-    af.setProgressBar(MessageManager.getString("status.running_hmmalign"),
-            barID);
+    af.setProgressBar("", barID);
 
   }
 
@@ -184,7 +173,7 @@ public class HMMAlignThread implements Runnable
   }
 
   /**
-   * Executes the hmmalign command in the command line.
+   * Executes the hmmalign command in the command line
    * 
    * @return
    * @throws IOException
@@ -192,22 +181,16 @@ public class HMMAlignThread implements Runnable
    */
   private boolean runCommand() throws IOException, InterruptedException
   {
-    File file = new File(cmds.HMMERFOLDER + "/hmmalign");
-    if (!file.canExecute())
-    {
-      file = new File(cmds.HMMERFOLDER + "/hmmalign.exe");
-      {
-        if (!file.canExecute())
-        {
-          return false;
-        }
-      }
+    String binaryPath = getCommandRoot(HMMALIGN);
+    if (binaryPath == null) {
+      return false;
     }
-    String command = cmds.HMMERFOLDER + cmds.HMMALIGN;
+    String command = binaryPath + SPACE;
+    // todo parse version from ./hmmerbuild -h
     String version = Cache.getProperty("HMMER_VERSION");
     if (!"3.1b2".equals(version))
     {
-      command += cmds.ALLCOL;
+      // command += ALLCOL; // todo obsolete option?
     }
     if (args != null)
     {
@@ -221,10 +204,10 @@ public class HMMAlignThread implements Runnable
         }
       }
     }
-    command += " -o " + inputTemp.getAbsolutePath() + cmds.SPACE
-            + hmmTemp.getAbsolutePath() + cmds.SPACE
+    command += " -o " + inputTemp.getAbsolutePath() + SPACE
+            + hmmTemp.getAbsolutePath() + SPACE
             + outTemp.getAbsolutePath();
-    return cmds.runCommand(command);
+    return runCommand(command);
   }
 
   /**
@@ -243,8 +226,8 @@ public class HMMAlignThread implements Runnable
             DataSourceType.FILE);
     SequenceI[] result = file.getSeqsAsArray();
     AlignmentOrder msaorder = new AlignmentOrder(result);
-    jalview.analysis.AlignmentSorter.recoverOrder(result);
-    jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, result);
+    AlignmentSorter.recoverOrder(result);
+    SeqsetUtils.deuniquify(hash, result);
     allOrders.add(msaorder);
     allResults[index] = result;
     hmmTemp.delete();
@@ -270,8 +253,7 @@ public class HMMAlignThread implements Runnable
   {
     AlignmentOrder[] arrOrders = allOrders
             .toArray(new AlignmentOrder[allOrders.size()]);
-    Object[] newview = msa.getUpdatedView(allResults,
-            arrOrders, '-');
+    Object[] newview = msa.getUpdatedView(allResults, arrOrders, '-');
     SequenceI[] alignment = (SequenceI[]) newview[0];
     HiddenColumns hidden = (HiddenColumns) newview[1];
     Alignment al = new Alignment(alignment);
@@ -430,6 +412,4 @@ public class HMMAlignThread implements Runnable
     }
 
   }
-  }
-
-
+}