JAL-2629 add ability to select hmmer binaries folder
[jalview.git] / src / jalview / gui / AlignFrame.java
index 8ac7c8a..9b5681b 100644 (file)
@@ -63,7 +63,8 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
-import jalview.hmmer.HMMERCommands;
+import jalview.hmmer.HMMAlignThread;
+import jalview.hmmer.HMMBuildThread;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
 import jalview.io.BioJsHTMLOutput;
@@ -145,6 +146,7 @@ import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
 import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 
@@ -164,6 +166,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)
    */
@@ -334,6 +340,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     init();
   }
 
+  public void setIsRecurring(boolean status)
+  {
+    recurring = status;
+  }
+
   /**
    * initalise the alignframe from the underlying viewport data and the
    * configurations
@@ -496,6 +507,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     hmmerMenu.removeAll();
 
+    hmmerMenu.add(changeHMMERLocation);
+    hmmerMenu.addSeparator();
+
     hmmerMenu.add(autoAlignSeqs);
     hmmerMenu.addSeparator();
 
@@ -800,6 +814,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       ap.av.updateConservation(ap);
       ap.av.updateConsensus(ap);
       ap.av.updateStrucConsensus(ap);
+      ap.av.updateInformation(ap);
     }
   }
 
@@ -1038,22 +1053,37 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void hmmBuild_actionPerformed(ActionEvent e)
           throws IOException, InterruptedException
   {
-
-    HMMERCommands.hmmBuild(this);
+    new Thread(new HMMBuildThread(this)).start();
     alignPanel.repaint();
+
   }
 
   @Override
   public void hmmAlign_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
+    new Thread(new HMMAlignThread(this, true)).start();
+    alignPanel.repaint();
+  }
 
+  @Override
+  public void changeHMMERLocation_actionPerformed(ActionEvent e)
+  {
+    String location = JOptionPane.showInputDialog(
+            MessageManager.getString("label.enter_location"));
+    Cache.setProperty(Preferences.HMMER_PATH, location);
+  }
+
+  @Override
+  public void autoAlignSeqs_actionPerformed(boolean autoAlignSeqs)
+  {
+    autoAlignNewSequences = autoAlignSeqs;
     alignPanel.repaint();
   }
 
   @Override
   public void hmmSearch_actionPerformed(ActionEvent e)
   {
-
     alignPanel.repaint();
   }
 
@@ -1468,6 +1498,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(
@@ -1959,9 +1990,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);
   }
@@ -1971,9 +2005,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);
   }
@@ -1983,8 +2020,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
@@ -2312,7 +2351,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       System.out.println("Exception whilst pasting: " + ex);
       // could be anything being pasted in here
     }
-
   }
 
   @Override
@@ -4617,9 +4655,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
     {
@@ -4700,39 +4741,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 annotArray[] = getViewport().getAlignment()
-                    .getAlignmentAnnotation();
-
-            AlignmentAnnotation reference = null;
-            for (AlignmentAnnotation annot : annotArray)
-            {
-              if (annot.label.contains("Reference"))
-              {
-                reference = annot;
-              }
-            }
+            SequenceI hmmSeq = hmm.initHMMSequence(this, 0);
+            getViewport().initInformation(hmmSeq);
+            getViewport().updateInformation(alignPanel);
 
-            if (reference != null)
-            {
-              hmm.mapToReferenceAnnotation(reference);
-            }
-
-            AlignmentAnnotation annotation = hmm.createAnnotation(
-                    getViewport().getAlignment().getWidth());
-            getViewport().getAlignment().addAnnotation(annotation);
-            AlignmentI newAlignment = hmm
-                    .initPlaceholder(getViewport().getAlignment());
-            getViewport().setAlignment(newAlignment);
             isAnnotation = true;
-            alignPanel.repaint();
 
           }
           else if (FileFormat.Jnet.equals(format))
@@ -4759,12 +4774,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           else
           {
             new FileLoader().LoadFile(viewport, file, sourceType, format);
+            if (autoAlignNewSequences && !recurring)
+            {
+              new Thread(new HMMAlignThread(this, false)).start();
+            }
           }
         }
       }
       if (isAnnotation)
       {
-
         alignPanel.adjustAnnotationHeight();
         viewport.updateSequenceIdColours();
         buildSortByAnnotationScoresMenu();
@@ -5744,4 +5762,6 @@ class PrintThread extends Thread
       }
     }
   }
+
+
 }