JAL-2629 add simple jackhmmer functionality
[jalview.git] / src / jalview / hmmer / HMMAlign.java
index 6255e9f..d66ec33 100644 (file)
@@ -14,6 +14,7 @@ import jalview.gui.JvOptionPane;
 import jalview.gui.SplitFrame;
 import jalview.io.DataSourceType;
 import jalview.io.StockholmFile;
+import jalview.util.FileUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
 import jalview.ws.params.ArgumentI;
@@ -30,8 +31,6 @@ public class HMMAlign extends HmmerCommand
 {
   static final String HMMALIGN = "hmmalign";
 
-  static final String ARG_TRIM = "--trim";
-
   private final AlignmentI dataset;
 
   /**
@@ -63,17 +62,15 @@ public class HMMAlign extends HmmerCommand
   @Override
   public void run()
   {
-    HiddenMarkovModel hmm = af.getSelectedHMM();
-    if (hmm == null)
-    {
-      System.err.println("Can't run hmmalign as no HMM profile selected");
-      return;
-    }
+    HiddenMarkovModel hmm = getHmmProfile();
 
     long msgId = System.currentTimeMillis();
     af.setProgressBar(MessageManager.getString("status.running_hmmalign"),
             msgId);
 
+    // ensure alignments are the same length
+    alignment.padGaps();
+
     AlignmentView msa = af.gatherSequencesForAlignment();
     SequenceI[][] subAlignments = msa.getVisibleContigs(alignment.getGapCharacter());
 
@@ -86,9 +83,9 @@ public class HMMAlign extends HmmerCommand
       Hashtable sequencesHash = stashSequences(seqs);
       try
       {
-        File modelFile = createTempFile("hmm", ".hmm");
-        File alignmentFile = createTempFile("output", ".sto");
-        File resultFile = createTempFile("input", ".sto");
+        File modelFile = FileUtils.createTempFile("hmm", ".hmm");
+        File alignmentFile = FileUtils.createTempFile("output", ".sto");
+        File resultFile = FileUtils.createTempFile("input", ".sto");
 
         exportStockholm(seqs, alignmentFile.getAbsoluteFile(), null);
         exportHmm(hmm, modelFile.getAbsoluteFile());
@@ -96,8 +93,8 @@ public class HMMAlign extends HmmerCommand
         boolean ran = runCommand(modelFile, alignmentFile, resultFile);
         if (!ran)
         {
-          JvOptionPane.showInternalMessageDialog(af,
-                  MessageManager.getString("warn.hmmalign_failed"));
+          JvOptionPane.showInternalMessageDialog(af, MessageManager
+                  .formatMessage("warn.command_failed", "hmmalign"));
           return;
         }
 
@@ -156,9 +153,9 @@ public class HMMAlign extends HmmerCommand
       }
     }
     args.add("-o");
-    args.add(resultFile.getAbsolutePath());
-    args.add(modelFile.getAbsolutePath());
-    args.add(alignmentFile.getAbsolutePath());
+    args.add(getFilePath(resultFile, true));
+    args.add(getFilePath(modelFile, true));
+    args.add(getFilePath(alignmentFile, true));
     
     return runCommand(args);
   }
@@ -176,7 +173,7 @@ public class HMMAlign extends HmmerCommand
   private SequenceI[] importData(File resultFile,
           List<AlignmentOrder> allOrders) throws IOException
   {
-    StockholmFile file = new StockholmFile(resultFile.getAbsolutePath(),
+    StockholmFile file = new StockholmFile(getFilePath(resultFile, false),
             DataSourceType.FILE);
     SequenceI[] result = file.getSeqsAsArray();
     AlignmentOrder msaorder = new AlignmentOrder(result);