1 package jalview.datamodel;
4 import java.util.Arrays;
5 import java.util.BitSet;
8 import jalview.util.ColorUtils;
9 import jalview.ws.datamodel.MappableContactMatrixI;
11 public interface ContactMatrixI
14 ContactListI getContactList(int column);
20 String getAnnotDescr();
22 String getAnnotLabel();
25 * string indicating how the contactMatrix should be rendered - stored in
36 public GroupSetI getGroupSet();
38 /// proxy methods to simplify use of the interface
39 /// Mappable contact matrices can override these to perform mapping
41 default public boolean hasGroupSet()
43 return getGroupSet() != null;
46 default boolean hasGroups()
48 return hasGroupSet() && getGroupSet().hasGroups();
51 default BitSet getGroupsFor(int column)
55 BitSet colbitset = new BitSet();
56 colbitset.set(column);
59 return getGroupSet().getGroupsFor(column);
62 default List<BitSet> getGroups()
66 return Arrays.asList();
68 return getGroupSet().getGroups();
71 default boolean hasTree()
73 return hasGroupSet() ? getGroupSet().hasTree() : false;
77 * Newick representation of clustered matrix
79 * @return null unless hasTree is true
81 default String getNewick()
83 return hasGroupSet() ? getGroupSet().getNewick() : null;
86 default String getTreeMethod()
88 return hasGroupSet() ? getGroupSet().getTreeMethod() : null;
91 default boolean hasCutHeight()
93 return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
96 default double getCutHeight()
98 return hasGroupSet() ? getGroupSet().getCutHeight() : 0;
101 default void updateGroups(List<BitSet> colGroups)
105 getGroupSet().updateGroups(colGroups);
109 default void setColorForGroup(BitSet bs, Color color)
113 getGroupSet().setColorForGroup(bs, color);
117 default Color getColourForGroup(BitSet bs)
121 return getGroupSet().getColourForGroup(bs);
129 void setGroupSet(GroupSet makeGroups);
131 default void randomlyReColourGroups()
135 GroupSetI groups = getGroupSet();
136 for (BitSet group : groups.getGroups())
138 groups.setColorForGroup(group, ColorUtils.getARandomColor());
143 default void transferGroupColorsTo(AlignmentAnnotation aa)
147 GroupSetI groups = getGroupSet();
148 // stash colors in linked annotation row.
149 // doesn't work yet. TESTS!
150 int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1
155 for (BitSet gp : groups.getGroups())
157 gpcol = groups.getColourForGroup(gp);
158 for (int p = gp.nextSetBit(0); p >= 0
159 && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
161 if (this instanceof MappableContactMatrixI)
163 MappableContactMatrixI mcm = (MappableContactMatrixI) this;
164 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p);
167 // no mapping for this column.
170 // TODO: handle ranges...
171 ae = aa.getAnnotationForPosition(seqpos[0]);
175 ae = aa.getAnnotationForPosition(p + sstart);
179 ae.colour = gpcol.brighter().darker();
187 * look up the colour for a column in the associated contact matrix
189 * @return Color.white or assigned colour
191 default Color getGroupColorForPosition(int column)
195 GroupSetI groups = getGroupSet();
196 for (BitSet gp : groups.getGroups())
200 return groups.getColourForGroup(gp);
208 * direct access to column and row position of matrix
210 * Implementations are allowed to throw RunTimeExceptions if _column/i are out
217 double getElementAt(int column, int row);