final List<AlignmentAnnotation> result = new ArrayList<>();
for (AlignmentAnnotation dsann : datasetAnnotations)
{
- /*
- * Find matching annotations on the alignment. If none is found, then
- * add this annotation to the list of 'addable' annotations for this
- * sequence.
- */
- final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
- .findAnnotations(seq, dsann.getCalcId(), dsann.label);
- if (!matchedAlignmentAnnotations.iterator().hasNext())
+ if (dsann.annotations != null) // ignore non-positional annotation
{
- result.add(dsann);
- if (labelForCalcId != null)
+ /*
+ * Find matching annotations on the alignment. If none is found, then
+ * add this annotation to the list of 'addable' annotations for this
+ * sequence.
+ */
+ final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
+ .findAnnotations(seq, dsann.getCalcId(), dsann.label);
+ if (!matchedAlignmentAnnotations.iterator().hasNext())
{
- labelForCalcId.put(dsann.getCalcId(), dsann.label);
+ result.add(dsann);
+ if (labelForCalcId != null)
+ {
+ labelForCalcId.put(dsann.getCalcId(), dsann.label);
+ }
}
}
- }
- /*
- * Save any addable annotations for this sequence
- */
- if (!result.isEmpty())
- {
- candidates.put(seq, result);
+ /*
+ * Save any addable annotations for this sequence
+ */
+ if (!result.isEmpty())
+ {
+ candidates.put(seq, result);
+ }
}
}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
}
if (viewport.getAlignment().getAlignmentAnnotation()
- .hashCode() != _annotationScoreVectorHash)
+ .hashCode() == _annotationScoreVectorHash)
{
- 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())
+ return;
+ }
+
+ sortByAnnotScore.removeAll();
+ Set<String> scoreSorts = new HashSet<>();
+ 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();
}
/**
}
@Override
- public void hmmerMenu_actionPerformed(ActionEvent e)
- {
- SequenceGroup grp = getViewport().getSelectionGroup();
- if (grp != null)
- {
- hmmBuild.setText(MessageManager.getString("label.hmmbuild") + " from "
- + grp.getName());
- }
- else
- {
- hmmBuild.setText(MessageManager.getString("label.hmmbuild")
- + " from Alignment");
- }
- }
-
- @Override
protected void loadVcf_actionPerformed()
{
JalviewFileChooser chooser = new JalviewFileChooser(
*/
private void checkIfModified()
{
- if (!adjusting)
+ Object newValue = updateSliderFromValueField();
+ boolean modified = true;
+ if (newValue.getClass() == lastVal.getClass())
{
- try
- {
- adjusting = true;
- Object newValue = updateSliderFromValueField();
- boolean modified = true;
- if (newValue.getClass() == lastVal.getClass())
- {
- modified = !newValue.equals(lastVal);
- }
- pmdialogbox.argSetModified(this, modified);
- } finally
- {
- adjusting = false;
- }
+ modified = !newValue.equals(lastVal);
}
+ pmdialogbox.argSetModified(this, modified);
}
@Override
if (isChoiceParameter)
{
choicebox = buildComboBox(parm);
+ choicebox.addActionListener(this);
controlsPanel.add(choicebox, BorderLayout.CENTER);
}
else
}
}
- if (!isChoiceParameter && parm != null)
+ String value = parm.getValue();
+ if (value != null)
{
- valueField.setText(parm.getValue());
+ if (isChoiceParameter)
+ {
+ choicebox.setSelectedItem(value);
+ }
+ else
+ {
+ valueField.setText(value);
+ }
}
lastVal = updateSliderFromValueField();
adjusting = false;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Annotation;
import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
import jalview.gui.JvOptionPane;
import jalview.io.DataSourceType;
import jalview.io.FileParse;
SequenceI[] seqs;
+ private String databaseName;
+
/**
* Constructor for the HMMSearchThread
*
return;
}
- SequenceI hmmSeq = hmm.getConsensusSequence();// af.getSelectedHMMSequence();
+ SequenceI hmmSeq = hmm.getConsensusSequence();
long msgId = System.currentTimeMillis();
af.setProgressBar(MessageManager.getString("status.running_hmmsearch"),
msgId);
List<String> args = new ArrayList<>();
args.add(command);
+ buildArguments(args, searchOutputFile, hitsAlignmentFile, hmmFile);
+
+ return runCommand(args);
+ }
+
+ /**
+ * Appends command line arguments to the given list, to specify input and
+ * output files for the search, and any additional options that may have been
+ * passed from the parameters dialog
+ *
+ * @param args
+ * @param searchOutputFile
+ * @param hitsAlignmentFile
+ * @param hmmFile
+ * @throws IOException
+ */
+ protected void buildArguments(List<String> args, File searchOutputFile,
+ File hitsAlignmentFile, File hmmFile) throws IOException
+ {
args.add("-o");
args.add(getFilePath(searchOutputFile));
args.add("-A");
String domEvalueCutoff = null;
String seqScoreCutoff = null;
String domScoreCutoff = null;
+ databaseName = "Alignment";
if (params != null)
{
else if (MessageManager.getString(AUTO_ALIGN_SEQS_KEY)
.equals(name))
{
- realign = true; // TODO: not used
+ realign = true;
}
else if (MessageManager.getString(USE_ACCESSIONS_KEY)
.equals(name))
if (!MessageManager.getString(THIS_ALIGNMENT_KEY)
.equals(dbPath))
{
+ int pos = dbPath.lastIndexOf(File.separator);
+ databaseName = dbPath.substring(pos + 1);
databaseFile = new File(dbPath);
}
}
args.add(getFilePath(hmmFile));
args.add(getFilePath(databaseFile));
-
- return runCommand(args);
}
/**
* Imports the data from the temporary file to which the output of hmmsearch
- * is directed.
+ * was directed. The results are optionally realigned using hmmalign.
*
* @param hmmSeq
*/
hmmAndSeqs[0] = hmmSeq;
System.arraycopy(seqs, 0, hmmAndSeqs, 1, seqCount);
- /*
- * and align the search results to the HMM profile
- */
- AlignmentI al = new Alignment(hmmAndSeqs);
- AlignFrame frame = new AlignFrame(al, 1, 1);
- List<ArgumentI> alignArgs = new ArrayList<>();
- String defSeq = hmmSeq.getName();
- List<String> options = Collections.singletonList(defSeq);
- Option option = new Option(MessageManager.getString("label.use_hmm"),
- "", true, defSeq, defSeq, options, null);
- alignArgs.add(option);
- if (trim)
+ if (realign)
{
- alignArgs.add(new BooleanOption(
- MessageManager.getString(TRIM_TERMINI_KEY),
- MessageManager.getString("label.trim_termini_desc"), true,
- true, true, null));
+ realignResults(hmmAndSeqs);
}
- HmmerCommand hmmalign = new HMMAlign(frame, alignArgs);
- hmmalign.run();
- frame = null;
+ else
+ {
+ AlignmentI al = new Alignment(hmmAndSeqs);
+ AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ String ttl = "hmmSearch of " + databaseName + " using "
+ + hmmSeq.getName();
+ Desktop.addInternalFrame(alignFrame, ttl, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ }
+
hmmTemp.delete();
inputAlignmentTemp.delete();
searchOutputFile.delete();
}
}
+ /**
+ * Realigns the given sequences using hmmalign, to the HMM profile sequence
+ * which is the first in the array, and opens the results in a new frame
+ *
+ * @param hmmAndSeqs
+ */
+ protected void realignResults(SequenceI[] hmmAndSeqs)
+ {
+ /*
+ * and align the search results to the HMM profile
+ */
+ AlignmentI al = new Alignment(hmmAndSeqs);
+ AlignFrame frame = new AlignFrame(al, 1, 1);
+ List<ArgumentI> alignArgs = new ArrayList<>();
+ String alignTo = hmmAndSeqs[0].getName();
+ List<String> options = Collections.singletonList(alignTo);
+ Option option = new Option(MessageManager.getString("label.use_hmm"),
+ "", true, alignTo, alignTo, options, null);
+ alignArgs.add(option);
+ if (trim)
+ {
+ alignArgs.add(new BooleanOption(
+ MessageManager.getString(TRIM_TERMINI_KEY),
+ MessageManager.getString("label.trim_termini_desc"), true,
+ true, true, null));
+ }
+ HmmerCommand hmmalign = new HMMAlign(frame, alignArgs);
+ hmmalign.run();
+ }
+
+ /**
+ * Reads in the scores table output by hmmsearch and adds annotation to
+ * sequences for E-value and bit score
+ *
+ * @param inputTableTemp
+ * @throws IOException
+ */
void readTable(File inputTableTemp) throws IOException
{
BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
while (!" ------ inclusion threshold ------".equals(line)
&& !"".equals(line))
{
+ SequenceI seq = seqs[index];
Scanner scanner = new Scanner(line);
-
- String str = scanner.next(); // full sequence eValue score
- float eValue = Float.parseFloat(str);
- int seqLength = seqs[index].getLength();
- Annotation[] annots = new Annotation[seqLength];
- for (int j = 0; j < seqLength; j++)
- {
- annots[j] = new Annotation(eValue);
- }
- AlignmentAnnotation annot = new AlignmentAnnotation("E-value",
- "Score", annots);
- annot.setScore(Double.parseDouble(str));
- annot.setSequenceRef(seqs[index]);
- seqs[index].addAlignmentAnnotation(annot);
-
+ String str = scanner.next();
+ addScoreAnnotation(str, seq, "hmmsearch E-value",
+ "Full sequence E-value");
+ str = scanner.next();
+ addScoreAnnotation(str, seq, "hmmsearch Score",
+ "Full sequence bit score");
scanner.close();
line = br.readLine();
index++;
br.close();
}
+ /**
+ * A helper method that adds one score-only (non-positional) annotation to a
+ * sequence
+ *
+ * @param value
+ * @param seq
+ * @param label
+ * @param description
+ */
+ protected void addScoreAnnotation(String value, SequenceI seq,
+ String label, String description)
+ {
+ try
+ {
+ AlignmentAnnotation annot = new AlignmentAnnotation(label,
+ description, null);
+ annot.setCalcId(HMMSEARCH);
+ double eValue = Double.parseDouble(value);
+ annot.setScore(eValue);
+ annot.setSequenceRef(seq);
+ seq.addAlignmentAnnotation(annot);
+ } catch (NumberFormatException e)
+ {
+ System.err.println("Error parsing " + label + " from " + value);
+ }
+ }
+
}
protected JMenu hmmerMenu = new JMenu();
- protected JMenu hmmAlign = new JMenu();
-
- protected JMenuItem hmmAlignRun = new JMenuItem();
-
- protected JMenuItem hmmAlignSettings = new JMenuItem();
-
- protected JMenu hmmSearch = new JMenu();
-
- protected JMenuItem hmmSearchRun = new JMenuItem();
-
- protected JMenuItem hmmSearchSettings = new JMenuItem();
-
- protected JMenuItem addDatabase = new JMenuItem();
-
- protected JMenu hmmBuild = new JMenu();
-
- protected JMenuItem hmmBuildRun = new JMenuItem();
-
- protected JMenuItem hmmBuildSettings = new JMenuItem();
-
protected JMenuItem webServiceNoServices;
protected JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
private void jbInit() throws Exception
{
initColourMenu();
- initHMMERMenu();
JMenuItem saveAs = new JMenuItem(
MessageManager.getString("action.save_as"));
JMenu calculateMenu = new JMenu(
MessageManager.getString("action.calculate"));
webService.setText(MessageManager.getString("action.web_service"));
- hmmerMenu.setText(MessageManager.getString("action.hmmer"));
- hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
- hmmerMenu.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmerMenu_actionPerformed(e);
- }
- });
- hmmerMenu.add(hmmBuild);
- hmmerMenu.add(hmmAlign);
- hmmerMenu.add(hmmSearch);
+
+ initHMMERMenu();
JMenuItem selectAllSequenceMenuItem = new JMenuItem(
MessageManager.getString("action.select_all"));
selectHighlightedColumns_actionPerformed(actionEvent);
}
};
- hmmBuildRun.setText(MessageManager.formatMessage(
- "label.action_with_default_settings", "hmmbuild"));
- hmmBuildRun.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmBuild_actionPerformed(true);
- }
- });
- hmmBuildSettings.setText(
- MessageManager.getString("label.edit_settings_and_run"));
- hmmBuildSettings.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmBuild_actionPerformed(false);
- }
- });
- hmmAlignRun.setText(MessageManager.formatMessage(
- "label.action_with_default_settings", "hmmalign"));
- hmmAlignRun.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmAlign_actionPerformed(true);
- }
- });
- hmmAlignSettings.setText(
- MessageManager.getString("label.edit_settings_and_run"));
- hmmAlignSettings.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmAlign_actionPerformed(false);
- }
- });
- hmmSearchRun.setText(MessageManager.formatMessage(
- "label.action_with_default_settings", "hmmsearch"));
- hmmSearchRun.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmSearch_actionPerformed(true);
- }
- });
- hmmSearchSettings.setText(
- MessageManager.getString("label.edit_settings_and_run"));
- hmmSearchSettings.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hmmSearch_actionPerformed(false);
- }
- });
- addDatabase.setText(MessageManager.getString("label.add_database"));
- addDatabase.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- try
- {
- addDatabase_actionPerformed();
- } catch (IOException e1)
- {
- e1.printStackTrace();
- }
- }
- });
selectHighlighted.addActionListener(al);
JMenu tooltipSettingsMenu = new JMenu(
MessageManager.getString("label.sequence_id_tooltip"));
// selectMenu.add(listenToViewSelections);
}
- public void hmmerMenu_actionPerformed(ActionEvent e)
- {
-
- }
-
/**
- * Constructs the entries on the HMMER menu (does not add them to the menu).
+ * Constructs the entries on the HMMER menu
*/
protected void initHMMERMenu()
{
- hmmAlign = new JMenu(MessageManager.getString("label.hmmalign"));
- hmmAlignSettings = new JMenuItem(
- MessageManager.getString("label.edit_settings_and_run"));
- hmmAlignRun = new JMenuItem(MessageManager.formatMessage(
- "label.action_with_default_settings", "hmmalign"));
- hmmAlign.add(hmmAlignSettings);
- hmmAlign.add(hmmAlignRun);
- hmmBuild = new JMenu(MessageManager.getString("label.hmmbuild"));
- hmmBuildSettings = new JMenuItem(
+ /*
+ * hmmbuild
+ */
+ JMenu hmmBuild = new JMenu(MessageManager.getString("label.hmmbuild"));
+ JMenuItem hmmBuildSettings = new JMenuItem(
MessageManager.getString("label.edit_settings_and_run"));
- hmmBuildRun = new JMenuItem(MessageManager.formatMessage(
+ hmmBuildSettings.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hmmBuild_actionPerformed(false);
+ }
+ });
+ JMenuItem hmmBuildRun = new JMenuItem(MessageManager.formatMessage(
"label.action_with_default_settings", "hmmbuild"));
- hmmBuild.add(hmmBuildSettings);
+ hmmBuildRun.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hmmBuild_actionPerformed(true);
+ }
+ });
hmmBuild.add(hmmBuildRun);
- hmmSearch = new JMenu(MessageManager.getString("label.hmmsearch"));
- hmmSearchSettings = new JMenuItem(
+ hmmBuild.add(hmmBuildSettings);
+
+ /*
+ * hmmalign
+ */
+ JMenu hmmAlign = new JMenu(MessageManager.getString("label.hmmalign"));
+ JMenuItem hmmAlignRun = new JMenuItem(MessageManager.formatMessage(
+ "label.action_with_default_settings", "hmmalign"));
+ hmmAlignRun.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hmmAlign_actionPerformed(true);
+ }
+ });
+ JMenuItem hmmAlignSettings = new JMenuItem(
+ MessageManager.getString("label.edit_settings_and_run"));
+ hmmAlignSettings.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hmmAlign_actionPerformed(false);
+ }
+ });
+ hmmAlign.add(hmmAlignRun);
+ hmmAlign.add(hmmAlignSettings);
+
+ /*
+ * hmmsearch
+ */
+ JMenu hmmSearch = new JMenu(
+ MessageManager.getString("label.hmmsearch"));
+ JMenuItem hmmSearchSettings = new JMenuItem(
MessageManager.getString("label.edit_settings_and_run"));
- hmmSearchRun = new JMenuItem(MessageManager.formatMessage(
+ hmmSearchSettings.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hmmSearch_actionPerformed(false);
+ }
+ });
+ JMenuItem hmmSearchRun = new JMenuItem(MessageManager.formatMessage(
"label.action_with_default_settings", "hmmsearch"));
- addDatabase = new JMenuItem(
+ hmmSearchRun.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hmmSearch_actionPerformed(true);
+ }
+ });
+ JMenuItem addDatabase = new JMenuItem(
MessageManager.getString("label.add_database"));
+ addDatabase.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ addDatabase_actionPerformed();
+ } catch (IOException e1)
+ {
+ e1.printStackTrace();
+ }
+ }
+ });
hmmSearch.add(hmmSearchSettings);
hmmSearch.add(hmmSearchRun);
hmmSearch.add(addDatabase);
+
+ /*
+ * top level menu
+ */
+ hmmerMenu.setText(MessageManager.getString("action.hmmer"));
+ hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
+ hmmerMenu.add(hmmBuild);
+ hmmerMenu.add(hmmAlign);
+ hmmerMenu.add(hmmSearch);
+
}
protected void loadVcf_actionPerformed()