X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FNewickFile.java;h=a43dc42ad400bddad9197261b064d74a5762268f;hb=faf491e024f9835435f5dd6c20a033250dd9297d;hp=67923db12ff9f7c6a789f60fbaa78cb1ca6fa9a3;hpb=80b889f0cca49103e1b20ed806755a0719789906;p=jalview.git diff --git a/src/jalview/io/NewickFile.java b/src/jalview/io/NewickFile.java index 67923db..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. @@ -579,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(); } } } @@ -617,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) { @@ -665,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); } @@ -946,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]); @@ -963,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(); } }