package jalview.ext.archaeopteryx;
+import jalview.analysis.Conservation;
+import jalview.api.AlignViewportI;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.ext.treeviewer.ExternalTreeViewerBindingI;
+import jalview.gui.AlignViewport;
import jalview.gui.Desktop;
import jalview.gui.JvOptionPane;
import jalview.gui.PaintRefresher;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.UserColourScheme;
import jalview.structure.SelectionSource;
import jalview.structure.StructureSelectionManager;
+import jalview.util.MappingUtils;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
private Map<PhylogenyNode, SequenceI> nodesBoundToSequences;
+ private float rootX;
+
+ private float furthestNodeX;
+
/**
*
* @param archaeopteryx
}
else
{
+
partitionTree(e.getX());
}
PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
+
+
+
}
});
if (matchingNode != null)
{
treeView.getFoundNodes0().add(matchingNode.getId());
+
+
+ if (!matchingNode.getBranchData().isHasBranchColor())
+ {
+ Color foundNodesColour = treeView.getTreeColorSet()
+ .getFoundColor0();
+ matchingNode.getBranchData()
+ .setBranchColor(new BranchColor(foundNodesColour));
+
+ }
+
}
}
- treeView.repaint();
+ treeView.repaint();
}
if (!tree.isEmpty())
{
- double longestBranch = tree.calculateHeight(true);
- if (longestBranch != 0)
+ // should be calculated on each partition as the tree can theoretically
+ // change in the meantime
+ PhylogenyNode furthestNode = PhylogenyMethods
+ .calculateNodeWithMaxDistanceToRoot(tree);
+ furthestNodeX = furthestNode.getXcoord();
+ rootX = tree.getRoot().getXcoord();
+
+ if (furthestNodeX != rootX && x < furthestNodeX) // don't bother if 0
+ // distance tree or
+ // clicked x lies outside
+ // of tree
{
Graphics g = treeView.getGraphics();
int panelHeight = treeView.getHeight();
g.drawLine(x, 0, x, panelHeight);
- // double relativeTreeWidth = treeDepth / viewWidth;
-
- float rootX = tree.getRoot().getXcoord();
- double threshold = ((double) x - rootX) / longestBranch;
+ float threshold = (x - rootX) / (furthestNodeX - rootX);
List<PhylogenyNode> foundNodes = getNodesAboveThreshold(threshold,
- longestBranch, tree.getRoot());
-
-
-
-
-
-
+ tree.getRoot());
}
}
}
public List<PhylogenyNode> getNodesAboveThreshold(double threshold,
- double treeLength, PhylogenyNode node)
+ PhylogenyNode node)
{
List<PhylogenyNode> nodesAboveThreshold = new ArrayList<>();
- // could also use PhylogenyMethods.getAllDescendants
- colourNodesAboveThreshold(nodesAboveThreshold, threshold, treeLength,
+ parentAvport.setSelectionGroup(null);
+ parentAvport.getAlignment().deleteAllGroups();
+ parentAvport.clearSequenceColours();
+ if (parentAvport.getCodingComplement() != null)
+ {
+ parentAvport.getCodingComplement().setSelectionGroup(null);
+ parentAvport.getCodingComplement().getAlignment().deleteAllGroups();
+ parentAvport.getCodingComplement().clearSequenceColours();
+ }
+
+
+ colourNodesAboveThreshold(nodesAboveThreshold, threshold,
node);
return nodesAboveThreshold;
}
+ /**
+ * Partially refactored from TreeCanvas colourGroups (can be made nicer).
+ *
+ * @param nodeList
+ * @param threshold
+ * @param treeLength
+ * @param node
+ * @return
+ */
private List<PhylogenyNode> colourNodesAboveThreshold(
List<PhylogenyNode> nodeList, double threshold,
- double treeLength, PhylogenyNode node)
+ PhylogenyNode node)
{
+ // could also use PhylogenyMethods.getAllDescendants
for (PhylogenyNode childNode : node.getDescendants())
{
- double nodeCutoff = childNode.calculateDistanceToRoot() / treeLength;
+ childNode.getBranchData()
+ .setBranchColor(new BranchColor(Color.black));
+ float nodeCutoff = (childNode.getXcoord() - rootX)
+ / (furthestNodeX - rootX);
if (nodeCutoff > threshold)
{
new BranchColor(randomColor));
List<PhylogenyNode> descendantNodes = childNode
.getAllExternalDescendants();
- List<SequenceI> descendantSeqs = new ArrayList<>();
+ List<SequenceI> descendantSeqs = new ArrayList<>(); // .forEach instead?
for (PhylogenyNode descNode : descendantNodes)
{
descendantSeqs.add(nodesBoundToSequences.get(descNode));
SequenceGroup sg = new SequenceGroup(descendantSeqs, 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
+ {
+ cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
+ .getColourName(parentAvport.getGlobalColourScheme()));
+ }
+ }
+ 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())
+ {
+ Conservation c = new Conservation("Group", sg.getSequences(null),
+ sg.getStartRes(), sg.getEndRes());
+ c.calculate();
+ c.verdict(false, parentAvport.getConsPercGaps());
+ sg.cs.setConservation(c);
+ }
+
+ parentAvport.getAlignment().addGroup(new SequenceGroup(sg));
+ // TODO can we push all of the below into AlignViewportI?
+ final AlignViewportI codingComplement = parentAvport
+ .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());
+ }
+ }
+ }
+
+
}
else
{
- colourNodesAboveThreshold(nodeList, threshold, treeLength,
+ colourNodesAboveThreshold(nodeList, threshold,
childNode);
}
+ }
+
+ // GROSS
+ ((AlignViewport) parentAvport).getAlignPanel().updateAnnotation();
+ final AlignViewportI codingComplement = parentAvport
+ .getCodingComplement();
+ if (codingComplement != null)
+ {
+ ((AlignViewport) codingComplement).getAlignPanel().updateAnnotation();
}
+
return nodeList;
}
// for (AlignmentPanel ap : PaintRefresher
// .getAssociatedPanels(parentAvport.getSequenceSetId()))
// {
- // commands.add(sortAlignmentIn(ap.av.getAlignPanel()));
+ // commands.add(sortAlignmentIn(ap.parentAvport.getAlignPanel()));
// }
- // av.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
+ // parentAvport.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
// {
//
// @Override
// }
// });
// for (AlignmentPanel ap : PaintRefresher
- // .getAssociatedPanels(av.getSequenceSetId()))
+ // .getAssociatedPanels(parentAvport.getSequenceSetId()))
// {
// // ensure all the alignFrames refresh their GI after adding an undo item
// ap.alignFrame.updateEditMenuBar();