import org.forester.archaeopteryx.ControlPanel;
+/**
+ * Wrapper for the Archaeopteryx control panel (left side panel) Currently just
+ * used for refreshing Aptx upon initialisation.
+ *
+ * @author kjvanderheide
+ *
+ */
public class AptxControlPanel implements TreeControlsI
{
ControlPanel aptxCp;
+ /**
+ * Note that this control panel MUST be part of an Archaeopteryx frame
+ *
+ * @param aptxControlPanel
+ * the original Control Panel from Archaeopteryx
+ */
protected AptxControlPanel(ControlPanel aptxControlPanel)
{
aptxCp = aptxControlPanel;
}
@Override
- public void defaultSettings()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
public void displayEntireTree()
{
aptxCp.showWhole();
}
@Override
- public void checkMultipleTrees()
+ public void enableMultipleTrees()
{
aptxFrame.activateSaveAllIfNeeded();
// APTX_CONFIG);
aptxApp.getTreeControls().displayEntireTree();
- aptxApp.checkMultipleTrees();
+ aptxApp.enableMultipleTrees();
aptxFrames[i++] = aptxApp;
}
}
LoadedTreeAssociationI bindAptxNodes = new LoadedTreeSequenceAssociation(
jalviewAlignport.getAlignment().getSequencesArray(),
jalviewTree);
- bindAptxNodes.associateLeavesToSequences();
+ bindAptxNodes.associateNodesToSequences();
TreeViewerUtils.associateNodesWithJalviewSequences(aptxApp, jalviewAlignport,
bindAptxNodes.getAlignmentWithNodes(),
LoadedTreeAssociationI bindAptxNodes = new LoadedTreeSequenceAssociation(
jalviewAlignport.getAlignment().getSequencesArray(),
jalviewTree);
- bindAptxNodes.associateLeavesToSequences();
+ bindAptxNodes.associateNodesToSequences();
TreeViewerUtils.associateNodesWithJalviewSequences(aptxApp, jalviewAlignport,
bindAptxNodes.getAlignmentWithNodes(),
bindAptxNodes.getNodesWithAlignment());
TreeViewerUtils.addTreeViewFrameToJalview(aptxApp);
- // adaptAptxGui(aptxApp); //moved to AptxFrame
return aptxApp;
}
LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation(
parentAvport.getAlignment().getSequencesArray(),
treeView.getTree());
- bindAptxNodes.associateLeavesToSequences();
+ bindAptxNodes.associateNodesToSequences();
sequencesBoundToNodes = bindAptxNodes.getAlignmentWithNodes();
nodesBoundToSequences = bindAptxNodes.getNodesWithAlignment();
TreeViewerUtils.associateNodesWithJalviewSequences(aptxFrame,
for (TreeNodeI childNode : childNodes)
{
- // childNode.getBranchData().setBranchColor(new BranchColor(Color.BLUE));
-
SequenceI matchingSequence = nodesBoundToSequences.get(childNode);
if (matchingSequence != null)
{
}
- /**
- * Refactored from TreeCanvas.
- *
- * @param sequence
- * of the node selected in the tree viewer.
- */
+
@Override
public void treeSelectionChanged(final SequenceI sequence)
{
.getAssociatedPanels(parentAvport.getSequenceSetId());
}
+ @Override
+ public Map<SequenceI, TreeNodeI> getAlignmentWithNodes()
+ {
+ return sequencesBoundToNodes;
+ }
+
+ @Override
+ public Map<TreeNodeI, SequenceI> getNodesWithAlignment()
+ {
+ return nodesBoundToSequences;
+ }
}
}
@Override
- public void writeToXml(File outputFile) throws IOException
+ public void outputAsFile(File outputFile) throws IOException
{
PhylogenyWriter treeWriter = new PhylogenyWriter();
treeWriter.toPhyloXML(tree, 0, outputFile);
import java.util.Map;
/**
- * Interface for associating the leaves of a loaded in (not calculated) tree to
- * the alignment sequences in Jalview.
+ * Interface for associating the nodes of a loaded in (instead of calculated)
+ * tree to the sequences of an alignment in Jalview.
*
* @author kjvanderheide
*
- *
*/
public interface LoadedTreeAssociationI
{
- public void associateLeavesToSequences();
+ /**
+ * Tries to match the loaded in tree nodes as best as possible with Jalview
+ * sequences
+ *
+ * Partially refactored from the old Jalview TreeModel
+ * associateLeavesToSequences method.
+ */
+ public void associateNodesToSequences();
+ /**
+ * See
+ * {@link jalview.ext.treeviewer.TreeViewerBindingI#getAlignmentWithNodes()}
+ *
+ *
+ */
public Map<SequenceI, TreeNodeI> getAlignmentWithNodes();
+ /**
+ * See
+ * {@link jalview.ext.treeviewer.TreeViewerBindingI#getNodesWithAlignment()}
+ *
+ *
+ */
public Map<TreeNodeI, SequenceI> getNodesWithAlignment();
}
import java.util.Iterator;
import java.util.Map;
+/**
+ * Generic implementation of {@link LoadedTreeAssociationI } that tries to
+ * associate tree nodes based on comparing Jalview's sequence IDs to tree node
+ * names.
+ *
+ * @author kjvanderheide
+ *
+ */
public class LoadedTreeSequenceAssociation
implements LoadedTreeAssociationI
{
}
- /**
- * Tries to match sequences from Jalview with tree nodes in Archaeopteryx and
- * fills in the tree node with sequence data if a match is found.
- *
- * Partially refactored from the old Jalview TreeModel
- * associateLeavesToSequences method.
- *
- * @param seqs
- * @param aptxTree
- */
@Override
- public void associateLeavesToSequences()
+ public void associateNodesToSequences()
{
SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences);
*/
public interface TreeBuilderI
{
+ public TreeI buildTree();
+
public TreeI buildTree(TreeNodeI treeRoot);
- public TreeI buildTree();
+ public String generateTreeName();
public Map<SequenceI, TreeNodeI> getAlignmentBoundNodes();
public Map<TreeNodeI, SequenceI> getNodesBoundAlignment();
- public String generateTreeName();
-
}
package jalview.ext.treeviewer;
+/**
+ * Interface for visually manipulating the tree with methods that might be user
+ * triggered.
+ *
+ * @author kjvanderheide
+ *
+ */
public interface TreeControlsI
{
- public void defaultSettings();
-
+ /**
+ * Resets the current view so that it shows the tree in its entirety (in case
+ * it was previously zoomed in etc.)
+ */
public void displayEntireTree();
}
import javax.swing.WindowConstants;
import javax.swing.event.InternalFrameListener;
+/**
+ * Interface for implementing the (probably) top level frame of an external tree
+ * viewer. Note that this extends many interfaces shared with Swing frames but
+ * doesn't demand that an implementation actually is a Swing frame.
+ *
+ * @author kjvanderheide
+ *
+ */
public interface TreeFrameI
extends Accessible, WindowConstants, RootPaneContainer,
ImageObserver, MenuContainer
{
- public abstract TreePanelI getTreePanel();
+ public void addFrameListener(InternalFrameListener listener);
- public abstract TreeI getTree();
+ /**
+ * Method for adding the actual frame to Jalview, probably through
+ * {@link jalview.gui.Desktop#addInternalFrame(javax.swing.JInternalFrame, String, boolean, int, int, boolean, boolean)}
+ *
+ * @param title
+ * @param makeVisible
+ * @param width
+ * @param height
+ * @param resizable
+ * @param ignoreMinSize
+ */
+ public void addFrameToJalview(String title, boolean makeVisible,
+ int width, int height, boolean resizable, boolean ignoreMinSize);
+
+ /**
+ * If the tree viewer used supports multiple trees in one frame this method
+ * should perform the needed adaptations.
+ */
+ public abstract void enableMultipleTrees();
- public abstract void checkMultipleTrees();
+ public InternalFrameListener[] getFrameListeners();
public abstract int getNumberOfTrees();
- public TreeControlsI getTreeControls();
+ public Container getTopLevelAncestor();
- public void addFrameListener(InternalFrameListener listener);
+ public abstract TreeI getTree();
- public void removeFrameListener(InternalFrameListener listener);
+ public TreeControlsI getTreeControls();
- public InternalFrameListener[] getFrameListeners();
+ public abstract TreePanelI getTreePanel();
- public void repaint();
+ public TreeViewerBindingI getViewBinding();
public boolean isShowing();
- public Container getTopLevelAncestor();
-
- public void addFrameToJalview(String title, boolean makeVisible,
- int width, int height, boolean resizable, boolean ignoreMinSize);
+ public void removeFrameListener(InternalFrameListener listener);
- public TreeViewerBindingI getViewBinding();
+ /**
+ * @see java.awt.Component#repaint()
+ */
+ public void repaint();
- public void setViewBinding(TreeViewerBindingI alignmentBinding);
+ public void setMaximumSize(Dimension maximumSize);
public void setMinimumSize(Dimension minimumSize);
- public void setMaximumSize(Dimension maximumSize);
-
public void setPreferredSize(Dimension preferredSize);
+ public void setViewBinding(TreeViewerBindingI alignmentBinding);
+
}
import java.util.Iterator;
import java.util.List;
+/**
+ * Interface for a generic phylogenetic tree, this does not necessarily have to
+ * be part of a tree panel.
+ *
+ * @author kjvanderheide
+ *
+ */
public interface TreeI
{
- public TreeNodeI getRoot();
-
- public TreeNodeI getNodeWithName(String name);
+ /**
+ * Uses this tree as the basis for a new tree frame.
+ *
+ * @param instanceTitle
+ * name of the new tree frame.
+ * @return
+ */
+ TreeFrameI createTreeViewerFromTree(String instanceTitle);
- public TreeNodeI getFurthestNode();
+ public String[] getAllLeafNames();
public TreeNodeI[] getAllNodes();
- public String[] getAllLeafNames();
+ public TreeNodeI getFurthestNode();
+
+ public double getHeight(boolean adjustForCollapsedSubtrees);
public List<SequenceI> getNodeSequences();
- public void setTreeName(String treeTitle);
+ public TreeNodeI getNodeWithName(String name);
- public void setRerootable(boolean b);
+ public TreeNodeI getRoot();
- public void setRooted(boolean b);
+ public String getTreeName();
+ /**
+ * Check if the tree actually contains any nodes.
+ *
+ * @return true if tree has no nodes (or is deleted), false otherwise.
+ */
public boolean isEmpty();
- public String getTreeName();
-
- public void setRoot(TreeNodeI rootNode);
+ public Iterator<TreeNodeI> iterateInLevelOrder();
- public double getHeight(boolean adjustForCollapsedSubtrees);
+ public Iterator<TreeNodeI> iterateInPostOrder();
public Iterator<TreeNodeI> iterateInPreOrder();
- public Iterator<TreeNodeI> iterateInLevelOrder();
+ /**
+ * This should write the tree to the richest file format available for
+ * compatibility reasons as this is the method used when Jalview saves a tree
+ * to its project.
+ *
+ * @param outputFile
+ * File that tree should be written to
+ * @throws IOException
+ */
+ public void outputAsFile(File outputFile) throws IOException;
- public Iterator<TreeNodeI> iterateInPostOrder();
+ public void setRerootable(boolean b);
- TreeFrameI createTreeViewerFromTree(String instanceTitle);
+ public void setRoot(TreeNodeI rootNode);
- public void writeToXml(File outputFile) throws IOException;
+ public void setRooted(boolean b);
+
+ public void setTreeName(String treeTitle);
}
public interface TreeNodeI
{
- public String getNodeName();
+ public void addAsChild(TreeNodeI childNode);
public List<TreeNodeI> getAllDescendants();
- public List<TreeNodeI> getExternalDescendants();
-
public List<TreeNodeI> getDirectChildren();
- public void setSequence(SequenceI seq);
+ public List<TreeNodeI> getExternalDescendants();
- public SequenceI getSequence();
+ public long getId();
- public void addAsChild(TreeNodeI childNode);
+ public String getNodeName();
- public long getId();
+ public SequenceI getSequence();
public float getXcoord();
public float getYcoord();
+ public boolean isInternal();
+
public void setBranchColor(Color branchColor);
- public boolean isInternal();
+ public void setSequence(SequenceI seq);
}
{
- public abstract void setTreeFile(File file);
-
- public abstract File getTreeFile();
-
- public abstract TreeI getTree();
+ public void addMouseListener(MouseListener listener);
public abstract TreeNodeI findNode(int x, int y);
- public abstract void setMatchingNodes(Set<Long> matchingNodes);
+ public int getHeight();
public abstract Set<Long> getMatchingNodes();
- public void addMouseListener(MouseListener listener);
+ public MouseListener[] getMouseListeners();
- public void removeMouseListener(MouseListener listener);
+ public float getPartitionThreshold();
- public MouseListener[] getMouseListeners();
+ public abstract TreeI getTree();
- public void repaint();
+ public abstract File getTreeFile();
- public void registerWithPaintRefresher(String sequenceSetIdentifier);
+ public abstract Rectangle getVisibleArea();
+
+ public int getWidth();
public void notifyPaintRefresher(boolean alignmentChanged,
boolean validateSequences);
public void notifyPaintRefresher(String newSeqSetIdentifier,
boolean alignmentChanged, boolean validateSequences);
- public int getWidth();
-
- public int getHeight();
-
public abstract void paintToFile(Graphics2D pg, int width, int height);
- public boolean showingSubTree();
+ public void registerWithPaintRefresher(String sequenceSetIdentifier);
- public float getPartitionThreshold();
+ public void removeMouseListener(MouseListener listener);
- public abstract Rectangle getVisibleArea();
+ public void repaint();
- public void setMinimumSize(Dimension minimumSize);
+ public abstract void setMatchingNodes(Set<Long> matchingNodes);
public void setMaximumSize(Dimension maximumSize);
+ public void setMinimumSize(Dimension minimumSize);
+
public void setPreferredSize(Dimension preferredSize);
+ public abstract void setTreeFile(File file);
+
+ public boolean showingSubTree();
+
}
public interface TreeParserI
{
- public TreeI[] parse() throws IOException;
-
- public void setSource(Object source) throws IOException;
-
public String getName();
public TreeI[] getParsedTrees();
+ public TreeI[] parse() throws IOException;
+
+ public void setSource(Object source) throws IOException;
+
}
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
+import java.util.Map;
/**
*
- * Interface for binding a tree viewer to Jalview alignments. Assumes a tree
- * viewer will both want to receive and send selection events.
+ * Interface for associating the nodes of a tree viewer with Jalview alignment
+ * sequences and communicating between the two. Assumes a tree viewer will both
+ * want to receive and send selection events.
*
* @author kjvanderheide
*
SelectionSource
{
/**
+ * Gets the mapping for sequences with their associated tree nodes
+ *
+ * @return
+ */
+ public Map<SequenceI, TreeNodeI> getAlignmentWithNodes();
+
+ /**
+ * Gets the mapping for tree nodes with their associated sequences
+ *
+ * @return
+ */
+ public Map<TreeNodeI, SequenceI> getNodesWithAlignment();
+
+ /**
+ *
+ * @param x
+ * coordinate that functions as the clustering threshold
+ */
+ public void partitionTree(final int x);
+
+ public void showMatchingChildSequences(TreeNodeI parentNode);
+
+ public void showMatchingSequence(TreeNodeI nodeToMatch);
+
+ /**
* If a node is selected in the tree panel this method highlights the
* corresponding sequence in the Jalview alignment view. If an internal node
* is selected all child sequences get highlighted as well.
*/
public void showNodeSelectionOnAlign(TreeNodeI node);
- public void treeSelectionChanged(SequenceI sequence);
-
- public void showMatchingSequence(TreeNodeI nodeToMatch);
-
- public void showMatchingChildSequences(TreeNodeI parentNode);
+ /**
+ * Sorts the given alignment by the order in which the sequences appear in the
+ * tree.
+ *
+ * @param alignPanel
+ * Panel containing the alignment to be sorted.
+ * @return the sorting Command
+ */
+ public CommandI sortAlignmentIn(AlignmentPanel alignPanel);
public void sortByTree_actionPerformed();
- public CommandI sortAlignmentIn(AlignmentPanel alignPanel);
+ public void treeSelectionChanged(SequenceI sequence);
}
{
private static Map<TreeFrameI, TreeViewerBindingI> activeViews = new HashMap<>();
- public static TreeViewerBindingI associateNodesWithJalviewSequences(
- final TreeFrameI treeFrame,
- final AlignmentViewport jalviewAlignViewport,
- final Map<SequenceI, TreeNodeI> alignMappedToNodes,
- final Map<TreeNodeI, SequenceI> nodesMappedToAlign)
- {
- TreeViewerBindingI treeBinding = new JalviewBinding(treeFrame,
- jalviewAlignViewport,
- alignMappedToNodes, nodesMappedToAlign);
- jalviewAlignViewport.setCurrentExtTree(treeFrame.getTree());
- activeViews.put(treeFrame, treeFrame.getViewBinding());
-
- return treeBinding;
- }
-
public static TreeFrameI addTreeViewFrameToJalview(
final TreeFrameI treeFrame)
{
treeFrame.addFrameToJalview(frameTitle, true, width, height, true,
false);
+ treeFrame.getTreeControls().displayEntireTree();
return treeFrame;
}
+ public static TreeViewerBindingI associateNodesWithJalviewSequences(
+ final TreeFrameI treeFrame,
+ final AlignmentViewport jalviewAlignViewport,
+ final Map<SequenceI, TreeNodeI> alignMappedToNodes,
+ final Map<TreeNodeI, SequenceI> nodesMappedToAlign)
+ {
+ TreeViewerBindingI treeBinding = new JalviewBinding(treeFrame,
+ jalviewAlignViewport,
+ alignMappedToNodes, nodesMappedToAlign);
+ jalviewAlignViewport.setCurrentExtTree(treeFrame.getTree());
+ activeViews.put(treeFrame, treeFrame.getViewBinding());
+
+ return treeBinding;
+ }
+
public static Map<TreeFrameI, TreeViewerBindingI> getActiveTreeViews()
{
return activeViews;
TreeI tree = treeView.getTree();
try
{
- tree.writeToXml(new File("word"));
+ tree.outputAsFile(new File("word"));
copyFileToJar(jout, "word", "aptx-test");