X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=8eb09abafb141569b1c3f79f92f54cc2283efe42;hb=3ba37699f5f799d357e0cb6f041f32fc490b6eda;hp=ab1ac0e1b533b8a208d859c7996dd24fb6e5d7c5;hpb=3965e9e3bc4ca05dcc82b8dc72c380f208c9a1e6;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ab1ac0e..8eb09ab 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -34,7 +34,7 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsControllerI; import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.SimilarityParamsI; import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.commands.CommandI; @@ -69,6 +69,7 @@ import jalview.io.FileFormat; import jalview.io.FileFormatI; import jalview.io.FileFormats; import jalview.io.FileLoader; +import jalview.io.FileParse; import jalview.io.FormatAdapter; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; @@ -77,12 +78,12 @@ import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.io.JnetAnnotationMaker; import jalview.io.NewickFile; +import jalview.io.ScoreMatrixFile; import jalview.io.TCoffeeScoreFile; import jalview.jbgui.GAlignFrame; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemes; import jalview.schemes.ResidueColourScheme; -import jalview.schemes.ResidueProperties; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -364,7 +365,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, setMenusFromViewport(viewport); buildSortByAnnotationScoresMenu(); - buildTreeMenu(); + calculateTree.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + openTreePcaDialog(); + } + }); buildColourMenu(); if (Desktop.desktop != null) @@ -2750,6 +2759,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ newap.av.replaceMappings(viewport.getAlignment()); + /* + * start up cDNA consensus (if applicable) now mappings are in place + */ + if (newap.av.initComplementConsensus()) + { + newap.refresh(true); // adjust layout of annotations + } + newap.av.viewName = getNewViewName(viewTitle); addAlignmentPanel(newap, true); @@ -3327,7 +3344,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ if (ResidueColourScheme.USER_DEFINED.equals(name)) { - new UserDefinedColours(alignPanel, null); + new UserDefinedColours(alignPanel); return; } @@ -3348,10 +3365,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void changeColour(ColourSchemeI cs) { // TODO: pull up to controller method - if (cs != null) - { - ColourMenuHelper.setColourSelected(colourMenu, cs.getSchemeName()); - } + ColourMenuHelper.setColourSelected(colourMenu, cs); viewport.setGlobalColourScheme(cs); @@ -3437,7 +3451,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByPID(viewport.getAlignment(), viewport - .getAlignment().getSequenceAt(0), null); + .getAlignment().getSequenceAt(0)); addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.getAlignment())); alignPanel.paintAlignment(true); @@ -3531,35 +3545,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! - */ - @Override - public void PCAMenuItem_actionPerformed(ActionEvent e) - { - if (((viewport.getSelectionGroup() != null) - && (viewport.getSelectionGroup().getSize() < 4) && (viewport - .getSelectionGroup().getSize() > 0)) - || (viewport.getAlignment().getHeight() < 4)) - { - JvOptionPane - .showInternalMessageDialog( - this, - MessageManager - .getString("label.principal_component_analysis_must_take_least_four_input_sequences"), - MessageManager - .getString("label.sequence_selection_insufficient"), - JvOptionPane.WARNING_MESSAGE); - - return; - } - - new PCAPanel(alignPanel); - } - @Override public void autoCalculate_actionPerformed(ActionEvent e) { @@ -3584,67 +3569,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! - */ - @Override - public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) - { - newTreePanel("AV", "PID", "Average distance tree using PID"); - } - - /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! - */ - @Override - public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) - { - newTreePanel("NJ", "PID", "Neighbour joining tree using PID"); - } - - /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! - */ - @Override - protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) - { - newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); - } - - /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! - */ - @Override - protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) - { - newTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); - } - - /** - * DOCUMENT ME! + * Constructs a tree panel and adds it to the desktop * * @param type - * DOCUMENT ME! - * @param pwType - * DOCUMENT ME! - * @param title - * DOCUMENT ME! + * tree type (NJ or AV) + * @param modelName + * name of score model used to compute the tree + * @param options + * parameters for the distance or similarity calculation */ - void newTreePanel(String type, String pwType, String title) + void newTreePanel(String type, String modelName, SimilarityParamsI options) { + String frameTitle = ""; TreePanel tp; + boolean onSelection = false; if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize() > 0) { @@ -3680,45 +3619,29 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } } - - title = title + " on region"; - tp = new TreePanel(alignPanel, type, pwType); + onSelection = true; } else { - // are the visible sequences aligned? - if (!viewport.getAlignment().isAligned(false)) - { - JvOptionPane - .showMessageDialog( - Desktop.desktop, - MessageManager - .getString("label.sequences_must_be_aligned_before_creating_tree"), - MessageManager - .getString("label.sequences_not_aligned"), - JvOptionPane.WARNING_MESSAGE); - - return; - } - if (viewport.getAlignment().getHeight() < 2) { return; } - - tp = new TreePanel(alignPanel, type, pwType); } - title += " from "; + tp = new TreePanel(alignPanel, type, modelName, options); + frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : ""); + + frameTitle += " from "; if (viewport.viewName != null) { - title += viewport.viewName + " of "; + frameTitle += viewport.viewName + " of "; } - title += this.title; + frameTitle += this.title; - Desktop.addInternalFrame(tp, title, 600, 500); + Desktop.addInternalFrame(tp, frameTitle, 600, 500); } /** @@ -3840,48 +3763,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * call. Listeners are added to remove the menu item when the treePanel is * closed, and adjust the tree leaf to sequence mapping when the alignment is * modified. - * - * @param treePanel - * Displayed tree window. - * @param title - * SortBy menu item title. */ @Override - public void buildTreeMenu() + public void buildTreeSortMenu() { - calculateTree.removeAll(); - // build the calculate menu - - for (final String type : new String[] { "NJ", "AV" }) - { - String treecalcnm = MessageManager.getString("label.tree_calc_" - + type.toLowerCase()); - for (final String pwtype : ResidueProperties.scoreMatrices.keySet()) - { - JMenuItem tm = new JMenuItem(); - ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype); - if (sm.isDNA() == viewport.getAlignment().isNucleotide() - || sm.isProtein() == !viewport.getAlignment() - .isNucleotide()) - { - String smn = MessageManager.getStringOrReturn( - "label.score_model_", sm.getName()); - final String title = MessageManager.formatMessage( - "label.treecalc_title", treecalcnm, smn); - tm.setText(title);// - tm.addActionListener(new java.awt.event.ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - newTreePanel(type, pwtype, title); - } - }); - calculateTree.add(tm); - } - - } - } sortByTreeMenu.removeAll(); List comps = PaintRefresher.components.get(viewport @@ -4032,13 +3917,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (value == JalviewFileChooser.APPROVE_OPTION) { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - jalview.io.NewickFile fin = null; + String filePath = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", filePath); + NewickFile fin = null; try { - fin = new NewickFile(choice, DataSourceType.FILE); - viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree()); + fin = new NewickFile(filePath, DataSourceType.FILE); + viewport.setCurrentTree(showNewickTree(fin, filePath).getTree()); } catch (Exception ex) { JvOptionPane @@ -4060,25 +3945,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - public TreePanel ShowNewickTree(NewickFile nf, String title) + public TreePanel showNewickTree(NewickFile nf, String treeTitle) { - return ShowNewickTree(nf, title, 600, 500, 4, 5); + return showNewickTree(nf, treeTitle, 600, 500, 4, 5); } - public TreePanel ShowNewickTree(NewickFile nf, String title, - AlignmentView input) - { - return ShowNewickTree(nf, title, input, 600, 500, 4, 5); - } - - public TreePanel ShowNewickTree(NewickFile nf, String title, int w, + public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w, int h, int x, int y) { - return ShowNewickTree(nf, title, null, w, h, x, y); + return showNewickTree(nf, treeTitle, null, w, h, x, y); } /** - * Add a treeviewer for the tree extracted from a newick file object to the + * Add a treeviewer for the tree extracted from a Newick file object to the * current alignment view * * @param nf @@ -4097,7 +3976,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * position * @return TreePanel handle */ - public TreePanel ShowNewickTree(NewickFile nf, String title, + public TreePanel showNewickTree(NewickFile nf, String treeTitle, AlignmentView input, int w, int h, int x, int y) { TreePanel tp = null; @@ -4108,7 +3987,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (nf.getTree() != null) { - tp = new TreePanel(alignPanel, "FromFile", title, nf, input); + tp = new TreePanel(alignPanel, nf, treeTitle, input); tp.setSize(w, h); @@ -4117,7 +3996,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, tp.setLocation(x, y); } - Desktop.addInternalFrame(tp, title, w, h); + Desktop.addInternalFrame(tp, treeTitle, w, h); } } catch (Exception ex) { @@ -4690,10 +4569,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * Attempt to load a "dropped" file or URL string: First by testing whether - * it's an Annotation file, then a JNet file, and finally a features file. If - * all are false then the user may have dropped an alignment file onto this - * AlignFrame. + * Attempt to load a "dropped" file or URL string, by testing in turn for + * * * @param file * either a filename or a URL string. @@ -4767,7 +4649,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { format = new IdentifyFile().identify(file, sourceType); } - if (FileFormat.Jnet.equals(format)) + if (FileFormat.ScoreMatrix == format) + { + ScoreMatrixFile sm = new ScoreMatrixFile(new FileParse(file, + sourceType)); + sm.parse(); + // todo: i18n this message + statusBar + .setText(MessageManager.formatMessage( + "label.successfully_loaded_matrix", + sm.getMatrixName())); + } + else if (FileFormat.Jnet.equals(format)) { JPredFile predictions = new JPredFile(file, sourceType); new JnetAnnotationMaker(); @@ -5700,10 +5593,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, colourMenu.add(annotationColour); ColourSchemeI colourScheme = viewport.getGlobalColourScheme(); - String schemeName = colourScheme == null ? null : colourScheme - .getSchemeName(); + ColourMenuHelper.setColourSelected(colourMenu, colourScheme); + } - ColourMenuHelper.setColourSelected(colourMenu, schemeName); + /** + * Open a dialog (if not already open) that allows the user to select and + * calculate PCA or Tree analysis + */ + protected void openTreePcaDialog() + { + if (alignPanel.getCalculationDialog() == null) + { + new CalculationChooser(AlignFrame.this); + } } }