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.FeatureRenderer; |
25 |
|
import jalview.api.analysis.ScoreModelI; |
26 |
|
import jalview.api.analysis.SimilarityParamsI; |
27 |
|
import jalview.datamodel.AlignmentView; |
28 |
|
import jalview.datamodel.SeqCigar; |
29 |
|
import jalview.datamodel.SequenceFeature; |
30 |
|
import jalview.math.Matrix; |
31 |
|
import jalview.math.MatrixI; |
32 |
|
import jalview.util.SetUtils; |
33 |
|
|
34 |
|
import java.util.HashMap; |
35 |
|
import java.util.HashSet; |
36 |
|
import java.util.List; |
37 |
|
import java.util.Map; |
38 |
|
import java.util.Set; |
39 |
|
|
|
|
| 88.2% |
Uncovered Elements: 10 (85) |
Complexity: 25 |
Complexity Density: 0.45 |
|
40 |
|
public class FeatureDistanceModel extends DistanceScoreModel |
41 |
|
{ |
42 |
|
private static final String NAME = "Sequence Feature Similarity"; |
43 |
|
|
44 |
|
private String description; |
45 |
|
|
46 |
|
FeatureRenderer fr; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
51 |
90 |
public FeatureDistanceModel()... |
52 |
|
{ |
53 |
|
} |
54 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.38 |
|
55 |
5 |
@Override... |
56 |
|
public ScoreModelI getInstance(AlignmentViewPanel view) |
57 |
|
{ |
58 |
5 |
FeatureDistanceModel instance; |
59 |
5 |
try |
60 |
|
{ |
61 |
5 |
instance = this.getClass().getDeclaredConstructor().newInstance(); |
62 |
5 |
instance.configureFromAlignmentView(view); |
63 |
5 |
return instance; |
64 |
|
} catch (InstantiationException | IllegalAccessException e) |
65 |
|
{ |
66 |
0 |
jalview.bin.Console.errPrintln("Error in " + getClass().getName() |
67 |
|
+ ".getInstance(): " + e.getMessage()); |
68 |
0 |
return null; |
69 |
|
} catch (ReflectiveOperationException roe) |
70 |
|
{ |
71 |
0 |
return null; |
72 |
|
} |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
75 |
5 |
boolean configureFromAlignmentView(AlignmentViewPanel view)... |
76 |
|
|
77 |
|
{ |
78 |
5 |
fr = view.cloneFeatureRenderer(); |
79 |
5 |
return true; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
@param |
94 |
|
@param |
95 |
|
|
|
|
| 93.8% |
Uncovered Elements: 3 (48) |
Complexity: 13 |
Complexity Density: 0.43 |
|
96 |
6 |
@Override... |
97 |
|
public MatrixI findDistances(AlignmentView seqData, |
98 |
|
SimilarityParamsI params) |
99 |
|
{ |
100 |
6 |
SeqCigar[] seqs = seqData.getSequences(); |
101 |
6 |
int noseqs = seqs.length; |
102 |
6 |
int cpwidth = 0; |
103 |
6 |
double[][] distances = new double[noseqs][noseqs]; |
104 |
6 |
List<String> dft = null; |
105 |
6 |
if (fr != null) |
106 |
|
{ |
107 |
6 |
dft = fr.getDisplayedFeatureTypes(); |
108 |
|
} |
109 |
6 |
if (dft == null || dft.isEmpty()) |
110 |
|
{ |
111 |
0 |
return new Matrix(distances); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
6 |
int[] viscont = seqData.getVisibleContigs(); |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
12 |
for (int vc = 0; vc < viscont.length; vc += 2) |
122 |
|
{ |
123 |
32 |
for (int cpos = viscont[vc]; cpos <= viscont[vc + 1]; cpos++) |
124 |
|
{ |
125 |
26 |
cpwidth++; |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
26 |
Map<SeqCigar, Set<String>> sfap = findFeatureTypesAtColumn(seqs, |
131 |
|
cpos); |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
70 |
for (int i = 0; i < (noseqs - 1); i++) |
138 |
|
{ |
139 |
115 |
for (int j = i + 1; j < noseqs; j++) |
140 |
|
{ |
141 |
71 |
SeqCigar sc1 = seqs[i]; |
142 |
71 |
SeqCigar sc2 = seqs[j]; |
143 |
71 |
Set<String> set1 = sfap.get(sc1); |
144 |
71 |
Set<String> set2 = sfap.get(sc2); |
145 |
71 |
boolean gap1 = set1 == null; |
146 |
71 |
boolean gap2 = set2 == null; |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
71 |
if ((!gap1 && !gap2) || params.includeGaps()) |
154 |
|
{ |
155 |
67 |
int seqDistance = SetUtils.countDisjunction(set1, set2); |
156 |
67 |
distances[i][j] += seqDistance; |
157 |
|
} |
158 |
|
} |
159 |
|
} |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
24 |
for (int i = 0; i < noseqs; i++) |
170 |
|
{ |
171 |
39 |
for (int j = i + 1; j < noseqs; j++) |
172 |
|
{ |
173 |
21 |
distances[i][j] /= cpwidth; |
174 |
21 |
distances[j][i] = distances[i][j]; |
175 |
|
} |
176 |
|
} |
177 |
6 |
return new Matrix(distances); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
@param |
187 |
|
@param |
188 |
|
|
189 |
|
@return |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
191 |
26 |
protected Map<SeqCigar, Set<String>> findFeatureTypesAtColumn(... |
192 |
|
SeqCigar[] seqs, int columnPosition) |
193 |
|
{ |
194 |
26 |
Map<SeqCigar, Set<String>> sfap = new HashMap<>(); |
195 |
26 |
for (SeqCigar seq : seqs) |
196 |
|
{ |
197 |
70 |
int spos = seq.findPosition(columnPosition); |
198 |
70 |
if (spos != -1) |
199 |
|
{ |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
60 |
Set<String> types = new HashSet<>(); |
204 |
60 |
List<SequenceFeature> sfs = fr |
205 |
|
.findFeaturesAtResidue(seq.getRefSeq(), spos, spos); |
206 |
60 |
for (SequenceFeature sf : sfs) |
207 |
|
{ |
208 |
70 |
types.add(sf.getType()); |
209 |
|
} |
210 |
60 |
sfap.put(seq, types); |
211 |
|
} |
212 |
|
} |
213 |
26 |
return sfap; |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
172 |
@Override... |
217 |
|
public String getName() |
218 |
|
{ |
219 |
172 |
return NAME; |
220 |
|
} |
221 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
222 |
0 |
@Override... |
223 |
|
public String getDescription() |
224 |
|
{ |
225 |
0 |
return description; |
226 |
|
} |
227 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
228 |
4 |
@Override... |
229 |
|
public boolean isDNA() |
230 |
|
{ |
231 |
4 |
return true; |
232 |
|
} |
233 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
234 |
2 |
@Override... |
235 |
|
public boolean isProtein() |
236 |
|
{ |
237 |
2 |
return true; |
238 |
|
} |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
0 |
@Override... |
241 |
|
public String toString() |
242 |
|
{ |
243 |
0 |
return "Score between sequences based on hamming distance between binary vectors marking features displayed at each column"; |
244 |
|
} |
245 |
|
} |