From: cmzmasek Date: Tue, 18 Feb 2014 02:27:58 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=df699a17e2a746285c79127645458d98e6e4a9be;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java b/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java index 3309661..b2543a0 100644 --- a/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java +++ b/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java @@ -114,24 +114,26 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse public final Phylogeny next() throws NHXFormatException, IOException { final Phylogeny phy = _next; getNext(); + return phy; } @Override public final Phylogeny[] parse() throws IOException { - reset(); + final List l = new ArrayList(); + int c = 0; while ( hasNext() ) { + l.add( next() ); + c++; } final Phylogeny[] p = new Phylogeny[ l.size() ]; for( int i = 0; i < l.size(); ++i ) { p[ i ] = l.get( i ); } - System.out.println( "going to return:" ); - for( Phylogeny phylogeny : p ) { - System.out.println( phylogeny.toString() ); - } + + reset(); return p; } @@ -280,7 +282,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse _current_phylogeny.setRooted( true ); } } - System.out.println( "finishPhylogeny()" + _current_phylogeny ); + return _current_phylogeny; } return null; @@ -331,7 +333,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse } } } - System.out.print( c ); + if ( !_in_single_quote && !_in_double_quote ) { if ( c == ':' ) { _saw_colon = true; @@ -425,7 +427,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse throw new PhylogenyParserException( "error in NH (Newick) formatted data: most likely cause: number of open parens does not equal number of close parens" ); } if ( _current_phylogeny != null ) { - System.out.println( "getNext() going to call finishPhylogeny()" ); + _next = finishPhylogeny(); _current_phylogeny = null; _current_anotation = null; @@ -508,7 +510,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse final PhylogenyNode new_node = new PhylogenyNode(); if ( _clade_level == 0 ) { if ( _current_phylogeny != null ) { - System.out.println( "processOpenParen() going to call finishPhylogeny()" ); + phy = finishPhylogeny(); } _clade_level = 1; diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index d39c9ea..08ae65e 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -401,28 +401,43 @@ public final class Test { return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF ); } - public static void main( final String[] args ) { + + public static final boolean testNHXparsingFromURL() { try { String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh"; final URL u = new URL( s ); final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - // final PhylogenyParser parser = new NHXParser(); final Phylogeny[] phys = factory.create( u.openStream(), new NHXParser() ); - System.out.println( "results 1:" ); - for( final Phylogeny phy : phys ) { - System.out.println( phy.toString() ); + + + if ( phys == null || phys.length != 1 ) { + return false; + } - System.out.println( "" ); - final Phylogeny[] phys3 = factory.create( "((a,b),c)", new NHXParser() ); - System.out.println( "results 3:" ); - for( final Phylogeny phy : phys3 ) { - System.out.println( phy.toString() ); + if ( !phys[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) { + System.out.println(phys[ 0 ].toNewHampshire() ); + return false; + } + + final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() ); + if ( phys2 == null || phys2.length != 1 ) { + return false; + + } + if ( !phys2[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) { + System.out.println(phys2[ 0 ].toNewHampshire() ); + return false; } } catch ( Exception e ) { e.printStackTrace(); } - System.exit( 0 ); + return true; + } + + public static void main( final String[] args ) { + + System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" ); System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION + "]" ); @@ -1223,6 +1238,18 @@ public final class Test { System.out.println( "failed." ); failed++; } + + + System.out.print( "NHX parsing from URL: " ); + if ( Test.testNHXparsingFromURL() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.println(); final Runtime rt = java.lang.Runtime.getRuntime(); final long free_memory = rt.freeMemory() / 1000000;