From: Jim Procter Date: Tue, 2 Jul 2024 11:31:35 +0000 (+0100) Subject: JAL-4435 WIP - to squash X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ac3a4627d9c6c7e419ecdf775889136092c4597f;p=jalview.git JAL-4435 WIP - to squash --- diff --git a/src/jalview/analysis/TreeModel.java b/src/jalview/analysis/TreeModel.java index 1068042..e29eb95 100644 --- a/src/jalview/analysis/TreeModel.java +++ b/src/jalview/analysis/TreeModel.java @@ -20,6 +20,7 @@ */ package jalview.analysis; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentView; import jalview.datamodel.BinaryNode; import jalview.datamodel.NodeTransformI; @@ -78,13 +79,21 @@ public class TreeModel * NewickFile */ public TreeModel(SequenceI[] seqs, AlignmentView odata, - NewickFile treefile) + NewickFile treefile, AlignmentAnnotation[] leafAnnotations) { this(seqs, treefile.getTree(), treefile.HasDistances(), treefile.HasBootstrap(), treefile.HasRootDistance()); seqData = odata; - - associateLeavesToSequences(seqs); + if (leafAnnotations != null) + { + // leaf names are seuqence ID + annotation for display + // leaf links are annotationId <> annotation object for import from project + // --> need to resolve before passing for display + // ==> do leafs need to be renamed after import ? + // ==> implies the 'nodeLabel' business needs to be callable independently of score function + } else { + associateLeavesToSequences(seqs); + } } /** diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 766b35e..d4de475 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4198,6 +4198,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return seqs; } + //// *************************************************** + //// TODO REFACTOR TREE I/O TO CONTROLLER/SEPARATE CLASS + //// *************************************************** + /** * DOCUMENT ME! * @@ -4304,6 +4308,36 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return tp; } + public TreePanel showNewickTreeForAnnotation(NewickFile nf, String treeTitle, + AlignmentView input, int w, int h, int x, int y) + { + TreePanel tp = null; + + try + { + nf.parse(); + + if (nf.getTree() != null) + { + tp = TreePanel.newTreeForAnnotations(alignPanel, nf, treeTitle, input); + // TODO - refactor layout code to one place for tree view methods + tp.setSize(w, h); + + if (x > 0 && y > 0) + { + tp.setLocation(x, y); + } + + Desktop.addInternalFrame(tp, treeTitle, w, h); + } + } catch (Exception ex) + { + ex.printStackTrace(); + } + + return tp; + } + public void showContactMapTree(AlignmentAnnotation aa, ContactMatrixI cm) { @@ -4355,6 +4389,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } return null; } + //// *************************************************** + //// TODO REFACTOR TREE I/O TO CONTROLLER/SEPARATE CLASS - END OF METHODS + //// *************************************************** private boolean buildingMenu = false; diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 24a5547..c80bf3a 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -119,7 +119,7 @@ public class TreePanel extends GTreePanel super(); this.setFrameIcon(null); this.similarityParams = options; - initTreePanel(ap, type, modelName, null, null); + initTreePanel(ap, type, modelName, null, null, null); // We know this tree has distances. JBPNote TODO: prolly should add this as // a userdefined default @@ -129,10 +129,22 @@ public class TreePanel extends GTreePanel public TreePanel(AlignmentPanel alignPanel, NewickFile newtree, String theTitle, AlignmentView inputData) { + this(alignPanel, newtree, theTitle, inputData, null,null); + } + + /** + * when true, leaf labels are annotations + */ + boolean forAnnotation = false; + + public TreePanel(AlignmentPanel alignPanel, NewickFile newtree, + String theTitle, AlignmentView inputData, AlignmentAnnotation[] leafAnnotations, String subTitle) + { super(); + this.forAnnotation=leafAnnotations!=null && leafAnnotations.length>0; this.setFrameIcon(null); this.treeTitle = theTitle; - initTreePanel(alignPanel, null, null, newtree, inputData); + initTreePanel(alignPanel, null, null, newtree, inputData, null); } /** @@ -151,7 +163,7 @@ public class TreePanel extends GTreePanel assocAnnotation = aa; this.setFrameIcon(null); this.treeTitle = title; - initTreePanel(alignPanel, null, null, fin, null); + initTreePanel(alignPanel, null, null, fin, null, null); } boolean columnWise = false; @@ -179,8 +191,19 @@ public class TreePanel extends GTreePanel return getTreeCanvas().getViewport(); } + private void addSubtitlePanel(String subTitle) + { + subtitleLabel = new JLabel(subTitle, SwingConstants.LEFT); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(subtitleLabel, BorderLayout.NORTH); + panel.add(scrollPane, BorderLayout.CENTER); + + this.add(panel); + } + void initTreePanel(AlignmentPanel ap, String type, String modelName, - NewickFile newTree, AlignmentView inputData) + NewickFile newTree, AlignmentView inputData, AlignmentAnnotation[] leafAnnotations) { av = ap.av; @@ -190,19 +213,17 @@ public class TreePanel extends GTreePanel treeCanvas = new TreeCanvas(this, ap, scrollPane); scrollPane.setViewportView(treeCanvas); - if(this.similarityParams!=null) - if(this.similarityParams.getSecondaryStructureSource()!=null ) { - - subtitleLabel = new JLabel(" Secondary Structure Provider : " - + this.similarityParams.getSecondaryStructureSource(), SwingConstants.LEFT); - - JPanel panel = new JPanel(new BorderLayout()); - panel.add(subtitleLabel, BorderLayout.NORTH); - panel.add(scrollPane, BorderLayout.CENTER); - - this.add(panel); - } + if (similarityParams != null + && similarityParams.getSecondaryStructureSource() != null) + { + addSubtitlePanel(" Secondary Structure Provider : " + + similarityParams.getSecondaryStructureSource()); + } + if (leafAnnotations!=null) + { + forAnnotation=true; + } if (columnWise) { bootstrapMenu.setVisible(false); @@ -251,7 +272,7 @@ public class TreePanel extends GTreePanel } }); - TreeLoader tl = new TreeLoader(newTree, inputData); + TreeLoader tl = new TreeLoader(newTree, inputData, leafAnnotations); tl.start(); } @@ -377,11 +398,13 @@ public class TreePanel extends GTreePanel private AlignmentView odata = null; - public TreeLoader(NewickFile newickFile, AlignmentView inputData) + private AlignmentAnnotation[] leafAnnotations; + public TreeLoader(NewickFile newickFile, AlignmentView inputData, AlignmentAnnotation[] leafAnnotations) { this.newtree = newickFile; this.odata = inputData; - + this.leafAnnotations = leafAnnotations; + if (newickFile != null) { // Must be outside run(), as Jalview2XML tries to @@ -398,7 +421,7 @@ public class TreePanel extends GTreePanel if (newtree != null) { tree = new TreeModel(av.getAlignment().getSequencesArray(), odata, - newtree); + newtree, leafAnnotations); if (tree.getOriginalData() == null) { originalSeqData.setVisible(false); @@ -939,4 +962,12 @@ public class TreePanel extends GTreePanel { return treeCanvas; } + + public static TreePanel newTreeForAnnotations(AlignmentPanel alignPanel, + NewickFile nf, String treeTitle2, AlignmentView input) + { + // TODO - recover subpanel name + TreePanel tp = new TreePanel(alignPanel, nf, treeTitle2, input, null, "Annotation Tree"); + return tp; + } } diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index e620c1c..d8b688a 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -4675,10 +4675,21 @@ public class Jalview2XML } else { - tp = af.showNewickTree(new NewickFile(tree.getNewick()), + if (false)//tree.isAnnotationAssociated()) + { + // TODO - resolve annotation IDs against newick tree labels + // then fix up labels so they are human readable + + tp = af.showNewickTreeForAnnotation(new NewickFile(tree.getNewick()), + tree.getTitle(), null, safeInt(tree.getWidth()), + safeInt(tree.getHeight()), safeInt(tree.getXpos()), + safeInt(tree.getYpos())); + } else { + tp = af.showNewickTree(new NewickFile(tree.getNewick()), tree.getTitle(), safeInt(tree.getWidth()), safeInt(tree.getHeight()), safeInt(tree.getXpos()), safeInt(tree.getYpos())); + } } if (tree.getId() != null) {