in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 15 Dec 2011 23:56:08 +0000 (23:56 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 15 Dec 2011 23:56:08 +0000 (23:56 +0000)
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/Constants.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/io/parsers/nhx/NHXParser.java
forester/java/src/org/forester/io/writers/PhylogenyWriter.java
forester/java/src/org/forester/phylogeny/Phylogeny.java
forester/java/src/org/forester/phylogeny/PhylogenyNode.java
forester/java/src/org/forester/surfacing/SurfacingUtil.java
forester/java/src/org/forester/test/Test.java

index d190da0..6d96616 100644 (file)
@@ -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() {
index fd4b353..da8bf0c 100644 (file)
@@ -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" };
index 89dd29b..2aaf8fc 100644 (file)
@@ -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() {
index efbd7ae..10d1a56 100644 (file)
@@ -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;
index 7725ee5..39f677a 100644 (file)
@@ -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):
index be4c24e..616ed5c 100644 (file)
@@ -414,34 +414,27 @@ public final class PhylogenyWriter {
         writeToFile( sb, out_file );
     }
 
-    public void toNexus( final File out_file, final List<Phylogeny> 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<Phylogeny> trees = new ArrayList<Phylogeny>( 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<Phylogeny> trees = new ArrayList<Phylogeny>( 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<Phylogeny> trees ) throws IOException {
+    public static void writeNexusTreesBlock( final Writer writer,
+                                             final List<Phylogeny> 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++;
         }
index 06058ed..772c860 100644 (file)
@@ -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() );
index a65de7c..a11fbd0 100644 (file)
@@ -968,7 +968,7 @@ public class PhylogenyNode implements PhylogenyNodeI, Comparable<PhylogenyNode>
             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() );
index bd27b56..f7efb8f 100644 (file)
@@ -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 + "\"" );
index a8b4e49..a508c87 100644 (file)
@@ -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 );