From: gmungoc Date: Fri, 24 Mar 2017 16:30:04 +0000 (+0000) Subject: JAL-2428 simplify TreeModel constructors, add getOriginalData X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~56 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2ff143c5a47bd7bde7409ce1457bf84e332660a8;p=jalview.git JAL-2428 simplify TreeModel constructors, add getOriginalData --- diff --git a/src/jalview/analysis/TreeModel.java b/src/jalview/analysis/TreeModel.java index 2f8d788..62b0594 100644 --- a/src/jalview/analysis/TreeModel.java +++ b/src/jalview/analysis/TreeModel.java @@ -46,7 +46,7 @@ public class TreeModel * SequenceData is a string representation of what the user * sees. The display may contain hidden columns. */ - public AlignmentView seqData; + private AlignmentView seqData; int noseqs; @@ -68,7 +68,7 @@ public class TreeModel /** * Create a new TreeModel object with leaves associated with sequences in - * seqs, and original alignment data represented by Cigar strings + * seqs, and (optionally) original alignment data represented by Cigar strings * * @param seqs * SequenceI[] @@ -79,22 +79,9 @@ public class TreeModel */ public TreeModel(SequenceI[] seqs, AlignmentView odata, NewickFile treefile) { - this(seqs, treefile); - seqData = odata; - } - - /** - * Creates a new TreeModel object from a tree from an external source - * - * @param seqs - * SequenceI which should be associated with leafs of treefile - * @param treefile - * A parsed tree - */ - public TreeModel(SequenceI[] seqs, NewickFile treefile) - { this(seqs, treefile.getTree(), treefile.HasDistances(), treefile .HasBootstrap(), treefile.HasRootDistance()); + seqData = odata; associateLeavesToSequences(seqs); } @@ -468,15 +455,6 @@ public class TreeModel } /** - * - * @return true if original sequence data can be recovered - */ - public boolean hasOriginalSequenceData() - { - return seqData != null; - } - - /** * Returns original alignment data used for calculation - or null where not * available. * @@ -710,4 +688,9 @@ public class TreeModel ; } } + + public AlignmentView getOriginalData() + { + return seqData; + } } diff --git a/src/jalview/api/analysis/ScoreModelI.java b/src/jalview/api/analysis/ScoreModelI.java index 9a633f0..4433cea 100644 --- a/src/jalview/api/analysis/ScoreModelI.java +++ b/src/jalview/api/analysis/ScoreModelI.java @@ -27,4 +27,5 @@ public interface ScoreModelI */ boolean isProtein(); + // TODO getName, isDNA, isProtein can be static methods in Java 8 } diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index a9e11a7..905a54a 100644 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -164,7 +164,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, // yields unaligned seqs) // or create a selection box around columns in alignment view // test Alignment(SeqCigar[]) - if (tree.seqData != null) + if (tree.getOriginalData() != null) { char gc = '-'; try @@ -175,8 +175,8 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, } catch (Exception ex) { } - ; - Object[] alAndColsel = tree.seqData + + Object[] alAndColsel = tree.getOriginalData() .getAlignmentAndColumnSelection(gc); if (alAndColsel != null && alAndColsel[0] != null) @@ -210,17 +210,8 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, { if (newtree != null) { - if (odata == null) - { - tree = new TreeModel(av.getAlignment().getSequencesArray(), - newtree); - } - else - { - tree = new TreeModel(av.getAlignment().getSequencesArray(), - odata, newtree); - } - + tree = new TreeModel(av.getAlignment().getSequencesArray(), odata, + newtree); } else { diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 1e98535..d4c6009 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -170,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(); } @@ -246,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 @@ -268,19 +266,11 @@ public class TreePanel extends GTreePanel if (newtree != null) { - if (odata == null) + tree = new TreeModel(av.getAlignment().getSequencesArray(), odata, + newtree); + if (tree.getOriginalData() == null) { - tree = new TreeModel(av.getAlignment().getSequencesArray(), - newtree); - } - else - { - tree = new TreeModel(av.getAlignment().getSequencesArray(), - odata, newtree); - } - if (!tree.hasOriginalSequenceData()) - { - allowOriginalSeqData(false); + originalSeqData.setVisible(false); } } else @@ -323,11 +313,6 @@ public class TreePanel extends GTreePanel treeCanvas.setMarkPlaceholders(b); } - private void allowOriginalSeqData(boolean b) - { - originalSeqData.setVisible(b); - } - /** * DOCUMENT ME! * @@ -422,7 +407,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."); @@ -444,8 +430,9 @@ public class TreePanel extends GTreePanel } catch (Exception ex) { } - ; - Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(gc); + + Object[] alAndColsel = originalData + .getAlignmentAndColumnSelection(gc); if (alAndColsel != null && alAndColsel[0] != null) { diff --git a/src/jalview/io/packed/JalviewDataset.java b/src/jalview/io/packed/JalviewDataset.java index 736591b..9f84c16 100644 --- a/src/jalview/io/packed/JalviewDataset.java +++ b/src/jalview/io/packed/JalviewDataset.java @@ -20,6 +20,7 @@ */ package jalview.io.packed; +import jalview.analysis.TreeModel; import jalview.api.FeatureColourI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; @@ -151,8 +152,7 @@ public class JalviewDataset { // the following works because all trees are already had node/SequenceI // associations created. - jalview.analysis.TreeModel njt = new jalview.analysis.TreeModel( - al.getSequencesArray(), nf); + TreeModel njt = new TreeModel(al.getSequencesArray(), null, nf); // this just updates the displayed leaf name on the tree according to // the SequenceIs. njt.renameAssociatedNodes(); diff --git a/src/jalview/io/vamsas/Tree.java b/src/jalview/io/vamsas/Tree.java index f676347..d800d20 100644 --- a/src/jalview/io/vamsas/Tree.java +++ b/src/jalview/io/vamsas/Tree.java @@ -220,15 +220,17 @@ public class Tree extends DatastoreItem prov.getEntry(0).setUser(provEntry.getUser()); prov.getEntry(0).setApp(provEntry.getApp()); prov.getEntry(0).setDate(provEntry.getDate()); - if (tp.getTree().hasOriginalSequenceData()) + + AlignmentView originalData = tp.getTree().getOriginalData(); + if (originalData != null) { Input vInput = new Input(); // LATER: check to see if tree input data is contained in this alignment - // or just correctly resolve the tree's seqData to the correct alignment // in // the document. - Vector alsqrefs = getjv2vObjs(findAlignmentSequences(jal, - tp.getTree().seqData.getSequences())); + Vector alsqrefs = getjv2vObjs(findAlignmentSequences(jal, tp + .getTree().getOriginalData().getSequences())); Object[] alsqs = new Object[alsqrefs.size()]; alsqrefs.copyInto(alsqs); vInput.setObjRef(alsqs); @@ -243,10 +245,10 @@ public class Tree extends DatastoreItem prov.getEntry(0).getParam(0) .setContent(TreeBuilder.NEIGHBOUR_JOINING); // TODO: type of tree is a general parameter - int ranges[] = tp.getTree().seqData.getVisibleContigs(); + int ranges[] = originalData.getVisibleContigs(); // VisibleContigs are with respect to alignment coordinates. Still need // offsets - int start = tp.getTree().seqData.getAlignmentOrigin(); + int start = tp.getTree().getOriginalData().getAlignmentOrigin(); for (int r = 0; r < ranges.length; r += 2) { Seg visSeg = new Seg(); diff --git a/test/jalview/io/NewickFileTests.java b/test/jalview/io/NewickFileTests.java index 4a32790..a92f5fb 100644 --- a/test/jalview/io/NewickFileTests.java +++ b/test/jalview/io/NewickFileTests.java @@ -125,7 +125,8 @@ public class NewickFileTests stage = "Compare original and generated tree" + treename; Vector oseqs, nseqs; - oseqs = new TreeModel(new SequenceI[0], nf).findLeaves(nf.getTree()); + oseqs = new TreeModel(new SequenceI[0], null, nf).findLeaves(nf + .getTree()); AssertJUnit.assertTrue(stage + "No nodes in original tree.", oseqs.size() > 0); SequenceI[] olsqs = new SequenceI[oseqs.size()]; @@ -133,7 +134,8 @@ public class NewickFileTests { olsqs[i] = (SequenceI) oseqs.get(i).element(); } - nseqs = new TreeModel(new SequenceI[0], nf_regen).findLeaves(nf_regen + nseqs = new TreeModel(new SequenceI[0], null, nf_regen) + .findLeaves(nf_regen .getTree()); AssertJUnit.assertTrue(stage + "No nodes in regerated tree.", nseqs.size() > 0);