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 |
|
|
|
|
| 0% |
Uncovered Elements: 150 (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 |
0 |
public SecondaryStructureDistanceModel()... |
59 |
|
{ |
60 |
|
|
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.38 |
|
63 |
0 |
@Override... |
64 |
|
public ScoreModelI getInstance(AlignmentViewPanel view) |
65 |
|
{ |
66 |
0 |
SecondaryStructureDistanceModel instance; |
67 |
0 |
try |
68 |
|
{ |
69 |
0 |
instance = this.getClass().getDeclaredConstructor().newInstance(); |
70 |
0 |
instance.configureFromAlignmentView(view); |
71 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
0 |
boolean configureFromAlignmentView(AlignmentViewPanel view)... |
84 |
|
|
85 |
|
{ |
86 |
0 |
fr = view.cloneFeatureRenderer(); |
87 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 91 (91) |
Complexity: 24 |
Complexity Density: 0.42 |
|
109 |
0 |
@Override... |
110 |
|
public MatrixI findDistances(AlignmentView seqData, |
111 |
|
SimilarityParamsI params) |
112 |
|
{ |
113 |
|
|
114 |
0 |
SeqCigar[] seqs = seqData.getSequences(); |
115 |
0 |
int noseqs = seqs.length; |
116 |
0 |
int cpwidth = 0; |
117 |
0 |
double[][] similarities = new double[noseqs][noseqs]; |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
0 |
String ssSource = params.getSecondaryStructureSource(); |
122 |
0 |
ssRateMatrix = ScoreModels.getInstance().getSecondaryStructureMatrix(); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
0 |
String selectedSSSource = Constants.SS_ANNOTATION_LABEL; |
128 |
0 |
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 |
0 |
int[] viscont = seqData.getVisibleContigs(); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
0 |
Map<String, HashSet<String>> ssAlignmentAnnotationForSequences = new HashMap<String, HashSet<String>>(); |
142 |
|
|
143 |
0 |
AlignmentAnnotation[] alignAnnotList = fr.getViewport().getAlignment() |
144 |
|
.getAlignmentAnnotation(); |
145 |
|
|
146 |
0 |
if (alignAnnotList.length > 0) |
147 |
|
{ |
148 |
0 |
for (AlignmentAnnotation aa : alignAnnotList) |
149 |
|
{ |
150 |
0 |
if (aa.sequenceRef==null) |
151 |
|
{ |
152 |
0 |
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 |
0 |
Set<SeqCigar> seqsWithUndefinedSS = findSeqsWithUndefinedSS(seqs, |
173 |
|
ssAlignmentAnnotationForSequences); |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
0 |
for (int vc = 0; vc < viscont.length; vc += 2) |
181 |
|
{ |
182 |
|
|
183 |
0 |
for (int cpos = viscont[vc]; cpos <= viscont[vc + 1]; cpos++) |
184 |
|
{ |
185 |
0 |
cpwidth++; |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
0 |
Set<SeqCigar> seqsWithoutGapAtCol = findSeqsWithoutGapAtColumn(seqs, |
191 |
|
cpos); |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
0 |
for (int i = 0; i < (noseqs - 1); i++) |
199 |
|
{ |
200 |
|
|
201 |
0 |
for (int j = i + 1; j < noseqs; j++) |
202 |
|
{ |
203 |
0 |
SeqCigar sc1 = seqs[i]; |
204 |
0 |
SeqCigar sc2 = seqs[j]; |
205 |
|
|
206 |
|
|
207 |
0 |
boolean undefinedSS1 = seqsWithUndefinedSS.contains(sc1); |
208 |
0 |
boolean undefinedSS2 = seqsWithUndefinedSS.contains(sc2); |
209 |
|
|
210 |
|
|
211 |
0 |
if (undefinedSS1 && undefinedSS2) |
212 |
|
{ |
213 |
0 |
similarities[i][j] += ssRateMatrix.getMaximumScore(); |
214 |
0 |
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 |
0 |
for (int i = 0; i < noseqs; i++) |
277 |
|
{ |
278 |
0 |
for (int j = i + 1; j < noseqs; j++) |
279 |
|
{ |
280 |
0 |
similarities[i][j] /= cpwidth; |
281 |
0 |
similarities[j][i] = similarities[i][j]; |
282 |
|
} |
283 |
|
} |
284 |
0 |
return ssRateMatrix.similarityToDistance(new Matrix(similarities)); |
285 |
|
|
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
@param |
293 |
|
@param |
294 |
|
|
295 |
|
@return |
296 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
297 |
0 |
private Set<SeqCigar> findSeqsWithoutGapAtColumn(SeqCigar[] seqs,... |
298 |
|
int columnPosition) |
299 |
|
{ |
300 |
0 |
Set<SeqCigar> seqsWithoutGapAtCol = new HashSet<>(); |
301 |
0 |
for (SeqCigar seq : seqs) |
302 |
|
{ |
303 |
0 |
int spos = seq.findPosition(columnPosition); |
304 |
0 |
if (spos != -1) |
305 |
|
{ |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
0 |
seqsWithoutGapAtCol.add(seq); |
310 |
|
} |
311 |
|
} |
312 |
0 |
return seqsWithoutGapAtCol; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
@param |
323 |
|
@param |
324 |
|
@return |
325 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
326 |
0 |
private Set<SeqCigar> findSeqsWithUndefinedSS(SeqCigar[] seqs,... |
327 |
|
Map<String, HashSet<String>> ssAlignmentAnnotationForSequences) |
328 |
|
{ |
329 |
0 |
Set<SeqCigar> seqsWithUndefinedSS = new HashSet<>(); |
330 |
0 |
for (SeqCigar seq : seqs) |
331 |
|
{ |
332 |
0 |
if (isSSUndefinedOrNotAdded(seq, ssAlignmentAnnotationForSequences)) |
333 |
|
{ |
334 |
0 |
seqsWithUndefinedSS.add(seq); |
335 |
|
} |
336 |
|
} |
337 |
0 |
return seqsWithUndefinedSS; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
@param |
348 |
|
@param |
349 |
|
@return |
350 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
351 |
0 |
private boolean isSSUndefinedOrNotAdded(SeqCigar seq,... |
352 |
|
Map<String, HashSet<String>> ssAlignmentAnnotationForSequences) |
353 |
|
{ |
354 |
0 |
for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) |
355 |
|
{ |
356 |
0 |
AlignmentAnnotation[] annotations = seq.getRefSeq() |
357 |
|
.getAnnotation(label); |
358 |
0 |
if (annotations != null) |
359 |
|
{ |
360 |
0 |
for (AlignmentAnnotation annotation : annotations) |
361 |
|
{ |
362 |
0 |
HashSet<String> descriptionSet = ssAlignmentAnnotationForSequences |
363 |
|
.get(annotation.sequenceRef.getName()); |
364 |
0 |
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 |
0 |
return true; |
378 |
|
} |
379 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
380 |
0 |
@Override... |
381 |
|
public String getName() |
382 |
|
{ |
383 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
392 |
0 |
@Override... |
393 |
|
public boolean isDNA() |
394 |
|
{ |
395 |
0 |
return false; |
396 |
|
} |
397 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
398 |
0 |
@Override... |
399 |
|
public boolean isProtein() |
400 |
|
{ |
401 |
0 |
return false; |
402 |
|
} |
403 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
404 |
0 |
@Override... |
405 |
|
public boolean isSecondaryStructure() |
406 |
|
{ |
407 |
0 |
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 |
|
} |