1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
package jalview.io; |
28 |
|
|
29 |
|
import java.io.BufferedReader; |
30 |
|
import java.io.File; |
31 |
|
import java.io.FileReader; |
32 |
|
import java.io.IOException; |
33 |
|
import java.util.Locale; |
34 |
|
import java.util.StringTokenizer; |
35 |
|
|
36 |
|
import com.stevesoft.pat.Regex; |
37 |
|
|
38 |
|
import jalview.bin.Jalview; |
39 |
|
import jalview.bin.Jalview.ExitCode; |
40 |
|
import jalview.datamodel.BinaryNode; |
41 |
|
import jalview.datamodel.SequenceNode; |
42 |
|
import jalview.util.MessageManager; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@author |
79 |
|
@version |
80 |
|
|
|
|
| 58.7% |
Uncovered Elements: 179 (433) |
Complexity: 112 |
Complexity Density: 0.42 |
|
81 |
|
public class NewickFile extends FileParse |
82 |
|
{ |
83 |
|
BinaryNode root; |
84 |
|
|
85 |
|
private boolean HasBootstrap = false; |
86 |
|
|
87 |
|
private boolean HasDistances = false; |
88 |
|
|
89 |
|
private boolean RootHasDistance = false; |
90 |
|
|
91 |
|
|
92 |
|
boolean ReplaceUnderscores = false; |
93 |
|
|
94 |
|
boolean printRootInfo = true; |
95 |
|
|
96 |
|
private Regex[] NodeSafeName = new Regex[] { |
97 |
|
new Regex().perlCode("m/[\\[,:'()]/"), |
98 |
|
|
99 |
|
|
100 |
|
new Regex().perlCode("s/'/''/"), |
101 |
|
|
102 |
|
new Regex().perlCode("s/\\/w/_/") |
103 |
|
|
104 |
|
}; |
105 |
|
|
106 |
|
char QuoteChar = '\''; |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
|
113 |
|
|
114 |
|
@throws |
115 |
|
|
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
public NewickFile(String inStr) throws IOException... |
118 |
|
{ |
119 |
0 |
super(inStr, DataSourceType.PASTE); |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@param |
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
|
130 |
|
@throws |
131 |
|
|
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
6 |
public NewickFile(String inFile, DataSourceType protocol)... |
134 |
|
throws IOException |
135 |
|
{ |
136 |
6 |
super(inFile, protocol); |
137 |
|
} |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
0 |
public NewickFile(FileParse source) throws IOException... |
140 |
|
{ |
141 |
0 |
super(source); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
@param |
148 |
|
|
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
3 |
public NewickFile(BinaryNode newtree)... |
151 |
|
{ |
152 |
3 |
root = newtree; |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
|
160 |
|
@param |
161 |
|
|
162 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
163 |
0 |
public NewickFile(SequenceNode newtree, boolean bootstrap)... |
164 |
|
{ |
165 |
0 |
HasBootstrap = bootstrap; |
166 |
0 |
root = newtree; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
174 |
|
@param |
175 |
|
|
176 |
|
@param |
177 |
|
|
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
179 |
2 |
public NewickFile(BinaryNode newtree, boolean bootstrap,... |
180 |
|
boolean distances) |
181 |
|
{ |
182 |
2 |
root = newtree; |
183 |
2 |
HasBootstrap = bootstrap; |
184 |
2 |
HasDistances = distances; |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@param |
191 |
|
|
192 |
|
@param |
193 |
|
|
194 |
|
@param |
195 |
|
|
196 |
|
@param |
197 |
|
|
198 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
199 |
0 |
public NewickFile(BinaryNode newtree, boolean bootstrap,... |
200 |
|
boolean distances, boolean rootdistance) |
201 |
|
{ |
202 |
0 |
root = newtree; |
203 |
0 |
HasBootstrap = bootstrap; |
204 |
0 |
HasDistances = distances; |
205 |
0 |
RootHasDistance = rootdistance; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
@param |
212 |
|
|
213 |
|
@param |
214 |
|
|
215 |
|
@param |
216 |
|
|
217 |
|
@param |
218 |
|
|
219 |
|
@param |
220 |
|
|
221 |
|
|
222 |
|
@return |
223 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 4 |
|
224 |
0 |
private String ErrorStringrange(String Error, String Er, int r, int p,... |
225 |
|
String s) |
226 |
|
{ |
227 |
0 |
return ((Error == null) ? "" : Error) + Er + " at position " + p + " ( " |
228 |
0 |
+ s.substring(((p - r) < 0) ? 0 : (p - r), |
229 |
0 |
((p + r) > s.length()) ? s.length() : (p + r)) |
230 |
|
+ " )\n"; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
9 |
public boolean HasBootstrap()... |
236 |
|
{ |
237 |
9 |
return HasBootstrap; |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@return |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
245 |
9 |
public boolean HasDistances()... |
246 |
|
{ |
247 |
9 |
return HasDistances; |
248 |
|
} |
249 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
250 |
6 |
public boolean HasRootDistance()... |
251 |
|
{ |
252 |
6 |
return RootHasDistance; |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
@throws |
259 |
|
|
260 |
|
|
261 |
|
|
|
|
| 71.4% |
Uncovered Elements: 64 (224) |
Complexity: 52 |
Complexity Density: 0.36 |
|
262 |
6 |
public void parse() throws IOException... |
263 |
|
{ |
264 |
6 |
String nf; |
265 |
|
|
266 |
|
{ |
267 |
|
|
268 |
6 |
StringBuffer file = new StringBuffer(); |
269 |
|
|
270 |
? |
while ((nf = nextLine()) != null) |
271 |
|
{ |
272 |
6 |
file.append(nf); |
273 |
|
} |
274 |
|
|
275 |
6 |
nf = file.toString(); |
276 |
|
} |
277 |
|
|
278 |
6 |
root = new SequenceNode(); |
279 |
|
|
280 |
6 |
BinaryNode realroot = null; |
281 |
6 |
BinaryNode c = root; |
282 |
|
|
283 |
6 |
int d = -1; |
284 |
6 |
int cp = 0; |
285 |
|
|
286 |
|
|
287 |
6 |
String Error = null; |
288 |
6 |
String nodename = null; |
289 |
6 |
String commentString2 = null; |
290 |
|
|
291 |
6 |
double DefDistance = (float) 0.001; |
292 |
|
|
293 |
6 |
int DefBootstrap = -1; |
294 |
|
|
295 |
6 |
double distance = DefDistance; |
296 |
6 |
int bootstrap = DefBootstrap; |
297 |
|
|
298 |
6 |
boolean ascending = false; |
299 |
|
|
300 |
|
|
301 |
6 |
Regex majorsyms = new Regex("[(\\['),;]"); |
302 |
|
|
303 |
6 |
int nextcp = 0; |
304 |
6 |
int ncp = cp; |
305 |
6 |
boolean parsednodename = false; |
306 |
116 |
while (majorsyms.searchFrom(nf, cp) && (Error == null)) |
307 |
|
{ |
308 |
110 |
int fcp = majorsyms.matchedFrom(); |
309 |
110 |
char schar; |
310 |
110 |
switch (schar = nf.charAt(fcp)) |
311 |
|
{ |
312 |
32 |
case '(': |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
32 |
if (ascending) |
317 |
|
{ |
318 |
0 |
Error = ErrorStringrange(Error, "Unexpected '('", 7, fcp, nf); |
319 |
|
|
320 |
0 |
continue; |
321 |
|
} |
322 |
32 |
d++; |
323 |
|
|
324 |
32 |
if (c.right() == null) |
325 |
|
{ |
326 |
20 |
c.setRight(new SequenceNode(null, c, null, DefDistance, |
327 |
|
DefBootstrap, false)); |
328 |
20 |
c = c.right(); |
329 |
|
} |
330 |
|
else |
331 |
|
{ |
332 |
12 |
if (c.left() != null) |
333 |
|
{ |
334 |
|
|
335 |
0 |
BinaryNode tmpn = new SequenceNode(null, c, null, 0, 0, true); |
336 |
0 |
tmpn.SetChildren(c.left(), c.right()); |
337 |
0 |
c.setRight(tmpn); |
338 |
|
} |
339 |
|
|
340 |
12 |
c.setLeft(new SequenceNode(null, c, null, DefDistance, |
341 |
|
DefBootstrap, false)); |
342 |
12 |
c = c.left(); |
343 |
|
} |
344 |
|
|
345 |
32 |
if (realroot == null) |
346 |
|
{ |
347 |
6 |
realroot = c; |
348 |
|
} |
349 |
|
|
350 |
32 |
nodename = null; |
351 |
32 |
distance = DefDistance; |
352 |
32 |
bootstrap = DefBootstrap; |
353 |
32 |
cp = fcp + 1; |
354 |
|
|
355 |
32 |
break; |
356 |
|
|
357 |
|
|
358 |
8 |
case '\'': |
359 |
|
|
360 |
8 |
Regex qnodename = new Regex("'([^']|'')+'"); |
361 |
|
|
362 |
8 |
if (qnodename.searchFrom(nf, fcp)) |
363 |
|
{ |
364 |
8 |
int nl = qnodename.stringMatched().length(); |
365 |
8 |
nodename = new String( |
366 |
|
qnodename.stringMatched().substring(1, nl - 1)); |
367 |
|
|
368 |
8 |
Regex xpandquotes = Regex.perlCode("s/''/'/"); |
369 |
8 |
String widernodename = xpandquotes.replaceAll(nodename); |
370 |
8 |
nodename = widernodename; |
371 |
|
|
372 |
8 |
nextcp = fcp + nl + 1; |
373 |
8 |
parsednodename = true; |
374 |
|
} |
375 |
|
else |
376 |
|
{ |
377 |
0 |
Error = ErrorStringrange(Error, |
378 |
|
"Unterminated quotes for nodename", 7, fcp, nf); |
379 |
|
} |
380 |
|
|
381 |
8 |
break; |
382 |
|
|
383 |
70 |
default: |
384 |
70 |
if (schar == ';') |
385 |
|
{ |
386 |
6 |
if (d != -1) |
387 |
|
{ |
388 |
0 |
Error = ErrorStringrange(Error, |
389 |
|
"Wayward semicolon (depth=" + d + ")", 7, fcp, nf); |
390 |
|
} |
391 |
|
|
392 |
|
} |
393 |
70 |
if (schar == '[') |
394 |
|
{ |
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
0 |
Regex comment = new Regex("]"); |
403 |
0 |
if (comment.searchFrom(nf, fcp)) |
404 |
|
{ |
405 |
|
|
406 |
0 |
nextcp = comment.matchedFrom() + 1; |
407 |
0 |
warningMessage = "Tree file contained comments which may confuse input algorithm."; |
408 |
0 |
break; |
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
} |
413 |
|
else |
414 |
|
{ |
415 |
0 |
Error = ErrorStringrange(Error, "Unterminated comment", 3, fcp, |
416 |
|
nf); |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
70 |
String fstring = nf.substring(ncp, fcp); |
421 |
|
|
422 |
|
|
423 |
|
|
424 |
70 |
while (fstring.indexOf(']') > -1) |
425 |
|
{ |
426 |
0 |
int cstart = fstring.indexOf('['); |
427 |
0 |
int cend = fstring.indexOf(']'); |
428 |
0 |
commentString2 = fstring.substring(cstart + 1, cend); |
429 |
0 |
fstring = fstring.substring(0, cstart) |
430 |
|
+ fstring.substring(cend + 1); |
431 |
|
|
432 |
|
} |
433 |
70 |
Regex uqnodename = new Regex("\\b([^' :;\\](),]+)"); |
434 |
70 |
Regex nbootstrap = new Regex("\\s*([0-9+]+)\\s*:"); |
435 |
70 |
Regex ndist = new Regex(":([-0-9Ee.+]+)"); |
436 |
|
|
437 |
70 |
if (!parsednodename && uqnodename.search(fstring) |
438 |
|
&& ((uqnodename.matchedFrom(1) == 0) || (fstring |
439 |
|
.charAt(uqnodename.matchedFrom(1) - 1) != ':'))) |
440 |
|
|
441 |
|
{ |
442 |
30 |
if (nodename == null) |
443 |
|
{ |
444 |
30 |
if (ReplaceUnderscores) |
445 |
|
{ |
446 |
0 |
nodename = uqnodename.stringMatched(1).replace('_', ' '); |
447 |
|
} |
448 |
|
else |
449 |
|
{ |
450 |
30 |
nodename = uqnodename.stringMatched(1); |
451 |
|
} |
452 |
|
} |
453 |
|
else |
454 |
|
{ |
455 |
0 |
Error = ErrorStringrange(Error, |
456 |
|
"File has broken algorithm - overwritten nodename", 10, |
457 |
|
fcp, nf); |
458 |
|
} |
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
70 |
if (nbootstrap.search(fstring)) |
463 |
|
{ |
464 |
0 |
if (nbootstrap.stringMatched(1) |
465 |
|
.equals(uqnodename.stringMatched(1))) |
466 |
|
{ |
467 |
0 |
nodename = null; |
468 |
|
} |
469 |
0 |
if (nodename == null || nodename.length() == 0 |
470 |
|
|| nbootstrap.matchedFrom(1) > (uqnodename.matchedFrom(1) |
471 |
|
+ uqnodename.stringMatched().length())) |
472 |
|
{ |
473 |
0 |
try |
474 |
|
{ |
475 |
0 |
bootstrap = (Integer.valueOf(nbootstrap.stringMatched(1))) |
476 |
|
.intValue(); |
477 |
0 |
HasBootstrap = true; |
478 |
|
} catch (Exception e) |
479 |
|
{ |
480 |
0 |
Error = ErrorStringrange(Error, "Can't parse bootstrap value", |
481 |
|
4, ncp + nbootstrap.matchedFrom(), nf); |
482 |
|
} |
483 |
|
} |
484 |
|
} |
485 |
|
|
486 |
70 |
boolean nodehasdistance = false; |
487 |
|
|
488 |
70 |
if (ndist.search(fstring)) |
489 |
|
{ |
490 |
64 |
try |
491 |
|
{ |
492 |
64 |
distance = (Double.valueOf(ndist.stringMatched(1))) |
493 |
|
.floatValue(); |
494 |
64 |
HasDistances = true; |
495 |
64 |
nodehasdistance = true; |
496 |
|
} catch (Exception e) |
497 |
|
{ |
498 |
0 |
Error = ErrorStringrange(Error, |
499 |
|
"Can't parse node distance value", 7, |
500 |
|
ncp + ndist.matchedFrom(), nf); |
501 |
|
} |
502 |
|
} |
503 |
|
|
504 |
70 |
if (ascending) |
505 |
|
{ |
506 |
|
|
507 |
32 |
c.setName(nodename); |
508 |
|
|
509 |
32 |
c.dist = (HasDistances) ? distance : DefDistance; |
510 |
|
|
511 |
32 |
c.setBootstrap((HasBootstrap) ? bootstrap : DefBootstrap); |
512 |
32 |
if (c == realroot) |
513 |
|
{ |
514 |
6 |
RootHasDistance = nodehasdistance; |
515 |
|
|
516 |
|
|
517 |
|
} |
518 |
32 |
parseNHXNodeProps(c, commentString2); |
519 |
32 |
commentString2 = null; |
520 |
|
} |
521 |
|
else |
522 |
|
{ |
523 |
|
|
524 |
38 |
BinaryNode newnode = new SequenceNode(null, c, nodename, |
525 |
38 |
(HasDistances) ? distance : DefDistance, |
526 |
38 |
(HasBootstrap) ? bootstrap : DefBootstrap, false); |
527 |
38 |
parseNHXNodeProps(c, commentString2); |
528 |
38 |
commentString2 = null; |
529 |
|
|
530 |
38 |
if (c.right() == null) |
531 |
|
{ |
532 |
18 |
c.setRight(newnode); |
533 |
|
} |
534 |
|
else |
535 |
|
{ |
536 |
20 |
if (c.left() == null) |
537 |
|
{ |
538 |
20 |
c.setLeft(newnode); |
539 |
|
} |
540 |
|
else |
541 |
|
{ |
542 |
|
|
543 |
|
|
544 |
0 |
BinaryNode newdummy = new SequenceNode(null, c, null, |
545 |
0 |
(HasDistances ? 0 : DefDistance), 0, true); |
546 |
0 |
newdummy.SetChildren(c.left(), newnode); |
547 |
0 |
c.setLeft(newdummy); |
548 |
|
} |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
70 |
if (ascending) |
553 |
|
{ |
554 |
|
|
555 |
32 |
c = c.AscendTree(); |
556 |
|
|
557 |
32 |
if ((d > -1) && (c == null)) |
558 |
|
{ |
559 |
0 |
Error = ErrorStringrange(Error, |
560 |
|
"File broke algorithm: Lost place in tree (is there an extra ')' ?)", |
561 |
|
7, fcp, nf); |
562 |
|
} |
563 |
|
} |
564 |
|
|
565 |
70 |
if (nf.charAt(fcp) == ')') |
566 |
|
{ |
567 |
32 |
d--; |
568 |
32 |
ascending = true; |
569 |
|
} |
570 |
|
else |
571 |
|
{ |
572 |
38 |
if (nf.charAt(fcp) == ',') |
573 |
|
{ |
574 |
32 |
if (ascending) |
575 |
|
{ |
576 |
14 |
ascending = false; |
577 |
|
} |
578 |
|
else |
579 |
|
{ |
580 |
|
|
581 |
18 |
if ((c.left() != null) && (!c.left().isLeaf())) |
582 |
|
{ |
583 |
0 |
c = c.left(); |
584 |
|
} |
585 |
|
} |
586 |
|
} |
587 |
|
} |
588 |
|
|
589 |
|
|
590 |
70 |
nodename = null; |
591 |
70 |
distance = DefDistance; |
592 |
70 |
bootstrap = DefBootstrap; |
593 |
70 |
commentString2 = null; |
594 |
70 |
parsednodename = false; |
595 |
|
} |
596 |
110 |
if (nextcp == 0) |
597 |
|
{ |
598 |
102 |
ncp = cp = fcp + 1; |
599 |
|
} |
600 |
|
else |
601 |
|
{ |
602 |
8 |
cp = nextcp; |
603 |
8 |
nextcp = 0; |
604 |
|
} |
605 |
|
} |
606 |
|
|
607 |
6 |
if (Error != null) |
608 |
|
{ |
609 |
0 |
throw (new IOException( |
610 |
|
MessageManager.formatMessage("exception.newfile", new String[] |
611 |
|
{ Error.toString() }))); |
612 |
|
} |
613 |
6 |
if (root == null) |
614 |
|
{ |
615 |
0 |
throw (new IOException( |
616 |
|
MessageManager.formatMessage("exception.newfile", new String[] |
617 |
|
{ MessageManager.getString("label.no_tree_read_in") }))); |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
6 |
root = root.right().detach(); |
622 |
|
|
623 |
6 |
if (!RootHasDistance) |
624 |
|
{ |
625 |
6 |
root.dist = (HasDistances) ? 0 : DefDistance; |
626 |
|
} |
627 |
|
} |
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
|
@param |
634 |
|
@param |
635 |
|
@param |
636 |
|
|
|
|
| 8% |
Uncovered Elements: 23 (25) |
Complexity: 7 |
Complexity Density: 0.41 |
|
637 |
70 |
private void parseNHXNodeProps(BinaryNode c, String commentString)... |
638 |
|
{ |
639 |
|
|
640 |
|
|
641 |
70 |
if (commentString != null && commentString.startsWith("&&NHX")) |
642 |
|
{ |
643 |
0 |
StringTokenizer st = new StringTokenizer(commentString.substring(5), |
644 |
|
":"); |
645 |
0 |
while (st.hasMoreTokens()) |
646 |
|
{ |
647 |
0 |
String tok = st.nextToken(); |
648 |
0 |
int colpos = tok.indexOf("="); |
649 |
|
|
650 |
0 |
if (colpos > -1) |
651 |
|
{ |
652 |
0 |
String code = tok.substring(0, colpos); |
653 |
0 |
String value = tok.substring(colpos + 1); |
654 |
0 |
try |
655 |
|
{ |
656 |
|
|
657 |
0 |
if (code.toLowerCase(Locale.ROOT).equals("b")) |
658 |
|
{ |
659 |
0 |
int v = -1; |
660 |
0 |
Float iv = Float.valueOf(value); |
661 |
0 |
v = iv.intValue(); |
662 |
|
|
663 |
0 |
c.setBootstrap(v); |
664 |
0 |
HasBootstrap = true; |
665 |
|
} |
666 |
|
|
667 |
|
} catch (Exception e) |
668 |
|
{ |
669 |
0 |
jalview.bin.Console.errPrintln( |
670 |
|
"Couldn't parse code '" + code + "' = '" + value + "'"); |
671 |
0 |
e.printStackTrace(System.err); |
672 |
|
} |
673 |
|
} |
674 |
|
} |
675 |
|
} |
676 |
|
|
677 |
|
} |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
|
@return |
683 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
684 |
18 |
public BinaryNode getTree()... |
685 |
|
{ |
686 |
18 |
return root; |
687 |
|
} |
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
|
693 |
|
@return |
694 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
695 |
5 |
public String print()... |
696 |
|
{ |
697 |
5 |
synchronized (this) |
698 |
|
{ |
699 |
5 |
StringBuffer tf = new StringBuffer(); |
700 |
5 |
print(tf, root); |
701 |
|
|
702 |
5 |
return (tf.append(";").toString()); |
703 |
|
} |
704 |
|
} |
705 |
|
|
706 |
|
|
707 |
|
|
708 |
|
|
709 |
|
|
710 |
|
|
711 |
|
|
712 |
|
@param |
713 |
|
|
714 |
|
|
715 |
|
@return |
716 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
717 |
3 |
public String print(boolean withbootstraps)... |
718 |
|
{ |
719 |
3 |
synchronized (this) |
720 |
|
{ |
721 |
3 |
boolean boots = this.HasBootstrap; |
722 |
3 |
this.HasBootstrap = withbootstraps; |
723 |
|
|
724 |
3 |
String rv = print(); |
725 |
3 |
this.HasBootstrap = boots; |
726 |
|
|
727 |
3 |
return rv; |
728 |
|
} |
729 |
|
} |
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
@param |
737 |
|
|
738 |
|
@param |
739 |
|
|
740 |
|
|
741 |
|
@return |
742 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
743 |
3 |
public String print(boolean withbootstraps, boolean withdists)... |
744 |
|
{ |
745 |
3 |
synchronized (this) |
746 |
|
{ |
747 |
3 |
boolean dists = this.HasDistances; |
748 |
3 |
this.HasDistances = withdists; |
749 |
|
|
750 |
3 |
String rv = print(withbootstraps); |
751 |
3 |
this.HasDistances = dists; |
752 |
|
|
753 |
3 |
return rv; |
754 |
|
} |
755 |
|
} |
756 |
|
|
757 |
|
|
758 |
|
|
759 |
|
|
760 |
|
@param |
761 |
|
|
762 |
|
@param |
763 |
|
|
764 |
|
@param |
765 |
|
|
766 |
|
|
767 |
|
@return |
768 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
769 |
0 |
public String print(boolean withbootstraps, boolean withdists,... |
770 |
|
boolean printRootInfo) |
771 |
|
{ |
772 |
0 |
synchronized (this) |
773 |
|
{ |
774 |
0 |
boolean rootinfo = printRootInfo; |
775 |
0 |
this.printRootInfo = printRootInfo; |
776 |
|
|
777 |
0 |
String rv = print(withbootstraps, withdists); |
778 |
0 |
this.printRootInfo = rootinfo; |
779 |
|
|
780 |
0 |
return rv; |
781 |
|
} |
782 |
|
} |
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
@return |
788 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
789 |
0 |
char getQuoteChar()... |
790 |
|
{ |
791 |
0 |
return QuoteChar; |
792 |
|
} |
793 |
|
|
794 |
|
|
795 |
|
|
796 |
|
|
797 |
|
@param |
798 |
|
|
799 |
|
|
800 |
|
@return |
801 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
802 |
0 |
char setQuoteChar(char c)... |
803 |
|
{ |
804 |
0 |
char old = QuoteChar; |
805 |
0 |
QuoteChar = c; |
806 |
|
|
807 |
0 |
return old; |
808 |
|
} |
809 |
|
|
810 |
|
|
811 |
|
|
812 |
|
|
813 |
|
@param |
814 |
|
|
815 |
|
|
816 |
|
@return |
817 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
818 |
83 |
private String nodeName(String name)... |
819 |
|
{ |
820 |
83 |
if (NodeSafeName[0].search(name)) |
821 |
|
{ |
822 |
4 |
return QuoteChar + NodeSafeName[1].replaceAll(name) + QuoteChar; |
823 |
|
} |
824 |
|
else |
825 |
|
{ |
826 |
79 |
return NodeSafeName[2].replaceAll(name); |
827 |
|
} |
828 |
|
} |
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
|
833 |
|
@param |
834 |
|
|
835 |
|
|
836 |
|
@return |
837 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 6 |
Complexity Density: 6 |
|
838 |
156 |
private String printNodeField(BinaryNode c)... |
839 |
|
{ |
840 |
156 |
return ((c.getName() == null) ? "" : nodeName(c.getName())) |
841 |
116 |
+ ((HasBootstrap) ? ((c.getBootstrap() > -1) |
842 |
116 |
? ((c.getName() != null ? " " : "") + c.getBootstrap()) |
843 |
|
: "") : "") |
844 |
156 |
+ ((HasDistances) ? (":" + c.dist) : ""); |
845 |
|
} |
846 |
|
|
847 |
|
|
848 |
|
|
849 |
|
|
850 |
|
@param |
851 |
|
|
852 |
|
|
853 |
|
@return |
854 |
|
|
|
|
| 61.5% |
Uncovered Elements: 5 (13) |
Complexity: 7 |
Complexity Density: 7 |
|
855 |
5 |
private String printRootField(BinaryNode root)... |
856 |
|
{ |
857 |
5 |
return (printRootInfo) |
858 |
5 |
? (((root.getName() == null) ? "" : nodeName(root.getName())) |
859 |
5 |
+ ((HasBootstrap) |
860 |
1 |
? ((root.getBootstrap() > -1) |
861 |
1 |
? ((root.getName() != null ? " " : "") |
862 |
|
+ +root.getBootstrap()) |
863 |
|
: "") |
864 |
|
: "") |
865 |
5 |
+ ((RootHasDistance) ? (":" + root.dist) : "")) |
866 |
|
: ""; |
867 |
|
} |
868 |
|
|
869 |
|
|
|
|
| 65% |
Uncovered Elements: 7 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
870 |
5 |
public void print(StringBuffer tf, BinaryNode root)... |
871 |
|
{ |
872 |
5 |
if (root != null) |
873 |
|
{ |
874 |
5 |
if (root.isLeaf() && printRootInfo) |
875 |
|
{ |
876 |
0 |
tf.append(printRootField(root)); |
877 |
|
} |
878 |
|
else |
879 |
|
{ |
880 |
5 |
if (root.isDummy()) |
881 |
|
{ |
882 |
0 |
_print(tf, root.right()); |
883 |
0 |
_print(tf, root.left()); |
884 |
|
} |
885 |
|
else |
886 |
|
{ |
887 |
5 |
tf.append("("); |
888 |
5 |
_print(tf, root.right()); |
889 |
|
|
890 |
5 |
if (root.left() != null) |
891 |
|
{ |
892 |
5 |
tf.append(","); |
893 |
|
} |
894 |
|
|
895 |
5 |
_print(tf, root.left()); |
896 |
5 |
tf.append(")" + printRootField(root)); |
897 |
|
} |
898 |
|
} |
899 |
|
} |
900 |
|
} |
901 |
|
|
902 |
|
|
|
|
| 62.5% |
Uncovered Elements: 9 (24) |
Complexity: 6 |
Complexity Density: 0.43 |
|
903 |
156 |
public void _print(StringBuffer tf, BinaryNode c)... |
904 |
|
{ |
905 |
156 |
if (c != null) |
906 |
|
{ |
907 |
156 |
if (c.isLeaf()) |
908 |
|
{ |
909 |
83 |
tf.append(printNodeField(c)); |
910 |
|
} |
911 |
|
else |
912 |
|
{ |
913 |
73 |
if (c.isDummy()) |
914 |
|
{ |
915 |
0 |
_print(tf, c.left()); |
916 |
0 |
if (c.left() != null) |
917 |
|
{ |
918 |
0 |
tf.append(","); |
919 |
|
} |
920 |
0 |
_print(tf, c.right()); |
921 |
|
} |
922 |
|
else |
923 |
|
{ |
924 |
73 |
tf.append("("); |
925 |
73 |
_print(tf, c.right()); |
926 |
|
|
927 |
73 |
if (c.left() != null) |
928 |
|
{ |
929 |
73 |
tf.append(","); |
930 |
|
} |
931 |
|
|
932 |
73 |
_print(tf, c.left()); |
933 |
73 |
tf.append(")" + printNodeField(c)); |
934 |
|
} |
935 |
|
} |
936 |
|
} |
937 |
|
} |
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
@param |
942 |
|
|
943 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 5 |
Complexity Density: 0.16 |
|
944 |
0 |
public static void main(String[] args)... |
945 |
|
{ |
946 |
0 |
try |
947 |
|
{ |
948 |
0 |
if (args == null || args.length != 1) |
949 |
|
{ |
950 |
0 |
Jalview.exit( |
951 |
|
"Takes one argument - file name of a newick tree file.", |
952 |
|
ExitCode.INVALID_ARGUMENT); |
953 |
|
} |
954 |
|
|
955 |
0 |
File fn = new File(args[0]); |
956 |
|
|
957 |
0 |
StringBuffer newickfile = new StringBuffer(); |
958 |
0 |
BufferedReader treefile = new BufferedReader(new FileReader(fn)); |
959 |
0 |
String l; |
960 |
|
|
961 |
0 |
while ((l = treefile.readLine()) != null) |
962 |
|
{ |
963 |
0 |
newickfile.append(l); |
964 |
|
} |
965 |
|
|
966 |
0 |
treefile.close(); |
967 |
0 |
jalview.bin.Console.outPrintln("Read file :\n"); |
968 |
|
|
969 |
0 |
NewickFile trf = new NewickFile(args[0], DataSourceType.FILE); |
970 |
0 |
trf.parse(); |
971 |
0 |
jalview.bin.Console.outPrintln("Original file :\n"); |
972 |
|
|
973 |
0 |
Regex nonl = new Regex("\n+", ""); |
974 |
0 |
jalview.bin.Console |
975 |
|
.outPrintln(nonl.replaceAll(newickfile.toString()) + "\n"); |
976 |
|
|
977 |
0 |
jalview.bin.Console.outPrintln("Parsed file.\n"); |
978 |
0 |
jalview.bin.Console |
979 |
|
.outPrintln("Default output type for original input.\n"); |
980 |
0 |
jalview.bin.Console.outPrintln(trf.print()); |
981 |
0 |
jalview.bin.Console.outPrintln("Without bootstraps.\n"); |
982 |
0 |
jalview.bin.Console.outPrintln(trf.print(false)); |
983 |
0 |
jalview.bin.Console.outPrintln("Without distances.\n"); |
984 |
0 |
jalview.bin.Console.outPrintln(trf.print(true, false)); |
985 |
0 |
jalview.bin.Console |
986 |
|
.outPrintln("Without bootstraps but with distanecs.\n"); |
987 |
0 |
jalview.bin.Console.outPrintln(trf.print(false, true)); |
988 |
0 |
jalview.bin.Console.outPrintln("Without bootstraps or distanecs.\n"); |
989 |
0 |
jalview.bin.Console.outPrintln(trf.print(false, false)); |
990 |
0 |
jalview.bin.Console |
991 |
|
.outPrintln("With bootstraps and with distances.\n"); |
992 |
0 |
jalview.bin.Console.outPrintln(trf.print(true, true)); |
993 |
|
} catch (java.io.IOException e) |
994 |
|
{ |
995 |
0 |
jalview.bin.Console.errPrintln("Exception\n" + e); |
996 |
0 |
e.printStackTrace(); |
997 |
|
} |
998 |
|
} |
999 |
|
} |