X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FTreePanel.java;h=32c5702fe47ca14cbaa04877afee31f76791a318;hb=f41d78dbf890fbb7597f75019d05841312fa4f52;hp=9ac2872a8b3173c4d55af634e8cce49092bcc74b;hpb=e2e2b85d7a8e3d7ed6926ef1bf55eb2328e744d1;p=jalview.git diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 9ac2872..32c5702 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -21,10 +21,13 @@ package jalview.gui; import jalview.analysis.AlignmentSorter; +import jalview.analysis.AverageDistanceTree; import jalview.analysis.NJTree; +import jalview.analysis.TreeBuilder; +import jalview.analysis.TreeModel; +import jalview.analysis.scoremodels.ScoreModels; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; -import jalview.api.analysis.ViewBasedAnalysisI; import jalview.bin.Cache; import jalview.commands.CommandI; import jalview.commands.OrderCommand; @@ -32,8 +35,8 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.BinaryNode; -import jalview.datamodel.ColumnSelection; import jalview.datamodel.DBRefEntry; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.NodeTransformI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; @@ -73,7 +76,7 @@ public class TreePanel extends GTreePanel { String treeType; - ScoreModelI scoreModel; // if tree computed + String scoreModelName; // if tree computed String treeTitle; // if tree loaded @@ -81,7 +84,7 @@ public class TreePanel extends GTreePanel TreeCanvas treeCanvas; - NJTree tree; + TreeModel tree; AlignViewport av; @@ -90,15 +93,15 @@ public class TreePanel extends GTreePanel * * @param ap * @param type - * @param sm + * @param modelName * @param options */ - public TreePanel(AlignmentPanel ap, String type, ScoreModelI sm, + public TreePanel(AlignmentPanel ap, String type, String modelName, SimilarityParamsI options) { super(); this.similarityParams = options; - initTreePanel(ap, type, sm, null, null); + initTreePanel(ap, type, modelName, null, null); // We know this tree has distances. JBPNote TODO: prolly should add this as // a userdefined default @@ -123,13 +126,13 @@ public class TreePanel extends GTreePanel return treeCanvas.av; } - void initTreePanel(AlignmentPanel ap, String type, ScoreModelI sm, + void initTreePanel(AlignmentPanel ap, String type, String modelName, NewickFile newTree, AlignmentView inputData) { av = ap.av; this.treeType = type; - this.scoreModel = sm; + this.scoreModelName = modelName; treeCanvas = new TreeCanvas(this, ap, scrollPane); scrollPane.setViewportView(treeCanvas); @@ -167,11 +170,7 @@ public class TreePanel extends GTreePanel } }); - TreeLoader tl = new TreeLoader(newTree); - if (inputData != null) - { - tl.odata = inputData; - } + TreeLoader tl = new TreeLoader(newTree, inputData); tl.start(); } @@ -243,13 +242,15 @@ public class TreePanel extends GTreePanel class TreeLoader extends Thread { - NewickFile newtree; + private NewickFile newtree; - AlignmentView odata = null; + private AlignmentView odata = null; - public TreeLoader(NewickFile newickFile) + public TreeLoader(NewickFile newickFile, AlignmentView inputData) { this.newtree = newickFile; + this.odata = inputData; + if (newickFile != null) { // Must be outside run(), as Jalview2XML tries to @@ -265,24 +266,21 @@ public class TreePanel extends GTreePanel if (newtree != null) { - if (odata == null) - { - tree = new NJTree(av.getAlignment().getSequencesArray(), newtree); - } - else - { - tree = new NJTree(av.getAlignment().getSequencesArray(), odata, - newtree); - } - if (!tree.hasOriginalSequenceData()) + tree = new TreeModel(av.getAlignment().getSequencesArray(), odata, + newtree); + if (tree.getOriginalData() == null) { - allowOriginalSeqData(false); + originalSeqData.setVisible(false); } } else { - ScoreModelI sm = configureScoreModel(); - tree = new NJTree(av, treeType, sm, similarityParams); + ScoreModelI sm = ScoreModels.getInstance().getScoreModel( + scoreModelName, treeCanvas.ap); + TreeBuilder njtree = treeType.equals(TreeBuilder.NEIGHBOUR_JOINING) ? new NJTree( + av, sm, similarityParams) : new AverageDistanceTree(av, sm, + similarityParams); + tree = new TreeModel(njtree); showDistances(true); } @@ -316,17 +314,12 @@ public class TreePanel extends GTreePanel treeCanvas.setMarkPlaceholders(b); } - private void allowOriginalSeqData(boolean b) - { - originalSeqData.setVisible(b); - } - /** * DOCUMENT ME! * * @return DOCUMENT ME! */ - public NJTree getTree() + public TreeModel getTree() { return tree; } @@ -415,7 +408,8 @@ public class TreePanel extends GTreePanel @Override public void originalSeqData_actionPerformed(ActionEvent e) { - if (!tree.hasOriginalSequenceData()) + AlignmentView originalData = tree.getOriginalData(); + if (originalData == null) { jalview.bin.Cache.log .info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action."); @@ -437,8 +431,8 @@ public class TreePanel extends GTreePanel } catch (Exception ex) { } - ; - Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(gc); + + Object[] alAndColsel = originalData.getAlignmentAndHiddenColumns(gc); if (alAndColsel != null && alAndColsel[0] != null) { @@ -455,8 +449,8 @@ public class TreePanel extends GTreePanel if (true) { // make a new frame! - AlignFrame af = new AlignFrame(al, - (ColumnSelection) alAndColsel[1], AlignFrame.DEFAULT_WIDTH, + AlignFrame af = new AlignFrame(al, (HiddenColumns) alAndColsel[1], + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // >>>This is a fix for the moment, until a better solution is @@ -795,19 +789,17 @@ public class TreePanel extends GTreePanel } if (newname == null) { - SequenceFeature sf[] = sq.getSequenceFeatures(); - for (int i = 0; sf != null && i < sf.length; i++) + List features = sq.getFeatures() + .getPositionalFeatures(labelClass); + for (SequenceFeature feature : features) { - if (sf[i].getType().equals(labelClass)) + if (newname == null) + { + newname = feature.getDescription(); + } + else { - if (newname == null) - { - newname = new String(sf[i].getDescription()); - } - else - { - newname = newname + "; " + sf[i].getDescription(); - } + newname = newname + "; " + feature.getDescription(); } } } @@ -845,10 +837,9 @@ public class TreePanel extends GTreePanel + treeType.toLowerCase()); /* - * i18n description (if available) of score model used + * short score model name (long description can be too long) */ - String smn = MessageManager.getStringOrReturn("label.score_model_", - scoreModel.getName()); + String smn = scoreModelName; /* * put them together as Using @@ -857,28 +848,4 @@ public class TreePanel extends GTreePanel treecalcnm, smn); return ttl; } - - /** - * If the score model is one that requires to get state data from the current - * view, create and configure a new instance of it - * - * @return - */ - protected ScoreModelI configureScoreModel() - { - if (scoreModel instanceof ViewBasedAnalysisI) - { - try - { - scoreModel = scoreModel.getClass().newInstance(); - ((ViewBasedAnalysisI) scoreModel) - .configureFromAlignmentView(treeCanvas.ap); - } catch (Exception q) - { - Cache.log.error("Couldn't create a scoremodel instance for " - + scoreModel.getName()); - } - } - return scoreModel; - } }