import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.HiddenSequences;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SeqCigar;
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.params.ArgumentI;
import jalview.ws.params.ParamDatastoreI;
import jalview.ws.params.WsParamSetI;
-import jalview.ws.params.simple.Option;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
+import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Scanner;
+import java.util.Set;
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 class AlignFrame extends GAlignFrame implements DropTargetListener,
IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
{
-
- Map<String, Float> distribution = new HashMap<>(); // temporary
-
public static final int DEFAULT_WIDTH = 700;
public static final int DEFAULT_HEIGHT = 500;
AlignViewport viewport;
public AlignViewControllerI avc;
- /*
- * The selected HMM for this align frame
- */
- SequenceI selectedHMMSequence;
List<AlignmentPanel> alignPanels = new ArrayList<>();
{
return;
}
- List<ArgumentI> args = new ArrayList<>();
- if (withDefaults)
- {
- // todo: construct this in HMMERPreset?
- String argName = MessageManager.getString("label.hmmbuild_for");
- String argValue = MessageManager.getString("label.alignment");
- args.add(
- new Option(argName, null, false, null, argValue, null, null));
- }
- else
+
+ /*
+ * get default parameters, and optionally show a dialog
+ * to allow them to be modified
+ */
+ ParamDatastoreI store = HMMERParamStore.forBuild(viewport);
+ List<ArgumentI> args = store.getServiceParameters();
+
+ if (!withDefaults)
{
WsParamSetI set = new HMMERPreset();
- ParamDatastoreI store = HMMERParamStore.forBuild();
- WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
- args);
+ WsJobParameters params = new WsJobParameters(store, set, args);
if (params.showRunDialog())
{
args = params.getJobParams();
{
return;
}
- List<ArgumentI> args = new ArrayList<>();
+
+ /*
+ * get default parameters, and optionally show a dialog
+ * to allow them to be modified
+ */
+ ParamDatastoreI store = HMMERParamStore.forAlign(viewport);
+ List<ArgumentI> args = store.getServiceParameters();
+
if (!withDefaults)
{
WsParamSetI set = new HMMERPreset();
- ParamDatastoreI store = HMMERParamStore.forAlign();
- WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
- args);
+ WsJobParameters params = new WsJobParameters(store, set, args);
if (params.showRunDialog())
{
args = params.getJobParams();
{
return;
}
- List<ArgumentI> args = new ArrayList<>();
+
+ /*
+ * get default parameters, and (if requested) show
+ * dialog to allow modification
+ */
+ ParamDatastoreI store = HMMERParamStore.forSearch(viewport);
+ List<ArgumentI> args = store.getServiceParameters();
+
if (!withDefaults)
{
WsParamSetI set = new HMMERPreset();
- ParamDatastoreI store = HMMERParamStore.forSearch();
- WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
- args);
+ WsJobParameters params = new WsJobParameters(store, set, args);
if (params.showRunDialog())
{
args = params.getJobParams();
}
/**
- * Checks if the frame has a selected hidden Markov model
+ * Checks if the alignment has at least one hidden Markov model, if not shows
+ * a dialog advising to run hmmbuild or load an HMM profile
*
* @return
*/
private boolean checkForHMM()
{
- if (getSelectedHMM() == null)
+ if (viewport.getAlignment().getHmmSequences().isEmpty())
{
JOptionPane.showMessageDialog(this,
- MessageManager.getString("warn.no_selected_hmm"));
+ MessageManager.getString("warn.no_hmm"));
return false;
}
return true;
if (getViewport().getAlignment().getSequences().size() < required)
{
JOptionPane.showMessageDialog(this,
- MessageManager.getString("warn.not_enough_sequences"));
+ MessageManager.getString("label.not_enough_sequences"));
return false;
}
return true;
}
+ /**
+ * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
+ * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
+ * comma-separated list)
+ */
@Override
public void addDatabase_actionPerformed() throws IOException
{
- if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null)
+ if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
{
Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
- Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
}
String path = openFileChooser(false);
- if (new File(path).exists())
+ if (path != null && 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, File.separator);
- 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);
+ .getProperty(Preferences.HMMSEARCH_DBS);
+ currentDbPaths += Preferences.COMMA + path;
Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
}
else
MessageManager.getString("warn.invalid_format"));
}
}
- else
- {
- JOptionPane.showMessageDialog(this,
- MessageManager.getString("warn.not_enough_sequences"));
- }
}
/**
- * Opens a file chooser
+ * Opens a file chooser, optionally restricted to selecting folders
+ * (directories) only. Answers the path to the selected file or folder, or
+ * null if none is chosen.
*
- * @param forFolder
+ * @param
* @return
*/
protected String openFileChooser(boolean forFolder)
{
+ // TODO duplicates GPreferences method - relocate to JalviewFileChooser?
String choice = null;
JFileChooser chooser = new JFileChooser();
if (forFolder)
}
if (viewport.getAlignment().getAlignmentAnnotation()
- .hashCode() != _annotationScoreVectorHash)
+ .hashCode() == _annotationScoreVectorHash)
+ {
+ return;
+ }
+
+ sortByAnnotScore.removeAll();
+ Set<String> scoreSorts = new HashSet<>();
+ for (SequenceI sqa : viewport.getAlignment().getSequences())
{
- sortByAnnotScore.removeAll();
- // almost certainly a quicker way to do this - but we keep it simple
- Hashtable scoreSorts = new Hashtable();
- AlignmentAnnotation aann[];
- for (SequenceI sqa : viewport.getAlignment().getSequences())
+ AlignmentAnnotation[] anns = sqa.getAnnotation();
+ for (int i = 0; anns != null && i < anns.length; i++)
{
- aann = sqa.getAnnotation();
- for (int i = 0; aann != null && i < aann.length; i++)
+ AlignmentAnnotation aa = anns[i];
+ if (aa != null && aa.hasScore() && aa.sequenceRef != null)
{
- if (aann[i].hasScore() && aann[i].sequenceRef != null)
- {
- scoreSorts.put(aann[i].label, aann[i].label);
- }
+ scoreSorts.add(aa.label);
}
}
- Enumeration labels = scoreSorts.keys();
- while (labels.hasMoreElements())
- {
- addSortByAnnotScoreMenuItem(sortByAnnotScore,
- (String) labels.nextElement());
- }
- sortByAnnotScore.setVisible(scoreSorts.size() > 0);
- scoreSorts.clear();
-
- _annotationScoreVectorHash = viewport.getAlignment()
- .getAlignmentAnnotation().hashCode();
}
+ for (String label : scoreSorts)
+ {
+ addSortByAnnotScoreMenuItem(sortByAnnotScore, label);
+ }
+ sortByAnnotScore.setVisible(!scoreSorts.isEmpty());
+
+ _annotationScoreVectorHash = viewport.getAlignment()
+ .getAlignmentAnnotation().hashCode();
}
/**
hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
}
- /**
- * Returns the selected hidden Markov model.
- *
- * @return
- */
- public HiddenMarkovModel getSelectedHMM()
- {
- if (selectedHMMSequence == null)
- {
- return null;
- }
- return selectedHMMSequence.getHMM();
- }
-
- /**
- * Returns the selected hidden Markov model.
- *
- * @return
- */
- public SequenceI getSelectedHMMSequence()
- {
- return selectedHMMSequence;
- }
-
- /**
- * Sets the selected hidden Markov model
- *
- * @param selectedHMM
- */
- public void setSelectedHMMSequence(SequenceI selectedHMM)
- {
- this.selectedHMMSequence = selectedHMM;
- hmmAlign.setText(MessageManager.getString("label.hmmalign") + " to "
- + selectedHMM.getHMM().getName());
- hmmSearch.setText(MessageManager.getString("label.hmmsearch") + " with "
- + selectedHMM.getHMM().getName());
- }
-
@Override
public void hmmerMenu_actionPerformed(ActionEvent e)
{