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 |
|
|
|
|
| 94.7% |
Uncovered Elements: 6 (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 |
7 |
public MappedFeatures(Mapping theMapping, SequenceI featureSeq, int pos,... |
103 |
|
char res, List<SequenceFeature> theFeatures) |
104 |
|
{ |
105 |
7 |
mapping = theMapping; |
106 |
7 |
featureSequence = featureSeq; |
107 |
7 |
toPosition = pos; |
108 |
7 |
toResidue = res; |
109 |
7 |
features = theFeatures; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
7 |
int[] codonIntervals = mapping.getMap().locateInFrom(toPosition, |
116 |
|
toPosition); |
117 |
7 |
int[] codonPositions = codonIntervals == null ? null |
118 |
|
: MappingUtils.flattenRanges(codonIntervals); |
119 |
7 |
if (codonPositions != null && codonPositions.length == 3) |
120 |
|
{ |
121 |
6 |
codonPos = codonPositions; |
122 |
6 |
baseCodon = new char[3]; |
123 |
6 |
int cdsStart = featureSequence.getStart(); |
124 |
6 |
baseCodon[0] = Character.toUpperCase( |
125 |
|
featureSequence.getCharAt(codonPos[0] - cdsStart)); |
126 |
6 |
baseCodon[1] = Character.toUpperCase( |
127 |
|
featureSequence.getCharAt(codonPos[1] - cdsStart)); |
128 |
6 |
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 |
|
|
|
|
| 96.1% |
Uncovered Elements: 3 (77) |
Complexity: 20 |
Complexity Density: 0.43 |
|
151 |
14 |
public String findProteinVariants(SequenceFeature sf)... |
152 |
|
{ |
153 |
14 |
if (!features.contains(sf) || baseCodon == null) |
154 |
|
{ |
155 |
2 |
return ""; |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
12 |
String hgvsp = sf.getValueAsString(CSQ, HGV_SP); |
162 |
12 |
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 |
11 |
int cdsPos = sf.getBegin(); |
179 |
11 |
if (cdsPos != sf.getEnd()) |
180 |
|
{ |
181 |
|
|
182 |
1 |
return ""; |
183 |
|
} |
184 |
10 |
if (cdsPos != codonPos[0] && cdsPos != codonPos[1] |
185 |
|
&& cdsPos != codonPos[2]) |
186 |
|
{ |
187 |
|
|
188 |
0 |
return ""; |
189 |
|
} |
190 |
|
|
191 |
10 |
String alls = (String) sf.getValue(Gff3Helper.ALLELES); |
192 |
10 |
if (alls == null) |
193 |
|
{ |
194 |
1 |
return ""; |
195 |
|
} |
196 |
|
|
197 |
9 |
String from3 = StringUtils.toSentenceCase( |
198 |
|
ResidueProperties.aa2Triplet.get(String.valueOf(toResidue))); |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
9 |
Set<String> variantPeptides = new HashSet<>(); |
205 |
9 |
String[] alleles = alls.toUpperCase(Locale.ROOT).split(","); |
206 |
9 |
StringBuilder vars = new StringBuilder(); |
207 |
|
|
208 |
9 |
for (String allele : alleles) |
209 |
|
{ |
210 |
23 |
allele = allele.trim().toUpperCase(Locale.ROOT); |
211 |
23 |
if (allele.length() > 1 || "-".equals(allele)) |
212 |
|
{ |
213 |
4 |
continue; |
214 |
|
} |
215 |
19 |
char[] variantCodon = new char[3]; |
216 |
19 |
variantCodon[0] = baseCodon[0]; |
217 |
19 |
variantCodon[1] = baseCodon[1]; |
218 |
19 |
variantCodon[2] = baseCodon[2]; |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
19 |
final int i = cdsPos == codonPos[0] ? 0 |
225 |
12 |
: (cdsPos == codonPos[1] ? 1 : 2); |
226 |
19 |
variantCodon[i] = allele.toUpperCase(Locale.ROOT).charAt(0); |
227 |
19 |
if (variantCodon[i] == baseCodon[i]) |
228 |
|
{ |
229 |
9 |
continue; |
230 |
|
} |
231 |
10 |
String codon = new String(variantCodon); |
232 |
10 |
String peptide = ResidueProperties.codonTranslate(codon); |
233 |
10 |
boolean synonymous = toResidue == peptide.charAt(0); |
234 |
10 |
StringBuilder var = new StringBuilder(); |
235 |
10 |
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 |
7 |
String to3 = ResidueProperties.STOP.equals(peptide) ? "Ter" |
250 |
|
: StringUtils.toSentenceCase( |
251 |
|
ResidueProperties.aa2Triplet.get(peptide)); |
252 |
7 |
var.append("p.").append(from3).append(String.valueOf(toPosition)) |
253 |
|
.append(to3); |
254 |
|
} |
255 |
10 |
if (!variantPeptides.contains(peptide)) |
256 |
|
{ |
257 |
10 |
variantPeptides.add(peptide); |
258 |
10 |
if (vars.length() > 0) |
259 |
|
{ |
260 |
1 |
vars.append(","); |
261 |
|
} |
262 |
10 |
vars.append(var); |
263 |
|
} |
264 |
|
} |
265 |
|
|
266 |
9 |
return vars.toString(); |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
@return |
273 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
274 |
2 |
public String getLinkedSequenceName()... |
275 |
|
{ |
276 |
2 |
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 |
5 |
public int[] getMappedPositions(int begin, int end)... |
297 |
|
{ |
298 |
5 |
MapList map = mapping.getMap(); |
299 |
5 |
return mapping.to == featureSequence ? map.getOverlapsInFrom(begin, end) |
300 |
|
: map.getOverlapsInTo(begin, end); |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
@return |
308 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
309 |
4 |
public boolean isFromCds()... |
310 |
|
{ |
311 |
4 |
if (mapping.getMap().getFromRatio() == 3) |
312 |
|
{ |
313 |
4 |
return mapping.to != featureSequence; |
314 |
|
} |
315 |
0 |
return mapping.to == featureSequence; |
316 |
|
} |
317 |
|
} |