From 89777a8ec581f13e3f28248e0391bce1103b8bb4 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Fri, 11 Aug 2017 16:09:01 +0100 Subject: [PATCH] JAL-2629 add ability to select HMMs --- resources/lang/Messages.properties | 4 + src/jalview/gui/PopupMenu.java | 309 +++++++++++++++----------- src/jalview/hmmer/HMMAlignThread.java | 22 +- src/jalview/viewmodel/AlignmentViewport.java | 68 ++++-- 4 files changed, 243 insertions(+), 160 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 339a764..96612f9 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1318,6 +1318,7 @@ label.warning_hidden = Warning: {0} {1} is currently hidden label.auto_align_seqs = Automatically Align New Sequences label.hmmalign = Align Sequences to HMM label.hmmbuild = Build HMM from Alignment +label.group_hmmbuild = Build HMM from Group label.hmmsearch = Search for Related Sequences label.change_hmmer_location = Set HMMER Installation Location warn.null_hmm = Please ensure the alignment contains a hidden Markov model. @@ -1325,3 +1326,6 @@ label.ignore_below_background_frequency = Ignore Below Background Frequency label.information_description = Information content, measured in bits label.enter_location = Please enter the path of your HMMER binaries folder. label.invalid_hmmer_folder = The folder that you selected does not contain the necessary HMMER binaries. +warn.no_selected_hmm = Please select a hidden Markov model sequence. +label.select_hmm = Select HMM +warn.no_sequence_data = No sequence data found. diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 0ebd271..e75798c 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -33,12 +33,14 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.DBRefEntry; import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.ColourMenuHelper.ColourChangeListener; +import jalview.hmmer.HMMBuildThread; import jalview.io.FileFormatI; import jalview.io.FileFormats; import jalview.io.FormatAdapter; @@ -157,6 +159,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener JMenuItem sequenceFeature = new JMenuItem(); + JMenuItem hmmBuildGroup = new JMenuItem(); + JMenuItem textColour = new JMenuItem(); JMenu jMenu1 = new JMenu(); @@ -179,7 +183,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * @param seq * DOCUMENT ME! */ - public PopupMenu(final AlignmentPanel ap, Sequence seq, List links) + public PopupMenu(final AlignmentPanel ap, Sequence seq, + List links) { this(ap, seq, links, null); } @@ -224,8 +229,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * 'reference annotations' that may be added to the alignment. First for the * currently selected sequence (if there is one): */ - final List selectedSequence = (seq == null ? Collections - . emptyList() : Arrays.asList(seq)); + final List selectedSequence = (seq == null + ? Collections. emptyList() : Arrays.asList(seq)); buildAnnotationTypesMenus(seqShowAnnotationsMenu, seqHideAnnotationsMenu, selectedSequence); configureReferenceAnnotationsMenu(seqAddReferenceAnnotations, @@ -234,9 +239,9 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener /* * And repeat for the current selection group (if there is one): */ - final List selectedGroup = (ap.av.getSelectionGroup() == null ? Collections - . emptyList() : ap.av.getSelectionGroup() - .getSequences()); + final List selectedGroup = (ap.av.getSelectionGroup() == null + ? Collections. emptyList() + : ap.av.getSelectionGroup().getSequences()); buildAnnotationTypesMenus(groupShowAnnotationsMenu, groupHideAnnotationsMenu, selectedGroup); configureReferenceAnnotationsMenu(groupAddReferenceAnnotations, @@ -256,13 +261,13 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequenceMenu.setText(sequence.getName()); if (seq == ap.av.getAlignment().getSeqrep()) { - makeReferenceSeq.setText(MessageManager - .getString("action.unmark_as_reference")); + makeReferenceSeq.setText( + MessageManager.getString("action.unmark_as_reference")); } else { - makeReferenceSeq.setText(MessageManager - .getString("action.set_as_reference")); + makeReferenceSeq.setText( + MessageManager.getString("action.set_as_reference")); } if (!ap.av.getAlignment().isNucleotide()) @@ -290,7 +295,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener menuItem = new JMenuItem(); menuItem.setText(MessageManager.formatMessage( "label.2d_rna_structure_line", - new Object[] { aa.label })); + new Object[] + { aa.label })); menuItem.addActionListener(new ActionListener() { @Override @@ -318,7 +324,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener menuItem = new JMenuItem(); menuItem.setText(MessageManager.formatMessage( "label.2d_rna_sequence_name", - new Object[] { seq.getName() })); + new Object[] + { seq.getName() })); menuItem.addActionListener(new ActionListener() { @Override @@ -350,12 +357,29 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener }); add(menuItem); + if (sequence.isHMMConsensusSequence()) + { + JMenuItem selectHMM = new JCheckBoxMenuItem(); + selectHMM.setText(MessageManager.getString("label.select_hmm")); + selectHMM.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + selectHMM_actionPerformed(e); + } + }); + add(selectHMM); + } + if (ap.av.getSelectionGroup() != null && ap.av.getSelectionGroup().getSize() > 1) { - menuItem = new JMenuItem(MessageManager.formatMessage( - "label.represent_group_with", - new Object[] { seq.getName() })); + menuItem = new JMenuItem( + MessageManager.formatMessage("label.represent_group_with", + new Object[] + { seq.getName() })); menuItem.addActionListener(new ActionListener() { @Override @@ -416,8 +440,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } SequenceGroup sg = ap.av.getSelectionGroup(); - boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment() - .getGroups().contains(sg) : false; + boolean isDefinedGroup = (sg != null) + ? ap.av.getAlignment().getGroups().contains(sg) : false; if (sg != null && sg.getSize() > 0) { @@ -451,7 +475,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener buildGroupURLMenu(sg, groupLinks); } // Add a 'show all structures' for the current selection - Hashtable pdbe = new Hashtable<>(), reppdb = new Hashtable<>(); + Hashtable pdbe = new Hashtable<>(), + reppdb = new Hashtable<>(); SequenceI sqass = null; for (SequenceI sq : ap.av.getSequenceSelection()) { @@ -471,9 +496,9 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } if (pdbe.size() > 0) { - final PDBEntry[] pe = pdbe.values().toArray( - new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray( - new PDBEntry[reppdb.size()]); + final PDBEntry[] pe = pdbe.values() + .toArray(new PDBEntry[pdbe.size()]), + pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]); final JMenuItem gpdbview, rpdbview; } } @@ -585,9 +610,11 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener showMenu.removeAll(); hideMenu.removeAll(); - final List all = Arrays.asList(new String[] { MessageManager - .getString("label.all") }); - addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true); + final List all = Arrays + .asList(new String[] + { MessageManager.getString("label.all") }); + addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, + true); addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true, false); showMenu.addSeparator(); @@ -713,8 +740,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener for (int sq = 0; sq < seqs.length; sq++) { - int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq] - .findPosition(sg.getEndRes()); + int start = seqs[sq].findPosition(sg.getStartRes()), + end = seqs[sq].findPosition(sg.getEndRes()); // just collect ids from dataset sequence // TODO: check if IDs collected from selecton group intersects with the // current selection, too @@ -741,8 +768,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener if (((String[]) sarray[1])[sq] == null) { - if (!dbr[d].hasMap() - || (dbr[d].getMap().locateMappedRange(start, end) != null)) + if (!dbr[d].hasMap() || (dbr[d].getMap() + .locateMappedRange(start, end) != null)) { ((String[]) sarray[1])[sq] = dbr[d].getAccessionId(); ((int[]) sarray[0])[0]++; @@ -814,9 +841,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener int type = urlLink.getGroupURLType() & 3; // first two bits ofurlLink type bitfield are sequenceids and sequences // TODO: FUTURE: ensure the groupURL menu structure can be generalised - addshowLink(linkMenus[type], label - + (((type & 1) == 1) ? ("(" - + (usingNames ? "Names" : ltarget) + ")") : ""), + addshowLink(linkMenus[type], label + (((type & 1) == 1) + ? ("(" + (usingNames ? "Names" : ltarget) + ")") : ""), urlLink, urlset); addMenu = true; } @@ -838,7 +864,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } } - private void addshowLinks(JMenu linkMenu, Collection> linkset) + private void addshowLinks(JMenu linkMenu, + Collection> linkset) { for (List linkstrset : linkset) { @@ -859,8 +886,9 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener private void addshowLink(JMenu linkMenu, String label, final String url) { JMenuItem item = new JMenuItem(label); - item.setToolTipText(MessageManager.formatMessage( - "label.open_url_param", new Object[] { url })); + item.setToolTipText(MessageManager.formatMessage("label.open_url_param", + new Object[] + { url })); item.addActionListener(new ActionListener() { @Override @@ -897,10 +925,11 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener final GroupUrlLink urlgenerator, final Object[] urlstub) { JMenuItem item = new JMenuItem(label); - item.setToolTipText(MessageManager.formatMessage( - "label.open_url_seqs_param", - new Object[] { urlgenerator.getUrl_prefix(), - urlgenerator.getNumberInvolved(urlstub) })); + item.setToolTipText( + MessageManager.formatMessage("label.open_url_seqs_param", + new Object[] + { urlgenerator.getUrl_prefix(), + urlgenerator.getNumberInvolved(urlstub) })); // TODO: put in info about what is being sent. item.addActionListener(new ActionListener() { @@ -947,8 +976,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } }); sequenceMenu.setText(MessageManager.getString("label.sequence")); - sequenceName.setText(MessageManager - .getString("label.edit_name_description")); + sequenceName.setText( + MessageManager.getString("label.edit_name_description")); sequenceName.addActionListener(new ActionListener() { @Override @@ -957,8 +986,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequenceName_actionPerformed(); } }); - chooseAnnotations.setText(MessageManager - .getString("action.choose_annotations")); + chooseAnnotations + .setText(MessageManager.getString("action.choose_annotations")); chooseAnnotations.addActionListener(new ActionListener() { @Override @@ -967,8 +996,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener chooseAnnotations_actionPerformed(e); } }); - sequenceDetails.setText(MessageManager - .getString("label.sequence_details")); + sequenceDetails + .setText(MessageManager.getString("label.sequence_details")); sequenceDetails.addActionListener(new ActionListener() { @Override @@ -977,8 +1006,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequenceDetails_actionPerformed(); } }); - sequenceSelDetails.setText(MessageManager - .getString("label.sequence_details")); + sequenceSelDetails + .setText(MessageManager.getString("label.sequence_details")); sequenceSelDetails.addActionListener(new ActionListener() { @Override @@ -998,8 +1027,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener unGroupMenuItem_actionPerformed(); } }); - createGroupMenuItem.setText(MessageManager - .getString("action.create_group")); + createGroupMenuItem + .setText(MessageManager.getString("action.create_group")); createGroupMenuItem.addActionListener(new ActionListener() { @Override @@ -1047,8 +1076,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener showColourText_actionPerformed(); } }); - displayNonconserved.setText(MessageManager - .getString("label.show_non_conserved")); + displayNonconserved + .setText(MessageManager.getString("label.show_non_conserved")); displayNonconserved.setState(true); displayNonconserved.addActionListener(new ActionListener() { @@ -1104,18 +1133,18 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener changeCase(e); } }); - outputMenu.setText(MessageManager.getString("label.out_to_textbox") - + "..."); - seqShowAnnotationsMenu.setText(MessageManager - .getString("label.show_annotations")); - seqHideAnnotationsMenu.setText(MessageManager - .getString("label.hide_annotations")); - groupShowAnnotationsMenu.setText(MessageManager - .getString("label.show_annotations")); - groupHideAnnotationsMenu.setText(MessageManager - .getString("label.hide_annotations")); - sequenceFeature.setText(MessageManager - .getString("label.create_sequence_feature")); + outputMenu.setText( + MessageManager.getString("label.out_to_textbox") + "..."); + seqShowAnnotationsMenu + .setText(MessageManager.getString("label.show_annotations")); + seqHideAnnotationsMenu + .setText(MessageManager.getString("label.hide_annotations")); + groupShowAnnotationsMenu + .setText(MessageManager.getString("label.show_annotations")); + groupHideAnnotationsMenu + .setText(MessageManager.getString("label.hide_annotations")); + sequenceFeature.setText( + MessageManager.getString("label.create_sequence_feature")); sequenceFeature.addActionListener(new ActionListener() { @Override @@ -1124,9 +1153,18 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequenceFeature_actionPerformed(); } }); + hmmBuildGroup.setText(MessageManager.getString("label.group_hmmbuild")); + hmmBuildGroup.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + hmmBuildGroup_actionPerformed(); + } + }); jMenu1.setText(MessageManager.getString("label.group")); - pdbStructureDialog.setText(MessageManager - .getString("label.show_pdbstruct_dialog")); + pdbStructureDialog.setText( + MessageManager.getString("label.show_pdbstruct_dialog")); pdbStructureDialog.addActionListener(new ActionListener() { @Override @@ -1141,12 +1179,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } }); - rnaStructureMenu.setText(MessageManager - .getString("label.view_rna_structure")); + rnaStructureMenu + .setText(MessageManager.getString("label.view_rna_structure")); // colStructureMenu.setText("Colour By Structure"); - editSequence.setText(MessageManager.getString("label.edit_sequence") - + "..."); + editSequence.setText( + MessageManager.getString("label.edit_sequence") + "..."); editSequence.addActionListener(new ActionListener() { @Override @@ -1155,8 +1193,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener editSequence_actionPerformed(actionEvent); } }); - makeReferenceSeq.setText(MessageManager - .getString("label.mark_as_representative")); + makeReferenceSeq.setText( + MessageManager.getString("label.mark_as_representative")); makeReferenceSeq.addActionListener(new ActionListener() { @@ -1167,8 +1205,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } }); - hideInsertions.setText(MessageManager - .getString("label.hide_insertions")); + hideInsertions + .setText(MessageManager.getString("label.hide_insertions")); hideInsertions.addActionListener(new ActionListener() { @@ -1232,7 +1270,20 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener jMenu1.add(outline); jMenu1.add(displayNonconserved); } - + + protected void hmmBuildGroup_actionPerformed() + { + new Thread(new HMMBuildThread(ap.alignFrame)).start(); + ap.repaint(); + + } + + protected void selectHMM_actionPerformed(ActionEvent e) + { + HiddenMarkovModel hmm = ap.av.getSequenceSelection()[0].getHMM(); + ap.av.setSelectedHMM(hmm); + } + /** * Constructs the entries for the colour menu */ @@ -1249,8 +1300,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } }); - abovePIDColour.setText(MessageManager - .getString("label.above_identity_threshold")); + abovePIDColour.setText( + MessageManager.getString("label.above_identity_threshold")); abovePIDColour.addActionListener(new ActionListener() { @Override @@ -1260,8 +1311,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } }); - modifyPID.setText(MessageManager - .getString("label.modify_identity_threshold")); + modifyPID.setText( + MessageManager.getString("label.modify_identity_threshold")); modifyPID.addActionListener(new ActionListener() { @Override @@ -1271,15 +1322,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } }); - conservationMenuItem.setText(MessageManager - .getString("action.by_conservation")); + conservationMenuItem + .setText(MessageManager.getString("action.by_conservation")); conservationMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - conservationMenuItem_actionPerformed(conservationMenuItem - .isSelected()); + conservationMenuItem_actionPerformed( + conservationMenuItem.isSelected()); } }); @@ -1340,8 +1391,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup() // .getName()); // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus()); - SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup() - .getName()); + SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName()); SliderPanel.showPIDSlider(); } } @@ -1371,8 +1421,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener SortedMap tipEntries = new TreeMap<>(); final Map> candidates = new LinkedHashMap<>(); AlignmentI al = this.ap.av.getAlignment(); - AlignmentUtils.findAddableReferenceAnnotations(forSequences, - tipEntries, candidates, al); + AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries, + candidates, al); if (!candidates.isEmpty()) { StringBuilder tooltip = new StringBuilder(64); @@ -1482,19 +1532,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener for (SequenceI seq : sequences) { contents.append("

" - + MessageManager - .formatMessage( - "label.create_sequence_details_report_annotation_for", - new Object[] { seq.getDisplayId(true) }) + + MessageManager.formatMessage( + "label.create_sequence_details_report_annotation_for", + new Object[] + { seq.getDisplayId(true) }) + "

"); new SequenceAnnotationReport(null) - .createSequenceAnnotationReport( - contents, - seq, - true, - true, - (ap.getSeqPanel().seqCanvas.fr != null) ? ap - .getSeqPanel().seqCanvas.fr.getMinMax() + .createSequenceAnnotationReport(contents, seq, true, true, + (ap.getSeqPanel().seqCanvas.fr != null) + ? ap.getSeqPanel().seqCanvas.fr.getMinMax() : null); contents.append("

"); } @@ -1502,9 +1548,11 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener Desktop.addInternalFrame(cap, MessageManager.formatMessage( "label.sequence_details_for", - (sequences.length == 1 ? new Object[] { sequences[0] - .getDisplayId(true) } : new Object[] { MessageManager - .getString("label.selection") })), 500, 400); + (sequences.length == 1 + ? new Object[] + { sequences[0].getDisplayId(true) } + : new Object[] + { MessageManager.getString("label.selection") })), 500, 400); } @@ -1552,8 +1600,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sg.getStartRes(), sg.getEndRes() + 1)); int threshold = SliderPanel.setPIDSliderSource(ap, - sg.getGroupColourScheme(), getGroup() - .getName()); + sg.getGroupColourScheme(), getGroup().getName()); sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus()); @@ -1599,9 +1646,9 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener if (selected) { // JBPNote: Conservation name shouldn't be i18n translated - Conservation c = new Conservation("Group", sg.getSequences(ap.av - .getHiddenRepSequences()), sg.getStartRes(), - sg.getEndRes() + 1); + Conservation c = new Conservation("Group", + sg.getSequences(ap.av.getHiddenRepSequences()), + sg.getStartRes(), sg.getEndRes() + 1); c.calculate(); c.verdict(false, ap.av.getConsPercGaps()); @@ -1633,8 +1680,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener SequenceGroup sg = getGroup(); EditNameDialog dialog = new EditNameDialog(sg.getName(), - sg.getDescription(), " " - + MessageManager.getString("label.group_name") + " ", + sg.getDescription(), + " " + MessageManager.getString("label.group_name") + " ", MessageManager.getString("label.group_description") + " ", MessageManager.getString("label.edit_group_name_description"), ap.alignFrame); @@ -1692,14 +1739,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { if (dialog.getName().indexOf(" ") > -1) { - JvOptionPane - .showMessageDialog( - ap, - MessageManager - .getString("label.spaces_converted_to_backslashes"), - MessageManager - .getString("label.no_spaces_allowed_sequence_name"), - JvOptionPane.WARNING_MESSAGE); + JvOptionPane.showMessageDialog(ap, + MessageManager + .getString("label.spaces_converted_to_backslashes"), + MessageManager + .getString("label.no_spaces_allowed_sequence_name"), + JvOptionPane.WARNING_MESSAGE); } sequence.setName(dialog.getName().replace(' ', '_')); @@ -1708,8 +1753,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequence.setDescription(dialog.getDescription()); - ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() - .getSequences()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); } @@ -1857,8 +1902,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener ap.alignFrame.addHistoryItem(caseCommand); - ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() - .getSequences()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); } } @@ -1867,9 +1912,10 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { CutAndPasteTransfer cap = new CutAndPasteTransfer(); cap.setForInput(null); - Desktop.addInternalFrame(cap, MessageManager.formatMessage( - "label.alignment_output_command", - new Object[] { e.getActionCommand() }), 600, 500); + Desktop.addInternalFrame(cap, + MessageManager.formatMessage("label.alignment_output_command", + new Object[] + { e.getActionCommand() }), 600, 500); String[] omitHidden = null; @@ -1877,8 +1923,10 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener // or we simply trust the user wants // wysiwig behaviour - FileFormatI fileFormat = FileFormats.getInstance().forName(e.getActionCommand()); - cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true)); + FileFormatI fileFormat = FileFormats.getInstance() + .forName(e.getActionCommand()); + cap.setText( + new FormatAdapter(ap).formatSequences(fileFormat, ap, true)); } public void sequenceFeature_actionPerformed() @@ -1904,7 +1952,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener if (start <= end) { seqs.add(sg.getSequenceAt(i).getDatasetSequence()); - features.add(new SequenceFeature(null, null, null, start, end, null)); + features.add( + new SequenceFeature(null, null, null, start, end, null)); } } @@ -1957,8 +2006,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener EditNameDialog dialog = new EditNameDialog( sequence.getSequenceAsString(sg.getStartRes(), - sg.getEndRes() + 1), null, - MessageManager.getString("label.edit_sequence"), null, + sg.getEndRes() + 1), + null, MessageManager.getString("label.edit_sequence"), null, MessageManager.getString("label.edit_sequence"), ap.alignFrame); @@ -1966,15 +2015,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { EditCommand editCommand = new EditCommand( MessageManager.getString("label.edit_sequences"), - Action.REPLACE, dialog.getName().replace(' ', - ap.av.getGapCharacter()), + Action.REPLACE, + dialog.getName().replace(' ', ap.av.getGapCharacter()), sg.getSequencesAsArray(ap.av.getHiddenRepSequences()), sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment()); ap.alignFrame.addHistoryItem(editCommand); - ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() - .getSequences()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); } } } diff --git a/src/jalview/hmmer/HMMAlignThread.java b/src/jalview/hmmer/HMMAlignThread.java index 2674c8c..49fc49d 100644 --- a/src/jalview/hmmer/HMMAlignThread.java +++ b/src/jalview/hmmer/HMMAlignThread.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import javax.swing.JInternalFrame; +import javax.swing.JOptionPane; public class HMMAlignThread implements Runnable { @@ -71,7 +72,6 @@ public class HMMAlignThread implements Runnable { dataset = alignment.getDataset(); } - hmm = alignment.getSequenceAt(0).getHMM(); newFrame = createNewFrame; featureSettings = af.getFeatureRenderer().getSettings(); } @@ -79,6 +79,16 @@ public class HMMAlignThread implements Runnable @Override public void run() { + if (af.getViewport().getSelectedHMM() == null) + { + JOptionPane.showMessageDialog(af, + MessageManager.getString("warn.no_selected_hmm")); + return; + } + else + { + hmm = af.getViewport().getSelectedHMM(); + } barID = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); @@ -212,16 +222,6 @@ public class HMMAlignThread implements Runnable inputTemp.delete(); } - private void addSeqs(AlignFrame alignFrame, Map map) - { - for (Map.Entry entry : map.entrySet()) - { - SequenceI seq = entry.getValue(); - Integer pos = entry.getKey(); - cmds.addHMMConsensusSequence(alignFrame, seq, pos); - } - } - private void prepareAlignment() { // hmmSeqs = alignment.getHMMConsensusSequences(true); diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index ee129db..aa3a22d 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -36,6 +36,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.CigarArray; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.HiddenSequences; import jalview.datamodel.ProfileI; import jalview.datamodel.Profiles; @@ -99,6 +100,8 @@ public abstract class AlignmentViewport protected Deque redoList = new ArrayDeque<>(); + HiddenMarkovModel selectedHMM; + /** * alignment displayed in the viewport. Please use get/setter */ @@ -928,6 +931,7 @@ public abstract class AlignmentViewport /** * trigger update of information annotation */ + @Override public void updateInformation(final AlignmentViewPanel ap) { if (calculator @@ -1970,12 +1974,11 @@ public abstract class AlignmentViewport } updateInformation(ap); - Map hmmSequences; + List hmmSequences; hmmSequences = alignment.getHMMConsensusSequences(false); - for (Map.Entry entry : hmmSequences.entrySet()) + for (SequenceI seq : hmmSequences) { - SequenceI seq = entry.getValue(); seq.updateHMMMapping(); } @@ -2111,24 +2114,31 @@ public abstract class AlignmentViewport } } + @Override public void initInformation() { - for (SequenceI seq : alignment.getHMMConsensusSequences()) - { - AlignmentAnnotation information; - information = new AlignmentAnnotation(seq.getName(), - MessageManager.getString("label.information_description"), - new Annotation[1], 0f, 6.52f, AlignmentAnnotation.BAR_GRAPH); - information.hasText = true; - information.autoCalculated = true; - information.hasText = true; - information.autoCalculated = false; - information.sequenceRef = seq; - information.setCalcId("HMM annotation"); - this.information.add(information); - hinformation.add(new Profiles(new ProfileI[1])); - alignment.addAnnotation(information); - seq.updateHMMMapping(); + for (SequenceI seq : alignment.getHMMConsensusSequences(false)) + { + if (!seq.hasHMMAnnotation()) + { + AlignmentAnnotation information; + information = new AlignmentAnnotation(seq.getName(), + MessageManager.getString("label.information_description"), + new Annotation[1], 0f, 6.52f, + AlignmentAnnotation.BAR_GRAPH); + information.hasText = true; + information.autoCalculated = true; + information.hasText = true; + information.autoCalculated = false; + information.sequenceRef = seq; + information.setCalcId("HMM annotation"); + this.information.add(information); + hinformation.add(new Profiles(new ProfileI[1])); + alignment.addAnnotation(information); + seq.updateHMMMapping(); + seq.setHasInfo(true); + seq.addAlignmentAnnotation(information); + } } } @@ -3042,4 +3052,24 @@ public abstract class AlignmentViewport return searchResults; } + /** + * Gets the selected hidden Markov model + * + * @return + */ + public HiddenMarkovModel getSelectedHMM() + { + return selectedHMM; + } + + /** + * Sets the selected hidden Markov model + * + * @param selectedHMM + */ + public void setSelectedHMM(HiddenMarkovModel selectedHMM) + { + this.selectedHMM = selectedHMM; + } + } -- 1.7.10.2