import jalview.gui.ViewSelectionMenu.ViewSetProvider;
import jalview.hmmer.HMMAlignThread;
import jalview.hmmer.HMMBuildThread;
+import jalview.hmmer.HMMERParamStore;
+import jalview.hmmer.HMMERPreset;
+import jalview.hmmer.HMMSearchThread;
import jalview.io.AlignmentProperties;
import jalview.io.AnnotationFile;
import jalview.io.BioJsHTMLOutput;
import jalview.schemes.ResidueColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.util.MessageManager;
+import jalview.util.StringUtils;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.WsParamSetI;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.awt.BorderLayout;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.Scanner;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JEditorPane;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
public static final int DEFAULT_HEIGHT = 500;
- boolean autoAlignNewSequences;
-
-
/*
* The currently displayed panel (selected tabbed view if more than one)
*/
}
@Override
- public void hmmBuild_actionPerformed(ActionEvent e)
+ public void hmmBuildSettings_actionPerformed(ActionEvent e)
throws IOException, InterruptedException
{
- new Thread(new HMMBuildThread(this)).start();
+ if (!(alignmentIsSufficient(1)))
+ {
+ return;
+ }
+ WsParamSetI set = new HMMERPreset();
+ List<ArgumentI> args = new ArrayList<>();
+ ParamDatastoreI store = new HMMERParamStore("hmmbuild");
+ WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+ args);
+ if (params.showRunDialog())
+ {
+ new Thread(new HMMBuildThread(this, params.getJobParams())).start();
+ }
alignPanel.repaint();
}
@Override
- public void hmmAlign_actionPerformed(ActionEvent e)
+ public void hmmAlignSettings_actionPerformed(ActionEvent e)
throws IOException, InterruptedException
{
- new Thread(new HMMAlignThread(this, true)).start();
+ if (!(checkForHMM() && alignmentIsSufficient(2)))
+ {
+ return;
+ }
+ WsParamSetI set = new HMMERPreset();
+ List<ArgumentI> args = new ArrayList<>();
+ ParamDatastoreI store = new HMMERParamStore("hmmalign");
+ WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+ args);
+ if (params.showRunDialog())
+ {
+ new Thread(new HMMAlignThread(this, true, params.getJobParams()))
+ .start();
+ }
alignPanel.repaint();
}
@Override
- public void changeHMMERLocation_actionPerformed(ActionEvent e)
+ public void hmmSearchSettings_actionPerformed(ActionEvent e)
{
- String location = JOptionPane.showInputDialog(
- MessageManager.getString("label.enter_location"));
- Cache.setProperty(Preferences.HMMER_PATH, location);
+ if (!checkForHMM())
+ {
+ return;
+ }
+ WsParamSetI set = new HMMERPreset();
+ List<ArgumentI> args = new ArrayList<>();
+ ParamDatastoreI store = new HMMERParamStore("hmmsearch");
+ WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+ args);
+ if (params.showRunDialog())
+ {
+ new Thread(new HMMSearchThread(this, true, params.getJobParams()))
+ .start();
+ }
+ alignPanel.repaint();
}
@Override
- public void hmmSearch_actionPerformed(ActionEvent e)
+ public void hmmBuildRun_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
{
+ if (!alignmentIsSufficient(1))
+ {
+ return;
+ }
+ new Thread(new HMMBuildThread(this, null))
+ .start();
alignPanel.repaint();
+
+ }
+
+ @Override
+ public void hmmAlignRun_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
+ {
+ if (!(checkForHMM() && alignmentIsSufficient(2)))
+ {
+ return;
+ }
+ new Thread(new HMMAlignThread(this, true, null))
+ .start();
+ alignPanel.repaint();
+ }
+
+ @Override
+ public void hmmSearchRun_actionPerformed(ActionEvent e)
+ {
+ if (!checkForHMM())
+ {
+ return;
+ }
+ new Thread(new HMMSearchThread(this, true, null))
+ .start();
+ alignPanel.repaint();
+ }
+
+ /**
+ * Checks if the frame has a selected hidden Markov model
+ *
+ * @return
+ */
+ private boolean checkForHMM()
+ {
+ if (getSelectedHMM() == null)
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.no_selected_hmm"));
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Checks if the alignment contains the required number of sequences.
+ *
+ * @param required
+ * @return
+ */
+ public boolean alignmentIsSufficient(int required)
+ {
+ if (getViewport().getAlignment().getSequences().size() < required)
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.not_enough_sequences"));
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void addDatabase_actionPerformed(ActionEvent e) throws IOException
+ {
+ if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null)
+ {
+ Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
+ Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
+ }
+
+ String path = openFileChooser(false);
+ if (new File(path).exists())
+ {
+ IdentifyFile identifier = new IdentifyFile();
+ FileFormatI format = identifier.identify(path, DataSourceType.FILE);
+ if (format == FileFormat.Fasta || format == FileFormat.Stockholm
+ || format == FileFormat.Pfam)
+ {
+ String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS);
+ String currentDbPaths = Cache
+ .getProperty(Preferences.HMMSEARCH_DB_PATHS);
+ currentDbPaths += " " + path;
+
+ String fileName = StringUtils.getLastToken(path, new String("/"));
+ Scanner scanner = new Scanner(fileName).useDelimiter(".");
+ String name = scanner.next();
+ scanner.close();
+ currentDbs += " " + path; // TODO remove path from file name
+ scanner.close();
+
+ Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths);
+ Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
+ }
+ else
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.invalid_format"));
+ }
+ }
+ else
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.not_enough_sequences"));
+ }
+ }
+
+ /**
+ * Opens a file chooser
+ *
+ * @param forFolder
+ * @return
+ */
+ protected String openFileChooser(boolean forFolder)
+ {
+ String choice = null;
+ JFileChooser chooser = new JFileChooser();
+ if (forFolder)
+ {
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ }
+ chooser.setDialogTitle(
+ MessageManager.getString("label.open_local_file"));
+ chooser.setToolTipText(MessageManager.getString("action.open"));
+
+ int value = chooser.showOpenDialog(this);
+
+ if (value == JFileChooser.APPROVE_OPTION)
+ {
+ choice = chooser.getSelectedFile().getPath();
+ }
+ return choice;
}
@Override
{
this.selectedHMMSequence = selectedHMM;
hmmAlign.setText(MessageManager.getString("label.hmmalign") + " to "
- + selectedHMM.getHMM().getName() + "_HMM");
+ + selectedHMM.getHMM().getName());
hmmSearch.setText(MessageManager.getString("label.hmmsearch") + " with "
- + selectedHMM.getHMM().getName() + "_HMM");
+ + selectedHMM.getHMM().getName());
}
@Override