256d43d347eab1a828220723bbe0452c8a5bea7e
[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 calcId
23    * @return 
24    */
25   String getType();
26
27   int getWidth();
28   int getHeight();
29   
30   public GroupSetI getGroupSet();
31   
32   /// proxy methods to simplify use of the interface
33   /// Mappable contact matrices can override these to perform mapping
34   
35   default public boolean hasGroupSet()
36   {
37     return getGroupSet()!=null;
38   }
39
40   default boolean hasGroups() {
41     return hasGroupSet() && getGroupSet().hasGroups();
42   }
43
44
45   default BitSet getGroupsFor(int column) {
46     if (!hasGroupSet())
47     {
48     BitSet colbitset  = new BitSet();
49     colbitset.set(column);
50     return colbitset;
51     }
52     return getGroupSet().getGroupsFor(column);
53   }
54
55   default List<BitSet> getGroups() {
56     if (!hasGroupSet())
57     {
58     return Arrays.asList();
59     } 
60     return getGroupSet().getGroups();
61   }
62
63   default boolean hasTree() {
64     return hasGroupSet() ? getGroupSet().hasTree() : false;
65   }
66
67   /**
68    * Newick representation of clustered matrix
69    * @return null unless hasTree is true
70    */
71   default String getNewick() {
72     return hasGroupSet() ? getGroupSet().getNewick(): null;
73   }
74
75   default String getTreeMethod() {
76     return hasGroupSet() ? getGroupSet().getTreeMethod() :null;
77   }
78
79   default boolean hasCutHeight() {
80     return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
81   }
82
83   default double getCutHeight() {
84     return hasGroupSet() ? getGroupSet().getCutHeight():0;
85   }
86
87   default void updateGroups(List<BitSet> colGroups)
88   {
89     if (hasGroupSet())
90     {
91       getGroupSet().updateGroups(colGroups);
92     }
93   }
94
95   default void setColorForGroup(BitSet bs, Color color)
96   {
97     if (hasGroupSet())
98     {
99       getGroupSet().setColorForGroup(bs, color);
100     }
101   }
102
103   default Color getColourForGroup(BitSet bs)
104   {
105     if (hasGroupSet())
106     {
107       return getGroupSet().getColourForGroup(bs);
108     }
109     else
110     {
111       return Color.white;
112     }
113   }
114
115   void setGroupSet(GroupSet makeGroups);
116
117 }