1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import java.io.IOException; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Enumeration; |
26 |
|
import java.util.Hashtable; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Vector; |
29 |
|
|
30 |
|
import jalview.datamodel.AlignmentAnnotation; |
31 |
|
import jalview.datamodel.AlignmentI; |
32 |
|
import jalview.datamodel.Sequence; |
33 |
|
import jalview.datamodel.SequenceGroup; |
34 |
|
import jalview.datamodel.SequenceI; |
35 |
|
import jalview.util.MessageManager; |
36 |
|
import jalview.util.StringUtils; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@author |
42 |
|
@version |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 146 (146) |
Complexity: 51 |
Complexity Density: 0.62 |
|
44 |
|
public abstract class AlignFile extends FileParse |
45 |
|
implements AlignmentFileReaderI, AlignmentFileWriterI |
46 |
|
{ |
47 |
|
int noSeqs = 0; |
48 |
|
|
49 |
|
int maxLength = 0; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
protected Vector<SequenceI> seqs; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
protected Vector<AlignmentAnnotation> annotations; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
protected List<SequenceGroup> seqGroups; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private Hashtable properties; |
71 |
|
|
72 |
|
long start; |
73 |
|
|
74 |
|
long end; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
private boolean parseCalled = false; |
80 |
|
|
81 |
|
private boolean parseImmediately = true; |
82 |
|
|
83 |
|
private boolean dataClosed = false; |
84 |
|
|
85 |
|
private boolean doXferSettings = true; |
86 |
|
|
87 |
|
|
88 |
|
@return |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0 |
protected boolean isParseImmediately()... |
91 |
|
{ |
92 |
0 |
return parseImmediately; |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
public AlignFile()... |
99 |
|
{ |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
0 |
initData(); |
104 |
|
} |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
0 |
public AlignFile(SequenceI[] seqs)... |
107 |
|
{ |
108 |
0 |
this(); |
109 |
0 |
setSeqs(seqs); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
@param |
118 |
|
|
119 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
0 |
public AlignFile(Object dataObject, DataSourceType sourceType)... |
121 |
|
throws IOException |
122 |
|
{ |
123 |
0 |
this(true, dataObject, sourceType); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
|
132 |
|
@param |
133 |
|
|
134 |
|
@param |
135 |
|
|
136 |
|
@throws |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
138 |
0 |
public AlignFile(boolean parseImmediately, Object dataObject,... |
139 |
|
DataSourceType sourceType) throws IOException |
140 |
|
{ |
141 |
|
|
142 |
0 |
super(dataObject, sourceType); |
143 |
0 |
initData(); |
144 |
0 |
if (parseImmediately) |
145 |
|
{ |
146 |
0 |
doParse(); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@param |
155 |
|
@throws |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
public AlignFile(FileParse source, boolean doXferSettings)... |
158 |
|
throws IOException |
159 |
|
{ |
160 |
0 |
this(true, source, true, doXferSettings); |
161 |
|
} |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
0 |
public AlignFile(FileParse source) throws IOException... |
164 |
|
{ |
165 |
0 |
this(true, source); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
174 |
|
@param |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
0 |
public AlignFile(boolean parseImmediately, FileParse source)... |
177 |
|
throws IOException |
178 |
|
{ |
179 |
0 |
this(parseImmediately, source, true); |
180 |
|
} |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0 |
public AlignFile(boolean parseImmediately, FileParse source,... |
183 |
|
boolean closeData) throws IOException |
184 |
|
{ |
185 |
0 |
this(parseImmediately, source, closeData, true); |
186 |
|
} |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
188 |
0 |
public AlignFile(boolean parseImmediately, FileParse source,... |
189 |
|
boolean closeData, boolean doXferSettings) throws IOException |
190 |
|
{ |
191 |
0 |
super(source); |
192 |
0 |
initData(); |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
0 |
this.parseImmediately = parseImmediately; |
197 |
0 |
this.doXferSettings = doXferSettings; |
198 |
|
|
199 |
0 |
if (parseImmediately) |
200 |
|
{ |
201 |
0 |
doParse(closeData); |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@throws |
209 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
0 |
public void doParse() throws IOException... |
211 |
|
{ |
212 |
0 |
doParse(true); |
213 |
|
} |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
215 |
0 |
public void doParse(boolean closeData) throws IOException... |
216 |
|
{ |
217 |
0 |
if (parseCalled) |
218 |
|
{ |
219 |
0 |
throw new IOException( |
220 |
|
"Implementation error: Parser called twice for same data.\n" |
221 |
|
+ "Need to call initData() again before parsing can be reattempted."); |
222 |
|
} |
223 |
0 |
parseCalled = true; |
224 |
0 |
parse(this.doXferSettings); |
225 |
0 |
if (closeData && !dataClosed) |
226 |
|
{ |
227 |
0 |
dataIn.close(); |
228 |
0 |
dataClosed = true; |
229 |
|
} |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0 |
public Vector<SequenceI> getSeqs()... |
236 |
|
{ |
237 |
0 |
return seqs; |
238 |
|
} |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
0 |
public List<SequenceGroup> getSeqGroups()... |
241 |
|
{ |
242 |
0 |
return seqGroups; |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
248 |
0 |
@Override... |
249 |
|
public SequenceI[] getSeqsAsArray() |
250 |
|
{ |
251 |
0 |
SequenceI[] s = new SequenceI[seqs.size()]; |
252 |
|
|
253 |
0 |
for (int i = 0; i < seqs.size(); i++) |
254 |
|
{ |
255 |
0 |
s[i] = seqs.elementAt(i); |
256 |
|
} |
257 |
|
|
258 |
0 |
return s; |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
@param |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
267 |
0 |
@Override... |
268 |
|
public void addAnnotations(AlignmentI al) |
269 |
|
{ |
270 |
0 |
addProperties(al); |
271 |
0 |
for (int i = 0; i < annotations.size(); i++) |
272 |
|
{ |
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
0 |
AlignmentAnnotation an = annotations.elementAt(i); |
281 |
0 |
an.validateRangeAndDisplay(); |
282 |
0 |
al.addAnnotation(an); |
283 |
|
} |
284 |
|
|
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@param |
291 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
292 |
0 |
public void addSeqGroups(AlignmentI al)... |
293 |
|
{ |
294 |
0 |
this.seqGroups = al.getGroups(); |
295 |
|
|
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
@param |
304 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
305 |
0 |
public void addProperties(AlignmentI al)... |
306 |
|
{ |
307 |
0 |
if (properties != null && properties.size() > 0) |
308 |
|
{ |
309 |
0 |
Enumeration keys = properties.keys(); |
310 |
0 |
Enumeration vals = properties.elements(); |
311 |
0 |
while (keys.hasMoreElements()) |
312 |
|
{ |
313 |
0 |
al.setProperty(keys.nextElement(), vals.nextElement()); |
314 |
|
} |
315 |
|
} |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
@param |
324 |
|
|
325 |
|
@param |
326 |
|
|
327 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
328 |
0 |
protected void setAlignmentProperty(Object key, Object value)... |
329 |
|
{ |
330 |
0 |
if (key == null) |
331 |
|
{ |
332 |
0 |
throw new Error(MessageManager.getString( |
333 |
|
"error.implementation_error_cannot_have_null_alignment")); |
334 |
|
} |
335 |
0 |
if (value == null) |
336 |
|
{ |
337 |
0 |
return; |
338 |
|
} |
339 |
0 |
if (properties == null) |
340 |
|
{ |
341 |
0 |
properties = new Hashtable(); |
342 |
|
} |
343 |
0 |
properties.put(key, value); |
344 |
|
} |
345 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
346 |
0 |
protected Object getAlignmentProperty(Object key)... |
347 |
|
{ |
348 |
0 |
if (properties != null && key != null) |
349 |
|
{ |
350 |
0 |
return properties.get(key); |
351 |
|
} |
352 |
0 |
return null; |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
358 |
0 |
protected void initData()... |
359 |
|
{ |
360 |
0 |
seqs = new Vector<SequenceI>(); |
361 |
0 |
annotations = new Vector<AlignmentAnnotation>(); |
362 |
0 |
seqGroups = new ArrayList<SequenceGroup>(); |
363 |
0 |
parseCalled = false; |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
@param |
370 |
|
|
371 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
372 |
0 |
@Override... |
373 |
|
public void setSeqs(SequenceI[] s) |
374 |
|
{ |
375 |
0 |
seqs = new Vector<SequenceI>(); |
376 |
|
|
377 |
0 |
for (int i = 0; i < s.length; i++) |
378 |
|
{ |
379 |
0 |
seqs.addElement(s[i]); |
380 |
|
} |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
public abstract void parse() throws IOException; |
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
@param |
393 |
|
@throws |
394 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
395 |
0 |
public void parse(boolean doXferSettings) throws IOException... |
396 |
|
{ |
397 |
0 |
parse(); |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
405 |
0 |
Sequence parseId(String id)... |
406 |
|
{ |
407 |
0 |
Sequence seq = null; |
408 |
0 |
id = id.trim(); |
409 |
0 |
int space = StringUtils.indexOfFirstWhitespace(id); |
410 |
0 |
if (space > -1) |
411 |
|
{ |
412 |
0 |
seq = new Sequence(id.substring(0, space), ""); |
413 |
0 |
String desc = id.substring(space + 1); |
414 |
0 |
seq.setDescription(desc); |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
} |
423 |
|
else |
424 |
|
{ |
425 |
0 |
seq = new Sequence(id, ""); |
426 |
|
} |
427 |
|
|
428 |
0 |
return seq; |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
@param |
436 |
|
|
437 |
|
|
438 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
439 |
0 |
String printId(SequenceI seq, boolean jvsuffix)... |
440 |
|
{ |
441 |
0 |
return seq.getDisplayId(jvsuffix); |
442 |
|
} |
443 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
444 |
0 |
String printId(SequenceI seq)... |
445 |
|
{ |
446 |
0 |
return printId(seq, true); |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
Vector<String[]> newickStrings = null; |
453 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
454 |
0 |
protected void addNewickTree(String treeName, String newickString)... |
455 |
|
{ |
456 |
0 |
if (newickStrings == null) |
457 |
|
{ |
458 |
0 |
newickStrings = new Vector<String[]>(); |
459 |
|
} |
460 |
0 |
newickStrings.addElement(new String[] { treeName, newickString }); |
461 |
|
} |
462 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
463 |
0 |
protected int getTreeCount()... |
464 |
|
{ |
465 |
0 |
return newickStrings == null ? 0 : newickStrings.size(); |
466 |
|
} |
467 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
468 |
0 |
@Override... |
469 |
|
public void addGroups(AlignmentI al) |
470 |
|
{ |
471 |
|
|
472 |
0 |
for (SequenceGroup sg : getSeqGroups()) |
473 |
|
{ |
474 |
0 |
al.addGroup(sg); |
475 |
|
} |
476 |
|
} |
477 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
478 |
0 |
protected void addSequence(SequenceI seq)... |
479 |
|
{ |
480 |
0 |
seqs.add(seq); |
481 |
|
} |
482 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
483 |
0 |
public void setDoXferSettings(boolean b)... |
484 |
|
{ |
485 |
0 |
doXferSettings = b; |
486 |
|
} |
487 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
488 |
0 |
public boolean getDoXferSettings()... |
489 |
|
{ |
490 |
0 |
return doXferSettings; |
491 |
|
} |
492 |
|
} |