JAL-3899 Update usages of uniquify and deuniquify.
[jalview.git] / src / jalview / hmmer / HMMAlign.java
index 942342c..dd85c74 100644 (file)
@@ -1,6 +1,7 @@
 package jalview.hmmer;
 
 import jalview.analysis.AlignmentSorter;
+import jalview.analysis.SeqsetUtils.SequenceInfo;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentOrder;
@@ -14,6 +15,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;
@@ -23,6 +25,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 
 import javax.swing.JInternalFrame;
 
@@ -30,12 +33,8 @@ public class HMMAlign extends HmmerCommand
 {
   static final String HMMALIGN = "hmmalign";
 
-  static final String ARG_TRIM = "--trim";
-
   private final AlignmentI dataset;
 
-  private AlignmentView msa;
-
   /**
    * Constructor for the HMMAlignThread
    * 
@@ -65,18 +64,17 @@ 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);
-    prepareAlignment();
-    SequenceI[][] subAlignments = msa.getVisibleContigs('-');
+
+    // ensure alignments are the same length
+    alignment.padGaps();
+
+    AlignmentView msa = af.gatherSequencesForAlignment();
+    SequenceI[][] subAlignments = msa.getVisibleContigs(alignment.getGapCharacter());
 
     List<AlignmentOrder> allOrders = new ArrayList<>();
 
@@ -84,12 +82,12 @@ public class HMMAlign extends HmmerCommand
     int job = 0;
     for (SequenceI[] seqs : subAlignments)
     {
-      Hashtable sequencesHash = stashSequences(seqs);
+      Map<String, SequenceInfo> 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());
@@ -97,8 +95,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;
         }
 
@@ -115,7 +113,8 @@ public class HMMAlign extends HmmerCommand
       job++;
     }
 
-    displayResults(allResults, allOrders);
+    String title = "hmmalign to " + hmm.getConsensusSequence().getName();
+    displayResults(allResults, allOrders, msa, title);
 
     af.setProgressBar("", msgId);
   }
@@ -134,8 +133,7 @@ public class HMMAlign extends HmmerCommand
    * @throws IOException
    */
   private boolean runCommand(File modelFile, File alignmentFile,
-          File resultFile)
-          throws IOException
+          File resultFile) throws IOException
   {
     String command = getCommandPath(HMMALIGN);
     if (command == null)
@@ -157,9 +155,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);
   }
@@ -177,7 +175,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);
@@ -188,26 +186,21 @@ public class HMMAlign extends HmmerCommand
   }
 
   /**
-   * Gathers the sequences in preparation for the alignment.
-   */
-  private void prepareAlignment()
-  {
-    msa = af.gatherSequencesForAlignment();
-  }
-
-  /**
    * Displays the results of all 'jobs' in a new frame
    * 
    * @param allResults
    * 
    * @param allOrders
+   * @param msa
+   * @param title
    */
   private void displayResults(SequenceI[][] allResults,
-          List<AlignmentOrder> allOrders)
+          List<AlignmentOrder> allOrders, AlignmentView msa, String title)
   {
     AlignmentOrder[] arrOrders = allOrders
             .toArray(new AlignmentOrder[allOrders.size()]);
-    Object[] newview = msa.getUpdatedView(allResults, arrOrders, '-');
+    Object[] newview = msa.getUpdatedView(allResults, arrOrders,
+            alignment.getGapCharacter());
     SequenceI[] seqs = (SequenceI[]) newview[0];
     HiddenColumns hidden = (HiddenColumns) newview[1];
     Alignment al = new Alignment(seqs);
@@ -217,7 +210,7 @@ public class HMMAlign extends HmmerCommand
       al.setDataset(dataset);
     }
 
-    displayInNewFrame(al, allOrders, hidden);
+    displayInNewFrame(al, allOrders, hidden, title);
   }
 
   /**
@@ -230,12 +223,14 @@ public class HMMAlign extends HmmerCommand
    *          run
    * @param hidden
    *          Hidden columns in the previous alignment
+   * @param title
    */
   private void displayInNewFrame(AlignmentI al,
-          List<AlignmentOrder> alorders, HiddenColumns hidden)
+          List<AlignmentOrder> alorders, HiddenColumns hidden, String title)
   {
     AlignFrame alignFrame = new AlignFrame(al, hidden, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
+    alignFrame.setTitle(title);
 
     FeatureRendererSettings featureSettings = af.getFeatureRenderer()
             .getSettings();