package jalview.ext.archaeopteryx;
import jalview.analysis.TreeBuilder;
+import jalview.datamodel.SequenceI;
import jalview.gui.Desktop;
+import jalview.viewmodel.AlignmentViewport;
import java.awt.Dimension;
+import java.util.Map;
import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.archaeopteryx.MainFrame;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyNode;
public final class ArchaeopteryxInit
{
- public static MainFrame createInstance(Phylogeny[] aptxTrees)
+ /**
+ * This method should generally not be used as it does not bind the tree to
+ * its alignment
+ *
+ * @param aptxTrees
+ * @return
+ */
+ public static MainFrame createUnboundInstance(Phylogeny aptxTree)
{
- return createBoundAptxFrame(aptxTrees);
+ Phylogeny[] aptxTrees = { aptxTree };
+ return createBoundAptxFrame(aptxTrees, null);
+ }
+
+ public static MainFrame createInstance(Phylogeny[] aptxTrees,
+ AlignmentViewport jalviewAlignmentView)
+ {
+ return createBoundAptxFrame(aptxTrees, jalviewAlignmentView);
}
- public static MainFrame createInstance(Phylogeny aptxTree)
+ public static MainFrame createInstance(Phylogeny aptxTree,
+ AlignmentViewport jalviewAlignmentView)
{
Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
// several trees simultaneously
- return createBoundAptxFrame(aptxTrees);
+ return createBoundAptxFrame(aptxTrees, jalviewAlignmentView);
}
public static MainFrame createInstance(
- TreeBuilder calculatedTree)
+ TreeBuilder calculatedTree) // very dense method, to be split up
{
ArchaeopteryxTreeConverter aptxTreeBuilder = new ArchaeopteryxTreeConverter(
calculatedTree);
+
Phylogeny aptxTree = aptxTreeBuilder.buildAptxTree();
Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
// several trees simultaneously
- return createBoundAptxFrame(aptxTrees);
+ MainFrame aptxApp = createBoundAptxFrame(aptxTrees,
+ calculatedTree.getAvport());
+ bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
+ aptxTreeBuilder.getAlignmentBoundNodes());
+ return bindFrameToJalview(aptxApp);
}
- private static MainFrame createBoundAptxFrame(Phylogeny[] aptxTrees)
+
+
+ private static MainFrame createBoundAptxFrame(Phylogeny[] aptxTrees,
+ AlignmentViewport jalviewAlignmentView)
{
MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
"_aptx_jalview_configuration_file", null);
- return bindFrameToJalview(aptxApp);
+
+ return aptxApp;
}
+ private static void bindNodesToJalviewSequences(MainFrame aptxApp,
+ AlignmentViewport jalviewAlignViewport,
+ Map<SequenceI, PhylogenyNode> alignMappedToNodes)
+ {
+ new JalviewAptxBinding(aptxApp, jalviewAlignViewport,
+ alignMappedToNodes);
+ }
private static MainFrame bindFrameToJalview(MainFrame aptxApp)
--- /dev/null
+package jalview.ext.archaeopteryx;
+
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.structure.SelectionSource;
+import jalview.structure.StructureSelectionManager;
+import jalview.viewmodel.AlignmentViewport;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.forester.archaeopteryx.MainFrame;
+import org.forester.phylogeny.PhylogenyNode;
+
+public class JalviewAptxBinding implements JalviewTreeViewerBindingI
+{
+ org.forester.archaeopteryx.TreePanel treeView;
+
+ AlignmentViewport parentAvport;
+
+ StructureSelectionManager ssm;
+
+ Map<SequenceI, PhylogenyNode> sequencesBelongingToNodes;
+
+
+ public JalviewAptxBinding(MainFrame archaeopteryx,
+ AlignmentViewport jalviewAlignmentViewport,
+ Map<SequenceI, PhylogenyNode> alignMappedToNodes)
+ {
+ parentAvport = jalviewAlignmentViewport;
+ sequencesBelongingToNodes = alignMappedToNodes;
+ treeView = archaeopteryx.getMainPanel().getCurrentTreePanel();
+ ssm = parentAvport.getStructureSelectionManager();
+ ssm.addSelectionListener(this);
+ treeView.addMouseListener(this);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e)
+ {
+
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e)
+ {
+ showNodeSelectionOnAlign(e);
+
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e)
+ {
+
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e)
+ {
+
+ }
+
+ @Override
+ public void selection(SequenceGroup seqsel, ColumnSelection colsel,
+ HiddenColumns hidden, SelectionSource source)
+ {
+ if (source == parentAvport) // check if source is alignment from where the
+ // tree originates
+ {
+ treeView.setFoundNodes0(
+ new HashSet<Long>(seqsel.getSequences().size()));
+
+ for (SequenceI sequence : seqsel.getSequences())
+ {
+ PhylogenyNode matchingNode = sequencesBelongingToNodes.get(sequence);
+ treeView.getFoundNodes0().add(matchingNode.getId());
+
+ }
+ treeView.repaint();
+
+ }
+
+
+ }
+
+ @Override
+ public void showNodeSelectionOnAlign(MouseEvent e)
+ {
+ final PhylogenyNode node = treeView.findNode(e.getX(), e.getY());
+ if (node != null && node.isExternal())
+ {
+
+ if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) // shift is pressed
+ // (so multiple nodes
+ // can be selected)
+ {
+
+ System.out.println(treeView.getFoundNodes0().toString());
+ }
+ }
+
+ }
+
+
+
+
+ }
+
+
+