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());
192 public void treeSelectionChanged(SequenceI sequence)
194 AlignmentPanel[] aps = getAssociatedPanels();
196 for (int a = 0; a < aps.length; a++)
198 SequenceGroup selected = aps[a].av.getSelectionGroup();
200 if (selected == null)
202 selected = new SequenceGroup();
203 aps[a].av.setSelectionGroup(selected);
206 selected.setEndRes(aps[a].av.getAlignment().getWidth() - 1);
207 selected.addOrRemove(sequence, true);
217 public void setTree(TreeModel tree)
220 tree.findHeight(tree.getTopNode());
222 // Now have to calculate longest name based on the leaves
223 Vector<BinaryNode> leaves = tree.findLeaves(tree.getTopNode());
224 boolean has_placeholders = false;
227 AlignmentAnnotation aa = tp.getAssocAnnotation();
228 ContactMatrixI cm = (aa != null) ? av.getContactMatrix(aa) : null;
229 if (cm != null && cm.hasCutHeight())
231 threshold = (float) cm.getCutHeight();
234 for (int i = 0; i < leaves.size(); i++)
236 BinaryNode lf = leaves.elementAt(i);
238 if (lf instanceof SequenceNode && ((SequenceNode) lf).isPlaceholder())
240 has_placeholders = true;
243 if (longestName.length() < ((Sequence) lf.element()).getName()
246 longestName = TreeCanvas.PLACEHOLDER
247 + ((Sequence) lf.element()).getName();
249 if (tp.isColumnWise() && cm != null)
251 // get color from group colours, if they are set for the matrix
254 Color col = cm.getGroupColorForPosition(parseColumnNode(lf));
255 setColor(lf, col.brighter());
256 } catch (NumberFormatException ex)
263 setMarkPlaceholders(has_placeholders);
284 public void drawNode(Graphics g, BinaryNode node, double chunk,
285 double wscale, int width, int offx, int offy)
292 if ((node.left() == null) && (node.right() == null))
295 double height = node.height;
296 double dist = node.dist;
298 int xstart = (int) ((height - dist) * wscale) + offx;
299 int xend = (int) (height * wscale) + offx;
301 int ypos = (int) (node.ycount * chunk) + offy;
303 if (node.element() instanceof SequenceI)
305 SequenceI seq = (SequenceI) node.element();
307 if (av.getSequenceColour(seq) == Color.white)
309 g.setColor(Color.black);
313 g.setColor(av.getSequenceColour(seq).darker());
318 g.setColor(Color.black);
321 // Draw horizontal line
322 g.drawLine(xstart, ypos, xend, ypos);
324 String nodeLabel = "";
326 if (showDistances && (node.dist > 0))
328 nodeLabel = new Format("%g").form(node.dist);
331 if (showBootstrap && node.bootstrap > -1)
335 nodeLabel = nodeLabel + " : ";
338 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
341 if (!nodeLabel.equals(""))
343 g.drawString(nodeLabel, xstart + 2, ypos - 2);
346 String name = (markPlaceholders && ((node instanceof SequenceNode
347 && ((SequenceNode) node).isPlaceholder())))
348 ? (PLACEHOLDER + node.getName())
351 int charWidth = fm.stringWidth(name) + 3;
352 int charHeight = font.getSize();
354 Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2,
355 charWidth, charHeight);
357 nameHash.put(node.element(), rect);
359 // Colour selected leaves differently
360 boolean isSelected = false;
361 if (tp.isColumnWise())
363 isSelected = isColumnForNodeSelected(node);
367 SequenceGroup selected = av.getSelectionGroup();
369 if ((selected != null)
370 && selected.getSequences(null).contains(node.element()))
377 g.setColor(Color.gray);
379 g.fillRect(xend + 10, ypos - charHeight / 2, charWidth, charHeight);
380 g.setColor(Color.white);
383 g.drawString(name, xend + 10, ypos + fm.getDescent());
384 g.setColor(Color.black);
388 drawNode(g, (BinaryNode) node.left(), chunk, wscale, width, offx,
390 drawNode(g, (BinaryNode) node.right(), chunk, wscale, width, offx,
393 double height = node.height;
394 double dist = node.dist;
396 int xstart = (int) ((height - dist) * wscale) + offx;
397 int xend = (int) (height * wscale) + offx;
398 int ypos = (int) (node.ycount * chunk) + offy;
400 g.setColor(node.color.darker());
402 // Draw horizontal line
403 g.drawLine(xstart, ypos, xend, ypos);
404 if (node == highlightNode)
406 g.fillRect(xend - 3, ypos - 3, 6, 6);
410 g.fillRect(xend - 2, ypos - 2, 4, 4);
413 int ystart = (node.left() == null ? 0
414 : (int) (node.left().ycount * chunk)) + offy;
415 int yend = (node.right() == null ? 0
416 : (int) (node.right().ycount * chunk)) + offy;
418 Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
419 nodeHash.put(node, pos);
421 g.drawLine((int) (height * wscale) + offx, ystart,
422 (int) (height * wscale) + offx, yend);
424 String nodeLabel = "";
426 if (showDistances && (node.dist > 0))
428 nodeLabel = new Format("%g").form(node.dist);
431 if (showBootstrap && node.bootstrap > -1)
435 nodeLabel = nodeLabel + " : ";
438 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
441 if (!nodeLabel.equals(""))
443 g.drawString(nodeLabel, xstart + 2, ypos - 2);
456 * @return DOCUMENT ME!
458 public Object findElement(int x, int y)
460 for (Entry<Object, Rectangle> entry : nameHash.entrySet())
462 Rectangle rect = entry.getValue();
464 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
465 && (y <= (rect.y + rect.height)))
467 return entry.getKey();
471 for (Entry<BinaryNode, Rectangle> entry : nodeHash.entrySet())
473 Rectangle rect = entry.getValue();
475 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
476 && (y <= (rect.y + rect.height)))
478 return entry.getKey();
491 public void pickNodes(Rectangle pickBox)
493 int width = getWidth();
494 int height = getHeight();
496 BinaryNode top = tree.getTopNode();
498 double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
502 top.count = ((BinaryNode) top.left()).count
503 + ((BinaryNode) top.right()).count;
506 float chunk = (float) (height - (offy)) / top.count;
508 pickNode(pickBox, top, chunk, wscale, width, offx, offy);
529 public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
530 double wscale, int width, int offx, int offy)
537 if ((node.left() == null) && (node.right() == null))
539 double height = node.height;
540 // double dist = node.dist;
541 // int xstart = (int) ((height - dist) * wscale) + offx;
542 int xend = (int) (height * wscale) + offx;
544 int ypos = (int) (node.ycount * chunk) + offy;
546 if (pickBox.contains(new Point(xend, ypos)))
548 if (node.element() instanceof SequenceI)
550 SequenceI seq = (SequenceI) node.element();
551 SequenceGroup sg = av.getSelectionGroup();
555 sg.addOrRemove(seq, true);
562 pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width,
564 pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width,
577 public void setColor(BinaryNode node, Color c)
585 if (node.element() instanceof SequenceI)
587 final SequenceI seq = (SequenceI) node.element();
588 AlignmentPanel[] aps = getAssociatedPanels();
591 for (int a = 0; a < aps.length; a++)
593 aps[a].av.setSequenceColour(seq, c);
597 setColor((BinaryNode) node.left(), c);
598 setColor((BinaryNode) node.right(), c);
606 Thread thread = new Thread(this);
610 // put printing in a thread to avoid painting problems
614 PrinterJob printJob = PrinterJob.getPrinterJob();
615 PageFormat defaultPage = printJob.defaultPage();
616 PageFormat pf = printJob.pageDialog(defaultPage);
618 if (defaultPage == pf)
626 printJob.setPrintable(this, pf);
628 if (printJob.printDialog())
633 } catch (Exception PrintException)
635 PrintException.printStackTrace();
650 * @return DOCUMENT ME!
652 * @throws PrinterException
656 public int print(Graphics pg, PageFormat pf, int pi)
657 throws PrinterException
660 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
662 int pwidth = (int) pf.getImageableWidth();
663 int pheight = (int) pf.getImageableHeight();
665 int noPages = getHeight() / pheight;
669 return Printable.NO_SUCH_PAGE;
672 if (pwidth > getWidth())
679 if (pheight > getHeight())
681 pheight = getHeight();
688 FontMetrics fm = pg.getFontMetrics(font);
689 int height = fm.getHeight() * nameHash.size();
690 pg.translate(0, -pi * pheight);
691 pg.setClip(0, pi * pheight, pwidth, (pi * pheight) + pheight);
693 // translate number of pages,
694 // height is screen size as this is the
695 // non overlapping text size
699 draw(pg, pwidth, pheight);
701 return Printable.PAGE_EXISTS;
711 public void paintComponent(Graphics g)
713 super.paintComponent(g);
719 MessageManager.getString("label.calculating_tree") + "....",
720 20, getHeight() / 2);
724 fm = g.getFontMetrics(font);
726 int nameCount = nameHash.size();
732 if (fitToWindow || (!fitToWindow && (scrollPane
733 .getHeight() > ((fm.getHeight() * nameCount) + offy))))
735 draw(g, scrollPane.getWidth(), scrollPane.getHeight());
736 setPreferredSize(null);
740 setPreferredSize(new Dimension(scrollPane.getWidth(),
741 fm.getHeight() * nameCount));
742 draw(g, scrollPane.getWidth(), fm.getHeight() * nameCount);
745 scrollPane.revalidate();
756 public void setFont(Font font)
772 public void draw(Graphics g1, int width, int height)
774 Graphics2D g2 = (Graphics2D) g1;
775 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
776 RenderingHints.VALUE_ANTIALIAS_ON);
777 g2.setColor(Color.white);
778 g2.fillRect(0, 0, width, height);
781 if (longestName == null || tree == null)
783 g2.drawString("Calculating tree.", 20, 20);
786 offy = font.getSize() + 10;
788 fm = g2.getFontMetrics(font);
790 labelLength = fm.stringWidth(longestName) + 20; // 20 allows for scrollbar
792 double wscale = (width - labelLength - (offx * 2))
793 / tree.getMaxHeight();
795 BinaryNode top = tree.getTopNode();
799 top.count = top.left().count + top.right().count;
802 float chunk = (float) (height - (offy)) / top.count;
804 drawNode(g2, tree.getTopNode(), chunk, wscale, width, offx, offy);
808 if (av.getCurrentTree() == tree)
810 g2.setColor(Color.red);
814 g2.setColor(Color.gray);
817 int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx)))
820 g2.drawLine(x, 0, x, getHeight());
825 * Empty method to satisfy the MouseListener interface
830 public void mouseReleased(MouseEvent e)
833 * isPopupTrigger is set on mouseReleased on Windows
835 if (e.isPopupTrigger())
837 chooseSubtreeColour();
838 e.consume(); // prevent mouseClicked happening
843 * Empty method to satisfy the MouseListener interface
848 public void mouseEntered(MouseEvent e)
853 * Empty method to satisfy the MouseListener interface
858 public void mouseExited(MouseEvent e)
863 * Handles a mouse click on a tree node (clicks elsewhere are handled in
864 * mousePressed). Click selects the sub-tree, double-click swaps leaf nodes
865 * order, right-click opens a dialogue to choose colour for the sub-tree.
870 public void mouseClicked(MouseEvent evt)
872 if (highlightNode == null)
877 if (evt.getClickCount() > 1)
879 tree.swapNodes(highlightNode);
880 tree.reCount(tree.getTopNode());
881 tree.findHeight(tree.getTopNode());
885 Vector<BinaryNode> leaves = tree.findLeaves(highlightNode);
886 if (tp.isColumnWise())
888 markColumnsFor(getAssociatedPanels(), leaves, Color.red, false);
892 for (int i = 0; i < leaves.size(); i++)
894 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
895 treeSelectionChanged(seq);
901 PaintRefresher.Refresh(tp, av.getSequenceSetId());
906 * Offer the user the option to choose a colour for the highlighted node and
907 * its children; this colour is also applied to the corresponding sequence ids
910 void chooseSubtreeColour()
912 String ttl = MessageManager.getString("label.select_subtree_colour");
913 ColourChooserListener listener = new ColourChooserListener()
916 public void colourSelected(Color c)
918 setColor(highlightNode, c);
919 PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
923 JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color,
928 public void mouseMoved(MouseEvent evt)
930 av.setCurrentTree(tree);
932 Object ob = findElement(evt.getX(), evt.getY());
934 if (ob instanceof BinaryNode)
936 highlightNode = (BinaryNode) ob;
938 "<html>" + MessageManager.getString("label.highlightnode"));
944 if (highlightNode != null)
946 highlightNode = null;
947 setToolTipText(null);
954 public void mouseDragged(MouseEvent ect)
959 * Handles a mouse press on a sequence name or the tree background canvas
960 * (click on a node is handled in mouseClicked). The action is to create
961 * groups by partitioning the tree at the mouse position. Colours for the
962 * groups (and sequence names) are generated randomly.
967 public void mousePressed(MouseEvent e)
969 av.setCurrentTree(tree);
972 * isPopupTrigger is set for mousePressed (Mac)
973 * or mouseReleased (Windows)
975 if (e.isPopupTrigger())
977 if (highlightNode != null)
979 chooseSubtreeColour();
985 * defer right-click handling on Windows to
986 * mouseClicked; note isRightMouseButton
987 * also matches Cmd-click on Mac which should do
990 if (SwingUtilities.isRightMouseButton(e))
998 Object ob = findElement(x, y);
1000 if (ob instanceof SequenceI)
1002 treeSelectionChanged((Sequence) ob);
1003 PaintRefresher.Refresh(tp,
1004 getAssociatedPanel().av.getSequenceSetId());
1009 else if (!(ob instanceof BinaryNode))
1012 if (tree.getMaxHeight() != 0)
1014 threshold = (float) (x - offx)
1015 / (float) (getWidth() - labelLength - (2 * offx));
1017 List<BinaryNode> groups = tree.groupNodes(threshold);
1018 setColor(tree.getTopNode(), Color.black);
1020 AlignmentPanel[] aps = getAssociatedPanels();
1022 // TODO push calls below into a single AlignViewportI method?
1023 // see also AlignViewController.deleteGroups
1024 for (int a = 0; a < aps.length; a++)
1026 aps[a].av.setSelectionGroup(null);
1027 aps[a].av.getAlignment().deleteAllGroups();
1028 aps[a].av.clearSequenceColours();
1029 if (aps[a].av.getCodingComplement() != null)
1031 aps[a].av.getCodingComplement().setSelectionGroup(null);
1032 aps[a].av.getCodingComplement().getAlignment()
1034 aps[a].av.getCodingComplement().clearSequenceColours();
1036 aps[a].av.setUpdateStructures(true);
1038 colourGroups(groups);
1041 * clear partition (don't show vertical line) if
1042 * it is to the right of all nodes
1044 if (groups.isEmpty())
1049 Console.log.debug("Tree cut threshold set at:" + threshold);
1050 PaintRefresher.Refresh(tp,
1051 getAssociatedPanel().av.getSequenceSetId());
1057 void colourGroups(List<BinaryNode> groups)
1059 AlignmentPanel[] aps = getAssociatedPanels();
1060 List<BitSet> colGroups = new ArrayList<>();
1061 Map<BitSet, Color> colors = new HashMap();
1062 for (int i = 0; i < groups.size(); i++)
1064 Color col = ColorUtils.getARandomColor();
1066 setColor(groups.get(i), col.brighter());
1068 Vector<BinaryNode> l = tree.findLeaves(groups.get(i));
1069 if (!tp.isColumnWise())
1071 createSeqGroupFor(aps, l, col);
1075 BitSet gp = createColumnGroupFor(l, col);
1078 colors.put(gp, col);
1081 if (tp.isColumnWise())
1083 AlignmentAnnotation aa = tp.getAssocAnnotation();
1086 ContactMatrixI cm = av.getContactMatrix(aa);
1089 cm.updateGroups(colGroups);
1090 for (BitSet gp : colors.keySet())
1092 cm.setColorForGroup(gp, colors.get(gp));
1095 cm.transferGroupColorsTo(aa);
1099 // notify the panel(s) to redo any group specific stuff
1100 // also updates structure views if necessary
1101 for (int a = 0; a < aps.length; a++)
1103 aps[a].updateAnnotation();
1104 final AlignViewportI codingComplement = aps[a].av
1105 .getCodingComplement();
1106 if (codingComplement != null)
1108 ((AlignViewport) codingComplement).getAlignPanel()
1109 .updateAnnotation();
1114 private int parseColumnNode(BinaryNode bn) throws NumberFormatException
1116 return Integer.parseInt(
1117 bn.getName().substring(bn.getName().indexOf("c") + 1));
1120 private boolean isColumnForNodeSelected(BinaryNode bn)
1122 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1126 colm = parseColumnNode(bn);
1127 } catch (Exception e)
1131 if (av == null || av.getAlignment() == null)
1133 // alignment is closed
1136 ColumnSelection cs = av.getColumnSelection();
1137 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1138 AlignmentAnnotation aa = tp.getAssocAnnotation();
1142 ContactMatrixI cm = av.getContactMatrix(aa);
1143 // generally, we assume cm has 1:1 mapping to annotation row - probably
1146 if (cm instanceof MappableContactMatrixI)
1149 // use the mappable's mapping - always the case for PAE Matrices so good
1151 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1152 pos = mcm.getMappedPositionsFor(rseq, colm + 1);
1153 // finally, look up the position of the column
1156 offp = rseq.findIndex(pos[0]);
1170 if (!av.hasHiddenColumns())
1172 return cs.contains(offp);
1174 if (hc.isVisible(offp))
1176 return cs.contains(offp);
1177 // return cs.contains(hc.absoluteToVisibleColumn(offp));
1182 private BitSet createColumnGroupFor(Vector<BinaryNode> l, Color col)
1184 BitSet gp = new BitSet();
1185 for (BinaryNode bn : l)
1188 if (bn.element() != null && bn.element() instanceof Integer)
1190 colm = (Integer) bn.element();
1194 // parse out from nodename
1197 colm = parseColumnNode(bn);
1198 } catch (Exception e)
1208 private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1209 Color col, boolean clearSelected)
1211 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1212 if (av == null || av.getAlignment() == null)
1214 // alignment is closed
1218 // TODO - sort indices for faster lookup
1219 ColumnSelection cs = av.getColumnSelection();
1220 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1221 ContactMatrixI cm = av.getContactMatrix(tp.assocAnnotation);
1222 MappableContactMatrixI mcm = null;
1224 if (cm instanceof MappableContactMatrixI)
1226 mcm = (MappableContactMatrixI) cm;
1228 for (BinaryNode bn : l)
1233 colm = Integer.parseInt(
1234 bn.getName().substring(bn.getName().indexOf("c") + 1));
1235 } catch (Exception e)
1241 int[] seqpos = mcm.getMappedPositionsFor(rseq, colm);
1244 // no mapping for this column.
1247 // TODO: handle ranges...
1248 offp = rseq.findIndex(seqpos[0]) - 1;
1252 offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1255 if (!av.hasHiddenColumns() || hc.isVisible(offp))
1257 if (clearSelected || cs.contains(offp))
1259 cs.removeElement(offp);
1263 cs.addElement(offp);
1267 PaintRefresher.Refresh(tp, av.getSequenceSetId());
1270 public void createSeqGroupFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1274 Vector<SequenceI> sequences = new Vector<>();
1276 for (int j = 0; j < l.size(); j++)
1278 SequenceI s1 = (SequenceI) l.elementAt(j).element();
1280 if (!sequences.contains(s1))
1282 sequences.addElement(s1);
1286 ColourSchemeI cs = null;
1287 SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
1288 false, 0, av.getAlignment().getWidth() - 1);
1290 _sg.setName("JTreeGroup:" + _sg.hashCode());
1291 _sg.setIdColour(col);
1293 for (int a = 0; a < aps.length; a++)
1295 SequenceGroup sg = new SequenceGroup(_sg);
1296 AlignViewport viewport = aps[a].av;
1298 // Propagate group colours in each view
1299 if (viewport.getGlobalColourScheme() != null)
1301 cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
1302 sg.setColourScheme(cs);
1303 sg.getGroupColourScheme().setThreshold(
1304 viewport.getResidueShading().getThreshold(),
1305 viewport.isIgnoreGapsConsensus());
1307 if (viewport.getResidueShading().conservationApplied())
1309 Conservation c = new Conservation("Group", sg.getSequences(null),
1310 sg.getStartRes(), sg.getEndRes());
1312 c.verdict(false, viewport.getConsPercGaps());
1313 sg.cs.setConservation(c);
1316 // indicate that associated structure views will need an update
1317 viewport.setUpdateStructures(true);
1318 // propagate structure view update and sequence group to complement view
1319 viewport.addSequenceGroup(sg);
1329 public void setShowDistances(boolean state)
1331 this.showDistances = state;
1341 public void setShowBootstrap(boolean state)
1343 this.showBootstrap = state;
1353 public void setMarkPlaceholders(boolean state)
1355 this.markPlaceholders = state;
1359 AlignmentPanel[] getAssociatedPanels()
1361 if (applyToAllViews)
1363 return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
1367 return new AlignmentPanel[] { getAssociatedPanel() };
1371 public AlignmentPanel getAssociatedPanel()
1376 public void setAssociatedPanel(AlignmentPanel ap)
1381 public AlignViewport getViewport()
1386 public void setViewport(AlignViewport av)
1391 public float getThreshold()
1396 public void setThreshold(float threshold)
1398 this.threshold = threshold;
1401 public boolean isApplyToAllViews()
1403 return this.applyToAllViews;
1406 public void setApplyToAllViews(boolean applyToAllViews)
1408 this.applyToAllViews = applyToAllViews;