| 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 |
|
|
| |
|
| 62.2% |
Uncovered Elements: 166 (439) |
Complexity: 114 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 117 |
15 |
public NewickFile(String inStr) throws IOException... |
| 118 |
|
{ |
| 119 |
15 |
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 |
8 |
public NewickFile(String inFile, DataSourceType protocol)... |
| 134 |
|
throws IOException |
| 135 |
|
{ |
| 136 |
8 |
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 |
9 |
public NewickFile(BinaryNode newtree)... |
| 151 |
|
{ |
| 152 |
9 |
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 |
3 |
public NewickFile(BinaryNode newtree, boolean bootstrap,... |
| 180 |
|
boolean distances) |
| 181 |
|
{ |
| 182 |
3 |
root = newtree; |
| 183 |
3 |
HasBootstrap = bootstrap; |
| 184 |
3 |
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 |
43 |
public boolean HasBootstrap()... |
| 236 |
|
{ |
| 237 |
43 |
return HasBootstrap; |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
@return |
| 244 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 245 |
43 |
public boolean HasDistances()... |
| 246 |
|
{ |
| 247 |
43 |
return HasDistances; |
| 248 |
|
} |
| 249 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 250 |
23 |
public boolean HasRootDistance()... |
| 251 |
|
{ |
| 252 |
23 |
return RootHasDistance; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
|
| 256 |
|
|
| 257 |
|
|
| 258 |
|
@throws |
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| |
|
| 73.7% |
Uncovered Elements: 59 (224) |
Complexity: 52 |
Complexity Density: 0.36 |
|
| 262 |
23 |
public void parse() throws IOException... |
| 263 |
|
{ |
| 264 |
23 |
String nf; |
| 265 |
|
|
| 266 |
|
{ |
| 267 |
|
|
| 268 |
23 |
StringBuffer file = new StringBuffer(); |
| 269 |
|
|
| 270 |
? |
while ((nf = nextLine()) != null) |
| 271 |
|
{ |
| 272 |
23 |
file.append(nf); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
23 |
nf = file.toString(); |
| 276 |
|
} |
| 277 |
|
|
| 278 |
23 |
root = new SequenceNode(); |
| 279 |
|
|
| 280 |
23 |
BinaryNode realroot = null; |
| 281 |
23 |
BinaryNode c = root; |
| 282 |
|
|
| 283 |
23 |
int d = -1; |
| 284 |
23 |
int cp = 0; |
| 285 |
|
|
| 286 |
|
|
| 287 |
23 |
String Error = null; |
| 288 |
23 |
String nodename = null; |
| 289 |
23 |
String commentString2 = null; |
| 290 |
|
|
| 291 |
23 |
double DefDistance = (float) 0.001; |
| 292 |
|
|
| 293 |
23 |
int DefBootstrap = -1; |
| 294 |
|
|
| 295 |
23 |
double distance = DefDistance; |
| 296 |
23 |
int bootstrap = DefBootstrap; |
| 297 |
|
|
| 298 |
23 |
boolean ascending = false; |
| 299 |
|
|
| 300 |
|
|
| 301 |
23 |
Regex majorsyms = new Regex("[(\\['),;]"); |
| 302 |
|
|
| 303 |
23 |
int nextcp = 0; |
| 304 |
23 |
int ncp = cp; |
| 305 |
23 |
boolean parsednodename = false; |
| 306 |
801 |
while (majorsyms.searchFrom(nf, cp) && (Error == null)) |
| 307 |
|
{ |
| 308 |
778 |
int fcp = majorsyms.matchedFrom(); |
| 309 |
778 |
char schar; |
| 310 |
778 |
switch (schar = nf.charAt(fcp)) |
| 311 |
|
{ |
| 312 |
249 |
case '(': |
| 313 |
|
|
| 314 |
|
|
| 315 |
|
|
| 316 |
249 |
if (ascending) |
| 317 |
|
{ |
| 318 |
0 |
Error = ErrorStringrange(Error, "Unexpected '('", 7, fcp, nf); |
| 319 |
|
|
| 320 |
0 |
continue; |
| 321 |
|
} |
| 322 |
249 |
d++; |
| 323 |
|
|
| 324 |
249 |
if (c.right() == null) |
| 325 |
|
{ |
| 326 |
113 |
c.setRight(new SequenceNode(null, c, null, DefDistance, |
| 327 |
|
DefBootstrap, false)); |
| 328 |
113 |
c = c.right(); |
| 329 |
|
} |
| 330 |
|
else |
| 331 |
|
{ |
| 332 |
136 |
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 |
136 |
c.setLeft(new SequenceNode(null, c, null, DefDistance, |
| 341 |
|
DefBootstrap, false)); |
| 342 |
136 |
c = c.left(); |
| 343 |
|
} |
| 344 |
|
|
| 345 |
249 |
if (realroot == null) |
| 346 |
|
{ |
| 347 |
23 |
realroot = c; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
249 |
nodename = null; |
| 351 |
249 |
distance = DefDistance; |
| 352 |
249 |
bootstrap = DefBootstrap; |
| 353 |
249 |
cp = fcp + 1; |
| 354 |
|
|
| 355 |
249 |
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 |
521 |
default: |
| 384 |
521 |
if (schar == ';') |
| 385 |
|
{ |
| 386 |
23 |
if (d != -1) |
| 387 |
|
{ |
| 388 |
0 |
Error = ErrorStringrange(Error, |
| 389 |
|
"Wayward semicolon (depth=" + d + ")", 7, fcp, nf); |
| 390 |
|
} |
| 391 |
|
|
| 392 |
|
} |
| 393 |
521 |
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 |
521 |
String fstring = nf.substring(ncp, fcp); |
| 421 |
|
|
| 422 |
|
|
| 423 |
|
|
| 424 |
521 |
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 |
521 |
Regex uqnodename = new Regex("\\b([^' :;\\](),]+)"); |
| 434 |
521 |
Regex nbootstrap = new Regex("\\s*([0-9+]+)\\s*:"); |
| 435 |
521 |
Regex ndist = new Regex(":([-0-9Ee.+]+)"); |
| 436 |
|
|
| 437 |
521 |
if (!parsednodename && uqnodename.search(fstring) |
| 438 |
|
&& ((uqnodename.matchedFrom(1) == 0) || (fstring |
| 439 |
|
.charAt(uqnodename.matchedFrom(1) - 1) != ':'))) |
| 440 |
|
|
| 441 |
|
{ |
| 442 |
264 |
if (nodename == null) |
| 443 |
|
{ |
| 444 |
264 |
if (ReplaceUnderscores) |
| 445 |
|
{ |
| 446 |
0 |
nodename = uqnodename.stringMatched(1).replace('_', ' '); |
| 447 |
|
} |
| 448 |
|
else |
| 449 |
|
{ |
| 450 |
264 |
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 |
521 |
if (nbootstrap.search(fstring)) |
| 463 |
|
{ |
| 464 |
36 |
if (nbootstrap.stringMatched(1) |
| 465 |
|
.equals(uqnodename.stringMatched(1))) |
| 466 |
|
{ |
| 467 |
0 |
nodename = null; |
| 468 |
|
} |
| 469 |
36 |
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 |
521 |
boolean nodehasdistance = false; |
| 487 |
|
|
| 488 |
521 |
if (ndist.search(fstring)) |
| 489 |
|
{ |
| 490 |
498 |
try |
| 491 |
|
{ |
| 492 |
498 |
distance = (Double.valueOf(ndist.stringMatched(1))) |
| 493 |
|
.floatValue(); |
| 494 |
498 |
HasDistances = true; |
| 495 |
498 |
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 |
521 |
if (ascending) |
| 505 |
|
{ |
| 506 |
|
|
| 507 |
249 |
c.setName(nodename); |
| 508 |
|
|
| 509 |
249 |
c.dist = (HasDistances) ? distance : DefDistance; |
| 510 |
|
|
| 511 |
249 |
c.setBootstrap((HasBootstrap) ? bootstrap : DefBootstrap); |
| 512 |
249 |
if (c == realroot) |
| 513 |
|
{ |
| 514 |
23 |
RootHasDistance = nodehasdistance; |
| 515 |
|
|
| 516 |
|
|
| 517 |
|
} |
| 518 |
249 |
parseNHXNodeProps(c, commentString2); |
| 519 |
249 |
commentString2 = null; |
| 520 |
|
} |
| 521 |
|
else |
| 522 |
|
{ |
| 523 |
|
|
| 524 |
272 |
BinaryNode newnode = new SequenceNode(null, c, nodename, |
| 525 |
272 |
(HasDistances) ? distance : DefDistance, |
| 526 |
272 |
(HasBootstrap) ? bootstrap : DefBootstrap, false); |
| 527 |
272 |
parseNHXNodeProps(c, commentString2); |
| 528 |
272 |
commentString2 = null; |
| 529 |
|
|
| 530 |
272 |
if (c.right() == null) |
| 531 |
|
{ |
| 532 |
159 |
c.setRight(newnode); |
| 533 |
|
} |
| 534 |
|
else |
| 535 |
|
{ |
| 536 |
113 |
if (c.left() == null) |
| 537 |
|
{ |
| 538 |
113 |
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 |
521 |
if (ascending) |
| 553 |
|
{ |
| 554 |
|
|
| 555 |
249 |
c = c.AscendTree(); |
| 556 |
|
|
| 557 |
249 |
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 |
521 |
if (nf.charAt(fcp) == ')') |
| 566 |
|
{ |
| 567 |
249 |
d--; |
| 568 |
249 |
ascending = true; |
| 569 |
|
} |
| 570 |
|
else |
| 571 |
|
{ |
| 572 |
272 |
if (nf.charAt(fcp) == ',') |
| 573 |
|
{ |
| 574 |
249 |
if (ascending) |
| 575 |
|
{ |
| 576 |
90 |
ascending = false; |
| 577 |
|
} |
| 578 |
|
else |
| 579 |
|
{ |
| 580 |
|
|
| 581 |
159 |
if ((c.left() != null) && (!c.left().isLeaf())) |
| 582 |
|
{ |
| 583 |
0 |
c = c.left(); |
| 584 |
|
} |
| 585 |
|
} |
| 586 |
|
} |
| 587 |
|
} |
| 588 |
|
|
| 589 |
|
|
| 590 |
521 |
nodename = null; |
| 591 |
521 |
distance = DefDistance; |
| 592 |
521 |
bootstrap = DefBootstrap; |
| 593 |
521 |
commentString2 = null; |
| 594 |
521 |
parsednodename = false; |
| 595 |
|
} |
| 596 |
778 |
if (nextcp == 0) |
| 597 |
|
{ |
| 598 |
770 |
ncp = cp = fcp + 1; |
| 599 |
|
} |
| 600 |
|
else |
| 601 |
|
{ |
| 602 |
8 |
cp = nextcp; |
| 603 |
8 |
nextcp = 0; |
| 604 |
|
} |
| 605 |
|
} |
| 606 |
|
|
| 607 |
23 |
if (Error != null) |
| 608 |
|
{ |
| 609 |
0 |
throw (new IOException( |
| 610 |
|
MessageManager.formatMessage("exception.newfile", new String[] |
| 611 |
|
{ Error.toString() }))); |
| 612 |
|
} |
| 613 |
23 |
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 |
23 |
root = root.right().detach(); |
| 622 |
|
|
| 623 |
23 |
if (!RootHasDistance) |
| 624 |
|
{ |
| 625 |
23 |
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 |
521 |
private void parseNHXNodeProps(BinaryNode c, String commentString)... |
| 638 |
|
{ |
| 639 |
|
|
| 640 |
|
|
| 641 |
521 |
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 |
52 |
public BinaryNode getTree()... |
| 685 |
|
{ |
| 686 |
52 |
return root; |
| 687 |
|
} |
| 688 |
|
|
| 689 |
|
|
| 690 |
|
|
| 691 |
|
|
| 692 |
|
|
| 693 |
|
@return |
| 694 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 695 |
12 |
public String print()... |
| 696 |
|
{ |
| 697 |
12 |
synchronized (this) |
| 698 |
|
{ |
| 699 |
12 |
StringBuffer tf = new StringBuffer(); |
| 700 |
12 |
print(tf, root); |
| 701 |
|
|
| 702 |
12 |
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 |
9 |
public String print(boolean withbootstraps)... |
| 718 |
|
{ |
| 719 |
9 |
synchronized (this) |
| 720 |
|
{ |
| 721 |
9 |
boolean boots = this.HasBootstrap; |
| 722 |
9 |
this.HasBootstrap = withbootstraps; |
| 723 |
|
|
| 724 |
9 |
String rv = print(); |
| 725 |
9 |
this.HasBootstrap = boots; |
| 726 |
|
|
| 727 |
9 |
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 |
9 |
public String print(boolean withbootstraps, boolean withdists)... |
| 744 |
|
{ |
| 745 |
9 |
synchronized (this) |
| 746 |
|
{ |
| 747 |
9 |
boolean dists = this.HasDistances; |
| 748 |
9 |
this.HasDistances = withdists; |
| 749 |
|
|
| 750 |
9 |
String rv = print(withbootstraps); |
| 751 |
9 |
this.HasDistances = dists; |
| 752 |
|
|
| 753 |
9 |
return rv; |
| 754 |
|
} |
| 755 |
|
} |
| 756 |
|
|
| 757 |
|
|
| 758 |
|
|
| 759 |
|
|
| 760 |
|
@param |
| 761 |
|
|
| 762 |
|
@param |
| 763 |
|
|
| 764 |
|
@param |
| 765 |
|
|
| 766 |
|
|
| 767 |
|
@return |
| 768 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 769 |
4 |
public String print(boolean withbootstraps, boolean withdists,... |
| 770 |
|
boolean printRootInfo) |
| 771 |
|
{ |
| 772 |
4 |
synchronized (this) |
| 773 |
|
{ |
| 774 |
4 |
boolean rootinfo = printRootInfo; |
| 775 |
4 |
this.printRootInfo = printRootInfo; |
| 776 |
|
|
| 777 |
4 |
String rv = print(withbootstraps, withdists); |
| 778 |
4 |
this.printRootInfo = rootinfo; |
| 779 |
|
|
| 780 |
4 |
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 |
185 |
private String nodeName(String name)... |
| 819 |
|
{ |
| 820 |
185 |
if (NodeSafeName[0].search(name)) |
| 821 |
|
{ |
| 822 |
4 |
return QuoteChar + NodeSafeName[1].replaceAll(name) + QuoteChar; |
| 823 |
|
} |
| 824 |
|
else |
| 825 |
|
{ |
| 826 |
181 |
return NodeSafeName[2].replaceAll(name); |
| 827 |
|
} |
| 828 |
|
} |
| 829 |
|
|
| 830 |
|
|
| 831 |
|
|
| 832 |
|
|
| 833 |
|
|
| 834 |
|
@param |
| 835 |
|
|
| 836 |
|
@return |
| 837 |
|
|
| 838 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 839 |
535 |
public String getNodenameFor(BinaryNode c)... |
| 840 |
|
{ |
| 841 |
535 |
if (c == null) |
| 842 |
|
{ |
| 843 |
0 |
return null; |
| 844 |
|
} |
| 845 |
535 |
return c.getName(); |
| 846 |
|
} |
| 847 |
|
|
| 848 |
|
|
| 849 |
|
|
| 850 |
|
|
| 851 |
|
@param |
| 852 |
|
|
| 853 |
|
|
| 854 |
|
@return |
| 855 |
|
|
| |
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 6 |
Complexity Density: 6 |
|
| 856 |
346 |
private String printNodeField(BinaryNode c)... |
| 857 |
|
{ |
| 858 |
346 |
return ((getNodenameFor(c) == null) ? "" : nodeName(getNodenameFor(c))) |
| 859 |
116 |
+ ((HasBootstrap) ? ((c.getBootstrap() > -1) |
| 860 |
116 |
? ((getNodenameFor(c) != null ? " " : "") |
| 861 |
|
+ c.getBootstrap()) |
| 862 |
|
: "") : "") |
| 863 |
346 |
+ ((HasDistances) ? (":" + c.dist) : ""); |
| 864 |
|
} |
| 865 |
|
|
| 866 |
|
|
| 867 |
|
|
| 868 |
|
|
| 869 |
|
@param |
| 870 |
|
|
| 871 |
|
|
| 872 |
|
@return |
| 873 |
|
|
| |
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 7 |
Complexity Density: 7 |
|
| 874 |
12 |
private String printRootField(BinaryNode root)... |
| 875 |
|
{ |
| 876 |
12 |
return (printRootInfo) |
| 877 |
8 |
? (((getNodenameFor(root) == null) ? "" |
| 878 |
|
: nodeName(getNodenameFor(root))) |
| 879 |
1 |
+ ((HasBootstrap) ? ((root.getBootstrap() > -1) |
| 880 |
1 |
? ((getNodenameFor(root) != null ? " " : "") |
| 881 |
|
+ +root.getBootstrap()) |
| 882 |
|
: "") : "") |
| 883 |
8 |
+ ((RootHasDistance) ? (":" + root.dist) : "")) |
| 884 |
|
: ""; |
| 885 |
|
} |
| 886 |
|
|
| 887 |
|
|
| |
|
| 65% |
Uncovered Elements: 7 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
| 888 |
12 |
public void print(StringBuffer tf, BinaryNode root)... |
| 889 |
|
{ |
| 890 |
12 |
if (root != null) |
| 891 |
|
{ |
| 892 |
12 |
if (root.isLeaf() && printRootInfo) |
| 893 |
|
{ |
| 894 |
0 |
tf.append(printRootField(root)); |
| 895 |
|
} |
| 896 |
|
else |
| 897 |
|
{ |
| 898 |
12 |
if (root.isDummy()) |
| 899 |
|
{ |
| 900 |
0 |
_print(tf, root.right()); |
| 901 |
0 |
_print(tf, root.left()); |
| 902 |
|
} |
| 903 |
|
else |
| 904 |
|
{ |
| 905 |
12 |
tf.append("("); |
| 906 |
12 |
_print(tf, root.right()); |
| 907 |
|
|
| 908 |
12 |
if (root.left() != null) |
| 909 |
|
{ |
| 910 |
12 |
tf.append(","); |
| 911 |
|
} |
| 912 |
|
|
| 913 |
12 |
_print(tf, root.left()); |
| 914 |
12 |
tf.append(")" + printRootField(root)); |
| 915 |
|
} |
| 916 |
|
} |
| 917 |
|
} |
| 918 |
|
} |
| 919 |
|
|
| 920 |
|
|
| |
|
| 62.5% |
Uncovered Elements: 9 (24) |
Complexity: 6 |
Complexity Density: 0.43 |
|
| 921 |
346 |
public void _print(StringBuffer tf, BinaryNode c)... |
| 922 |
|
{ |
| 923 |
346 |
if (c != null) |
| 924 |
|
{ |
| 925 |
346 |
if (c.isLeaf()) |
| 926 |
|
{ |
| 927 |
185 |
tf.append(printNodeField(c)); |
| 928 |
|
} |
| 929 |
|
else |
| 930 |
|
{ |
| 931 |
161 |
if (c.isDummy()) |
| 932 |
|
{ |
| 933 |
0 |
_print(tf, c.left()); |
| 934 |
0 |
if (c.left() != null) |
| 935 |
|
{ |
| 936 |
0 |
tf.append(","); |
| 937 |
|
} |
| 938 |
0 |
_print(tf, c.right()); |
| 939 |
|
} |
| 940 |
|
else |
| 941 |
|
{ |
| 942 |
161 |
tf.append("("); |
| 943 |
161 |
_print(tf, c.right()); |
| 944 |
|
|
| 945 |
161 |
if (c.left() != null) |
| 946 |
|
{ |
| 947 |
161 |
tf.append(","); |
| 948 |
|
} |
| 949 |
|
|
| 950 |
161 |
_print(tf, c.left()); |
| 951 |
161 |
tf.append(")" + printNodeField(c)); |
| 952 |
|
} |
| 953 |
|
} |
| 954 |
|
} |
| 955 |
|
} |
| 956 |
|
|
| 957 |
|
|
| 958 |
|
|
| 959 |
|
@param |
| 960 |
|
|
| 961 |
|
|
| |
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 5 |
Complexity Density: 0.16 |
|
| 962 |
0 |
public static void main(String[] args)... |
| 963 |
|
{ |
| 964 |
0 |
try |
| 965 |
|
{ |
| 966 |
0 |
if (args == null || args.length != 1) |
| 967 |
|
{ |
| 968 |
0 |
Jalview.exit( |
| 969 |
|
"Takes one argument - file name of a newick tree file.", |
| 970 |
|
ExitCode.INVALID_ARGUMENT); |
| 971 |
|
} |
| 972 |
|
|
| 973 |
0 |
File fn = new File(args[0]); |
| 974 |
|
|
| 975 |
0 |
StringBuffer newickfile = new StringBuffer(); |
| 976 |
0 |
BufferedReader treefile = new BufferedReader(new FileReader(fn)); |
| 977 |
0 |
String l; |
| 978 |
|
|
| 979 |
0 |
while ((l = treefile.readLine()) != null) |
| 980 |
|
{ |
| 981 |
0 |
newickfile.append(l); |
| 982 |
|
} |
| 983 |
|
|
| 984 |
0 |
treefile.close(); |
| 985 |
0 |
jalview.bin.Console.outPrintln("Read file :\n"); |
| 986 |
|
|
| 987 |
0 |
NewickFile trf = new NewickFile(args[0], DataSourceType.FILE); |
| 988 |
0 |
trf.parse(); |
| 989 |
0 |
jalview.bin.Console.outPrintln("Original file :\n"); |
| 990 |
|
|
| 991 |
0 |
Regex nonl = new Regex("\n+", ""); |
| 992 |
0 |
jalview.bin.Console |
| 993 |
|
.outPrintln(nonl.replaceAll(newickfile.toString()) + "\n"); |
| 994 |
|
|
| 995 |
0 |
jalview.bin.Console.outPrintln("Parsed file.\n"); |
| 996 |
0 |
jalview.bin.Console |
| 997 |
|
.outPrintln("Default output type for original input.\n"); |
| 998 |
0 |
jalview.bin.Console.outPrintln(trf.print()); |
| 999 |
0 |
jalview.bin.Console.outPrintln("Without bootstraps.\n"); |
| 1000 |
0 |
jalview.bin.Console.outPrintln(trf.print(false)); |
| 1001 |
0 |
jalview.bin.Console.outPrintln("Without distances.\n"); |
| 1002 |
0 |
jalview.bin.Console.outPrintln(trf.print(true, false)); |
| 1003 |
0 |
jalview.bin.Console |
| 1004 |
|
.outPrintln("Without bootstraps but with distanecs.\n"); |
| 1005 |
0 |
jalview.bin.Console.outPrintln(trf.print(false, true)); |
| 1006 |
0 |
jalview.bin.Console.outPrintln("Without bootstraps or distanecs.\n"); |
| 1007 |
0 |
jalview.bin.Console.outPrintln(trf.print(false, false)); |
| 1008 |
0 |
jalview.bin.Console |
| 1009 |
|
.outPrintln("With bootstraps and with distances.\n"); |
| 1010 |
0 |
jalview.bin.Console.outPrintln(trf.print(true, true)); |
| 1011 |
|
} catch (java.io.IOException e) |
| 1012 |
|
{ |
| 1013 |
0 |
jalview.bin.Console.errPrintln("Exception\n" + e); |
| 1014 |
0 |
e.printStackTrace(); |
| 1015 |
|
} |
| 1016 |
|
} |
| 1017 |
|
} |