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.
21 package jalview.datamodel;
23 import java.awt.Color;
24 import java.util.Arrays;
25 import java.util.BitSet;
26 import java.util.List;
28 import jalview.util.ColorUtils;
29 import jalview.ws.datamodel.MappableContactMatrixI;
31 public interface ContactMatrixI
34 ContactListI getContactList(int column);
40 String getAnnotDescr();
42 String getAnnotLabel();
45 * string indicating how the contactMatrix should be rendered - stored in
56 public GroupSetI getGroupSet();
58 /// proxy methods to simplify use of the interface
59 /// Mappable contact matrices can override these to perform mapping
61 default public boolean hasGroupSet()
63 return getGroupSet() != null;
66 default boolean hasGroups()
68 return hasGroupSet() && getGroupSet().hasGroups();
71 default BitSet getGroupsFor(int column)
75 BitSet colbitset = new BitSet();
76 colbitset.set(column);
79 return getGroupSet().getGroupsFor(column);
82 default List<BitSet> getGroups()
86 return Arrays.asList();
88 return getGroupSet().getGroups();
91 default boolean hasTree()
93 return hasGroupSet() ? getGroupSet().hasTree() : false;
97 * Newick representation of clustered matrix
99 * @return null unless hasTree is true
101 default String getNewick()
103 return hasGroupSet() ? getGroupSet().getNewick() : null;
106 default String getTreeMethod()
108 return hasGroupSet() ? getGroupSet().getTreeMethod() : null;
111 default boolean hasCutHeight()
113 return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
116 default double getCutHeight()
118 return hasGroupSet() ? getGroupSet().getCutHeight() : 0;
121 default void updateGroups(List<BitSet> colGroups)
125 getGroupSet().updateGroups(colGroups);
129 default void setColorForGroup(BitSet bs, Color color)
133 getGroupSet().setColorForGroup(bs, color);
137 default Color getColourForGroup(BitSet bs)
141 return getGroupSet().getColourForGroup(bs);
149 void setGroupSet(GroupSet makeGroups);
151 default void randomlyReColourGroups()
155 GroupSetI groups = getGroupSet();
156 for (BitSet group : groups.getGroups())
158 groups.setColorForGroup(group, ColorUtils.getARandomColor());
163 default void transferGroupColorsTo(AlignmentAnnotation aa)
167 GroupSetI groups = getGroupSet();
168 // stash colors in linked annotation row.
169 // doesn't work yet. TESTS!
170 int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1
175 for (BitSet gp : groups.getGroups())
177 gpcol = groups.getColourForGroup(gp);
178 for (int p = gp.nextSetBit(0); p >= 0
179 && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
181 if (this instanceof MappableContactMatrixI)
183 MappableContactMatrixI mcm = (MappableContactMatrixI) this;
184 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p);
187 // no mapping for this column.
190 // TODO: handle ranges...
191 ae = aa.getAnnotationForPosition(seqpos[0]);
195 ae = aa.getAnnotationForPosition(p + sstart);
199 ae.colour = gpcol.brighter().darker();
207 * look up the colour for a column in the associated contact matrix
209 * @return Color.white or assigned colour
211 default Color getGroupColorForPosition(int column)
215 GroupSetI groups = getGroupSet();
216 for (BitSet gp : groups.getGroups())
220 return groups.getColourForGroup(gp);
228 * direct access to column and row position of matrix
230 * Implementations are allowed to throw RunTimeExceptions if _column/i are out
237 double getElementAt(int column, int row);