1d20987117ba409ebb79782c9453ca51acf03f19
[jalview.git] / src / jalview / datamodel / ContactMatrixI.java
1 package jalview.datamodel;
2
3 import java.awt.Color;
4 import java.util.Arrays;
5 import java.util.BitSet;
6 import java.util.List;
7
8 public interface ContactMatrixI
9 {
10
11   ContactListI getContactList(int column);
12
13   float getMin();
14
15   float getMax();
16
17   String getAnnotDescr();
18
19   String getAnnotLabel();
20
21   /**
22    * string indicating how the contactMatrix should be rendered - stored in
23    * calcId
24    * 
25    * @return
26    */
27   String getType();
28
29   int getWidth();
30   int getHeight();
31   public GroupSetI getGroupSet();
32
33   /// proxy methods to simplify use of the interface
34   /// Mappable contact matrices can override these to perform mapping
35
36   default public boolean hasGroupSet()
37   {
38     return getGroupSet() != null;
39   }
40
41   default boolean hasGroups()
42   {
43     return hasGroupSet() && getGroupSet().hasGroups();
44   }
45
46   default BitSet getGroupsFor(int column)
47   {
48     if (!hasGroupSet())
49     {
50       BitSet colbitset = new BitSet();
51       colbitset.set(column);
52       return colbitset;
53     }
54     return getGroupSet().getGroupsFor(column);
55   }
56
57   default List<BitSet> getGroups()
58   {
59     if (!hasGroupSet())
60     {
61       return Arrays.asList();
62     }
63     return getGroupSet().getGroups();
64   }
65
66   default boolean hasTree()
67   {
68     return hasGroupSet() ? getGroupSet().hasTree() : false;
69   }
70
71   /**
72    * Newick representation of clustered matrix
73    * 
74    * @return null unless hasTree is true
75    */
76   default String getNewick()
77   {
78     return hasGroupSet() ? getGroupSet().getNewick() : null;
79   }
80
81   default String getTreeMethod()
82   {
83     return hasGroupSet() ? getGroupSet().getTreeMethod() : null;
84   }
85
86   default boolean hasCutHeight()
87   {
88     return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
89   }
90
91   default double getCutHeight()
92   {
93     return hasGroupSet() ? getGroupSet().getCutHeight() : 0;
94   }
95
96   default void updateGroups(List<BitSet> colGroups)
97   {
98     if (hasGroupSet())
99     {
100       getGroupSet().updateGroups(colGroups);
101     }
102   }
103
104   default void setColorForGroup(BitSet bs, Color color)
105   {
106     if (hasGroupSet())
107     {
108       getGroupSet().setColorForGroup(bs, color);
109     }
110   }
111
112   default Color getColourForGroup(BitSet bs)
113   {
114     if (hasGroupSet())
115     {
116       return getGroupSet().getColourForGroup(bs);
117     }
118     else
119     {
120       return Color.white;
121     }
122   }
123
124   void setGroupSet(GroupSet makeGroups);
125 }