// Copyright (C) 2008-2009 Christian M. Zmasek
// Copyright (C) 2008-2009 Burnham Institute for Medical Research
// All rights reserved
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
-//
+//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
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;
private Stack<PostOrderStackObject> _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;
public PhylogenyWriter() {
setIndentPhyloxml( INDENT_PHYLOXML_DEAFULT );
+ setNhConversionSupportStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
}
private void appendPhylogenyLevelPhyloXml( final Writer writer, final Phylogeny tree ) throws IOException {
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 );
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,
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 NH_CONVERSION_SUPPORT_VALUE_STYLE svs )
+ 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, 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<Phylogeny> trees = new ArrayList<Phylogeny>( 1 );
trees.add( tree );
writeNexusStart( writer );
writeNexusTaxaBlock( writer, tree );
- writeNexusTreesBlock( writer, trees );
+ writeNexusTreesBlock( writer, trees, svs );
writer.flush();
writer.close();
return string_writer.getBuffer();
writer.close();
}
+ public void toPhyloXML( final Phylogeny phy, final int phyloxml_level, final File out_file ) throws IOException {
+ final Writer writer = new BufferedWriter( new PrintWriter( out_file ) );
+ toPhyloXML( writer, phy, phyloxml_level );
+ writer.flush();
+ writer.close();
+ }
+
public void toPhyloXML( final Writer writer,
final List<Phylogeny> trees,
final int phyloxml_level,
}
PhylogenyDataUtil.appendOpen( getWriter(), PhyloXmlMapping.CLADE );
}
- if ( indentation != null ) {
- PhyloXmlNodeWriter.toPhyloXml( getWriter(), node, getPhyloXmlLevel(), indentation.toString() );
- }
- else {
- PhyloXmlNodeWriter.toPhyloXml( getWriter(), node, getPhyloXmlLevel(), "" );
- }
+ PhyloXmlNodeWriter.toPhyloXml( getWriter(),
+ node,
+ getPhyloXmlLevel(),
+ indentation != null ? indentation.toString() : "" );
if ( node.isExternal() ) {
getWriter().write( ForesterUtil.LINE_SEPARATOR );
if ( indentation != null ) {
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() ) {
if ( isIndentPhyloxml() ) {
getWriter().write( createIndentation().toString() );
}
- PhylogenyDataUtil.appendOpen( getWriter(), PhyloXmlMapping.CLADE );
+ if ( node.isCollapse() ) {
+ PhylogenyDataUtil.appendOpen( getWriter(),
+ PhyloXmlMapping.CLADE,
+ PhyloXmlMapping.NODE_COLLAPSE,
+ "true" );
+ }
+ else {
+ PhylogenyDataUtil.appendOpen( getWriter(), PhyloXmlMapping.CLADE );
+ }
}
else if ( ( getOutputFormt() == FORMAT.NHX ) || ( getOutputFormt() == FORMAT.NH ) ) {
getBuffer().append( "(" );
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 NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException {
writer.write( NexusConstants.BEGIN_TREES );
writer.write( ForesterUtil.LINE_SEPARATOR );
int i = 1;
else {
writer.write( "[&U]" );
}
- writer.write( phylogeny.toNewHampshire( false ) );
+ writer.write( phylogeny.toNewHampshire( false, svs ) );
writer.write( ForesterUtil.LINE_SEPARATOR );
i++;
}