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.api.AlignmentViewPanel; |
24 |
|
import jalview.api.analysis.PairwiseScoreModelI; |
25 |
|
import jalview.api.analysis.ScoreModelI; |
26 |
|
import jalview.api.analysis.SimilarityParamsI; |
27 |
|
import jalview.datamodel.AlignmentView; |
28 |
|
import jalview.math.Matrix; |
29 |
|
import jalview.math.MatrixI; |
30 |
|
import jalview.util.Comparison; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
|
|
| 71% |
Uncovered Elements: 31 (107) |
Complexity: 34 |
Complexity Density: 0.56 |
|
37 |
|
public class PIDModel extends SimilarityScoreModel |
38 |
|
implements PairwiseScoreModelI |
39 |
|
{ |
40 |
|
private static final String NAME = "PID"; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
45 |
85 |
public PIDModel()... |
46 |
|
{ |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
165 |
@Override... |
50 |
|
public String getName() |
51 |
|
{ |
52 |
165 |
return NAME; |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0 |
@Override... |
60 |
|
public String getDescription() |
61 |
|
{ |
62 |
0 |
return null; |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
4 |
@Override... |
66 |
|
public boolean isDNA() |
67 |
|
{ |
68 |
4 |
return true; |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
2 |
@Override... |
72 |
|
public boolean isProtein() |
73 |
|
{ |
74 |
2 |
return true; |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
81 |
10 |
@Override... |
82 |
|
public float getPairwiseScore(char c, char d) |
83 |
|
{ |
84 |
10 |
c = toUpper(c); |
85 |
10 |
d = toUpper(d); |
86 |
10 |
if (c == d && !Comparison.isGap(c)) |
87 |
|
{ |
88 |
4 |
return 1f; |
89 |
|
} |
90 |
6 |
return 0f; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
96 |
180 |
protected static char toUpper(char c)... |
97 |
|
{ |
98 |
180 |
if ('a' <= c && c <= 'z') |
99 |
|
{ |
100 |
3 |
c += 'A' - 'a'; |
101 |
|
} |
102 |
180 |
return c; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
111 |
0 |
@Override... |
112 |
|
public MatrixI findSimilarities(AlignmentView seqData, |
113 |
|
SimilarityParamsI options) |
114 |
|
{ |
115 |
0 |
String[] seqs = seqData.getSequenceStrings(Comparison.GAP_DASH); |
116 |
|
|
117 |
0 |
MatrixI result = findSimilarities(seqs, options); |
118 |
|
|
119 |
0 |
result.multiply(seqData.getWidth() / 100d); |
120 |
|
|
121 |
0 |
return result; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
130 |
0 |
@Override... |
131 |
|
public MatrixI findDistances(AlignmentView seqData, |
132 |
|
SimilarityParamsI options) |
133 |
|
{ |
134 |
0 |
MatrixI result = super.findDistances(seqData, options); |
135 |
|
|
136 |
0 |
if (seqData.getWidth() != 0) |
137 |
|
{ |
138 |
0 |
result.multiply(100d / seqData.getWidth()); |
139 |
|
} |
140 |
|
|
141 |
0 |
return result; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
@param |
149 |
|
@param |
150 |
|
@return |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
152 |
0 |
protected MatrixI findSimilarities(String[] seqs,... |
153 |
|
SimilarityParamsI options) |
154 |
|
{ |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
0 |
double[][] values = new double[seqs.length][seqs.length]; |
159 |
0 |
for (int row = 0; row < seqs.length; row++) |
160 |
|
{ |
161 |
0 |
for (int col = row; col < seqs.length; col++) |
162 |
|
{ |
163 |
0 |
double total = computePID(seqs[row], seqs[col], options); |
164 |
0 |
values[row][col] = total; |
165 |
0 |
values[col][row] = total; |
166 |
|
} |
167 |
|
} |
168 |
0 |
return new Matrix(values); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@param |
176 |
|
@param |
177 |
|
@param |
178 |
|
@return |
179 |
|
|
|
|
| 94.7% |
Uncovered Elements: 3 (57) |
Complexity: 16 |
Complexity Density: 0.48 |
|
180 |
26 |
public static double computePID(String seq1, String seq2,... |
181 |
|
SimilarityParamsI options) |
182 |
|
{ |
183 |
26 |
int len1 = seq1.length(); |
184 |
26 |
int len2 = seq2.length(); |
185 |
26 |
int width = Math.max(len1, len2); |
186 |
26 |
int total = 0; |
187 |
26 |
int divideBy = 0; |
188 |
|
|
189 |
182 |
for (int i = 0; i < width; i++) |
190 |
|
{ |
191 |
170 |
if (i >= len1 || i >= len2) |
192 |
|
{ |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
22 |
if (options.denominateByShortestLength()) |
198 |
|
{ |
199 |
14 |
break; |
200 |
|
} |
201 |
8 |
if (options.includeGaps()) |
202 |
|
{ |
203 |
8 |
divideBy++; |
204 |
|
} |
205 |
8 |
if (options.matchGaps()) |
206 |
|
{ |
207 |
4 |
total++; |
208 |
|
} |
209 |
8 |
continue; |
210 |
|
} |
211 |
148 |
char c1 = seq1.charAt(i); |
212 |
148 |
char c2 = seq2.charAt(i); |
213 |
148 |
boolean gap1 = Comparison.isGap(c1); |
214 |
148 |
boolean gap2 = Comparison.isGap(c2); |
215 |
|
|
216 |
148 |
if (gap1 && gap2) |
217 |
|
{ |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
20 |
if (options.includeGappedColumns()) |
223 |
|
{ |
224 |
12 |
divideBy++; |
225 |
12 |
total++; |
226 |
|
} |
227 |
20 |
continue; |
228 |
|
} |
229 |
|
|
230 |
128 |
if (gap1 || gap2) |
231 |
|
{ |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
48 |
if (options.includeGaps()) |
237 |
|
{ |
238 |
48 |
divideBy++; |
239 |
|
} |
240 |
48 |
if (options.matchGaps()) |
241 |
|
{ |
242 |
32 |
total++; |
243 |
|
} |
244 |
48 |
continue; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
80 |
if (toUpper(c1) == toUpper(c2)) |
251 |
|
{ |
252 |
50 |
total++; |
253 |
|
} |
254 |
80 |
divideBy++; |
255 |
|
} |
256 |
|
|
257 |
26 |
return divideBy == 0 ? 0D : 100D * total / divideBy; |
258 |
|
} |
259 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
260 |
0 |
@Override... |
261 |
|
public ScoreModelI getInstance(AlignmentViewPanel avp) |
262 |
|
{ |
263 |
0 |
return this; |
264 |
|
} |
265 |
|
} |