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 java.util.Locale; |
24 |
|
|
25 |
|
import jalview.datamodel.AlignedCodonFrame; |
26 |
|
import jalview.datamodel.AlignmentI; |
27 |
|
import jalview.datamodel.MappingType; |
28 |
|
import jalview.datamodel.SequenceFeature; |
29 |
|
import jalview.datamodel.SequenceI; |
30 |
|
import jalview.util.MapList; |
31 |
|
|
32 |
|
import java.io.IOException; |
33 |
|
import java.util.List; |
34 |
|
import java.util.Map; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 84.9% |
Uncovered Elements: 19 (126) |
Complexity: 37 |
Complexity Density: 0.42 |
|
39 |
|
public class ExonerateHelper extends Gff2Helper |
40 |
|
{ |
41 |
|
private static final String SIMILARITY = "similarity"; |
42 |
|
|
43 |
|
private static final String GENOME2GENOME = "genome2genome"; |
44 |
|
|
45 |
|
private static final String CDNA2GENOME = "cdna2genome"; |
46 |
|
|
47 |
|
private static final String CODING2GENOME = "coding2genome"; |
48 |
|
|
49 |
|
private static final String CODING2CODING = "coding2coding"; |
50 |
|
|
51 |
|
private static final String PROTEIN2GENOME = "protein2genome"; |
52 |
|
|
53 |
|
private static final String PROTEIN2DNA = "protein2dna"; |
54 |
|
|
55 |
|
private static final String ALIGN = "Align"; |
56 |
|
|
57 |
|
private static final String QUERY = "Query"; |
58 |
|
|
59 |
|
private static final String TARGET = "Target"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
|
66 |
|
@param |
67 |
|
|
68 |
|
|
69 |
|
@param |
70 |
|
|
71 |
|
@param |
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@return |
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
79 |
7 |
@Override... |
80 |
|
public SequenceFeature processGff(SequenceI seq, String[] gffColumns, |
81 |
|
AlignmentI align, List<SequenceI> newseqs, |
82 |
|
boolean relaxedIdMatching) |
83 |
|
{ |
84 |
7 |
String attr = gffColumns[ATTRIBUTES_COL]; |
85 |
7 |
Map<String, List<String>> set = parseNameValuePairs(attr); |
86 |
|
|
87 |
7 |
try |
88 |
|
{ |
89 |
7 |
processGffSimilarity(set, seq, gffColumns, align, newseqs, |
90 |
|
relaxedIdMatching); |
91 |
|
} catch (IOException ivfe) |
92 |
|
{ |
93 |
0 |
jalview.bin.Console.errPrintln(ivfe); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
7 |
return null; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
|
110 |
|
@param |
111 |
|
|
112 |
|
@param |
113 |
|
|
114 |
|
@param |
115 |
|
|
116 |
|
|
117 |
|
@param |
118 |
|
|
119 |
|
@param |
120 |
|
|
121 |
|
@throws |
122 |
|
|
|
|
| 80% |
Uncovered Elements: 9 (45) |
Complexity: 12 |
Complexity Density: 0.39 |
|
123 |
11 |
protected void processGffSimilarity(Map<String, List<String>> set,... |
124 |
|
SequenceI seq, String[] gff, AlignmentI align, |
125 |
|
List<SequenceI> newseqs, boolean relaxedIdMatching) |
126 |
|
throws IOException |
127 |
|
{ |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
11 |
boolean featureIsOnTarget = true; |
138 |
11 |
List<String> mapTo = set.get(QUERY); |
139 |
11 |
if (mapTo == null) |
140 |
|
{ |
141 |
3 |
mapTo = set.get(TARGET); |
142 |
3 |
featureIsOnTarget = false; |
143 |
|
} |
144 |
11 |
MappingType type = getMappingType(gff[SOURCE_COL]); |
145 |
|
|
146 |
11 |
if (type == null) |
147 |
|
{ |
148 |
0 |
throw new IOException("Sorry, I don't handle " + gff[SOURCE_COL]); |
149 |
|
} |
150 |
|
|
151 |
11 |
if (mapTo == null || mapTo.size() != 1) |
152 |
|
{ |
153 |
0 |
throw new IOException( |
154 |
|
"Expecting exactly one sequence in Query or Target field (got " |
155 |
|
+ mapTo + ")"); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
11 |
SequenceI mappedSequence = findSequence(mapTo.get(0), align, newseqs, |
162 |
|
relaxedIdMatching); |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
11 |
SequenceI mapFromSequence = seq; |
168 |
11 |
SequenceI mapToSequence = mappedSequence; |
169 |
11 |
if ((type == MappingType.NucleotideToPeptide && featureIsOnTarget) |
170 |
|
|| (type == MappingType.PeptideToNucleotide |
171 |
|
&& !featureIsOnTarget)) |
172 |
|
{ |
173 |
3 |
mapFromSequence = mappedSequence; |
174 |
3 |
mapToSequence = seq; |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
11 |
AlignedCodonFrame acf = getMapping(align, mapFromSequence, |
189 |
|
mapToSequence); |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
11 |
String strand = gff[STRAND_COL]; |
196 |
11 |
boolean forwardStrand = true; |
197 |
11 |
if ("-".equals(strand)) |
198 |
|
{ |
199 |
9 |
forwardStrand = false; |
200 |
|
} |
201 |
2 |
else if (!"+".equals(strand)) |
202 |
|
{ |
203 |
0 |
jalview.bin.Console |
204 |
|
.errPrintln("Strand must be specified for alignment"); |
205 |
0 |
return; |
206 |
|
} |
207 |
|
|
208 |
11 |
List<String> alignedRegions = set.get(ALIGN); |
209 |
11 |
for (String region : alignedRegions) |
210 |
|
{ |
211 |
15 |
MapList mapping = buildMapping(region, type, forwardStrand, |
212 |
|
featureIsOnTarget, gff); |
213 |
|
|
214 |
15 |
if (mapping == null) |
215 |
|
{ |
216 |
0 |
continue; |
217 |
|
} |
218 |
|
|
219 |
15 |
acf.addMap(mapFromSequence, mapToSequence, mapping); |
220 |
|
} |
221 |
11 |
align.addCodonFrame(acf); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
@param |
228 |
|
@param |
229 |
|
@param |
230 |
|
@param |
231 |
|
@param |
232 |
|
@return |
233 |
|
|
|
|
| 88.1% |
Uncovered Elements: 5 (42) |
Complexity: 6 |
Complexity Density: 0.18 |
|
234 |
15 |
protected MapList buildMapping(String region, MappingType type,... |
235 |
|
boolean forwardStrand, boolean featureIsOnTarget, String[] gff) |
236 |
|
{ |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
15 |
String[] tokens = region.split(" "); |
241 |
15 |
if (tokens.length != 3) |
242 |
|
{ |
243 |
0 |
jalview.bin.Console |
244 |
|
.errPrintln("Malformed Align descriptor: " + region); |
245 |
0 |
return null; |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
15 |
int alignFromStart; |
253 |
15 |
int alignToStart; |
254 |
15 |
int alignCount; |
255 |
15 |
try |
256 |
|
{ |
257 |
15 |
alignFromStart = Integer.parseInt(tokens[0]); |
258 |
15 |
alignToStart = Integer.parseInt(tokens[1]); |
259 |
15 |
alignCount = Integer.parseInt(tokens[2]); |
260 |
|
} catch (NumberFormatException nfe) |
261 |
|
{ |
262 |
0 |
jalview.bin.Console.errPrintln(nfe.toString()); |
263 |
0 |
return null; |
264 |
|
} |
265 |
|
|
266 |
15 |
int fromStart; |
267 |
15 |
int fromEnd; |
268 |
15 |
int toStart; |
269 |
15 |
int toEnd; |
270 |
|
|
271 |
15 |
if (featureIsOnTarget) |
272 |
|
{ |
273 |
12 |
fromStart = alignToStart; |
274 |
12 |
toStart = alignFromStart; |
275 |
12 |
toEnd = forwardStrand ? toStart + alignCount - 1 |
276 |
|
: toStart - (alignCount - 1); |
277 |
12 |
int toLength = Math.abs(toEnd - toStart) + 1; |
278 |
12 |
int fromLength = toLength * type.getFromRatio() / type.getToRatio(); |
279 |
12 |
fromEnd = fromStart + fromLength - 1; |
280 |
|
} |
281 |
|
else |
282 |
|
{ |
283 |
|
|
284 |
|
|
285 |
3 |
fromStart = alignFromStart; |
286 |
3 |
fromEnd = alignFromStart + alignCount - 1; |
287 |
3 |
int fromLength = fromEnd - fromStart + 1; |
288 |
3 |
int toLength = fromLength * type.getToRatio() / type.getFromRatio(); |
289 |
3 |
toStart = alignToStart; |
290 |
3 |
if (forwardStrand) |
291 |
|
{ |
292 |
1 |
toEnd = toStart + toLength - 1; |
293 |
|
} |
294 |
|
else |
295 |
|
{ |
296 |
2 |
toEnd = toStart - (toLength - 1); |
297 |
|
} |
298 |
|
} |
299 |
|
|
300 |
15 |
MapList codonmapping = constructMappingFromAlign(fromStart, fromEnd, |
301 |
|
toStart, toEnd, type); |
302 |
15 |
return codonmapping; |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
@param |
309 |
|
@return |
310 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 7 |
Complexity Density: 1.17 |
|
311 |
18 |
protected static MappingType getMappingType(String model)... |
312 |
|
{ |
313 |
18 |
MappingType result = null; |
314 |
|
|
315 |
18 |
if (model.contains(PROTEIN2DNA) || model.contains(PROTEIN2GENOME)) |
316 |
|
{ |
317 |
13 |
result = MappingType.PeptideToNucleotide; |
318 |
|
} |
319 |
5 |
else if (model.contains(CODING2CODING) || model.contains(CODING2GENOME) |
320 |
|
|| model.contains(CDNA2GENOME) || model.contains(GENOME2GENOME)) |
321 |
|
{ |
322 |
4 |
result = MappingType.NucleotideToNucleotide; |
323 |
|
} |
324 |
18 |
return result; |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
@param |
332 |
|
@return |
333 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 9 |
Complexity Density: 1 |
|
334 |
38 |
public static boolean recognises(String[] columns)... |
335 |
|
{ |
336 |
38 |
if (!SIMILARITY.equalsIgnoreCase(columns[TYPE_COL])) |
337 |
|
{ |
338 |
22 |
return false; |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
16 |
String model = columns[SOURCE_COL]; |
345 |
|
|
346 |
16 |
if (model != null) |
347 |
|
{ |
348 |
16 |
String mdl = model.toLowerCase(Locale.ROOT); |
349 |
16 |
if (mdl.contains(PROTEIN2DNA) || mdl.contains(PROTEIN2GENOME) |
350 |
|
|| mdl.contains(CODING2CODING) || mdl.contains(CODING2GENOME) |
351 |
|
|| mdl.contains(CDNA2GENOME) || mdl.contains(GENOME2GENOME)) |
352 |
|
{ |
353 |
14 |
return true; |
354 |
|
} |
355 |
|
} |
356 |
2 |
jalview.bin.Console |
357 |
|
.errPrintln("Sorry, I don't handle exonerate model " + model); |
358 |
2 |
return false; |
359 |
|
} |
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
365 |
0 |
@Override... |
366 |
|
protected SequenceFeature buildSequenceFeature(String[] gff, |
367 |
|
Map<String, List<String>> set) |
368 |
|
{ |
369 |
0 |
SequenceFeature sf = super.buildSequenceFeature(gff, TYPE_COL, |
370 |
|
"exonerate", set); |
371 |
|
|
372 |
0 |
return sf; |
373 |
|
} |
374 |
|
|
375 |
|
} |