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 |
|
|
|
|
| 6.5% |
Uncovered Elements: 100 (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 |
21 |
public PIDModel()... |
46 |
|
{ |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
47 |
@Override... |
50 |
|
public String getName() |
51 |
|
{ |
52 |
47 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
81 |
0 |
@Override... |
82 |
|
public float getPairwiseScore(char c, char d) |
83 |
|
{ |
84 |
0 |
c = toUpper(c); |
85 |
0 |
d = toUpper(d); |
86 |
0 |
if (c == d && !Comparison.isGap(c)) |
87 |
|
{ |
88 |
0 |
return 1f; |
89 |
|
} |
90 |
0 |
return 0f; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
96 |
0 |
protected static char toUpper(char c)... |
97 |
|
{ |
98 |
0 |
if ('a' <= c && c <= 'z') |
99 |
|
{ |
100 |
0 |
c += 'A' - 'a'; |
101 |
|
} |
102 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 16 |
Complexity Density: 0.48 |
|
180 |
0 |
public static double computePID(String seq1, String seq2,... |
181 |
|
SimilarityParamsI options) |
182 |
|
{ |
183 |
0 |
int len1 = seq1.length(); |
184 |
0 |
int len2 = seq2.length(); |
185 |
0 |
int width = Math.max(len1, len2); |
186 |
0 |
int total = 0; |
187 |
0 |
int divideBy = 0; |
188 |
|
|
189 |
0 |
for (int i = 0; i < width; i++) |
190 |
|
{ |
191 |
0 |
if (i >= len1 || i >= len2) |
192 |
|
{ |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
0 |
if (options.denominateByShortestLength()) |
198 |
|
{ |
199 |
0 |
break; |
200 |
|
} |
201 |
0 |
if (options.includeGaps()) |
202 |
|
{ |
203 |
0 |
divideBy++; |
204 |
|
} |
205 |
0 |
if (options.matchGaps()) |
206 |
|
{ |
207 |
0 |
total++; |
208 |
|
} |
209 |
0 |
continue; |
210 |
|
} |
211 |
0 |
char c1 = seq1.charAt(i); |
212 |
0 |
char c2 = seq2.charAt(i); |
213 |
0 |
boolean gap1 = Comparison.isGap(c1); |
214 |
0 |
boolean gap2 = Comparison.isGap(c2); |
215 |
|
|
216 |
0 |
if (gap1 && gap2) |
217 |
|
{ |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
0 |
if (options.includeGappedColumns()) |
223 |
|
{ |
224 |
0 |
divideBy++; |
225 |
0 |
total++; |
226 |
|
} |
227 |
0 |
continue; |
228 |
|
} |
229 |
|
|
230 |
0 |
if (gap1 || gap2) |
231 |
|
{ |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
0 |
if (options.includeGaps()) |
237 |
|
{ |
238 |
0 |
divideBy++; |
239 |
|
} |
240 |
0 |
if (options.matchGaps()) |
241 |
|
{ |
242 |
0 |
total++; |
243 |
|
} |
244 |
0 |
continue; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
0 |
if (toUpper(c1) == toUpper(c2)) |
251 |
|
{ |
252 |
0 |
total++; |
253 |
|
} |
254 |
0 |
divideBy++; |
255 |
|
} |
256 |
|
|
257 |
0 |
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 |
|
} |