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.bin.Console;
57 import jalview.datamodel.AlignmentAnnotation;
58 import jalview.datamodel.Annotation;
59 import jalview.datamodel.BinaryNode;
60 import jalview.datamodel.ColumnSelection;
61 import jalview.datamodel.ContactMatrixI;
62 import jalview.datamodel.HiddenColumns;
63 import jalview.datamodel.Sequence;
64 import jalview.datamodel.SequenceGroup;
65 import jalview.datamodel.SequenceI;
66 import jalview.datamodel.SequenceNode;
67 import jalview.gui.JalviewColourChooser.ColourChooserListener;
68 import jalview.schemes.ColourSchemeI;
69 import jalview.structure.SelectionSource;
70 import jalview.util.ColorUtils;
71 import jalview.util.Format;
72 import jalview.util.MessageManager;
73 import jalview.ws.datamodel.MappableContactMatrixI;
81 public class TreeCanvas extends JPanel implements MouseListener, Runnable,
82 Printable, MouseMotionListener, SelectionSource
85 public static final String PLACEHOLDER = " * ";
89 JScrollPane scrollPane;
93 private AlignViewport av;
95 private AlignmentPanel ap;
101 boolean fitToWindow = true;
103 boolean showDistances = false;
105 boolean showBootstrap = false;
107 boolean markPlaceholders = false;
113 private float threshold;
117 int labelLength = -1;
119 Map<Object, Rectangle> nameHash = new Hashtable<>();
121 Map<BinaryNode, Rectangle> nodeHash = new Hashtable<>();
123 BinaryNode highlightNode;
125 boolean applyToAllViews = false;
128 * Creates a new TreeCanvas object.
139 public TreeCanvas(TreePanel tp, AlignmentPanel ap, JScrollPane scroller)
143 this.setAssociatedPanel(ap);
145 scrollPane = scroller;
146 addMouseListener(this);
147 addMouseMotionListener(this);
149 ToolTipManager.sharedInstance().registerComponent(this);
152 public void clearSelectedLeaves()
154 Vector<BinaryNode> leaves = tp.getTree()
155 .findLeaves(tp.getTree().getTopNode());
156 if (tp.isColumnWise())
158 markColumnsFor(getAssociatedPanels(), leaves, Color.white, true);
162 for (AlignmentPanel ap : getAssociatedPanels())
164 SequenceGroup selected = ap.av.getSelectionGroup();
165 if (selected != null)
168 for (int i = 0; i < leaves.size(); i++)
170 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
171 if (selected.contains(seq))
173 selected.addOrRemove(seq, false);
176 selected.recalcConservation();
179 ap.av.sendSelection();
182 PaintRefresher.Refresh(tp, av.getSequenceSetId());
191 public void treeSelectionChanged(SequenceI sequence)
193 AlignmentPanel[] aps = getAssociatedPanels();
195 for (int a = 0; a < aps.length; a++)
197 SequenceGroup selected = aps[a].av.getSelectionGroup();
199 if (selected == null)
201 selected = new SequenceGroup();
202 aps[a].av.setSelectionGroup(selected);
205 selected.setEndRes(aps[a].av.getAlignment().getWidth() - 1);
206 selected.addOrRemove(sequence, true);
216 public void setTree(TreeModel tree)
219 tree.findHeight(tree.getTopNode());
221 // Now have to calculate longest name based on the leaves
222 Vector<BinaryNode> leaves = tree.findLeaves(tree.getTopNode());
223 boolean has_placeholders = false;
226 AlignmentAnnotation aa = tp.getAssocAnnotation();
227 ContactMatrixI cm = (aa!=null) ? av.getContactMatrix(aa) : null;
228 if (cm!=null && cm.hasCutHeight())
230 threshold=(float) cm.getCutHeight();
233 for (int i = 0; i < leaves.size(); i++)
235 BinaryNode lf = leaves.elementAt(i);
237 if (lf instanceof SequenceNode && ((SequenceNode) lf).isPlaceholder())
239 has_placeholders = true;
242 if (longestName.length() < ((Sequence) lf.element()).getName()
245 longestName = TreeCanvas.PLACEHOLDER
246 + ((Sequence) lf.element()).getName();
248 if (tp.isColumnWise() && cm!=null)
250 // get color from group colours, if they are set for the matrix
252 Color col = cm.getGroupColorForPosition(parseColumnNode(lf));
253 setColor(lf,col.brighter());
254 } catch (NumberFormatException ex) {};
258 setMarkPlaceholders(has_placeholders);
279 public void drawNode(Graphics g, BinaryNode node, double chunk,
280 double wscale, int width, int offx, int offy)
287 if ((node.left() == null) && (node.right() == null))
290 double height = node.height;
291 double dist = node.dist;
293 int xstart = (int) ((height - dist) * wscale) + offx;
294 int xend = (int) (height * wscale) + offx;
296 int ypos = (int) (node.ycount * chunk) + offy;
298 if (node.element() instanceof SequenceI)
300 SequenceI seq = (SequenceI) node.element();
302 if (av.getSequenceColour(seq) == Color.white)
304 g.setColor(Color.black);
308 g.setColor(av.getSequenceColour(seq).darker());
313 g.setColor(Color.black);
316 // Draw horizontal line
317 g.drawLine(xstart, ypos, xend, ypos);
319 String nodeLabel = "";
321 if (showDistances && (node.dist > 0))
323 nodeLabel = new Format("%g").form(node.dist);
326 if (showBootstrap && node.bootstrap > -1)
330 nodeLabel = nodeLabel + " : ";
333 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
336 if (!nodeLabel.equals(""))
338 g.drawString(nodeLabel, xstart + 2, ypos - 2);
341 String name = (markPlaceholders && ((node instanceof SequenceNode
342 && ((SequenceNode) node).isPlaceholder())))
343 ? (PLACEHOLDER + node.getName())
346 int charWidth = fm.stringWidth(name) + 3;
347 int charHeight = font.getSize();
349 Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2,
350 charWidth, charHeight);
352 nameHash.put(node.element(), rect);
354 // Colour selected leaves differently
355 boolean isSelected = false;
356 if (tp.isColumnWise())
358 isSelected = isColumnForNodeSelected(node);
362 SequenceGroup selected = av.getSelectionGroup();
364 if ((selected != null)
365 && selected.getSequences(null).contains(node.element()))
372 g.setColor(Color.gray);
374 g.fillRect(xend + 10, ypos - charHeight / 2, charWidth, charHeight);
375 g.setColor(Color.white);
378 g.drawString(name, xend + 10, ypos + fm.getDescent());
379 g.setColor(Color.black);
383 drawNode(g, (BinaryNode) node.left(), chunk, wscale, width, offx,
385 drawNode(g, (BinaryNode) node.right(), chunk, wscale, width, offx,
388 double height = node.height;
389 double dist = node.dist;
391 int xstart = (int) ((height - dist) * wscale) + offx;
392 int xend = (int) (height * wscale) + offx;
393 int ypos = (int) (node.ycount * chunk) + offy;
395 g.setColor(node.color.darker());
397 // Draw horizontal line
398 g.drawLine(xstart, ypos, xend, ypos);
399 if (node == highlightNode)
401 g.fillRect(xend - 3, ypos - 3, 6, 6);
405 g.fillRect(xend - 2, ypos - 2, 4, 4);
408 int ystart = (node.left() == null ? 0
409 : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy;
410 int yend = (node.right() == null ? 0
411 : (int) (((BinaryNode) node.right()).ycount * chunk)) + offy;
413 Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
414 nodeHash.put(node, pos);
416 g.drawLine((int) (height * wscale) + offx, ystart,
417 (int) (height * wscale) + offx, yend);
419 String nodeLabel = "";
421 if (showDistances && (node.dist > 0))
423 nodeLabel = new Format("%g").form(node.dist);
426 if (showBootstrap && node.bootstrap > -1)
430 nodeLabel = nodeLabel + " : ";
433 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
436 if (!nodeLabel.equals(""))
438 g.drawString(nodeLabel, xstart + 2, ypos - 2);
451 * @return DOCUMENT ME!
453 public Object findElement(int x, int y)
455 for (Entry<Object, Rectangle> entry : nameHash.entrySet())
457 Rectangle rect = entry.getValue();
459 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
460 && (y <= (rect.y + rect.height)))
462 return entry.getKey();
466 for (Entry<BinaryNode, Rectangle> entry : nodeHash.entrySet())
468 Rectangle rect = entry.getValue();
470 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
471 && (y <= (rect.y + rect.height)))
473 return entry.getKey();
486 public void pickNodes(Rectangle pickBox)
488 int width = getWidth();
489 int height = getHeight();
491 BinaryNode top = tree.getTopNode();
493 double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
497 top.count = ((BinaryNode) top.left()).count
498 + ((BinaryNode) top.right()).count;
501 float chunk = (float) (height - (offy)) / top.count;
503 pickNode(pickBox, top, chunk, wscale, width, offx, offy);
524 public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
525 double wscale, int width, int offx, int offy)
532 if ((node.left() == null) && (node.right() == null))
534 double height = node.height;
535 // double dist = node.dist;
536 // int xstart = (int) ((height - dist) * wscale) + offx;
537 int xend = (int) (height * wscale) + offx;
539 int ypos = (int) (node.ycount * chunk) + offy;
541 if (pickBox.contains(new Point(xend, ypos)))
543 if (node.element() instanceof SequenceI)
545 SequenceI seq = (SequenceI) node.element();
546 SequenceGroup sg = av.getSelectionGroup();
550 sg.addOrRemove(seq, true);
557 pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width,
559 pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width,
572 public void setColor(BinaryNode node, Color c)
580 if (node.element() instanceof SequenceI)
582 final SequenceI seq = (SequenceI) node.element();
583 AlignmentPanel[] aps = getAssociatedPanels();
586 for (int a = 0; a < aps.length; a++)
588 aps[a].av.setSequenceColour(seq, c);
592 setColor((BinaryNode) node.left(), c);
593 setColor((BinaryNode) node.right(), c);
601 Thread thread = new Thread(this);
605 // put printing in a thread to avoid painting problems
609 PrinterJob printJob = PrinterJob.getPrinterJob();
610 PageFormat defaultPage = printJob.defaultPage();
611 PageFormat pf = printJob.pageDialog(defaultPage);
613 if (defaultPage == pf)
621 printJob.setPrintable(this, pf);
623 if (printJob.printDialog())
628 } catch (Exception PrintException)
630 PrintException.printStackTrace();
645 * @return DOCUMENT ME!
647 * @throws PrinterException
651 public int print(Graphics pg, PageFormat pf, int pi)
652 throws PrinterException
655 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
657 int pwidth = (int) pf.getImageableWidth();
658 int pheight = (int) pf.getImageableHeight();
660 int noPages = getHeight() / pheight;
664 return Printable.NO_SUCH_PAGE;
667 if (pwidth > getWidth())
674 if (pheight > getHeight())
676 pheight = getHeight();
683 FontMetrics fm = pg.getFontMetrics(font);
684 int height = fm.getHeight() * nameHash.size();
685 pg.translate(0, -pi * pheight);
686 pg.setClip(0, pi * pheight, pwidth, (pi * pheight) + pheight);
688 // translate number of pages,
689 // height is screen size as this is the
690 // non overlapping text size
694 draw(pg, pwidth, pheight);
696 return Printable.PAGE_EXISTS;
706 public void paintComponent(Graphics g)
708 super.paintComponent(g);
714 MessageManager.getString("label.calculating_tree") + "....",
715 20, getHeight() / 2);
719 fm = g.getFontMetrics(font);
721 int nameCount = nameHash.size();
727 if (fitToWindow || (!fitToWindow && (scrollPane
728 .getHeight() > ((fm.getHeight() * nameCount) + offy))))
730 draw(g, scrollPane.getWidth(), scrollPane.getHeight());
731 setPreferredSize(null);
735 setPreferredSize(new Dimension(scrollPane.getWidth(),
736 fm.getHeight() * nameCount));
737 draw(g, scrollPane.getWidth(), fm.getHeight() * nameCount);
740 scrollPane.revalidate();
751 public void setFont(Font font)
767 public void draw(Graphics g1, int width, int height)
769 Graphics2D g2 = (Graphics2D) g1;
770 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
771 RenderingHints.VALUE_ANTIALIAS_ON);
772 g2.setColor(Color.white);
773 g2.fillRect(0, 0, width, height);
776 if (longestName == null || tree == null)
778 g2.drawString("Calculating tree.", 20, 20);
781 offy = font.getSize() + 10;
783 fm = g2.getFontMetrics(font);
785 labelLength = fm.stringWidth(longestName) + 20; // 20 allows for scrollbar
787 double wscale = (width - labelLength - (offx * 2))
788 / tree.getMaxHeight();
790 BinaryNode top = tree.getTopNode();
794 top.count = ((BinaryNode) top.left()).count
795 + ((BinaryNode) top.right()).count;
798 double chunk = (double) (height - (offy)) / (double)top.count;
800 drawNode(g2, tree.getTopNode(), chunk, wscale, width, offx, offy);
804 if (av.getCurrentTree() == tree)
806 g2.setColor(Color.red);
810 g2.setColor(Color.gray);
813 int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx)))
816 g2.drawLine(x, 0, x, getHeight());
821 * Empty method to satisfy the MouseListener interface
826 public void mouseReleased(MouseEvent e)
829 * isPopupTrigger is set on mouseReleased on Windows
831 if (e.isPopupTrigger())
833 chooseSubtreeColour();
834 e.consume(); // prevent mouseClicked happening
839 * Empty method to satisfy the MouseListener interface
844 public void mouseEntered(MouseEvent e)
849 * Empty method to satisfy the MouseListener interface
854 public void mouseExited(MouseEvent e)
859 * Handles a mouse click on a tree node (clicks elsewhere are handled in
860 * mousePressed). Click selects the sub-tree, double-click swaps leaf nodes
861 * order, right-click opens a dialogue to choose colour for the sub-tree.
866 public void mouseClicked(MouseEvent evt)
868 if (highlightNode == null)
873 if (evt.getClickCount() > 1)
875 tree.swapNodes(highlightNode);
876 tree.reCount(tree.getTopNode());
877 tree.findHeight(tree.getTopNode());
881 Vector<BinaryNode> leaves = tree.findLeaves(highlightNode);
882 if (tp.isColumnWise())
884 markColumnsFor(getAssociatedPanels(), leaves, Color.red,false);
888 for (int i = 0; i < leaves.size(); i++)
890 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
891 treeSelectionChanged(seq);
897 PaintRefresher.Refresh(tp, av.getSequenceSetId());
902 * Offer the user the option to choose a colour for the highlighted node and
903 * its children; this colour is also applied to the corresponding sequence ids
906 void chooseSubtreeColour()
908 String ttl = MessageManager.getString("label.select_subtree_colour");
909 ColourChooserListener listener = new ColourChooserListener()
912 public void colourSelected(Color c)
914 setColor(highlightNode, c);
915 PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
919 JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color,
924 public void mouseMoved(MouseEvent evt)
926 av.setCurrentTree(tree);
928 Object ob = findElement(evt.getX(), evt.getY());
930 if (ob instanceof BinaryNode)
932 highlightNode = (BinaryNode) ob;
934 "<html>" + MessageManager.getString("label.highlightnode"));
940 if (highlightNode != null)
942 highlightNode = null;
943 setToolTipText(null);
950 public void mouseDragged(MouseEvent ect)
955 * Handles a mouse press on a sequence name or the tree background canvas
956 * (click on a node is handled in mouseClicked). The action is to create
957 * groups by partitioning the tree at the mouse position. Colours for the
958 * groups (and sequence names) are generated randomly.
963 public void mousePressed(MouseEvent e)
965 av.setCurrentTree(tree);
968 * isPopupTrigger is set for mousePressed (Mac)
969 * or mouseReleased (Windows)
971 if (e.isPopupTrigger())
973 if (highlightNode != null)
975 chooseSubtreeColour();
981 * defer right-click handling on Windows to
982 * mouseClicked; note isRightMouseButton
983 * also matches Cmd-click on Mac which should do
986 if (SwingUtilities.isRightMouseButton(e))
994 Object ob = findElement(x, y);
996 if (ob instanceof SequenceI)
998 treeSelectionChanged((Sequence) ob);
999 PaintRefresher.Refresh(tp,
1000 getAssociatedPanel().av.getSequenceSetId());
1005 else if (!(ob instanceof BinaryNode))
1008 if (tree.getMaxHeight() != 0)
1010 threshold = (float) (x - offx)
1011 / (float) (getWidth() - labelLength - (2 * offx));
1013 List<BinaryNode> groups = tree.groupNodes(threshold);
1014 setColor(tree.getTopNode(), Color.black);
1016 AlignmentPanel[] aps = getAssociatedPanels();
1018 // TODO push calls below into a single AlignViewportI method?
1019 // see also AlignViewController.deleteGroups
1020 for (int a = 0; a < aps.length; a++)
1022 aps[a].av.setSelectionGroup(null);
1023 aps[a].av.getAlignment().deleteAllGroups();
1024 aps[a].av.clearSequenceColours();
1025 if (aps[a].av.getCodingComplement() != null)
1027 aps[a].av.getCodingComplement().setSelectionGroup(null);
1028 aps[a].av.getCodingComplement().getAlignment()
1030 aps[a].av.getCodingComplement().clearSequenceColours();
1032 aps[a].av.setUpdateStructures(true);
1034 colourGroups(groups);
1037 * clear partition (don't show vertical line) if
1038 * it is to the right of all nodes
1040 if (groups.isEmpty())
1045 Console.log.debug("Tree cut threshold set at:" + threshold);
1046 PaintRefresher.Refresh(tp,
1047 getAssociatedPanel().av.getSequenceSetId());
1053 void colourGroups(List<BinaryNode> groups)
1055 AlignmentPanel[] aps = getAssociatedPanels();
1056 List<BitSet> colGroups = new ArrayList<>();
1057 Map<BitSet, Color> colors = new HashMap();
1058 for (int i = 0; i < groups.size(); i++)
1060 Color col = ColorUtils.getARandomColor();
1062 setColor(groups.get(i), col.brighter());
1064 Vector<BinaryNode> l = tree.findLeaves(groups.get(i));
1065 if (!tp.isColumnWise())
1067 createSeqGroupFor(aps, l, col);
1071 BitSet gp = createColumnGroupFor(l, col);
1074 colors.put(gp, col);
1077 if (tp.isColumnWise())
1079 AlignmentAnnotation aa = tp.getAssocAnnotation();
1082 ContactMatrixI cm = av.getContactMatrix(aa);
1085 cm.updateGroups(colGroups);
1086 for (BitSet gp : colors.keySet())
1088 cm.setColorForGroup(gp, colors.get(gp));
1091 cm.transferGroupColorsTo(aa);
1095 // notify the panel(s) to redo any group specific stuff
1096 // also updates structure views if necessary
1097 for (int a = 0; a < aps.length; a++)
1099 aps[a].updateAnnotation();
1100 final AlignViewportI codingComplement = aps[a].av
1101 .getCodingComplement();
1102 if (codingComplement != null)
1104 ((AlignViewport) codingComplement).getAlignPanel()
1105 .updateAnnotation();
1109 private int parseColumnNode(BinaryNode bn) throws NumberFormatException
1111 return Integer.parseInt(
1112 bn.getName().substring(bn.getName().indexOf("c") + 1));
1114 private boolean isColumnForNodeSelected(BinaryNode bn)
1116 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1120 colm = parseColumnNode(bn);
1121 } catch (Exception e)
1125 if (av == null || av.getAlignment() == null)
1127 // alignment is closed
1130 ColumnSelection cs = av.getColumnSelection();
1131 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1132 AlignmentAnnotation aa = tp.getAssocAnnotation();
1136 ContactMatrixI cm = av.getContactMatrix(aa);
1137 // generally, we assume cm has 1:1 mapping to annotation row - probably wrong
1139 if (cm instanceof MappableContactMatrixI)
1142 // use the mappable's mapping - always the case for PAE Matrices so good
1144 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1145 pos = mcm.getMappedPositionsFor(rseq, colm + 1);
1146 // finally, look up the position of the column
1149 offp = rseq.findIndex(pos[0]);
1161 if (!av.hasHiddenColumns())
1163 return cs.contains(offp);
1165 if (hc.isVisible(offp))
1167 return cs.contains(offp);
1168 // return cs.contains(hc.absoluteToVisibleColumn(offp));
1172 private BitSet createColumnGroupFor(Vector<BinaryNode> l, Color col)
1174 BitSet gp = new BitSet();
1175 for (BinaryNode bn : l)
1178 if (bn.element() != null && bn.element() instanceof Integer)
1180 colm = (Integer) bn.element();
1184 // parse out from nodename
1187 colm = parseColumnNode(bn);
1188 } catch (Exception e)
1198 private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1199 Color col, boolean clearSelected)
1201 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1202 if (av == null || av.getAlignment() == null)
1204 // alignment is closed
1208 // TODO - sort indices for faster lookup
1209 ColumnSelection cs = av.getColumnSelection();
1210 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1211 ContactMatrixI cm = av.getContactMatrix(tp.assocAnnotation);
1212 MappableContactMatrixI mcm = null;
1214 if (cm instanceof MappableContactMatrixI)
1216 mcm = (MappableContactMatrixI) cm;
1218 for (BinaryNode bn : l)
1223 colm = Integer.parseInt(
1224 bn.getName().substring(bn.getName().indexOf("c") + 1));
1225 } catch (Exception e)
1231 int[] seqpos = mcm.getMappedPositionsFor(
1235 // no mapping for this column.
1238 // TODO: handle ranges...
1239 offp = rseq.findIndex(seqpos[0])-1;
1243 offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1246 if (!av.hasHiddenColumns() || hc.isVisible(offp))
1248 if (clearSelected || cs.contains(offp))
1250 cs.removeElement(offp);
1254 cs.addElement(offp);
1258 PaintRefresher.Refresh(tp, av.getSequenceSetId());
1261 public void createSeqGroupFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1265 Vector<SequenceI> sequences = new Vector<>();
1267 for (int j = 0; j < l.size(); j++)
1269 SequenceI s1 = (SequenceI) l.elementAt(j).element();
1271 if (!sequences.contains(s1))
1273 sequences.addElement(s1);
1277 ColourSchemeI cs = null;
1278 SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
1279 false, 0, av.getAlignment().getWidth() - 1);
1281 _sg.setName("JTreeGroup:" + _sg.hashCode());
1282 _sg.setIdColour(col);
1284 for (int a = 0; a < aps.length; a++)
1286 SequenceGroup sg = new SequenceGroup(_sg);
1287 AlignViewport viewport = aps[a].av;
1289 // Propagate group colours in each view
1290 if (viewport.getGlobalColourScheme() != null)
1292 cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
1293 sg.setColourScheme(cs);
1294 sg.getGroupColourScheme().setThreshold(
1295 viewport.getResidueShading().getThreshold(),
1296 viewport.isIgnoreGapsConsensus());
1298 if (viewport.getResidueShading().conservationApplied())
1300 Conservation c = new Conservation("Group", sg.getSequences(null),
1301 sg.getStartRes(), sg.getEndRes());
1303 c.verdict(false, viewport.getConsPercGaps());
1304 sg.cs.setConservation(c);
1307 // indicate that associated structure views will need an update
1308 viewport.setUpdateStructures(true);
1309 // propagate structure view update and sequence group to complement view
1310 viewport.addSequenceGroup(sg);
1320 public void setShowDistances(boolean state)
1322 this.showDistances = state;
1332 public void setShowBootstrap(boolean state)
1334 this.showBootstrap = state;
1344 public void setMarkPlaceholders(boolean state)
1346 this.markPlaceholders = state;
1350 AlignmentPanel[] getAssociatedPanels()
1352 if (applyToAllViews)
1354 return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
1358 return new AlignmentPanel[] { getAssociatedPanel() };
1362 public AlignmentPanel getAssociatedPanel()
1367 public void setAssociatedPanel(AlignmentPanel ap)
1372 public AlignViewport getViewport()
1377 public void setViewport(AlignViewport av)
1382 public float getThreshold()
1387 public void setThreshold(float threshold)
1389 this.threshold = threshold;
1392 public boolean isApplyToAllViews()
1394 return this.applyToAllViews;
1397 public void setApplyToAllViews(boolean applyToAllViews)
1399 this.applyToAllViews = applyToAllViews;