1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io.gff; |
22 |
|
|
23 |
|
import jalview.datamodel.AlignedCodonFrame; |
24 |
|
import jalview.datamodel.AlignmentI; |
25 |
|
import jalview.datamodel.MappingType; |
26 |
|
import jalview.datamodel.SequenceFeature; |
27 |
|
import jalview.datamodel.SequenceI; |
28 |
|
import jalview.util.MapList; |
29 |
|
import jalview.util.StringUtils; |
30 |
|
|
31 |
|
import java.io.IOException; |
32 |
|
import java.util.List; |
33 |
|
import java.util.Map; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
|
|
| 0% |
Uncovered Elements: 133 (133) |
Complexity: 28 |
Complexity Density: 0.3 |
|
40 |
|
public class Gff3Helper extends GffHelperBase |
41 |
|
{ |
42 |
|
public static final String ALLELES = "alleles"; |
43 |
|
|
44 |
|
protected static final String TARGET = "Target"; |
45 |
|
|
46 |
|
protected static final String ID = "ID"; |
47 |
|
|
48 |
|
private static final String NAME = "Name"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@return |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
public static Map<String, List<String>> parseNameValuePairs(String text)... |
58 |
|
{ |
59 |
0 |
return parseNameValuePairs(text, ";", '=', ","); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
@param |
68 |
|
|
69 |
|
|
70 |
|
@param |
71 |
|
|
72 |
|
@param |
73 |
|
|
74 |
|
@param |
75 |
|
|
76 |
|
@return |
77 |
|
|
78 |
|
|
79 |
|
@throws |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
81 |
0 |
@Override... |
82 |
|
public SequenceFeature processGff(SequenceI seq, String[] gff, |
83 |
|
AlignmentI align, List<SequenceI> newseqs, |
84 |
|
boolean relaxedIdMatching) throws IOException |
85 |
|
{ |
86 |
0 |
SequenceFeature sf = null; |
87 |
|
|
88 |
0 |
if (gff.length == 9) |
89 |
|
{ |
90 |
0 |
String soTerm = gff[TYPE_COL]; |
91 |
0 |
String atts = gff[ATTRIBUTES_COL]; |
92 |
0 |
Map<String, List<String>> attributes = parseNameValuePairs(atts); |
93 |
|
|
94 |
0 |
SequenceOntologyI so = SequenceOntologyFactory.getInstance(); |
95 |
0 |
if (so.isA(soTerm, SequenceOntologyI.PROTEIN_MATCH)) |
96 |
|
{ |
97 |
0 |
sf = processProteinMatch(attributes, seq, gff, align, newseqs, |
98 |
|
relaxedIdMatching); |
99 |
|
} |
100 |
0 |
else if (so.isA(soTerm, SequenceOntologyI.NUCLEOTIDE_MATCH)) |
101 |
|
{ |
102 |
0 |
sf = processNucleotideMatch(attributes, seq, gff, align, newseqs, |
103 |
|
relaxedIdMatching); |
104 |
|
} |
105 |
|
else |
106 |
|
{ |
107 |
0 |
sf = buildSequenceFeature(gff, attributes); |
108 |
|
} |
109 |
|
} |
110 |
|
else |
111 |
|
{ |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
0 |
sf = buildSequenceFeature(gff, null); |
116 |
|
} |
117 |
|
|
118 |
0 |
return sf; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@param |
125 |
|
|
126 |
|
@param |
127 |
|
|
128 |
|
@param |
129 |
|
|
130 |
|
@param |
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
|
135 |
|
@param |
136 |
|
|
137 |
|
@return |
138 |
|
|
139 |
|
@throws |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 9 |
Complexity Density: 0.26 |
|
141 |
0 |
protected SequenceFeature processNucleotideMatch(... |
142 |
|
Map<String, List<String>> attributes, SequenceI seq, |
143 |
|
String[] gffColumns, AlignmentI align, List<SequenceI> newseqs, |
144 |
|
boolean relaxedIdMatching) throws IOException |
145 |
|
{ |
146 |
0 |
String strand = gffColumns[STRAND_COL]; |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
0 |
if ("-".equals(strand)) |
156 |
|
{ |
157 |
0 |
jalview.bin.Console.errPrintln( |
158 |
|
"Skipping mapping from reverse complement as not yet supported"); |
159 |
0 |
return null; |
160 |
|
} |
161 |
|
|
162 |
0 |
List<String> targets = attributes.get(TARGET); |
163 |
0 |
if (targets == null) |
164 |
|
{ |
165 |
0 |
jalview.bin.Console.errPrintln("'Target' missing in GFF"); |
166 |
0 |
return null; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
0 |
for (String target : targets) |
174 |
|
{ |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
0 |
String[] tokens = target.split(" "); |
179 |
0 |
if (tokens.length < 3) |
180 |
|
{ |
181 |
0 |
jalview.bin.Console.errPrintln("Incomplete Target: " + target); |
182 |
0 |
continue; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
0 |
String targetId = findTargetId(tokens[0], attributes); |
190 |
0 |
SequenceI mappedSequence1 = findSequence(targetId, align, newseqs, |
191 |
|
relaxedIdMatching); |
192 |
0 |
SequenceI mappedSequence = mappedSequence1; |
193 |
0 |
if (mappedSequence == null) |
194 |
|
{ |
195 |
0 |
continue; |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
0 |
AlignedCodonFrame acf = getMapping(align, seq, mappedSequence); |
203 |
|
|
204 |
0 |
try |
205 |
|
{ |
206 |
0 |
int toStart = Integer.parseInt(tokens[1]); |
207 |
0 |
int toEnd = Integer.parseInt(tokens[2]); |
208 |
0 |
if (tokens.length > 3 && "-".equals(tokens[3])) |
209 |
|
{ |
210 |
|
|
211 |
0 |
int temp = toStart; |
212 |
0 |
toStart = toEnd; |
213 |
0 |
toEnd = temp; |
214 |
|
} |
215 |
|
|
216 |
0 |
int fromStart = Integer.parseInt(gffColumns[START_COL]); |
217 |
0 |
int fromEnd = Integer.parseInt(gffColumns[END_COL]); |
218 |
0 |
MapList mapping = constructMappingFromAlign(fromStart, fromEnd, |
219 |
|
toStart, toEnd, MappingType.NucleotideToNucleotide); |
220 |
|
|
221 |
0 |
if (mapping != null) |
222 |
|
{ |
223 |
0 |
acf.addMap(seq, mappedSequence, mapping); |
224 |
0 |
align.addCodonFrame(acf); |
225 |
|
} |
226 |
|
} catch (NumberFormatException nfe) |
227 |
|
{ |
228 |
0 |
jalview.bin.Console |
229 |
|
.errPrintln("Invalid start or end in Target " + target); |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
0 |
SequenceFeature sf = buildSequenceFeature(gffColumns, attributes); |
234 |
0 |
return sf; |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
@param |
243 |
|
|
244 |
|
|
245 |
|
@param |
246 |
|
|
247 |
|
@return |
248 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
249 |
0 |
@SuppressWarnings("unused")... |
250 |
|
protected String findTargetId(String target, |
251 |
|
Map<String, List<String>> set) |
252 |
|
{ |
253 |
0 |
return target; |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
@param |
266 |
|
|
267 |
|
@param |
268 |
|
|
269 |
|
@param |
270 |
|
|
271 |
|
@param |
272 |
|
|
273 |
|
|
274 |
|
@param |
275 |
|
|
276 |
|
@param |
277 |
|
|
278 |
|
@return |
279 |
|
@throws |
280 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 4 |
Complexity Density: 0.17 |
|
281 |
0 |
protected SequenceFeature processProteinMatch(... |
282 |
|
Map<String, List<String>> set, SequenceI seq, String[] gffColumns, |
283 |
|
AlignmentI align, List<SequenceI> newseqs, |
284 |
|
boolean relaxedIdMatching) |
285 |
|
{ |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
0 |
SequenceFeature sf = buildSequenceFeature(gffColumns, set); |
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
0 |
List<String> targets = set.get(TARGET); |
300 |
0 |
if (targets != null) |
301 |
|
{ |
302 |
0 |
for (String target : targets) |
303 |
|
{ |
304 |
|
|
305 |
0 |
SequenceI mappedSequence1 = findSequence(findTargetId(target, set), |
306 |
|
align, newseqs, relaxedIdMatching); |
307 |
0 |
SequenceI mappedSequence = mappedSequence1; |
308 |
0 |
if (mappedSequence == null) |
309 |
|
{ |
310 |
0 |
continue; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
0 |
int sequenceFeatureLength = 1 + sf.getEnd() - sf.getBegin(); |
318 |
0 |
SequenceFeature sf2 = new SequenceFeature(sf, 1, |
319 |
|
sequenceFeatureLength, sf.getFeatureGroup(), sf.getScore()); |
320 |
0 |
mappedSequence.addSequenceFeature(sf2); |
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
0 |
String accessionId = StringUtils |
328 |
|
.listToDelimitedString(set.get(NAME), ","); |
329 |
0 |
if (accessionId.length() > 0) |
330 |
|
{ |
331 |
0 |
String database = sf.getType(); |
332 |
0 |
String qualifiedAccId = database + "|" + accessionId; |
333 |
0 |
sf2.setValue(RENAME_TOKEN, qualifiedAccId); |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
0 |
AlignedCodonFrame alco = getMapping(align, seq, mappedSequence); |
341 |
0 |
int[] from = new int[] { sf.getBegin(), sf.getEnd() }; |
342 |
0 |
int[] to = new int[] { 1, sequenceFeatureLength }; |
343 |
0 |
MapList mapping = new MapList(from, to, 1, 1); |
344 |
|
|
345 |
0 |
alco.addMap(seq, mappedSequence, mapping); |
346 |
0 |
align.addCodonFrame(alco); |
347 |
|
} |
348 |
|
} |
349 |
|
|
350 |
0 |
return sf; |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
357 |
0 |
@Override... |
358 |
|
protected SequenceFeature buildSequenceFeature(String[] gff, |
359 |
|
int typeColumn, String group, |
360 |
|
Map<String, List<String>> attributes) |
361 |
|
{ |
362 |
0 |
SequenceFeature sf = super.buildSequenceFeature(gff, typeColumn, group, |
363 |
|
attributes); |
364 |
0 |
String desc = getDescription(sf, attributes); |
365 |
0 |
if (desc != null) |
366 |
|
{ |
367 |
0 |
sf.setDescription(desc); |
368 |
|
} |
369 |
0 |
return sf; |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
@param |
376 |
|
@param |
377 |
|
@return |
378 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 7 |
Complexity Density: 0.5 |
|
379 |
0 |
protected String getDescription(SequenceFeature sf,... |
380 |
|
Map<String, List<String>> attributes) |
381 |
|
{ |
382 |
0 |
String desc = null; |
383 |
0 |
String target = (String) sf.getValue(TARGET); |
384 |
0 |
if (target != null) |
385 |
|
{ |
386 |
0 |
desc = target.split(" ")[0]; |
387 |
|
} |
388 |
|
|
389 |
0 |
SequenceOntologyI so = SequenceOntologyFactory.getInstance(); |
390 |
0 |
String type = sf.getType(); |
391 |
0 |
if (so.isA(type, SequenceOntologyI.SEQUENCE_VARIANT)) |
392 |
|
{ |
393 |
|
|
394 |
|
|
395 |
|
|
396 |
0 |
desc = StringUtils.listToDelimitedString(attributes.get(ALLELES), |
397 |
|
","); |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
0 |
if (SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(type) |
405 |
|
|| so.isA(type, SequenceOntologyI.TRANSCRIPT) |
406 |
|
|| so.isA(type, SequenceOntologyI.EXON)) |
407 |
|
{ |
408 |
0 |
desc = StringUtils.listToDelimitedString(attributes.get("Name"), ","); |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
0 |
if (desc == null) |
415 |
|
{ |
416 |
0 |
desc = (String) sf.getValue(ID); |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
0 |
desc = StringUtils.urlDecode(desc, GFF_ENCODABLE); |
423 |
|
|
424 |
0 |
return desc; |
425 |
|
} |
426 |
|
} |