From c6c5bb81268853e40676be495619a0b4b072ab45 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Thu, 15 Dec 2011 23:56:08 +0000 Subject: [PATCH] in progress --- .../org/forester/archaeopteryx/ArchaeopteryxE.java | 6 ++-- .../src/org/forester/archaeopteryx/Constants.java | 4 +-- .../src/org/forester/archaeopteryx/MainFrame.java | 10 +++--- .../archaeopteryx/MainFrameApplication.java | 2 +- .../src/org/forester/io/parsers/nhx/NHXParser.java | 6 ++-- .../org/forester/io/writers/PhylogenyWriter.java | 25 ++++++------- .../java/src/org/forester/phylogeny/Phylogeny.java | 11 +++--- .../src/org/forester/phylogeny/PhylogenyNode.java | 2 +- .../src/org/forester/surfacing/SurfacingUtil.java | 2 +- forester/java/src/org/forester/test/Test.java | 38 ++++++++++++++++++++ 10 files changed, 71 insertions(+), 35 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index d190da0..6d96616 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -333,7 +333,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { case NHX: return getMainPanel().getCurrentPhylogeny().toNewHampshireX(); case NEXUS: - return getMainPanel().getCurrentPhylogeny().toNexus(); + return getMainPanel().getCurrentPhylogeny().toNexus( false ); case PHYLOXML: return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 ); default: @@ -1068,7 +1068,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) { return; } - _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() ); + _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus( false ) ); } void viewAsNH() { @@ -1077,7 +1077,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) { return; } - _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false ) ); + _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false, false ) ); } void viewAsNHX() { diff --git a/forester/java/src/org/forester/archaeopteryx/Constants.java b/forester/java/src/org/forester/archaeopteryx/Constants.java index fd4b353..da8bf0c 100644 --- a/forester/java/src/org/forester/archaeopteryx/Constants.java +++ b/forester/java/src/org/forester/archaeopteryx/Constants.java @@ -41,8 +41,8 @@ public final class Constants { public final static boolean __SNAPSHOT_RELEASE = true; // TODO remove me public final static boolean __SYNTH_LF = false; // TODO remove me public final static String PRG_NAME = "Archaeopteryx"; - final static String VERSION = "0.965 beta T2P"; - final static String PRG_DATE = "2011.12.14"; + final static String VERSION = "0.966 beta T2P"; + final static String PRG_DATE = "2011.12.15"; final static String DEFAULT_CONFIGURATION_FILE_NAME = "_aptx_configuration_file"; final static String[] DEFAULT_FONT_CHOICES = { "Verdana", "Tahoma", "Arial", "Helvetica", "Dialog", "Lucida Sans", "SansSerif", "Sans-serif", "Sans" }; diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 89dd29b..2aaf8fc 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -1041,19 +1041,21 @@ public abstract class MainFrame extends JFrame implements ActionListener { void viewAsNexus() { removeTextFrame(); if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() - || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) { + || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 20000 ) ) { return; } - _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny().toNexus() ); + _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny().toNexus( getOptions() + .isUseBracketsForConfInNhExport() ) ); } void viewAsNH() { removeTextFrame(); if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() - || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) { + || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 20000 ) ) { return; } - _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny().toNewHampshire( false ) ); + _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny() + .toNewHampshire( false, getOptions().isUseBracketsForConfInNhExport() ) ); } void viewAsNHX() { diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index efbd7ae..10d1a56 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -2330,7 +2330,7 @@ public final class MainFrameApplication extends MainFrame { private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) { try { final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toNexus( file, t ); + writer.toNexus( file, t, getOptions().isUseBracketsForConfInNhExport() ); } catch ( final Exception e ) { exception = true; 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 7725ee5..39f677a 100644 --- a/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java +++ b/forester/java/src/org/forester/io/parsers/nhx/NHXParser.java @@ -308,9 +308,9 @@ public final class NHXParser implements PhylogenyParser { && ( ( c != '[' ) && ( c != '.' ) && ( ( c < 48 ) || ( c > 57 ) ) ) ) { saw_colon = false; } - } - if ( in_open_bracket && ( c == ']' ) ) { - in_open_bracket = false; + if ( in_open_bracket && ( c == ']' ) ) { + in_open_bracket = false; + } } // \n\t is always ignored, // as is " (34) and ' (39) (space is 32): diff --git a/forester/java/src/org/forester/io/writers/PhylogenyWriter.java b/forester/java/src/org/forester/io/writers/PhylogenyWriter.java index be4c24e..616ed5c 100644 --- a/forester/java/src/org/forester/io/writers/PhylogenyWriter.java +++ b/forester/java/src/org/forester/io/writers/PhylogenyWriter.java @@ -414,34 +414,27 @@ public final class PhylogenyWriter { writeToFile( sb, out_file ); } - public void toNexus( final File out_file, final List trees ) throws IOException { - final Writer writer = new BufferedWriter( new PrintWriter( out_file ) ); - writeNexusStart( writer ); - writeNexusTaxaBlock( writer, trees.get( 0 ) ); - writeNexusTreesBlock( writer, trees ); - writer.flush(); - writer.close(); - } - - public void toNexus( final File out_file, final Phylogeny tree ) throws IOException { + public void toNexus( final File out_file, final Phylogeny tree, final boolean write_conf_values_in_branckets_in_nh ) + throws IOException { final Writer writer = new BufferedWriter( new PrintWriter( out_file ) ); final List trees = new ArrayList( 1 ); trees.add( tree ); writeNexusStart( writer ); writeNexusTaxaBlock( writer, tree ); - writeNexusTreesBlock( writer, trees ); + writeNexusTreesBlock( writer, trees, write_conf_values_in_branckets_in_nh ); writer.flush(); writer.close(); } - public StringBuffer toNexus( final Phylogeny tree ) throws IOException { + public StringBuffer toNexus( final Phylogeny tree, final boolean write_conf_values_in_branckets_in_nh ) + throws IOException { final StringWriter string_writer = new StringWriter(); final Writer writer = new BufferedWriter( string_writer ); final List trees = new ArrayList( 1 ); trees.add( tree ); writeNexusStart( writer ); writeNexusTaxaBlock( writer, tree ); - writeNexusTreesBlock( writer, trees ); + writeNexusTreesBlock( writer, trees, write_conf_values_in_branckets_in_nh ); writer.flush(); writer.close(); return string_writer.getBuffer(); @@ -742,7 +735,9 @@ public final class PhylogenyWriter { writer.write( ForesterUtil.LINE_SEPARATOR ); } - public static void writeNexusTreesBlock( final Writer writer, final List trees ) throws IOException { + public static void writeNexusTreesBlock( final Writer writer, + final List trees, + final boolean write_conf_values_in_branckets_in_nh ) throws IOException { writer.write( NexusConstants.BEGIN_TREES ); writer.write( ForesterUtil.LINE_SEPARATOR ); int i = 1; @@ -766,7 +761,7 @@ public final class PhylogenyWriter { else { writer.write( "[&U]" ); } - writer.write( phylogeny.toNewHampshire( false ) ); + writer.write( phylogeny.toNewHampshire( false, write_conf_values_in_branckets_in_nh ) ); writer.write( ForesterUtil.LINE_SEPARATOR ); i++; } diff --git a/forester/java/src/org/forester/phylogeny/Phylogeny.java b/forester/java/src/org/forester/phylogeny/Phylogeny.java index 06058ed..772c860 100644 --- a/forester/java/src/org/forester/phylogeny/Phylogeny.java +++ b/forester/java/src/org/forester/phylogeny/Phylogeny.java @@ -1278,12 +1278,13 @@ public class Phylogeny { } // swapChildren( PhylogenyNode ) public String toNewHampshire() { - return toNewHampshire( false ); + return toNewHampshire( false, false ); } - public String toNewHampshire( final boolean simple_nh ) { + public String toNewHampshire( final boolean simple_nh, final boolean write_conf_values_in_branckets_in_nh ) { try { - return new PhylogenyWriter().toNewHampshire( this, simple_nh, true ).toString(); + return new PhylogenyWriter().toNewHampshire( this, simple_nh, true, write_conf_values_in_branckets_in_nh ) + .toString(); } catch ( final IOException e ) { throw new Error( "this should not have happend: " + e.getMessage() ); @@ -1299,9 +1300,9 @@ public class Phylogeny { } } - public String toNexus() { + public String toNexus( final boolean write_conf_values_in_branckets_in_nh ) { try { - return new PhylogenyWriter().toNexus( this ).toString(); + return new PhylogenyWriter().toNexus( this, write_conf_values_in_branckets_in_nh ).toString(); } catch ( final IOException e ) { throw new Error( "this should not have happend: " + e.getMessage() ); diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index a65de7c..a11fbd0 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -968,7 +968,7 @@ public class PhylogenyNode implements PhylogenyNodeI, Comparable sb.append( ":" ); sb.append( getDistanceToParent() ); } - if ( write_support_values_in_brackets && !isExternal() + if ( write_support_values_in_brackets && !isExternal() && getBranchData().isHasConfidences() && ( getBranchData().getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) { sb.append( "[" ); sb.append( getBranchData().getConfidence( 0 ).getValue() ); diff --git a/forester/java/src/org/forester/surfacing/SurfacingUtil.java b/forester/java/src/org/forester/surfacing/SurfacingUtil.java index bd27b56..f7efb8f 100644 --- a/forester/java/src/org/forester/surfacing/SurfacingUtil.java +++ b/forester/java/src/org/forester/surfacing/SurfacingUtil.java @@ -2363,7 +2363,7 @@ public final class SurfacingUtil { w.write( ForesterUtil.LINE_SEPARATOR ); my_matrix.writeNexusTaxaBlock( w ); my_matrix.writeNexusBinaryChractersBlock( w ); - PhylogenyWriter.writeNexusTreesBlock( w, phylogenies ); + PhylogenyWriter.writeNexusTreesBlock( w, phylogenies, false ); w.flush(); w.close(); ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote Nexus file: \"" + outfile_name + "\"" ); diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index a8b4e49..a508c87 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -4453,6 +4453,44 @@ public final class Test { if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) { return false; } + final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + return false; + } + final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + return false; + } + final Phylogeny p49 = factory + .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ), + new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + return false; + } + final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p50.getNode( "A" ) == null ) { + return false; + } + if ( !p50.toNewHampshire( false, true ).equals( "((A,B)ab:2.0[88.0],C);" ) ) { + return false; + } + if ( !p50.toNewHampshire( false, false ).equals( "((A,B)ab:2.0,C);" ) ) { + return false; + } + final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p51.getNode( "A(A" ) == null ) { + return false; + } + final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p52.getNode( "A(A" ) == null ) { + return false; + } + final Phylogeny p53 = factory + .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ), + new NHXParser() )[ 0 ]; + if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) { + return false; + } } catch ( final Exception e ) { e.printStackTrace( System.out ); -- 1.7.10.2