2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Color;
24 import java.awt.Dimension;
26 import java.awt.FontMetrics;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.Point;
30 import java.awt.Rectangle;
31 import java.awt.RenderingHints;
32 import java.awt.event.MouseEvent;
33 import java.awt.event.MouseListener;
34 import java.awt.event.MouseMotionListener;
35 import java.awt.print.PageFormat;
36 import java.awt.print.Printable;
37 import java.awt.print.PrinterException;
38 import java.awt.print.PrinterJob;
39 import java.util.ArrayList;
40 import java.util.BitSet;
41 import java.util.HashMap;
42 import java.util.Hashtable;
43 import java.util.List;
45 import java.util.Map.Entry;
46 import java.util.Vector;
48 import javax.swing.JPanel;
49 import javax.swing.JScrollPane;
50 import javax.swing.SwingUtilities;
51 import javax.swing.ToolTipManager;
53 import jalview.analysis.Conservation;
54 import jalview.analysis.TreeModel;
55 import jalview.api.AlignViewportI;
56 import jalview.datamodel.AlignmentAnnotation;
57 import jalview.datamodel.Annotation;
58 import jalview.datamodel.BinaryNode;
59 import jalview.datamodel.ColumnSelection;
60 import jalview.datamodel.ContactMatrixI;
61 import jalview.datamodel.HiddenColumns;
62 import jalview.datamodel.Sequence;
63 import jalview.datamodel.SequenceGroup;
64 import jalview.datamodel.SequenceI;
65 import jalview.datamodel.SequenceNode;
66 import jalview.gui.JalviewColourChooser.ColourChooserListener;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.structure.SelectionSource;
69 import jalview.util.Format;
70 import jalview.util.MessageManager;
71 import jalview.ws.datamodel.MappableContactMatrixI;
79 public class TreeCanvas extends JPanel implements MouseListener, Runnable,
80 Printable, MouseMotionListener, SelectionSource
83 public static final String PLACEHOLDER = " * ";
87 JScrollPane scrollPane;
91 private AlignViewport av;
93 private AlignmentPanel ap;
99 boolean fitToWindow = true;
101 boolean showDistances = false;
103 boolean showBootstrap = false;
105 boolean markPlaceholders = false;
111 private float threshold;
115 int labelLength = -1;
117 Map<Object, Rectangle> nameHash = new Hashtable<>();
119 Map<BinaryNode, Rectangle> nodeHash = new Hashtable<>();
121 BinaryNode highlightNode;
123 boolean applyToAllViews = false;
126 * Creates a new TreeCanvas object.
137 public TreeCanvas(TreePanel tp, AlignmentPanel ap, JScrollPane scroller)
141 this.setAssociatedPanel(ap);
143 scrollPane = scroller;
144 addMouseListener(this);
145 addMouseMotionListener(this);
147 ToolTipManager.sharedInstance().registerComponent(this);
150 public void clearSelectedLeaves()
152 Vector<BinaryNode> leaves = tp.getTree()
153 .findLeaves(tp.getTree().getTopNode());
154 if (tp.isColumnWise())
156 markColumnsFor(getAssociatedPanels(), leaves, Color.white, true);
160 for (AlignmentPanel ap : getAssociatedPanels())
162 SequenceGroup selected = ap.av.getSelectionGroup();
163 if (selected != null)
166 for (int i = 0; i < leaves.size(); i++)
168 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
169 if (selected.contains(seq))
171 selected.addOrRemove(seq, false);
174 selected.recalcConservation();
177 ap.av.sendSelection();
180 PaintRefresher.Refresh(tp, av.getSequenceSetId());
189 public void treeSelectionChanged(SequenceI sequence)
191 AlignmentPanel[] aps = getAssociatedPanels();
193 for (int a = 0; a < aps.length; a++)
195 SequenceGroup selected = aps[a].av.getSelectionGroup();
197 if (selected == null)
199 selected = new SequenceGroup();
200 aps[a].av.setSelectionGroup(selected);
203 selected.setEndRes(aps[a].av.getAlignment().getWidth() - 1);
204 selected.addOrRemove(sequence, true);
214 public void setTree(TreeModel tree)
217 tree.findHeight(tree.getTopNode());
219 // Now have to calculate longest name based on the leaves
220 Vector<BinaryNode> leaves = tree.findLeaves(tree.getTopNode());
221 boolean has_placeholders = false;
224 for (int i = 0; i < leaves.size(); i++)
226 BinaryNode lf = leaves.elementAt(i);
228 if (lf instanceof SequenceNode && ((SequenceNode) lf).isPlaceholder())
230 has_placeholders = true;
233 if (longestName.length() < ((Sequence) lf.element()).getName()
236 longestName = TreeCanvas.PLACEHOLDER
237 + ((Sequence) lf.element()).getName();
241 setMarkPlaceholders(has_placeholders);
262 public void drawNode(Graphics g, BinaryNode node, float chunk,
263 double wscale, int width, int offx, int offy)
270 if ((node.left() == null) && (node.right() == null))
273 double height = node.height;
274 double dist = node.dist;
276 int xstart = (int) ((height - dist) * wscale) + offx;
277 int xend = (int) (height * wscale) + offx;
279 int ypos = (int) (node.ycount * chunk) + offy;
281 if (node.element() instanceof SequenceI)
283 SequenceI seq = (SequenceI) node.element();
285 if (av.getSequenceColour(seq) == Color.white)
287 g.setColor(Color.black);
291 g.setColor(av.getSequenceColour(seq).darker());
296 g.setColor(Color.black);
299 // Draw horizontal line
300 g.drawLine(xstart, ypos, xend, ypos);
302 String nodeLabel = "";
304 if (showDistances && (node.dist > 0))
306 nodeLabel = new Format("%g").form(node.dist);
309 if (showBootstrap && node.bootstrap > -1)
313 nodeLabel = nodeLabel + " : ";
316 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
319 if (!nodeLabel.equals(""))
321 g.drawString(nodeLabel, xstart + 2, ypos - 2);
324 String name = (markPlaceholders && ((node instanceof SequenceNode
325 && ((SequenceNode) node).isPlaceholder())))
326 ? (PLACEHOLDER + node.getName())
329 int charWidth = fm.stringWidth(name) + 3;
330 int charHeight = font.getSize();
332 Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2,
333 charWidth, charHeight);
335 nameHash.put(node.element(), rect);
337 // Colour selected leaves differently
338 boolean isSelected = false;
339 if (tp.isColumnWise())
341 isSelected = isColumnForNodeSelected(node);
345 SequenceGroup selected = av.getSelectionGroup();
347 if ((selected != null)
348 && selected.getSequences(null).contains(node.element()))
355 g.setColor(Color.gray);
357 g.fillRect(xend + 10, ypos - charHeight / 2, charWidth, charHeight);
358 g.setColor(Color.white);
361 g.drawString(name, xend + 10, ypos + fm.getDescent());
362 g.setColor(Color.black);
366 drawNode(g, (BinaryNode) node.left(), chunk, wscale, width, offx,
368 drawNode(g, (BinaryNode) node.right(), chunk, wscale, width, offx,
371 double height = node.height;
372 double dist = node.dist;
374 int xstart = (int) ((height - dist) * wscale) + offx;
375 int xend = (int) (height * wscale) + offx;
376 int ypos = (int) (node.ycount * chunk) + offy;
378 g.setColor(node.color.darker());
380 // Draw horizontal line
381 g.drawLine(xstart, ypos, xend, ypos);
382 if (node == highlightNode)
384 g.fillRect(xend - 3, ypos - 3, 6, 6);
388 g.fillRect(xend - 2, ypos - 2, 4, 4);
391 int ystart = (node.left() == null ? 0
392 : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy;
393 int yend = (node.right() == null ? 0
394 : (int) (((BinaryNode) node.right()).ycount * chunk)) + offy;
396 Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
397 nodeHash.put(node, pos);
399 g.drawLine((int) (height * wscale) + offx, ystart,
400 (int) (height * wscale) + offx, yend);
402 String nodeLabel = "";
404 if (showDistances && (node.dist > 0))
406 nodeLabel = new Format("%g").form(node.dist);
409 if (showBootstrap && node.bootstrap > -1)
413 nodeLabel = nodeLabel + " : ";
416 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
419 if (!nodeLabel.equals(""))
421 g.drawString(nodeLabel, xstart + 2, ypos - 2);
434 * @return DOCUMENT ME!
436 public Object findElement(int x, int y)
438 for (Entry<Object, Rectangle> entry : nameHash.entrySet())
440 Rectangle rect = entry.getValue();
442 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
443 && (y <= (rect.y + rect.height)))
445 return entry.getKey();
449 for (Entry<BinaryNode, Rectangle> entry : nodeHash.entrySet())
451 Rectangle rect = entry.getValue();
453 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
454 && (y <= (rect.y + rect.height)))
456 return entry.getKey();
469 public void pickNodes(Rectangle pickBox)
471 int width = getWidth();
472 int height = getHeight();
474 BinaryNode top = tree.getTopNode();
476 double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
480 top.count = ((BinaryNode) top.left()).count
481 + ((BinaryNode) top.right()).count;
484 float chunk = (float) (height - (offy)) / top.count;
486 pickNode(pickBox, top, chunk, wscale, width, offx, offy);
507 public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
508 double wscale, int width, int offx, int offy)
515 if ((node.left() == null) && (node.right() == null))
517 double height = node.height;
518 // double dist = node.dist;
519 // int xstart = (int) ((height - dist) * wscale) + offx;
520 int xend = (int) (height * wscale) + offx;
522 int ypos = (int) (node.ycount * chunk) + offy;
524 if (pickBox.contains(new Point(xend, ypos)))
526 if (node.element() instanceof SequenceI)
528 SequenceI seq = (SequenceI) node.element();
529 SequenceGroup sg = av.getSelectionGroup();
533 sg.addOrRemove(seq, true);
540 pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width,
542 pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width,
555 public void setColor(BinaryNode node, Color c)
563 if (node.element() instanceof SequenceI)
565 final SequenceI seq = (SequenceI) node.element();
566 AlignmentPanel[] aps = getAssociatedPanels();
569 for (int a = 0; a < aps.length; a++)
571 aps[a].av.setSequenceColour(seq, c);
575 setColor((BinaryNode) node.left(), c);
576 setColor((BinaryNode) node.right(), c);
584 Thread thread = new Thread(this);
588 // put printing in a thread to avoid painting problems
592 PrinterJob printJob = PrinterJob.getPrinterJob();
593 PageFormat defaultPage = printJob.defaultPage();
594 PageFormat pf = printJob.pageDialog(defaultPage);
596 if (defaultPage == pf)
604 printJob.setPrintable(this, pf);
606 if (printJob.printDialog())
611 } catch (Exception PrintException)
613 PrintException.printStackTrace();
628 * @return DOCUMENT ME!
630 * @throws PrinterException
634 public int print(Graphics pg, PageFormat pf, int pi)
635 throws PrinterException
638 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
640 int pwidth = (int) pf.getImageableWidth();
641 int pheight = (int) pf.getImageableHeight();
643 int noPages = getHeight() / pheight;
647 return Printable.NO_SUCH_PAGE;
650 if (pwidth > getWidth())
657 if (pheight > getHeight())
659 pheight = getHeight();
666 FontMetrics fm = pg.getFontMetrics(font);
667 int height = fm.getHeight() * nameHash.size();
668 pg.translate(0, -pi * pheight);
669 pg.setClip(0, pi * pheight, pwidth, (pi * pheight) + pheight);
671 // translate number of pages,
672 // height is screen size as this is the
673 // non overlapping text size
677 draw(pg, pwidth, pheight);
679 return Printable.PAGE_EXISTS;
689 public void paintComponent(Graphics g)
691 super.paintComponent(g);
697 MessageManager.getString("label.calculating_tree") + "....",
698 20, getHeight() / 2);
702 fm = g.getFontMetrics(font);
704 int nameCount = nameHash.size();
710 if (fitToWindow || (!fitToWindow && (scrollPane
711 .getHeight() > ((fm.getHeight() * nameCount) + offy))))
713 draw(g, scrollPane.getWidth(), scrollPane.getHeight());
714 setPreferredSize(null);
718 setPreferredSize(new Dimension(scrollPane.getWidth(),
719 fm.getHeight() * nameCount));
720 draw(g, scrollPane.getWidth(), fm.getHeight() * nameCount);
723 scrollPane.revalidate();
734 public void setFont(Font font)
750 public void draw(Graphics g1, int width, int height)
752 Graphics2D g2 = (Graphics2D) g1;
753 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
754 RenderingHints.VALUE_ANTIALIAS_ON);
755 g2.setColor(Color.white);
756 g2.fillRect(0, 0, width, height);
759 if (longestName == null || tree == null)
761 g2.drawString("Calculating tree.", 20, 20);
764 offy = font.getSize() + 10;
766 fm = g2.getFontMetrics(font);
768 labelLength = fm.stringWidth(longestName) + 20; // 20 allows for scrollbar
770 double wscale = (width - labelLength - (offx * 2))
771 / tree.getMaxHeight();
773 BinaryNode top = tree.getTopNode();
777 top.count = ((BinaryNode) top.left()).count
778 + ((BinaryNode) top.right()).count;
781 float chunk = (float) (height - (offy)) / top.count;
783 drawNode(g2, tree.getTopNode(), chunk, wscale, width, offx, offy);
787 if (av.getCurrentTree() == tree)
789 g2.setColor(Color.red);
793 g2.setColor(Color.gray);
796 int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx)))
799 g2.drawLine(x, 0, x, getHeight());
804 * Empty method to satisfy the MouseListener interface
809 public void mouseReleased(MouseEvent e)
812 * isPopupTrigger is set on mouseReleased on Windows
814 if (e.isPopupTrigger())
816 chooseSubtreeColour();
817 e.consume(); // prevent mouseClicked happening
822 * Empty method to satisfy the MouseListener interface
827 public void mouseEntered(MouseEvent e)
832 * Empty method to satisfy the MouseListener interface
837 public void mouseExited(MouseEvent e)
842 * Handles a mouse click on a tree node (clicks elsewhere are handled in
843 * mousePressed). Click selects the sub-tree, double-click swaps leaf nodes
844 * order, right-click opens a dialogue to choose colour for the sub-tree.
849 public void mouseClicked(MouseEvent evt)
851 if (highlightNode == null)
856 if (evt.getClickCount() > 1)
858 tree.swapNodes(highlightNode);
859 tree.reCount(tree.getTopNode());
860 tree.findHeight(tree.getTopNode());
864 Vector<BinaryNode> leaves = tree.findLeaves(highlightNode);
865 if (tp.isColumnWise())
867 markColumnsFor(getAssociatedPanels(), leaves, Color.red,false);
871 for (int i = 0; i < leaves.size(); i++)
873 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
874 treeSelectionChanged(seq);
880 PaintRefresher.Refresh(tp, av.getSequenceSetId());
885 * Offer the user the option to choose a colour for the highlighted node and
886 * its children; this colour is also applied to the corresponding sequence ids
889 void chooseSubtreeColour()
891 String ttl = MessageManager.getString("label.select_subtree_colour");
892 ColourChooserListener listener = new ColourChooserListener()
895 public void colourSelected(Color c)
897 setColor(highlightNode, c);
898 PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
902 JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color,
907 public void mouseMoved(MouseEvent evt)
909 av.setCurrentTree(tree);
911 Object ob = findElement(evt.getX(), evt.getY());
913 if (ob instanceof BinaryNode)
915 highlightNode = (BinaryNode) ob;
917 "<html>" + MessageManager.getString("label.highlightnode"));
923 if (highlightNode != null)
925 highlightNode = null;
926 setToolTipText(null);
933 public void mouseDragged(MouseEvent ect)
938 * Handles a mouse press on a sequence name or the tree background canvas
939 * (click on a node is handled in mouseClicked). The action is to create
940 * groups by partitioning the tree at the mouse position. Colours for the
941 * groups (and sequence names) are generated randomly.
946 public void mousePressed(MouseEvent e)
948 av.setCurrentTree(tree);
951 * isPopupTrigger is set for mousePressed (Mac)
952 * or mouseReleased (Windows)
954 if (e.isPopupTrigger())
956 if (highlightNode != null)
958 chooseSubtreeColour();
964 * defer right-click handling on Windows to
965 * mouseClicked; note isRightMouseButton
966 * also matches Cmd-click on Mac which should do
969 if (SwingUtilities.isRightMouseButton(e))
977 Object ob = findElement(x, y);
979 if (ob instanceof SequenceI)
981 treeSelectionChanged((Sequence) ob);
982 PaintRefresher.Refresh(tp,
983 getAssociatedPanel().av.getSequenceSetId());
988 else if (!(ob instanceof BinaryNode))
991 if (tree.getMaxHeight() != 0)
993 threshold = (float) (x - offx)
994 / (float) (getWidth() - labelLength - (2 * offx));
996 List<BinaryNode> groups = tree.groupNodes(threshold);
997 setColor(tree.getTopNode(), Color.black);
999 AlignmentPanel[] aps = getAssociatedPanels();
1001 // TODO push calls below into a single AlignViewportI method?
1002 // see also AlignViewController.deleteGroups
1003 for (int a = 0; a < aps.length; a++)
1005 aps[a].av.setSelectionGroup(null);
1006 aps[a].av.getAlignment().deleteAllGroups();
1007 aps[a].av.clearSequenceColours();
1008 if (aps[a].av.getCodingComplement() != null)
1010 aps[a].av.getCodingComplement().setSelectionGroup(null);
1011 aps[a].av.getCodingComplement().getAlignment()
1013 aps[a].av.getCodingComplement().clearSequenceColours();
1015 aps[a].av.setUpdateStructures(true);
1017 colourGroups(groups);
1020 * clear partition (don't show vertical line) if
1021 * it is to the right of all nodes
1023 if (groups.isEmpty())
1029 PaintRefresher.Refresh(tp,
1030 getAssociatedPanel().av.getSequenceSetId());
1036 void colourGroups(List<BinaryNode> groups)
1038 AlignmentPanel[] aps = getAssociatedPanels();
1039 List<BitSet> colGroups = new ArrayList<>();
1040 Map<BitSet, Color> colors = new HashMap();
1041 for (int i = 0; i < groups.size(); i++)
1043 Color col = new Color((int) (Math.random() * 255),
1044 (int) (Math.random() * 255), (int) (Math.random() * 255));
1045 setColor(groups.get(i), col.brighter());
1047 Vector<BinaryNode> l = tree.findLeaves(groups.get(i));
1048 if (!tp.isColumnWise())
1050 createSeqGroupFor(aps, l, col);
1054 BitSet gp = createColumnGroupFor(l, col);
1057 colors.put(gp, col);
1060 if (tp.isColumnWise())
1062 AlignmentAnnotation aa = tp.getAssocAnnotation();
1065 ContactMatrixI cm = av.getContactMatrix(aa);
1068 cm.updateGroups(colGroups);
1069 for (BitSet gp : colors.keySet())
1071 cm.setColorForGroup(gp, colors.get(gp));
1074 // stash colors in linked annotation row.
1075 // doesn't work yet. TESTS!
1076 int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1
1080 int[] seqpos = null;
1081 for (BitSet gp : colors.keySet())
1083 gpcol = colors.get(gp);
1084 for (int p = gp.nextSetBit(0); p >= 0
1085 && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
1087 if (cm instanceof MappableContactMatrixI)
1089 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1090 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p);
1093 // no mapping for this column.
1096 // TODO: handle ranges...
1097 ae = aa.getAnnotationForPosition(seqpos[0]);
1101 ae = aa.getAnnotationForPosition(p + sstart);
1105 ae.colour = gpcol.brighter().darker();
1112 // notify the panel(s) to redo any group specific stuff
1113 // also updates structure views if necessary
1114 for (int a = 0; a < aps.length; a++)
1116 aps[a].updateAnnotation();
1117 final AlignViewportI codingComplement = aps[a].av
1118 .getCodingComplement();
1119 if (codingComplement != null)
1121 ((AlignViewport) codingComplement).getAlignPanel()
1122 .updateAnnotation();
1127 private boolean isColumnForNodeSelected(BinaryNode bn)
1129 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1133 colm = Integer.parseInt(
1134 bn.getName().substring(bn.getName().indexOf("c") + 1));
1135 } catch (Exception e)
1139 if (av == null || av.getAlignment() == null)
1141 // alignment is closed
1144 ColumnSelection cs = av.getColumnSelection();
1145 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1146 AlignmentAnnotation aa = tp.getAssocAnnotation();
1150 ContactMatrixI cm = av.getContactMatrix(aa);
1151 // generally, we assume cm has 1:1 mapping to annotation row - probably wrong
1153 if (cm instanceof MappableContactMatrixI)
1156 // use the mappable's mapping - always the case for PAE Matrices so good
1158 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1159 pos = mcm.getMappedPositionsFor(rseq, colm + 1);
1160 // finally, look up the position of the column
1163 offp = rseq.findIndex(pos[0]);
1175 if (!av.hasHiddenColumns())
1177 return cs.contains(offp);
1179 if (hc.isVisible(offp))
1181 return cs.contains(offp);
1182 // return cs.contains(hc.absoluteToVisibleColumn(offp));
1186 private BitSet createColumnGroupFor(Vector<BinaryNode> l, Color col)
1188 BitSet gp = new BitSet();
1189 for (BinaryNode bn : l)
1192 if (bn.element() != null && bn.element() instanceof Integer)
1194 colm = (Integer) bn.element();
1198 // parse out from nodename
1201 colm = Integer.parseInt(
1202 bn.getName().substring(bn.getName().indexOf("c") + 1));
1203 } catch (Exception e)
1213 private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1214 Color col, boolean clearSelected)
1216 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1217 if (av == null || av.getAlignment() == null)
1219 // alignment is closed
1223 // TODO - sort indices for faster lookup
1224 ColumnSelection cs = av.getColumnSelection();
1225 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1226 ContactMatrixI cm = av.getContactMatrix(tp.assocAnnotation);
1227 MappableContactMatrixI mcm = null;
1229 if (cm instanceof MappableContactMatrixI)
1231 mcm = (MappableContactMatrixI) cm;
1233 for (BinaryNode bn : l)
1238 colm = Integer.parseInt(
1239 bn.getName().substring(bn.getName().indexOf("c") + 1));
1240 } catch (Exception e)
1246 int[] seqpos = mcm.getMappedPositionsFor(
1247 tp.assocAnnotation.sequenceRef, colm);
1250 // no mapping for this column.
1253 // TODO: handle ranges...
1258 offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1261 if (!av.hasHiddenColumns() || hc.isVisible(offp))
1263 if (clearSelected || cs.contains(offp))
1265 cs.removeElement(offp);
1269 cs.addElement(offp);
1273 PaintRefresher.Refresh(tp, av.getSequenceSetId());
1276 public void createSeqGroupFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1280 Vector<SequenceI> sequences = new Vector<>();
1282 for (int j = 0; j < l.size(); j++)
1284 SequenceI s1 = (SequenceI) l.elementAt(j).element();
1286 if (!sequences.contains(s1))
1288 sequences.addElement(s1);
1292 ColourSchemeI cs = null;
1293 SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
1294 false, 0, av.getAlignment().getWidth() - 1);
1296 _sg.setName("JTreeGroup:" + _sg.hashCode());
1297 _sg.setIdColour(col);
1299 for (int a = 0; a < aps.length; a++)
1301 SequenceGroup sg = new SequenceGroup(_sg);
1302 AlignViewport viewport = aps[a].av;
1304 // Propagate group colours in each view
1305 if (viewport.getGlobalColourScheme() != null)
1307 cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
1308 sg.setColourScheme(cs);
1309 sg.getGroupColourScheme().setThreshold(
1310 viewport.getResidueShading().getThreshold(),
1311 viewport.isIgnoreGapsConsensus());
1313 if (viewport.getResidueShading().conservationApplied())
1315 Conservation c = new Conservation("Group", sg.getSequences(null),
1316 sg.getStartRes(), sg.getEndRes());
1318 c.verdict(false, viewport.getConsPercGaps());
1319 sg.cs.setConservation(c);
1322 // indicate that associated structure views will need an update
1323 viewport.setUpdateStructures(true);
1324 // propagate structure view update and sequence group to complement view
1325 viewport.addSequenceGroup(sg);
1335 public void setShowDistances(boolean state)
1337 this.showDistances = state;
1347 public void setShowBootstrap(boolean state)
1349 this.showBootstrap = state;
1359 public void setMarkPlaceholders(boolean state)
1361 this.markPlaceholders = state;
1365 AlignmentPanel[] getAssociatedPanels()
1367 if (applyToAllViews)
1369 return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
1373 return new AlignmentPanel[] { getAssociatedPanel() };
1377 public AlignmentPanel getAssociatedPanel()
1382 public void setAssociatedPanel(AlignmentPanel ap)
1387 public AlignViewport getViewport()
1392 public void setViewport(AlignViewport av)
1397 public float getThreshold()
1402 public void setThreshold(float threshold)
1404 this.threshold = threshold;
1407 public boolean isApplyToAllViews()
1409 return this.applyToAllViews;
1412 public void setApplyToAllViews(boolean applyToAllViews)
1414 this.applyToAllViews = applyToAllViews;