1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis.scoremodels; |
22 |
|
|
23 |
|
import jalview.analysis.AlignmentUtils; |
24 |
|
import jalview.api.AlignmentViewPanel; |
25 |
|
import jalview.api.FeatureRenderer; |
26 |
|
import jalview.api.analysis.ScoreModelI; |
27 |
|
import jalview.api.analysis.SimilarityParamsI; |
28 |
|
import jalview.datamodel.AlignmentAnnotation; |
29 |
|
import jalview.datamodel.AlignmentView; |
30 |
|
import jalview.datamodel.Annotation; |
31 |
|
import jalview.datamodel.SeqCigar; |
32 |
|
import jalview.math.Matrix; |
33 |
|
import jalview.math.MatrixI; |
34 |
|
import jalview.util.Constants; |
35 |
|
import jalview.util.SetUtils; |
36 |
|
|
37 |
|
import java.util.HashMap; |
38 |
|
import java.util.HashSet; |
39 |
|
import java.util.Map; |
40 |
|
import java.util.Set; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 64% |
Uncovered Elements: 54 (150) |
Complexity: 43 |
Complexity Density: 0.46 |
|
45 |
|
public class SecondaryStructureDistanceModel extends DistanceScoreModel |
46 |
|
{ |
47 |
|
private static final String NAME = "Secondary Structure Similarity"; |
48 |
|
|
49 |
|
private ScoreMatrix ssRateMatrix; |
50 |
|
|
51 |
|
private String description; |
52 |
|
|
53 |
|
FeatureRenderer fr; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
58 |
94 |
public SecondaryStructureDistanceModel()... |
59 |
|
{ |
60 |
|
|
61 |
|
} |
62 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.38 |
|
63 |
3 |
@Override... |
64 |
|
public ScoreModelI getInstance(AlignmentViewPanel view) |
65 |
|
{ |
66 |
3 |
SecondaryStructureDistanceModel instance; |
67 |
3 |
try |
68 |
|
{ |
69 |
3 |
instance = this.getClass().getDeclaredConstructor().newInstance(); |
70 |
3 |
instance.configureFromAlignmentView(view); |
71 |
3 |
return instance; |
72 |
|
} catch (InstantiationException | IllegalAccessException e) |
73 |
|
{ |
74 |
0 |
jalview.bin.Console.errPrintln("Error in " + getClass().getName() |
75 |
|
+ ".getInstance(): " + e.getMessage()); |
76 |
0 |
return null; |
77 |
|
} catch (ReflectiveOperationException roe) |
78 |
|
{ |
79 |
0 |
return null; |
80 |
|
} |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
3 |
boolean configureFromAlignmentView(AlignmentViewPanel view)... |
84 |
|
|
85 |
|
{ |
86 |
3 |
fr = view.cloneFeatureRenderer(); |
87 |
3 |
return true; |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
|
104 |
|
|
105 |
|
@param |
106 |
|
|
107 |
|
|
108 |
|
|
|
|
| 54.9% |
Uncovered Elements: 41 (91) |
Complexity: 24 |
Complexity Density: 0.42 |
|
109 |
6 |
@Override... |
110 |
|
public MatrixI findDistances(AlignmentView seqData, |
111 |
|
SimilarityParamsI params) |
112 |
|
{ |
113 |
|
|
114 |
6 |
SeqCigar[] seqs = seqData.getSequences(); |
115 |
6 |
int noseqs = seqs.length; |
116 |
6 |
int cpwidth = 0; |
117 |
6 |
double[][] similarities = new double[noseqs][noseqs]; |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
6 |
String ssSource = params.getSecondaryStructureSource(); |
122 |
6 |
ssRateMatrix = ScoreModels.getInstance().getSecondaryStructureMatrix(); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
6 |
String selectedSSSource = Constants.SS_ANNOTATION_LABEL; |
128 |
6 |
if (ssSource.equals(Constants.SECONDARY_STRUCTURE_LABELS |
129 |
|
.get(Constants.SS_ANNOTATION_FROM_JPRED_LABEL))) |
130 |
|
{ |
131 |
0 |
selectedSSSource = Constants.SS_ANNOTATION_FROM_JPRED_LABEL; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
6 |
int[] viscont = seqData.getVisibleContigs(); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
6 |
Map<String, HashSet<String>> ssAlignmentAnnotationForSequences = new HashMap<String, HashSet<String>>(); |
142 |
|
|
143 |
6 |
AlignmentAnnotation[] alignAnnotList = fr.getViewport().getAlignment() |
144 |
|
.getAlignmentAnnotation(); |
145 |
|
|
146 |
6 |
if (alignAnnotList.length > 0) |
147 |
|
{ |
148 |
6 |
for (AlignmentAnnotation aa : alignAnnotList) |
149 |
|
{ |
150 |
24 |
if (aa.sequenceRef==null) |
151 |
|
{ |
152 |
24 |
continue; |
153 |
|
} |
154 |
0 |
if (selectedSSSource.equals(aa.label)) |
155 |
|
{ |
156 |
0 |
ssAlignmentAnnotationForSequences |
157 |
|
.computeIfAbsent(aa.sequenceRef.getName(), |
158 |
|
k -> new HashSet<>()) |
159 |
|
.add(aa.description); |
160 |
|
} |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
6 |
Set<SeqCigar> seqsWithUndefinedSS = findSeqsWithUndefinedSS(seqs, |
173 |
|
ssAlignmentAnnotationForSequences); |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
12 |
for (int vc = 0; vc < viscont.length; vc += 2) |
181 |
|
{ |
182 |
|
|
183 |
30 |
for (int cpos = viscont[vc]; cpos <= viscont[vc + 1]; cpos++) |
184 |
|
{ |
185 |
24 |
cpwidth++; |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
24 |
Set<SeqCigar> seqsWithoutGapAtCol = findSeqsWithoutGapAtColumn(seqs, |
191 |
|
cpos); |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
48 |
for (int i = 0; i < (noseqs - 1); i++) |
199 |
|
{ |
200 |
|
|
201 |
48 |
for (int j = i + 1; j < noseqs; j++) |
202 |
|
{ |
203 |
24 |
SeqCigar sc1 = seqs[i]; |
204 |
24 |
SeqCigar sc2 = seqs[j]; |
205 |
|
|
206 |
|
|
207 |
24 |
boolean undefinedSS1 = seqsWithUndefinedSS.contains(sc1); |
208 |
24 |
boolean undefinedSS2 = seqsWithUndefinedSS.contains(sc2); |
209 |
|
|
210 |
|
|
211 |
24 |
if (undefinedSS1 && undefinedSS2) |
212 |
|
{ |
213 |
24 |
similarities[i][j] += ssRateMatrix.getMaximumScore(); |
214 |
24 |
continue; |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
0 |
else if (undefinedSS1 || undefinedSS2) |
219 |
|
{ |
220 |
0 |
similarities[i][j] += ssRateMatrix.getMinimumScore(); |
221 |
0 |
continue; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
0 |
boolean gap1 = !seqsWithoutGapAtCol.contains(sc1); |
226 |
0 |
boolean gap2 = !seqsWithoutGapAtCol.contains(sc2); |
227 |
|
|
228 |
|
|
229 |
0 |
char ss1 = '*'; |
230 |
0 |
char ss2 = '*'; |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
0 |
if (!gap1 && !undefinedSS1) |
235 |
|
{ |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
0 |
int seqPosition = seqs[i].findPosition(cpos); |
240 |
0 |
AlignmentAnnotation[] aa = seqs[i].getRefSeq() |
241 |
|
.getAnnotation(selectedSSSource); |
242 |
0 |
if (aa != null) |
243 |
0 |
ss1 = AlignmentUtils.findSSAnnotationForGivenSeqposition( |
244 |
|
aa[0], seqPosition); |
245 |
|
} |
246 |
|
|
247 |
0 |
if (!gap2 && !undefinedSS2) |
248 |
|
{ |
249 |
0 |
int seqPosition = seqs[j].findPosition(cpos); |
250 |
0 |
AlignmentAnnotation[] aa = seqs[j].getRefSeq() |
251 |
|
.getAnnotation(selectedSSSource); |
252 |
0 |
if (aa != null) |
253 |
0 |
ss2 = AlignmentUtils.findSSAnnotationForGivenSeqposition( |
254 |
|
aa[0], seqPosition); |
255 |
|
} |
256 |
|
|
257 |
0 |
if ((!gap1 && !gap2) || params.includeGaps()) |
258 |
|
{ |
259 |
|
|
260 |
0 |
double similarityScore = ssRateMatrix.getPairwiseScore(ss1, |
261 |
|
ss2); |
262 |
0 |
similarities[i][j] += similarityScore; |
263 |
|
} |
264 |
|
} |
265 |
|
} |
266 |
|
} |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
18 |
for (int i = 0; i < noseqs; i++) |
277 |
|
{ |
278 |
18 |
for (int j = i + 1; j < noseqs; j++) |
279 |
|
{ |
280 |
6 |
similarities[i][j] /= cpwidth; |
281 |
6 |
similarities[j][i] = similarities[i][j]; |
282 |
|
} |
283 |
|
} |
284 |
6 |
return ssRateMatrix.similarityToDistance(new Matrix(similarities)); |
285 |
|
|
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
@param |
293 |
|
@param |
294 |
|
|
295 |
|
@return |
296 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
297 |
24 |
private Set<SeqCigar> findSeqsWithoutGapAtColumn(SeqCigar[] seqs,... |
298 |
|
int columnPosition) |
299 |
|
{ |
300 |
24 |
Set<SeqCigar> seqsWithoutGapAtCol = new HashSet<>(); |
301 |
24 |
for (SeqCigar seq : seqs) |
302 |
|
{ |
303 |
48 |
int spos = seq.findPosition(columnPosition); |
304 |
48 |
if (spos != -1) |
305 |
|
{ |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
42 |
seqsWithoutGapAtCol.add(seq); |
310 |
|
} |
311 |
|
} |
312 |
24 |
return seqsWithoutGapAtCol; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
@param |
323 |
|
@param |
324 |
|
@return |
325 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
326 |
6 |
private Set<SeqCigar> findSeqsWithUndefinedSS(SeqCigar[] seqs,... |
327 |
|
Map<String, HashSet<String>> ssAlignmentAnnotationForSequences) |
328 |
|
{ |
329 |
6 |
Set<SeqCigar> seqsWithUndefinedSS = new HashSet<>(); |
330 |
6 |
for (SeqCigar seq : seqs) |
331 |
|
{ |
332 |
12 |
if (isSSUndefinedOrNotAdded(seq, ssAlignmentAnnotationForSequences)) |
333 |
|
{ |
334 |
12 |
seqsWithUndefinedSS.add(seq); |
335 |
|
} |
336 |
|
} |
337 |
6 |
return seqsWithUndefinedSS; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
@param |
348 |
|
@param |
349 |
|
@return |
350 |
|
|
|
|
| 66.7% |
Uncovered Elements: 5 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
351 |
12 |
private boolean isSSUndefinedOrNotAdded(SeqCigar seq,... |
352 |
|
Map<String, HashSet<String>> ssAlignmentAnnotationForSequences) |
353 |
|
{ |
354 |
12 |
for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
355 |
|
{ |
356 |
24 |
AlignmentAnnotation[] annotations = seq.getRefSeq() |
357 |
|
.getAnnotation(label); |
358 |
24 |
if (annotations != null) |
359 |
|
{ |
360 |
6 |
for (AlignmentAnnotation annotation : annotations) |
361 |
|
{ |
362 |
6 |
HashSet<String> descriptionSet = ssAlignmentAnnotationForSequences |
363 |
|
.get(annotation.sequenceRef.getName()); |
364 |
6 |
if (descriptionSet != null) |
365 |
|
{ |
366 |
0 |
if (descriptionSet.contains(annotation.description)) |
367 |
|
{ |
368 |
|
|
369 |
|
|
370 |
0 |
return false; |
371 |
|
} |
372 |
|
} |
373 |
|
} |
374 |
|
} |
375 |
|
} |
376 |
|
|
377 |
12 |
return true; |
378 |
|
} |
379 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
380 |
183 |
@Override... |
381 |
|
public String getName() |
382 |
|
{ |
383 |
183 |
return NAME; |
384 |
|
} |
385 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
386 |
0 |
@Override... |
387 |
|
public String getDescription() |
388 |
|
{ |
389 |
0 |
return description; |
390 |
|
} |
391 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
392 |
4 |
@Override... |
393 |
|
public boolean isDNA() |
394 |
|
{ |
395 |
4 |
return false; |
396 |
|
} |
397 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
398 |
2 |
@Override... |
399 |
|
public boolean isProtein() |
400 |
|
{ |
401 |
2 |
return false; |
402 |
|
} |
403 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
404 |
6 |
@Override... |
405 |
|
public boolean isSecondaryStructure() |
406 |
|
{ |
407 |
6 |
return true; |
408 |
|
} |
409 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
410 |
0 |
@Override... |
411 |
|
public String toString() |
412 |
|
{ |
413 |
0 |
return "Score between sequences based on similarity between binary " |
414 |
|
+ "vectors marking secondary structure displayed at each column"; |
415 |
|
} |
416 |
|
} |