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