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