1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
import java.util.StringTokenizer; |
26 |
|
|
27 |
|
import jalview.bin.Console; |
28 |
|
|
|
|
| 31.6% |
Uncovered Elements: 93 (136) |
Complexity: 39 |
Complexity Density: 0.51 |
|
29 |
|
public abstract class ContactMatrix extends GroupSetHolder |
30 |
|
implements ContactMatrixI |
31 |
|
{ |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
boolean symmetric = true; |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
0 |
public ContactMatrix(boolean symmetric)... |
38 |
|
{ |
39 |
0 |
this.symmetric = symmetric; |
40 |
|
} |
41 |
|
|
42 |
|
List<List<Float>> contacts = null; |
43 |
|
|
44 |
|
int width = 0, numcontacts = 0; |
45 |
|
|
46 |
|
float min = 0f, max = 0f; |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 8 |
Complexity Density: 0.47 |
|
48 |
0 |
public void addContact(int left, int right, float strength)... |
49 |
|
{ |
50 |
0 |
if (left < 0 || right < 0) |
51 |
|
{ |
52 |
0 |
throw new Error(new RuntimeException( |
53 |
|
"Cannot have negative indices for contact left=" + left |
54 |
|
+ " right=" + right + " strength=" + strength)); |
55 |
|
} |
56 |
0 |
if (symmetric) |
57 |
|
{ |
58 |
0 |
if (left > right) |
59 |
|
{ |
60 |
|
|
61 |
0 |
int r = right; |
62 |
0 |
right = left; |
63 |
0 |
left = r; |
64 |
|
} |
65 |
|
} |
66 |
0 |
if (contacts == null) |
67 |
|
{ |
68 |
|
|
69 |
0 |
contacts = new ArrayList<List<Float>>(); |
70 |
|
} |
71 |
0 |
List<Float> clist = contacts.get(left); |
72 |
0 |
if (clist == null) |
73 |
|
{ |
74 |
0 |
clist = new ArrayList<Float>(); |
75 |
0 |
contacts.set(left, clist); |
76 |
|
} |
77 |
0 |
Float last = clist.set(right, strength); |
78 |
|
|
79 |
0 |
checkBounds(strength); |
80 |
0 |
if (last == null) |
81 |
|
{ |
82 |
0 |
numcontacts++; |
83 |
|
} |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
86 |
0 |
private void checkBounds(float strength)... |
87 |
|
{ |
88 |
0 |
if (min > strength) |
89 |
|
{ |
90 |
0 |
min = strength; |
91 |
|
} |
92 |
0 |
if (max < strength) |
93 |
|
{ |
94 |
0 |
max = strength; |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
98 |
0 |
@Override... |
99 |
|
public ContactListI getContactList(final int column) |
100 |
|
{ |
101 |
0 |
if (column < 0 || column >= width) |
102 |
|
{ |
103 |
0 |
return null; |
104 |
|
} |
105 |
|
|
106 |
0 |
return new ContactListImpl(new ContactListProviderI() |
107 |
|
{ |
108 |
|
int p = column; |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
0 |
@Override... |
111 |
|
public int getPosition() |
112 |
|
{ |
113 |
0 |
return p; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0 |
@Override... |
117 |
|
public int getContactHeight() |
118 |
|
{ |
119 |
0 |
return width; |
120 |
|
|
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
123 |
0 |
@Override... |
124 |
|
public double getContactAt(int column) |
125 |
|
{ |
126 |
0 |
Float cl = getFloatElementAt(column, p); |
127 |
0 |
if (cl == null) |
128 |
|
{ |
129 |
|
|
130 |
0 |
return Double.NaN; |
131 |
|
} |
132 |
0 |
return cl.doubleValue(); |
133 |
|
} |
134 |
|
}); |
135 |
|
} |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
137 |
0 |
private Float getFloatElementAt(int column, int p)... |
138 |
|
{ |
139 |
|
|
140 |
0 |
List<Float> clist; |
141 |
0 |
Float cl = null; |
142 |
0 |
if (symmetric) |
143 |
|
{ |
144 |
0 |
if (p < column) |
145 |
|
{ |
146 |
0 |
clist = contacts.get(p); |
147 |
0 |
cl = clist.get(column); |
148 |
|
} |
149 |
|
else |
150 |
|
{ |
151 |
0 |
clist = contacts.get(column); |
152 |
0 |
cl = clist.get(p); |
153 |
|
} |
154 |
|
} |
155 |
|
else |
156 |
|
{ |
157 |
0 |
clist = contacts.get(p); |
158 |
0 |
cl = clist.get(column); |
159 |
|
} |
160 |
0 |
return cl; |
161 |
|
} |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
163 |
0 |
@Override... |
164 |
|
public double getElementAt(int column, int row) |
165 |
|
{ |
166 |
0 |
Float cl = getFloatElementAt(column, row); |
167 |
0 |
if (cl != null) |
168 |
|
{ |
169 |
0 |
return cl; |
170 |
|
} |
171 |
0 |
throw (new RuntimeException("Out of Bounds " + column + "," + row)); |
172 |
|
} |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0 |
@Override... |
175 |
|
public float getMin() |
176 |
|
{ |
177 |
0 |
return min; |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
@Override... |
181 |
|
public float getMax() |
182 |
|
{ |
183 |
0 |
return max; |
184 |
|
} |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
0 |
@Override... |
187 |
|
public String getAnnotLabel() |
188 |
|
{ |
189 |
0 |
return "Contact Matrix"; |
190 |
|
} |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
0 |
@Override... |
193 |
|
public String getAnnotDescr() |
194 |
|
{ |
195 |
0 |
return "Contact Matrix"; |
196 |
|
} |
197 |
|
|
|
|
| 95.7% |
Uncovered Elements: 1 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
198 |
5 |
public static String contactToFloatString(ContactMatrixI cm)... |
199 |
|
{ |
200 |
5 |
StringBuilder sb = new StringBuilder(); |
201 |
2049 |
for (int c = 0; c < cm.getWidth(); c++) |
202 |
|
{ |
203 |
2044 |
ContactListI cl = cm.getContactList(c); |
204 |
2044 |
long lastsb = -1; |
205 |
2044 |
if (cl != null) |
206 |
|
{ |
207 |
4002528 |
for (int h = 0; h <= cl.getContactHeight(); h++) |
208 |
|
{ |
209 |
4000484 |
if (sb.length() > 0) |
210 |
|
{ |
211 |
4000479 |
if (sb.length() - lastsb > 320) |
212 |
|
{ |
213 |
|
|
214 |
56466 |
sb.append('\n'); |
215 |
56466 |
lastsb = sb.length(); |
216 |
|
} |
217 |
|
else |
218 |
|
{ |
219 |
3944013 |
sb.append('\t'); |
220 |
|
} |
221 |
|
} |
222 |
4000484 |
sb.append(cl.getContactAt(h)); |
223 |
|
} |
224 |
|
} |
225 |
|
} |
226 |
5 |
return sb.toString(); |
227 |
|
} |
228 |
|
|
|
|
| 86.4% |
Uncovered Elements: 3 (22) |
Complexity: 5 |
Complexity Density: 0.36 |
|
229 |
4 |
public static float[][] fromFloatStringToContacts(String values, int cols,... |
230 |
|
int rows) |
231 |
|
{ |
232 |
4 |
float[][] vals = new float[cols][rows]; |
233 |
4 |
StringTokenizer tabsep = new StringTokenizer(values, "" + '\t' + '\n'); |
234 |
4 |
int c = 0, r = 0; |
235 |
4000363 |
while (tabsep.hasMoreTokens()) |
236 |
|
{ |
237 |
4000363 |
double elem = Double.valueOf(tabsep.nextToken()); |
238 |
4000363 |
vals[c][r++] = (float) elem; |
239 |
4000363 |
if (r >= vals[c].length) |
240 |
|
{ |
241 |
2033 |
r = 0; |
242 |
2033 |
c++; |
243 |
|
} |
244 |
4000363 |
if (c >= vals.length) |
245 |
|
{ |
246 |
4 |
break; |
247 |
|
} |
248 |
|
} |
249 |
4 |
if (tabsep.hasMoreElements()) |
250 |
|
{ |
251 |
0 |
Console.warn( |
252 |
|
"Ignoring additional elements for Float string to contact matrix parsing."); |
253 |
|
} |
254 |
4 |
return vals; |
255 |
|
} |
256 |
|
} |