X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FNewickFile.java;h=a43dc42ad400bddad9197261b064d74a5762268f;hb=85299bc2db43c8b108169661ebc1c4d9b2d3d2e5;hp=269ffb308b50518233320fff668cc01609c88cfa;hpb=8fbc01654883e68f8843ad6632efaabfaf21692e;p=jalview.git diff --git a/src/jalview/io/NewickFile.java b/src/jalview/io/NewickFile.java index 269ffb3..a43dc42 100755 --- a/src/jalview/io/NewickFile.java +++ b/src/jalview/io/NewickFile.java @@ -26,20 +26,21 @@ // TODO: Extended SequenceNodeI to hold parsed NHX strings package jalview.io; -import java.util.Locale; - -import jalview.datamodel.BinaryNode; -import jalview.datamodel.SequenceNode; -import jalview.util.MessageManager; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.Locale; import java.util.StringTokenizer; import com.stevesoft.pat.Regex; +import jalview.bin.Jalview; +import jalview.bin.Jalview.ExitCode; +import jalview.datamodel.BinaryNode; +import jalview.datamodel.SequenceNode; +import jalview.util.MessageManager; + /** * Parse a new hanpshire style tree Caveats: NHX files are NOT supported and the * tree distances and topology are unreliable when they are parsed. TODO: on @@ -324,7 +325,7 @@ public class NewickFile extends FileParse { c.setRight(new SequenceNode(null, c, null, DefDistance, DefBootstrap, false)); - c = (BinaryNode) c.right(); + c = c.right(); } else { @@ -338,7 +339,7 @@ public class NewickFile extends FileParse c.setLeft(new SequenceNode(null, c, null, DefDistance, DefBootstrap, false)); - c = (BinaryNode) c.left(); + c = c.left(); } if (realroot == null) @@ -394,7 +395,7 @@ public class NewickFile extends FileParse // node string contains Comment or structured/extended NH format info /* * if ((fcp-cp>1 && nf.substring(cp,fcp).trim().length()>1)) { // will - * process in remains System.err.println("skipped text: + * process in remains jalview.bin.Console.errPrintln("skipped text: * '"+nf.substring(cp,fcp)+"'"); } */ // verify termination. @@ -488,7 +489,8 @@ public class NewickFile extends FileParse { try { - distance = (Double.valueOf(ndist.stringMatched(1))).floatValue(); + distance = (Double.valueOf(ndist.stringMatched(1))) + .floatValue(); HasDistances = true; nodehasdistance = true; } catch (Exception e) @@ -578,7 +580,7 @@ public class NewickFile extends FileParse // Just advance focus, if we need to if ((c.left() != null) && (!c.left().isLeaf())) { - c = (BinaryNode) c.left(); + c = c.left(); } } } @@ -616,7 +618,7 @@ public class NewickFile extends FileParse } // THe next line is failing for topali trees - not sure why yet. if // (root.right()!=null && root.isDummy()) - root = (SequenceNode) root.right().detach(); // remove the imaginary root. + root = root.right().detach(); // remove the imaginary root. if (!RootHasDistance) { @@ -664,7 +666,7 @@ public class NewickFile extends FileParse // more codes here. } catch (Exception e) { - System.err.println( + jalview.bin.Console.errPrintln( "Couldn't parse code '" + code + "' = '" + value + "'"); e.printStackTrace(System.err); } @@ -877,20 +879,20 @@ public class NewickFile extends FileParse { if (root.isDummy()) { - _print(tf, root.right()); - _print(tf, root.left()); + _print(tf, root.right()); + _print(tf, root.left()); } else { tf.append("("); - _print(tf, root.right()); + _print(tf, root.right()); if (root.left() != null) { tf.append(","); } - _print(tf, root.left()); + _print(tf, root.left()); tf.append(")" + printRootField(root)); } } @@ -910,24 +912,24 @@ public class NewickFile extends FileParse { if (c.isDummy()) { - _print(tf, c.left()); + _print(tf, c.left()); if (c.left() != null) { tf.append(","); } - _print(tf, c.right()); + _print(tf, c.right()); } else { tf.append("("); - _print(tf, c.right()); + _print(tf, c.right()); if (c.left() != null) { tf.append(","); } - _print(tf, c.left()); + _print(tf, c.left()); tf.append(")" + printNodeField(c)); } } @@ -945,9 +947,9 @@ public class NewickFile extends FileParse { if (args == null || args.length != 1) { - System.err.println( - "Takes one argument - file name of a newick tree file."); - System.exit(0); + Jalview.exit( + "Takes one argument - file name of a newick tree file.", + ExitCode.INVALID_ARGUMENT); } File fn = new File(args[0]); @@ -962,31 +964,35 @@ public class NewickFile extends FileParse } treefile.close(); - System.out.println("Read file :\n"); + jalview.bin.Console.outPrintln("Read file :\n"); NewickFile trf = new NewickFile(args[0], DataSourceType.FILE); trf.parse(); - System.out.println("Original file :\n"); + jalview.bin.Console.outPrintln("Original file :\n"); Regex nonl = new Regex("\n+", ""); - System.out.println(nonl.replaceAll(newickfile.toString()) + "\n"); - - System.out.println("Parsed file.\n"); - System.out.println("Default output type for original input.\n"); - System.out.println(trf.print()); - System.out.println("Without bootstraps.\n"); - System.out.println(trf.print(false)); - System.out.println("Without distances.\n"); - System.out.println(trf.print(true, false)); - System.out.println("Without bootstraps but with distanecs.\n"); - System.out.println(trf.print(false, true)); - System.out.println("Without bootstraps or distanecs.\n"); - System.out.println(trf.print(false, false)); - System.out.println("With bootstraps and with distances.\n"); - System.out.println(trf.print(true, true)); + jalview.bin.Console + .outPrintln(nonl.replaceAll(newickfile.toString()) + "\n"); + + jalview.bin.Console.outPrintln("Parsed file.\n"); + jalview.bin.Console + .outPrintln("Default output type for original input.\n"); + jalview.bin.Console.outPrintln(trf.print()); + jalview.bin.Console.outPrintln("Without bootstraps.\n"); + jalview.bin.Console.outPrintln(trf.print(false)); + jalview.bin.Console.outPrintln("Without distances.\n"); + jalview.bin.Console.outPrintln(trf.print(true, false)); + jalview.bin.Console + .outPrintln("Without bootstraps but with distanecs.\n"); + jalview.bin.Console.outPrintln(trf.print(false, true)); + jalview.bin.Console.outPrintln("Without bootstraps or distanecs.\n"); + jalview.bin.Console.outPrintln(trf.print(false, false)); + jalview.bin.Console + .outPrintln("With bootstraps and with distances.\n"); + jalview.bin.Console.outPrintln(trf.print(true, true)); } catch (java.io.IOException e) { - System.err.println("Exception\n" + e); + jalview.bin.Console.errPrintln("Exception\n" + e); e.printStackTrace(); } }