import jalview.datamodel.SequenceI;
import jalview.ext.treeviewer.ExternalTreeViewerBindingI;
import jalview.gui.AlignViewport;
+import jalview.gui.AlignmentPanel;
import jalview.gui.Desktop;
import jalview.gui.JvOptionPane;
import jalview.gui.PaintRefresher;
import jalview.viewmodel.AlignmentViewport;
import java.awt.Color;
-import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import javax.swing.event.ChangeListener;
import org.forester.archaeopteryx.MainFrame;
-import org.forester.archaeopteryx.TreePanelUtil;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
private final StructureSelectionManager ssm;
+ private AlignmentPanel[] associatedPanels;
+
private Map<SequenceI, PhylogenyNode> sequencesBoundToNodes;
private Map<PhylogenyNode, SequenceI> nodesBoundToSequences;
private float furthestNodeX;
+ private int nrTreeGroups = 0;
+
/**
*
* @param archaeopteryx
treeView.addMouseListener(this);
PaintRefresher.Register(treeView, parentAvport.getSequenceSetId());
+ associatedPanels = PaintRefresher
+ .getAssociatedPanels(parentAvport.getSequenceSetId());
+
treeTabs.addChangeListener(new ChangeListener()
{
partitionTree(e.getX());
}
PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
+ treeView.repaint();
// clicked x lies outside
// of tree
{
- Graphics g = treeView.getGraphics();
- int panelHeight = treeView.getHeight();
- g.drawLine(x, 0, x, panelHeight);
+
+ // int panelHeight = treeView.getHeight();
+ // g.drawLine(x, 0, x, panelHeight);
float threshold = (x - rootX) / (furthestNodeX - rootX);
List<PhylogenyNode> foundNodes = getNodesAboveThreshold(threshold,
List<PhylogenyNode> nodeList, double threshold,
PhylogenyNode node)
{
- // could also use PhylogenyMethods.getAllDescendants
+
for (PhylogenyNode childNode : node.getDescendants())
{
childNode.getBranchData()
{
nodeList.add(childNode);
- Color randomColor = new Color((int) (Math.random() * 255),
+ Color randomColour = new Color((int) (Math.random() * 255),
(int) (Math.random() * 255), (int) (Math.random() * 255));
- TreePanelUtil.colorizeSubtree(childNode,
- new BranchColor(randomColor));
- List<PhylogenyNode> descendantNodes = childNode
- .getAllExternalDescendants();
- List<SequenceI> descendantSeqs = new ArrayList<>(); // .forEach instead?
- for (PhylogenyNode descNode : descendantNodes)
+ childNode.getBranchData()
+ .setBranchColor(new BranchColor(randomColour));
+
+ List<SequenceI> groupSeqs = new ArrayList<>();
+ SequenceI seq = nodesBoundToSequences.get(childNode);
+ if (seq != null)
{
- descendantSeqs.add(nodesBoundToSequences.get(descNode));
+ groupSeqs.add(seq);
+ parentAvport.setSequenceColour(seq, randomColour);
}
- SequenceGroup sg = new SequenceGroup(descendantSeqs, null, null,
- true, true, false, 0,
- parentAvport.getAlignment().getWidth() - 1);
-
- ColourSchemeI cs = null;
- if (parentAvport.getGlobalColourScheme() != null)
+ List<PhylogenyNode> descendantNodes = PhylogenyMethods
+ .getAllDescendants(childNode);
+ // .forEach instead?
+ for (PhylogenyNode descNode : descendantNodes)
{
- if (parentAvport.getGlobalColourScheme() instanceof UserColourScheme)
- {
- cs = new UserColourScheme(
- ((UserColourScheme) parentAvport.getGlobalColourScheme())
- .getColours());
- }
- else
+ seq = nodesBoundToSequences.get(descNode);
+ if (seq != null)
{
- cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
- .getColourName(parentAvport.getGlobalColourScheme()));
+ groupSeqs.add(seq);
+ parentAvport.setSequenceColour(seq, randomColour);
}
+
+ descNode.getBranchData()
+ .setBranchColor(new BranchColor(randomColour));
}
- sg.setColourScheme(cs);
- sg.getGroupColourScheme().setThreshold(
- parentAvport.getResidueShading().getThreshold(),
- parentAvport.isIgnoreGapsConsensus());
- // sg.recalcConservation();
- sg.setName("Tree Group:" + sg.hashCode());
- sg.setIdColour(randomColor);
-
- if (parentAvport.getGlobalColourScheme() != null
- && parentAvport.getResidueShading().conservationApplied())
+
+ if (groupSeqs != null)
{
- Conservation c = new Conservation("Group", sg.getSequences(null),
- sg.getStartRes(), sg.getEndRes());
- c.calculate();
- c.verdict(false, parentAvport.getConsPercGaps());
- sg.cs.setConservation(c);
- }
+ nrTreeGroups++;
+ groupThresholdSequences(groupSeqs, randomColour);
+ }}
- parentAvport.getAlignment().addGroup(new SequenceGroup(sg));
- // TODO can we push all of the below into AlignViewportI?
- final AlignViewportI codingComplement = parentAvport
+ else
+ {
+ colourNodesAboveThreshold(nodeList, threshold, childNode);
+ }
+ }
+
+
+ for (AlignmentPanel associatedPanel : associatedPanels) {
+
+ associatedPanel.updateAnnotation();
+
+ final AlignViewportI codingComplement = associatedPanel.getAlignViewport()
.getCodingComplement();
if (codingComplement != null)
{
- SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg,
- parentAvport,
- codingComplement);
- if (mappedGroup.getSequences().size() > 0)
- {
- codingComplement.getAlignment().addGroup(mappedGroup);
- for (SequenceI seq : mappedGroup.getSequences())
- {
- codingComplement.setSequenceColour(seq,
- randomColor.brighter());
- }
- }
+ // GROSS
+ ((AlignViewport) codingComplement).getAlignPanel()
+ .updateAnnotation();
}
+ }
- }
+ return nodeList;
+ }
+ public void groupThresholdSequences(List<SequenceI> groupedSeqs,
+ Color groupColour)
+ {
+ SequenceGroup treeGroup = new SequenceGroup(groupedSeqs, null, null,
+ true, true, false, 0,
+ parentAvport.getAlignment().getWidth() - 1);
+
+ ColourSchemeI cs = null;
+ if (parentAvport.getGlobalColourScheme() != null)
+ {
+ if (parentAvport.getGlobalColourScheme() instanceof UserColourScheme)
+ {
+ cs = new UserColourScheme(
+ ((UserColourScheme) parentAvport.getGlobalColourScheme())
+ .getColours());
+ }
else
{
- colourNodesAboveThreshold(nodeList, threshold,
- childNode);
+ cs = ColourSchemeProperty.getColourScheme(treeGroup,
+ ColourSchemeProperty.getColourName(
+ parentAvport.getGlobalColourScheme()));
}
- }
-
- // GROSS
- ((AlignViewport) parentAvport).getAlignPanel().updateAnnotation();
- final AlignViewportI codingComplement = parentAvport
- .getCodingComplement();
- if (codingComplement != null)
- {
- ((AlignViewport) codingComplement).getAlignPanel().updateAnnotation();
}
+ treeGroup.setColourScheme(cs);
+ treeGroup.getGroupColourScheme().setThreshold(
+ parentAvport.getResidueShading().getThreshold(),
+ parentAvport.isIgnoreGapsConsensus());
- return nodeList;
- }
+ treeGroup.setName("Tree Group " + nrTreeGroups);
+ treeGroup.setIdColour(groupColour);
+ for (AlignmentPanel associatedPanel : associatedPanels)
+ {
+ AlignViewportI altViewport = associatedPanel
+ .getAlignViewport();
+ if (altViewport.getGlobalColourScheme() != null
+ && altViewport.getResidueShading()
+ .conservationApplied())
+ {
+ Conservation conserv = new Conservation(treeGroup.getName(),
+ treeGroup.getSequences(null), treeGroup.getStartRes(),
+ treeGroup.getEndRes());
+ conserv.calculate();
+ conserv.verdict(false, altViewport.getConsPercGaps());
+ treeGroup.getGroupColourScheme().setConservation(conserv);
+ }
+ altViewport.getAlignment().addGroup(treeGroup);
+ // TODO can we push all of the below into AlignViewportI?
+ final AlignViewportI codingComplement = altViewport
+ .getCodingComplement();
+ if (codingComplement != null)
+ {
+ SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(treeGroup,
+ parentAvport, codingComplement);
+ if (mappedGroup.getSequences().size() > 0)
+ {
+ codingComplement.getAlignment().addGroup(mappedGroup);
+ for (SequenceI seq : mappedGroup.getSequences())
+ {
+ codingComplement.setSequenceColour(seq, groupColour.brighter());
+ }
+ }
+ }
- // public List<PhylogenyNode> groupNodes(float threshold, PhylogenyNode root,
- // double treeHeight)
- // {
- // List<PhylogenyNode> groups = new ArrayList<>();
- // _groupNodes(groups, root, threshold, treeHeight);
- // System.out.println(groups);
- // return groups;
- // }
- //
- // protected void _groupNodes(List<PhylogenyNode> groups, PhylogenyNode nd,
- // float threshold, double treeHeight)
- // {
- // if (nd == null)
- // {
- // return;
- // }
- //
- // if ((nd.calculateDistanceToRoot() / treeHeight) > threshold)
- // {
- // groups.add(nd);
- // }
- // else
- // {
- // for (PhylogenyNode childNode : nd.getDescendants())
- // {
- // _groupNodes(groups, childNode, threshold, treeHeight);
- // }
- // }
- // }
- //
+ }
+ }
/**
* may or may not need an extra repaint on the alignment view (check what kira
}
public void sortByTree_actionPerformed() {
- // parentAvport.mirrorCommand(command, undo, ssm, source);
- // alignFrame
- // .addHistoryItem(sortAlignmentIn(treeCanvas.ap));
-
}
- /**
- * sort the associated alignment view by the current tree.
- *
- * @param e
- */
- // @Override
- // public void sortByTree_actionPerformed()// modify for Aptx
- // {
- //
- // // if (treeCanvas.applyToAllViews)
- //
- // final ArrayList<CommandI> commands = new ArrayList<>();
- // for (AlignmentPanel ap : PaintRefresher
- // .getAssociatedPanels(parentAvport.getSequenceSetId()))
- // {
- // commands.add(sortAlignmentIn(ap.parentAvport.getAlignPanel()));
- // }
- // parentAvport.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
- // {
- //
- // @Override
- // public void undoCommand(AlignmentI[] views)
- // {
- // for (CommandI tsort : commands)
- // {
- // tsort.undoCommand(views);
- // }
- // }
- //
- // @Override
- // public int getSize()
- // {
- // return commands.size();
- // }
- //
- // @Override
- // public String getDescription()
- // {
- // return "Tree Sort (many views)";
- // }
- //
- // @Override
- // public void doCommand(AlignmentI[] views)
- // {
- //
- // for (CommandI tsort : commands)
- // {
- // tsort.doCommand(views);
- // }
- // }
- // });
- // for (AlignmentPanel ap : PaintRefresher
- // .getAssociatedPanels(parentAvport.getSequenceSetId()))
- // {
- // // ensure all the alignFrames refresh their GI after adding an undo item
- // ap.alignFrame.updateEditMenuBar();
- // }
- // }
- // else
- // {
- // treeCanvas.ap.alignFrame
- // .addHistoryItem(sortAlignmentIn(treeCanvas.ap));
- // }
-
-
/**
* TO BE MOVED
{
this.parentAvport = parentAvport;
}
+
+ public AlignmentPanel[] getAssociatedPanels()
+ {
+ return associatedPanels;
+ }
+
+ public void setAssociatedPanels(AlignmentPanel[] associatedPanels)
+ {
+ this.associatedPanels = associatedPanels;
+ }
+
}