JAL-2629 current hmmer commands are now executed in threads
[jalview.git] / src / jalview / gui / AlignFrame.java
index b14423c..dba6717 100644 (file)
@@ -63,6 +63,8 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
+import jalview.hmmer.HMMAlignThread;
+import jalview.hmmer.HMMBuildThread;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
 import jalview.io.BioJsHTMLOutput;
@@ -125,6 +127,7 @@ import java.awt.print.PrinterJob;
 import java.beans.PropertyChangeEvent;
 import java.io.File;
 import java.io.FileWriter;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.util.ArrayList;
@@ -162,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)
    */
@@ -798,6 +805,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       ap.av.updateConservation(ap);
       ap.av.updateConsensus(ap);
       ap.av.updateStrucConsensus(ap);
+      ap.av.updateInformation(ap);
     }
   }
 
@@ -1033,6 +1041,38 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
+  public void hmmBuild_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
+  {
+    new Thread(new HMMBuildThread(this)).start();
+    alignPanel.repaint();
+
+  }
+
+  @Override
+  public void hmmAlign_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
+  {
+    SequenceI seq = getViewport().getAlignment()
+            .getHMMConsensusSequences(false).get(0);
+    new Thread(new HMMAlignThread(this, true)).start();
+    alignPanel.repaint();
+  }
+
+  @Override
+  public void autoAlignSeqs_actionPerformed(boolean autoAlignSeqs)
+  {
+    autoAlignNewSequences = autoAlignSeqs;
+    alignPanel.repaint();
+  }
+
+  @Override
+  public void hmmSearch_actionPerformed(ActionEvent e)
+  {
+    alignPanel.repaint();
+  }
+
+  @Override
   public void reload_actionPerformed(ActionEvent e)
   {
     if (fileName != null)
@@ -1443,6 +1483,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(
@@ -1934,9 +1975,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);
   }
@@ -1946,9 +1990,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);
   }
@@ -1958,8 +2005,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
@@ -2287,7 +2336,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       System.out.println("Exception whilst pasting: " + ex);
       // could be anything being pasted in here
     }
-
   }
 
   @Override
@@ -4592,9 +4640,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
     {
@@ -4675,26 +4726,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else if (FileFormat.HMMER3.equals(format))
           {
-            HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType)); // TODO
-                                                                            // need
-                                                                            // to
-                                                                            // follow
-                                                                            // standard
-                                                                            // pipeline
-            hmmFile.parse();
+            HMMFile hmmFile = new HMMFile(new FileParse(file, sourceType));
             HiddenMarkovModel hmm = hmmFile.getHMM();
-            AlignmentAnnotation annotation = hmm.createAnnotation(
-                    getViewport().getAlignment().getWidth());
-            getViewport().getAlignment().addAnnotation(annotation);
-            annotation.setHMM(hmm);
-            int length = getViewport().getAlignment().getWidth();
-            Sequence consensus = hmm.getConsensusSequence(length);
-            SequenceI[] consensusArr = new Sequence[] { consensus };
-            AlignmentI newAlignment = new Alignment(consensusArr);
-            newAlignment.append(getViewport().getAlignment());
-            getViewport().setAlignment(newAlignment);
+            SequenceI hmmSeq = hmm.initHMMSequence(this, 0);
+            getViewport().initInformation(hmmSeq);
+            getViewport().updateInformation(alignPanel);
+
             isAnnotation = true;
-            alignPanel.repaint();
 
           }
           else if (FileFormat.Jnet.equals(format))
@@ -4726,7 +4764,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       if (isAnnotation)
       {
-
         alignPanel.adjustAnnotationHeight();
         viewport.updateSequenceIdColours();
         buildSortByAnnotationScoresMenu();
@@ -4751,6 +4788,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();
+      new Thread(new HMMAlignThread(this, false)).start();
+    }
+    recurring = false;
   }
 
   /**
@@ -5706,4 +5751,5 @@ class PrintThread extends Thread
       }
     }
   }
+
 }