X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FContactMatrixI.java;h=925025fc3c70ba4ee4babe2bb1a2d9b2c1f54111;hb=a0bd24f90375fc1d4be619bf65746a912dfcfc89;hp=256d43d347eab1a828220723bbe0452c8a5bea7e;hpb=cc3341f9d1465b0226d184be4216d022a62e5cee;p=jalview.git diff --git a/src/jalview/datamodel/ContactMatrixI.java b/src/jalview/datamodel/ContactMatrixI.java index 256d43d..925025f 100644 --- a/src/jalview/datamodel/ContactMatrixI.java +++ b/src/jalview/datamodel/ContactMatrixI.java @@ -5,6 +5,9 @@ import java.util.Arrays; import java.util.BitSet; import java.util.List; +import jalview.util.ColorUtils; +import jalview.ws.datamodel.MappableContactMatrixI; + public interface ContactMatrixI { @@ -19,69 +22,78 @@ public interface ContactMatrixI String getAnnotLabel(); /** - * string indicating how the contactMatrix should be rendered - stored in calcId - * @return + * string indicating how the contactMatrix should be rendered - stored in + * calcId + * + * @return */ String getType(); int getWidth(); int getHeight(); - public GroupSetI getGroupSet(); - + /// proxy methods to simplify use of the interface /// Mappable contact matrices can override these to perform mapping - + default public boolean hasGroupSet() { - return getGroupSet()!=null; + return getGroupSet() != null; } - default boolean hasGroups() { + default boolean hasGroups() + { return hasGroupSet() && getGroupSet().hasGroups(); } - - default BitSet getGroupsFor(int column) { + default BitSet getGroupsFor(int column) + { if (!hasGroupSet()) { - BitSet colbitset = new BitSet(); - colbitset.set(column); - return colbitset; + BitSet colbitset = new BitSet(); + colbitset.set(column); + return colbitset; } return getGroupSet().getGroupsFor(column); } - default List getGroups() { + default List getGroups() + { if (!hasGroupSet()) { - return Arrays.asList(); - } + return Arrays.asList(); + } return getGroupSet().getGroups(); } - default boolean hasTree() { + default boolean hasTree() + { return hasGroupSet() ? getGroupSet().hasTree() : false; } /** * Newick representation of clustered matrix + * * @return null unless hasTree is true */ - default String getNewick() { - return hasGroupSet() ? getGroupSet().getNewick(): null; + default String getNewick() + { + return hasGroupSet() ? getGroupSet().getNewick() : null; } - default String getTreeMethod() { - return hasGroupSet() ? getGroupSet().getTreeMethod() :null; + default String getTreeMethod() + { + return hasGroupSet() ? getGroupSet().getTreeMethod() : null; } - default boolean hasCutHeight() { + default boolean hasCutHeight() + { return hasGroupSet() ? getGroupSet().hasCutHeight() : false; } - default double getCutHeight() { - return hasGroupSet() ? getGroupSet().getCutHeight():0; + default double getCutHeight() + { + return hasGroupSet() ? getGroupSet().getCutHeight() : 0; } default void updateGroups(List colGroups) @@ -114,4 +126,78 @@ public interface ContactMatrixI void setGroupSet(GroupSet makeGroups); + default void randomlyReColourGroups() { + if (hasGroupSet()) + { + GroupSetI groups = getGroupSet(); + for (BitSet group:groups.getGroups()) + { + groups.setColorForGroup(group, ColorUtils.getARandomColor()); + } + } + } + + default void transferGroupColorsTo(AlignmentAnnotation aa) + { + if (hasGroupSet()) + { + GroupSetI groups = getGroupSet(); + // stash colors in linked annotation row. + // doesn't work yet. TESTS! + int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1 + : 0; + Annotation ae; + Color gpcol = null; + int[] seqpos = null; + for (BitSet gp : groups.getGroups()) + { + gpcol = groups.getColourForGroup(gp); + for (int p = gp.nextSetBit(0); p >= 0 + && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1)) + { + if (this instanceof MappableContactMatrixI) + { + MappableContactMatrixI mcm = (MappableContactMatrixI) this; + seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p); + if (seqpos == null) + { + // no mapping for this column. + continue; + } + // TODO: handle ranges... + ae = aa.getAnnotationForPosition(seqpos[0]); + } + else + { + ae = aa.getAnnotationForPosition(p + sstart); + } + if (ae != null) + { + ae.colour = gpcol.brighter().darker(); + } + } + } + } + } + + /** + * look up the colour for a column in the associated contact matrix + * @return Color.white or assigned colour + */ + default Color getGroupColorForPosition(int column) + { + if (hasGroupSet()) + { + GroupSetI groups = getGroupSet(); + for (BitSet gp:groups.getGroups()) + { + if (gp.get(column)) + { + return groups.getColourForGroup(gp); + } + } + } + return Color.white; + } + }