X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fio%2Fwriters%2FPhylogenyWriter.java;h=b41d8d7d60b6f4e2567bfef89d67899d45347810;hb=780b50a029ad352bd7b309eab711c48c6bce3ef0;hp=c443842db2bc10396454adf17eee56553f32f3c9;hpb=eee996a6476a1e3d84c07f8f690dcde3ff4b2ef5;p=jalview.git diff --git a/forester/java/src/org/forester/io/writers/PhylogenyWriter.java b/forester/java/src/org/forester/io/writers/PhylogenyWriter.java index c443842..b41d8d7 100644 --- a/forester/java/src/org/forester/io/writers/PhylogenyWriter.java +++ b/forester/java/src/org/forester/io/writers/PhylogenyWriter.java @@ -41,6 +41,7 @@ import org.forester.io.parsers.nexus.NexusConstants; import org.forester.io.parsers.phyloxml.PhyloXmlMapping; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; +import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.PhylogenyDataUtil; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.phylogeny.iterators.PostOrderStackObject; @@ -73,6 +74,7 @@ public final class PhylogenyWriter { private Stack _stack; private boolean _simple_nh; private boolean _nh_write_distance_to_parent; + NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_style; private boolean _indent_phyloxml; private int _node_level; private int _phyloxml_level; @@ -80,6 +82,7 @@ public final class PhylogenyWriter { public PhylogenyWriter() { setIndentPhyloxml( INDENT_PHYLOXML_DEAFULT ); + setNhConversionSupportStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ); } private void appendPhylogenyLevelPhyloXml( final Writer writer, final Phylogeny tree ) throws IOException { @@ -336,6 +339,17 @@ public final class PhylogenyWriter { public StringBuffer toNewHampshire( final Phylogeny tree, final boolean simple_nh, + final boolean nh_write_distance_to_parent, + final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException { + setOutputFormt( FORMAT.NH ); + setNhConversionSupportStyle( svs ); + setSimpleNH( simple_nh ); + setWriteDistanceToParentInNH( nh_write_distance_to_parent ); + return getOutput( tree ); + } + + public StringBuffer toNewHampshire( final Phylogeny tree, + final boolean simple_nh, final boolean nh_write_distance_to_parent ) throws IOException { setOutputFormt( FORMAT.NH ); setSimpleNH( simple_nh ); @@ -350,6 +364,14 @@ public final class PhylogenyWriter { writeToFile( toNewHampshire( tree, simple_nh, write_distance_to_parent ), out_file ); } + public void toNewHampshire( final Phylogeny tree, + final boolean simple_nh, + final boolean write_distance_to_parent, + final NH_CONVERSION_SUPPORT_VALUE_STYLE svs, + final File out_file ) throws IOException { + writeToFile( toNewHampshire( tree, simple_nh, write_distance_to_parent, svs ), out_file ); + } + public void toNewHampshire( final Phylogeny[] trees, final boolean simple_nh, final boolean write_distance_to_parent, @@ -393,34 +415,26 @@ 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 NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) + 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, svs ); writer.flush(); writer.close(); } - public StringBuffer toNexus( final Phylogeny tree ) throws IOException { + public StringBuffer toNexus( final Phylogeny tree, final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) 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, svs ); writer.flush(); writer.close(); return string_writer.getBuffer(); @@ -556,10 +570,20 @@ public final class PhylogenyWriter { getBuffer().append( node.toNewHampshireX() ); } else if ( getOutputFormt() == FORMAT.NH ) { - getBuffer().append( node.toNewHampshire( isSimpleNH(), isWriteDistanceToParentInNH() ) ); + getBuffer().append( node.toNewHampshire( isSimpleNH(), + isWriteDistanceToParentInNH(), + getNhConversionSupportStyle() ) ); } } + private NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportStyle() { + return _nh_conversion_support_style; + } + + private void setNhConversionSupportStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_style ) { + _nh_conversion_support_style = nh_conversion_support_style; + } + private void writeOpenClade( final PhylogenyNode node ) throws IOException { if ( !isSawComma() ) { if ( !node.isRoot() && node.isFirstChildNode() ) { @@ -711,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 NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException { writer.write( NexusConstants.BEGIN_TREES ); writer.write( ForesterUtil.LINE_SEPARATOR ); int i = 1; @@ -735,7 +761,7 @@ public final class PhylogenyWriter { else { writer.write( "[&U]" ); } - writer.write( phylogeny.toNewHampshire( false ) ); + writer.write( phylogeny.toNewHampshire( false, svs ) ); writer.write( ForesterUtil.LINE_SEPARATOR ); i++; }