Merge branch 'develop' into features/JAL-4134_use_annotation_row_for_colours_and_groups
[jalview.git] / src / jalview / datamodel / ContactMatrixI.java
index c16b457..1d20987 100644 (file)
@@ -1,5 +1,10 @@
 package jalview.datamodel;
 
+import java.awt.Color;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.List;
+
 public interface ContactMatrixI
 {
 
@@ -9,8 +14,112 @@ public interface ContactMatrixI
 
   float getMax();
 
-  boolean hasReferenceSeq();
+  String getAnnotDescr();
+
+  String getAnnotLabel();
+
+  /**
+   * 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;
+  }
+
+  default boolean hasGroups()
+  {
+    return hasGroupSet() && getGroupSet().hasGroups();
+  }
+
+  default BitSet getGroupsFor(int column)
+  {
+    if (!hasGroupSet())
+    {
+      BitSet colbitset = new BitSet();
+      colbitset.set(column);
+      return colbitset;
+    }
+    return getGroupSet().getGroupsFor(column);
+  }
+
+  default List<BitSet> getGroups()
+  {
+    if (!hasGroupSet())
+    {
+      return Arrays.asList();
+    }
+    return getGroupSet().getGroups();
+  }
+
+  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 getTreeMethod()
+  {
+    return hasGroupSet() ? getGroupSet().getTreeMethod() : null;
+  }
+
+  default boolean hasCutHeight()
+  {
+    return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
+  }
+
+  default double getCutHeight()
+  {
+    return hasGroupSet() ? getGroupSet().getCutHeight() : 0;
+  }
+
+  default void updateGroups(List<BitSet> colGroups)
+  {
+    if (hasGroupSet())
+    {
+      getGroupSet().updateGroups(colGroups);
+    }
+  }
+
+  default void setColorForGroup(BitSet bs, Color color)
+  {
+    if (hasGroupSet())
+    {
+      getGroupSet().setColorForGroup(bs, color);
+    }
+  }
 
-  SequenceI getReferenceSeq();
+  default Color getColourForGroup(BitSet bs)
+  {
+    if (hasGroupSet())
+    {
+      return getGroupSet().getColourForGroup(bs);
+    }
+    else
+    {
+      return Color.white;
+    }
+  }
 
+  void setGroupSet(GroupSet makeGroups);
 }