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
34 public GroupSetI getGroupSet();
36 /// proxy methods to simplify use of the interface
37 /// Mappable contact matrices can override these to perform mapping
39 default public boolean hasGroupSet()
41 return getGroupSet() != null;
44 default boolean hasGroups()
46 return hasGroupSet() && getGroupSet().hasGroups();
49 default BitSet getGroupsFor(int column)
53 BitSet colbitset = new BitSet();
54 colbitset.set(column);
57 return getGroupSet().getGroupsFor(column);
60 default List<BitSet> getGroups()
64 return Arrays.asList();
66 return getGroupSet().getGroups();
69 default boolean hasTree()
71 return hasGroupSet() ? getGroupSet().hasTree() : false;
75 * Newick representation of clustered matrix
77 * @return null unless hasTree is true
79 default String getNewick()
81 return hasGroupSet() ? getGroupSet().getNewick() : null;
84 default String getTreeMethod()
86 return hasGroupSet() ? getGroupSet().getTreeMethod() : null;
89 default boolean hasCutHeight()
91 return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
94 default double getCutHeight()
96 return hasGroupSet() ? getGroupSet().getCutHeight() : 0;
99 default void updateGroups(List<BitSet> colGroups)
103 getGroupSet().updateGroups(colGroups);
107 default void setColorForGroup(BitSet bs, Color color)
111 getGroupSet().setColorForGroup(bs, color);
115 default Color getColourForGroup(BitSet bs)
119 return getGroupSet().getColourForGroup(bs);
127 void setGroupSet(GroupSet makeGroups);
129 default void randomlyReColourGroups() {
132 GroupSetI groups = getGroupSet();
133 for (BitSet group:groups.getGroups())
135 groups.setColorForGroup(group, ColorUtils.getARandomColor());
140 default void transferGroupColorsTo(AlignmentAnnotation aa)
144 GroupSetI groups = getGroupSet();
145 // stash colors in linked annotation row.
146 // doesn't work yet. TESTS!
147 int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1
152 for (BitSet gp : groups.getGroups())
154 gpcol = groups.getColourForGroup(gp);
155 for (int p = gp.nextSetBit(0); p >= 0
156 && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
158 if (this instanceof MappableContactMatrixI)
160 MappableContactMatrixI mcm = (MappableContactMatrixI) this;
161 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p);
164 // no mapping for this column.
167 // TODO: handle ranges...
168 ae = aa.getAnnotationForPosition(seqpos[0]);
172 ae = aa.getAnnotationForPosition(p + sstart);
176 ae.colour = gpcol.brighter().darker();
184 * look up the colour for a column in the associated contact matrix
185 * @return Color.white or assigned colour
187 default Color getGroupColorForPosition(int column)
191 GroupSetI groups = getGroupSet();
192 for (BitSet gp:groups.getGroups())
196 return groups.getColourForGroup(gp);