JAL-2629 multiple HMMs can now be dropped onto an alignment
[jalview.git] / src / jalview / gui / AlignFrame.java
index 2168bd1..05b1e33 100644 (file)
@@ -165,6 +165,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   public static final int DEFAULT_HEIGHT = 500;
 
+  boolean autoAlignNewSequences;
+
+  boolean recurring;
+
   /*
    * The currently displayed panel (selected tabbed view if more than one)
    */
@@ -1050,14 +1054,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void hmmAlign_actionPerformed(ActionEvent e)
           throws IOException, InterruptedException
   {
-    HMMERCommands.hmmAlign(this);
+    SequenceI seq = getViewport().getAlignment()
+            .getHMMConsensusSequences(false).get(0);
+    HMMERCommands.hmmAlign(this, true, seq.getHMM());
     alignPanel.repaint();
   }
 
   @Override
-  public void hmmSearch_actionPerformed(ActionEvent e)
+  public void autoAlignSeqs_actionPerformed(boolean autoAlignSeqs)
   {
+    autoAlignNewSequences = autoAlignSeqs;
+    alignPanel.repaint();
+  }
 
+  @Override
+  public void hmmSearch_actionPerformed(ActionEvent e)
+  {
     alignPanel.repaint();
   }
 
@@ -1472,6 +1484,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   @Override
   public void associatedData_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
     // Pick the tree file
     JalviewFileChooser chooser = new JalviewFileChooser(
@@ -1963,9 +1976,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param e
    *          DOCUMENT ME!
+   * @throws InterruptedException
+   * @throws IOException
    */
   @Override
   protected void pasteNew_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
     paste(true);
   }
@@ -1975,9 +1991,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param e
    *          DOCUMENT ME!
+   * @throws InterruptedException
+   * @throws IOException
    */
   @Override
   protected void pasteThis_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
     paste(false);
   }
@@ -1987,8 +2006,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param newAlignment
    *          true to paste to a new alignment, otherwise add to this.
+   * @throws InterruptedException
+   * @throws IOException
    */
-  void paste(boolean newAlignment)
+  void paste(boolean newAlignment) throws IOException, InterruptedException
   {
     boolean externalPaste = true;
     try
@@ -2316,7 +2337,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       System.out.println("Exception whilst pasting: " + ex);
       // could be anything being pasted in here
     }
-
   }
 
   @Override
@@ -4621,9 +4641,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param file
    *          either a filename or a URL string.
+   * @throws InterruptedException
+   * @throws IOException
    */
   public void loadJalviewDataFile(String file, DataSourceType sourceType,
           FileFormatI format, SequenceI assocSeq)
+          throws IOException, InterruptedException
   {
     try
     {
@@ -4712,9 +4735,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                                                                             // pipeline
             hmmFile.parse();
             HiddenMarkovModel hmm = hmmFile.getHMM();
-
-            hmm.mapToReferenceAnnotation(this);
-            SequenceI hmmSeq = hmm.initPlaceholder(this);
+            SequenceI hmmSeq = hmm.initHMMSequence(this, 0);
             getViewport().initInformation(hmmSeq);
             new Thread(new InformationThread(getViewport(),
                     getViewport().getAlignPanel())
@@ -4722,7 +4743,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             }).start();
 
             isAnnotation = true;
-            alignPanel.repaint();
 
           }
           else if (FileFormat.Jnet.equals(format))
@@ -4778,6 +4798,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                       + (format != null ? "(parsing as '" + format
                               + "' file)" : ""), oom, Desktop.desktop);
     }
+    if (autoAlignNewSequences && !recurring)
+    {
+      recurring = true;
+      HiddenMarkovModel hmm = getViewport().getAlignment()
+              .getHMMConsensusSequences(false).get(0).getHMM();
+      HMMERCommands.hmmAlign(this, false, hmm);
+    }
+    recurring = false;
   }
 
   /**