From 656fe31e8c71a0306b133e1d08d617bb7a56d4d8 Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 22 Aug 2007 09:30:19 +0000 Subject: [PATCH] better 'main' test and support creation of treenodes for all or just 'associated' binarynodes. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@441 be28352e-c001-0410-b1a7-c7978e42abec --- .../ac/vamsas/objects/utils/trees/NewickFile.java | 30 ++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java b/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java index 2e1e893..f8e49aa 100644 --- a/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java +++ b/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java @@ -203,13 +203,13 @@ public class NewickFile { String errormessage; java.io.BufferedReader dataIn=null; public String nextLine() throws IOException { + if (dataIn==null && newickFile==null) + throw new IOException("IMPLEMENTATION ERROR: NewickFile has not been initialised for reading a newick string."); if (dataIn==null) { dataIn = new BufferedReader(new StringReader(newickFile)); error=false; } - else - throw new IOException("IMPLEMENTATION ERROR: NewickFile has not been initialised for reading a newick string."); if (!error) return dataIn.readLine(); throw new IOException("Invalid Source Stream:" + errormessage); @@ -744,6 +744,18 @@ public class NewickFile { System.out.println(trf.print(false, false)); System.out.println("With bootstraps and with distances.\n"); System.out.println(trf.print(true, true)); + System.out.println("leaves.\n"); + Vector lvs = new Vector(); + trf.findLeaves(trf.root, lvs); + Enumeration lv =lvs.elements(); + while (lv.hasMoreElements()) + { + BinaryNode leave = (BinaryNode) lv.nextElement(); + if (leave.getName()!=null) + { + System.out.println("Node:'"+leave.getName()+"'"); + } + } } catch (java.io.IOException e) { System.err.println("Exception\n" + e); e.printStackTrace(); @@ -786,9 +798,17 @@ public class NewickFile { /** * make tree node vector from a newick tree structure with associated vamsas objects * @param ntree - * @return + * @return Treenode definitions for nodes with associated objects + */ + public Treenode[] makeTreeNodes() { + return makeTreeNodes(true); + } + /** + * make treenode vector for a parsed tree with/out leaf node associations + * @param ignoreplaceholders if true means only associated nodes are returned + * @return treenode vector for associated or all leaves */ - public Treenode[] makeTreeNodes() { + public Treenode[] makeTreeNodes(boolean ignoreplaceholders) { Vector leaves = new Vector(); findLeaves(root, leaves); Vector tnv = new Vector(); @@ -799,7 +819,7 @@ public class NewickFile { BinaryNode tnode = (BinaryNode) l.nextElement(); if (tnode instanceof SequenceNode) { - if (!((SequenceNode) tnode).isPlaceholder()) + if (!(ignoreplaceholders && ((SequenceNode) tnode).isPlaceholder())) { Object assocseq = ((SequenceNode) tnode).element(); if (assocseq instanceof Vobject) -- 1.7.10.2