Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.datamodel

File ContactMatrixI.java

 

Coverage histogram

../../img/srcFileCovDistChart3.png
52% of files have more coverage

Code metrics

38
50
15
1
239
156
35
0.7
3.33
15
2.33

Classes

Class Line # Actions
ContactMatrixI 31 50 35
0.3009708830.1%
 

Contributing tests

This file is covered by 11 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.datamodel;
22   
23    import java.awt.Color;
24    import java.util.Arrays;
25    import java.util.BitSet;
26    import java.util.List;
27   
28    import jalview.util.ColorUtils;
29    import jalview.ws.datamodel.MappableContactMatrixI;
30   
 
31    public interface ContactMatrixI
32    {
33   
34    ContactListI getContactList(int column);
35   
36    float getMin();
37   
38    float getMax();
39   
40    String getAnnotDescr();
41   
42    String getAnnotLabel();
43   
44    /**
45    * string indicating how the contactMatrix should be rendered - stored in
46    * calcId
47    *
48    * @return
49    */
50    String getType();
51   
52    int getWidth();
53   
54    int getHeight();
55   
56    public GroupSetI getGroupSet();
57   
58    /// proxy methods to simplify use of the interface
59    /// Mappable contact matrices can override these to perform mapping
60   
 
61  6977 toggle default public boolean hasGroupSet()
62    {
63  6977 return getGroupSet() != null;
64    }
65   
 
66  5 toggle default boolean hasGroups()
67    {
68  5 return hasGroupSet() && getGroupSet().hasGroups();
69    }
70   
 
71  3473 toggle default BitSet getGroupsFor(int column)
72    {
73  3473 if (!hasGroupSet())
74    {
75  0 BitSet colbitset = new BitSet();
76  0 colbitset.set(column);
77  0 return colbitset;
78    }
79  3473 return getGroupSet().getGroupsFor(column);
80    }
81   
 
82  6 toggle default List<BitSet> getGroups()
83    {
84  6 if (!hasGroupSet())
85    {
86  0 return Arrays.asList();
87    }
88  6 return getGroupSet().getGroups();
89    }
90   
 
91  5 toggle default boolean hasTree()
92    {
93  5 return hasGroupSet() ? getGroupSet().hasTree() : false;
94    }
95   
96    /**
97    * Newick representation of clustered matrix
98    *
99    * @return null unless hasTree is true
100    */
 
101  6 toggle default String getNewick()
102    {
103  6 return hasGroupSet() ? getGroupSet().getNewick() : null;
104    }
105   
 
106  3 toggle default String getTreeMethod()
107    {
108  3 return hasGroupSet() ? getGroupSet().getTreeMethod() : null;
109    }
110   
 
111  3 toggle default boolean hasCutHeight()
112    {
113  3 return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
114    }
115   
 
116  3 toggle default double getCutHeight()
117    {
118  3 return hasGroupSet() ? getGroupSet().getCutHeight() : 0;
119    }
120   
 
121  0 toggle default void updateGroups(List<BitSet> colGroups)
122    {
123  0 if (hasGroupSet())
124    {
125  0 getGroupSet().updateGroups(colGroups);
126    }
127    }
128   
 
129  0 toggle default void setColorForGroup(BitSet bs, Color color)
130    {
131  0 if (hasGroupSet())
132    {
133  0 getGroupSet().setColorForGroup(bs, color);
134    }
135    }
136   
 
137  3473 toggle default Color getColourForGroup(BitSet bs)
138    {
139  3473 if (hasGroupSet())
140    {
141  3473 return getGroupSet().getColourForGroup(bs);
142    }
143    else
144    {
145  0 return Color.white;
146    }
147    }
148   
149    void setGroupSet(GroupSet makeGroups);
150   
 
151  0 toggle default void randomlyReColourGroups()
152    {
153  0 if (hasGroupSet())
154    {
155  0 GroupSetI groups = getGroupSet();
156  0 for (BitSet group : groups.getGroups())
157    {
158  0 groups.setColorForGroup(group, ColorUtils.getARandomColor());
159    }
160    }
161    }
162   
 
163  0 toggle default void transferGroupColorsTo(AlignmentAnnotation aa)
164    {
165  0 if (hasGroupSet())
166    {
167  0 GroupSetI groups = getGroupSet();
168    // stash colors in linked annotation row.
169    // doesn't work yet. TESTS!
170  0 int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1
171    : 0;
172  0 Annotation ae;
173  0 Color gpcol = null;
174  0 int[] seqpos = null;
175  0 for (BitSet gp : groups.getGroups())
176    {
177  0 gpcol = groups.getColourForGroup(gp);
178  0 for (int p = gp.nextSetBit(0); p >= 0
179    && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
180    {
181  0 if (this instanceof MappableContactMatrixI)
182    {
183  0 MappableContactMatrixI mcm = (MappableContactMatrixI) this;
184  0 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p);
185  0 if (seqpos == null)
186    {
187    // no mapping for this column.
188  0 continue;
189    }
190    // TODO: handle ranges...
191  0 ae = aa.getAnnotationForPosition(seqpos[0]);
192    }
193    else
194    {
195  0 ae = aa.getAnnotationForPosition(p + sstart);
196    }
197  0 if (ae != null)
198    {
199  0 ae.colour = gpcol.brighter().darker();
200    }
201    }
202    }
203    }
204    }
205   
206    /**
207    * look up the colour for a column in the associated contact matrix
208    *
209    * @return Color.white or assigned colour
210    */
 
211  0 toggle default Color getGroupColorForPosition(int column)
212    {
213  0 if (hasGroupSet())
214    {
215  0 GroupSetI groups = getGroupSet();
216  0 for (BitSet gp : groups.getGroups())
217    {
218  0 if (gp.get(column))
219    {
220  0 return groups.getColourForGroup(gp);
221    }
222    }
223    }
224  0 return Color.white;
225    }
226   
227    /**
228    * direct access to column and row position of matrix
229    *
230    * Implementations are allowed to throw RunTimeExceptions if _column/i are out
231    * of bounds
232    *
233    * @param column
234    * @param row
235    * @return
236    */
237    double getElementAt(int column, int row);
238   
239    }