+ public void hmmBuildSettings_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
+ {
+ 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 hmmAlignSettings_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
+ {
+ 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 hmmSearchSettings_actionPerformed(ActionEvent e)
+ {
+ 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 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