1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import java.util.HashSet; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Set; |
26 |
|
|
27 |
|
import jalview.io.gff.Gff3Helper; |
28 |
|
import jalview.schemes.ResidueProperties; |
29 |
|
import jalview.util.MapList; |
30 |
|
import jalview.util.MappingUtils; |
31 |
|
import jalview.util.StringUtils; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@author |
39 |
|
|
|
|
| 93% |
Uncovered Elements: 8 (114) |
Complexity: 30 |
Complexity Density: 0.43 |
|
40 |
|
public class MappedFeatures |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static final String HGV_SP = "HGVSp"; |
46 |
|
|
47 |
|
private static final String CSQ = "CSQ"; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private final SequenceI featureSequence; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private final Mapping mapping; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
public final List<SequenceFeature> features; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private final int toPosition; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
private final char toResidue; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private final int[] codonPos; |
81 |
|
|
82 |
|
private final char[] baseCodon; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@param |
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
|
92 |
|
@param |
93 |
|
|
94 |
|
@param |
95 |
|
|
96 |
|
@param |
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.25 |
|
100 |
7 |
public MappedFeatures(Mapping theMapping, SequenceI featureSeq, int pos,... |
101 |
|
char res, List<SequenceFeature> theFeatures) |
102 |
|
{ |
103 |
7 |
mapping = theMapping; |
104 |
7 |
featureSequence = featureSeq; |
105 |
7 |
toPosition = pos; |
106 |
7 |
toResidue = res; |
107 |
7 |
features = theFeatures; |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
7 |
int[] codonIntervals = mapping.getMap().locateInFrom(toPosition, toPosition); |
114 |
7 |
int[] codonPositions = codonIntervals == null ? null |
115 |
|
: MappingUtils.flattenRanges(codonIntervals); |
116 |
7 |
if (codonPositions != null && codonPositions.length == 3) |
117 |
|
{ |
118 |
6 |
codonPos = codonPositions; |
119 |
6 |
baseCodon = new char[3]; |
120 |
6 |
int cdsStart = featureSequence.getStart(); |
121 |
6 |
baseCodon[0] = Character |
122 |
|
.toUpperCase(featureSequence.getCharAt(codonPos[0] - cdsStart)); |
123 |
6 |
baseCodon[1] = Character |
124 |
|
.toUpperCase(featureSequence.getCharAt(codonPos[1] - cdsStart)); |
125 |
6 |
baseCodon[2] = Character |
126 |
|
.toUpperCase(featureSequence.getCharAt(codonPos[2] - cdsStart)); |
127 |
|
} |
128 |
|
else |
129 |
|
{ |
130 |
1 |
codonPos = null; |
131 |
1 |
baseCodon = null; |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
|
145 |
|
|
146 |
|
@return |
147 |
|
|
|
|
| 93.5% |
Uncovered Elements: 5 (77) |
Complexity: 20 |
Complexity Density: 0.43 |
|
148 |
13 |
public String findProteinVariants(SequenceFeature sf)... |
149 |
|
{ |
150 |
13 |
if (!features.contains(sf) || baseCodon == null) |
151 |
|
{ |
152 |
2 |
return ""; |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
11 |
String hgvsp = sf.getValueAsString(CSQ, HGV_SP); |
159 |
11 |
if (hgvsp != null) |
160 |
|
{ |
161 |
3 |
int colonPos = hgvsp.lastIndexOf(':'); |
162 |
3 |
if (colonPos >= 0) |
163 |
|
{ |
164 |
2 |
String var = hgvsp.substring(colonPos + 1); |
165 |
2 |
if (var.contains("p.")) |
166 |
|
{ |
167 |
1 |
return var; |
168 |
|
} |
169 |
|
} |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
10 |
int cdsPos = sf.getBegin(); |
176 |
10 |
if (cdsPos != sf.getEnd()) |
177 |
|
{ |
178 |
|
|
179 |
0 |
return ""; |
180 |
|
} |
181 |
10 |
if (cdsPos != codonPos[0] && cdsPos != codonPos[1] |
182 |
|
&& cdsPos != codonPos[2]) |
183 |
|
{ |
184 |
|
|
185 |
0 |
return ""; |
186 |
|
} |
187 |
|
|
188 |
10 |
String alls = (String) sf.getValue(Gff3Helper.ALLELES); |
189 |
10 |
if (alls == null) |
190 |
|
{ |
191 |
1 |
return ""; |
192 |
|
} |
193 |
|
|
194 |
9 |
String from3 = StringUtils.toSentenceCase( |
195 |
|
ResidueProperties.aa2Triplet.get(String.valueOf(toResidue))); |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
9 |
Set<String> variantPeptides = new HashSet<>(); |
202 |
9 |
String[] alleles = alls.toUpperCase().split(","); |
203 |
9 |
StringBuilder vars = new StringBuilder(); |
204 |
|
|
205 |
9 |
for (String allele : alleles) |
206 |
|
{ |
207 |
23 |
allele = allele.trim().toUpperCase(); |
208 |
23 |
if (allele.length() > 1 || "-".equals(allele)) |
209 |
|
{ |
210 |
4 |
continue; |
211 |
|
} |
212 |
19 |
char[] variantCodon = new char[3]; |
213 |
19 |
variantCodon[0] = baseCodon[0]; |
214 |
19 |
variantCodon[1] = baseCodon[1]; |
215 |
19 |
variantCodon[2] = baseCodon[2]; |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
19 |
final int i = cdsPos == codonPos[0] ? 0 |
222 |
12 |
: (cdsPos == codonPos[1] ? 1 : 2); |
223 |
19 |
variantCodon[i] = allele.toUpperCase().charAt(0); |
224 |
19 |
if (variantCodon[i] == baseCodon[i]) |
225 |
|
{ |
226 |
9 |
continue; |
227 |
|
} |
228 |
10 |
String codon = new String(variantCodon); |
229 |
10 |
String peptide = ResidueProperties.codonTranslate(codon); |
230 |
10 |
boolean synonymous = toResidue == peptide.charAt(0); |
231 |
10 |
StringBuilder var = new StringBuilder(); |
232 |
10 |
if (synonymous) |
233 |
|
{ |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
3 |
var.append("c.").append(String.valueOf(cdsPos)) |
238 |
|
.append(String.valueOf(baseCodon[i])).append(">") |
239 |
|
.append(String.valueOf(variantCodon[i])) |
240 |
|
.append("(p.=)"); |
241 |
|
} |
242 |
|
else |
243 |
|
{ |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
7 |
String to3 = ResidueProperties.STOP.equals(peptide) ? "Ter" |
248 |
|
: StringUtils.toSentenceCase( |
249 |
|
ResidueProperties.aa2Triplet.get(peptide)); |
250 |
7 |
var.append("p.").append(from3).append(String.valueOf(toPosition)) |
251 |
|
.append(to3); |
252 |
|
} |
253 |
10 |
if (!variantPeptides.contains(peptide)) |
254 |
|
{ |
255 |
10 |
variantPeptides.add(peptide); |
256 |
10 |
if (vars.length() > 0) |
257 |
|
{ |
258 |
1 |
vars.append(","); |
259 |
|
} |
260 |
10 |
vars.append(var); |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
9 |
return vars.toString(); |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
@return |
271 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
272 |
1 |
public String getLinkedSequenceName()... |
273 |
|
{ |
274 |
1 |
return featureSequence == null ? null : featureSequence.getName(); |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@param |
291 |
|
@param |
292 |
|
@return |
293 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
294 |
8 |
public int[] getMappedPositions(int begin, int end)... |
295 |
|
{ |
296 |
8 |
MapList map = mapping.getMap(); |
297 |
8 |
return mapping.to == featureSequence ? map.locateInFrom(begin, end) |
298 |
|
: map.locateInTo(begin, end); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
@return |
306 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
307 |
2 |
public boolean isFromCds()... |
308 |
|
{ |
309 |
2 |
if (mapping.getMap().getFromRatio() == 3) |
310 |
|
{ |
311 |
2 |
return mapping.to != featureSequence; |
312 |
|
} |
313 |
0 |
return mapping.to == featureSequence; |
314 |
|
} |
315 |
|
} |