private static void writeTree( final Phylogeny p, final File f, final String comment ) throws IOException { final PhylogenyWriter writer = new PhylogenyWriter(); writer.toPhyloXML( f, p, 0 ); System.out.println( comment + " \"" + f + "\"" ); } }
/** * Convert a Phylogenetic tree to its Newick representation, so that it can * be exported to an external application. * * @param phylo * Phylogeny phylogenetic tree * @param writeDistances * write the branch lengths if true * @return * @throws IOException */ public static String getNewickString(Phylogeny phylo, boolean writeDistances) throws IOException { PhylogenyWriter w = new PhylogenyWriter(); StringBuffer newickString = w.toNewHampshire(phylo, writeDistances); return newickString.toString(); }
private void writeOpenClade( final PhylogenyNode node ) throws IOException { if ( !isSawComma() ) { if ( !node.isRoot() && node.isFirstChildNode() ) { increaseNodeLevel(); } if ( getOutputFormt() == FORMAT.PHYLO_XML ) { getWriter().write( ForesterUtil.LINE_SEPARATOR ); if ( isIndentPhyloxml() ) { getWriter().write( createIndentation().toString() ); } 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( "(" ); } } setSawComma( false ); }
public StringBuffer toNewHampshire( final Phylogeny tree, final boolean nh_write_distance_to_parent, final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException { setOutputFormt( FORMAT.NH ); setNhConversionSupportStyle( svs ); setWriteDistanceToParentInNH( nh_write_distance_to_parent ); return getOutput( tree ); }
public StringBuffer toNewHampshire( final Phylogeny tree, final boolean nh_write_distance_to_parent ) throws IOException { setOutputFormt( FORMAT.NH ); setWriteDistanceToParentInNH( nh_write_distance_to_parent ); return getOutput( tree ); }
public void toNewHampshire( final Phylogeny tree, final boolean write_distance_to_parent, final NH_CONVERSION_SUPPORT_VALUE_STYLE svs, final File out_file ) throws IOException { writeToFile( toNewHampshire( tree, write_distance_to_parent, svs ), out_file ); }
private void next() throws IOException { while ( true ) { final PostOrderStackObject si = getStack().pop(); final PhylogenyNode node = si.getNode(); final int phase = si.getPhase(); if ( phase > node.getNumberOfDescendants() ) { setHasNext( node != getRoot() ); if ( ( getOutputFormt() != FORMAT.PHYLO_XML ) || node.isExternal() ) { if ( !node.isRoot() && node.isFirstChildNode() ) { increaseNodeLevel(); if ( getOutputFormt() == FORMAT.PHYLO_XML ) { writeNode( node, createIndentation() ); writeNode( node, null ); writeCladeSeparator(); writeCloseClade(); getStack().push( new PostOrderStackObject( node, ( phase + 1 ) ) ); if ( node.isInternal() ) { getStack().push( new PostOrderStackObject( node.getChildNode( phase - 1 ), 1 ) ); writeOpenClade( node ); if ( getOutputFormt() == FORMAT.PHYLO_XML ) { if ( phase == 1 ) { writeNode( node, createIndentation() );
private void writeCloseClade() throws IOException { decreaseNodeLevel(); if ( getOutputFormt() == FORMAT.PHYLO_XML ) { getWriter().write( ForesterUtil.LINE_SEPARATOR ); if ( isIndentPhyloxml() ) { getWriter().write( createIndentation().toString() ); } PhylogenyDataUtil.appendClose( getWriter(), PhyloXmlMapping.CLADE ); } else if ( ( getOutputFormt() == FORMAT.NHX ) || ( getOutputFormt() == FORMAT.NH ) ) { getBuffer().append( ")" ); } }
final PhylogenyWriter w = new PhylogenyWriter(); w.toPhyloXML( phylogeny_outfile, p, 1 ); if ( evaluators_outfile != null ) { try { final PhylogenyWriter w = new PhylogenyWriter(); if ( evaluator_phylogenies_above_threshold != null ) { System.out.println( "Writing " + evaluator_phylogenies_above_threshold.size() w.toNewHampshire( evaluator_phylogenies_above_threshold, branch_lengths_in_ev_out, evaluators_outfile, w.toNewHampshire( Arrays.asList( ev ), branch_lengths_in_ev_out, evaluators_outfile, ";" + ForesterUtil.getLineSeparator() );
private void writeNode( final PhylogenyNode node, final StringBuffer indentation ) throws IOException { if ( getOutputFormt() == FORMAT.PHYLO_XML ) { if ( node.isExternal() ) { getWriter().write( ForesterUtil.LINE_SEPARATOR ); if ( indentation != null ) { getWriter().write( indentation.toString() ); } PhylogenyDataUtil.appendOpen( getWriter(), PhyloXmlMapping.CLADE ); } PhyloXmlNodeWriter.toPhyloXml( getWriter(), node, getPhyloXmlLevel(), indentation != null ? indentation.toString() : "" ); if ( node.isExternal() ) { getWriter().write( ForesterUtil.LINE_SEPARATOR ); if ( indentation != null ) { getWriter().write( indentation.toString() ); } PhylogenyDataUtil.appendClose( getWriter(), PhyloXmlMapping.CLADE ); } } else if ( getOutputFormt() == FORMAT.NHX ) { getBuffer().append( node.toNewHampshireX() ); } else if ( getOutputFormt() == FORMAT.NH ) { getBuffer().append( node.toNewHampshire( isWriteDistanceToParentInNH(), getNhConversionSupportStyle() ) ); } }
private StringBuffer getOutput( final Phylogeny tree ) throws IOException { if ( getOutputFormt() == FORMAT.PHYLO_XML ) { throw new RuntimeException( "method inappropriately called" ); } if ( tree != null ) { reset( tree ); while ( isHasNext() ) { next(); } if ( getOutputFormt() == FORMAT.NH ) { getBuffer().append( ';' ); } return getBuffer(); } else { return new StringBuffer( 0 ); } }
public String toNexus( final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) { try { return new PhylogenyWriter().toNexus( this, svs ).toString(); } catch ( final IOException e ) { throw new Error( "this should not have happend: " + e.getMessage() ); } }
private void writeOutput( final Writer writer, final Phylogeny tree ) throws IOException { if ( getOutputFormt() != FORMAT.PHYLO_XML ) { throw new RuntimeException( "method inappropriately called" ); reset( writer, tree ); String unit = ""; String type = ""; PhyloXmlMapping.PHYLOGENY_IS_REROOTABLE_ATTR, tree.isRerootable() + "" ); appendPhylogenyLevelPhyloXml( writer, tree ); while ( isHasNext() ) { next();
public String toNewHampshireX() { try { return new PhylogenyWriter().toNewHampshireX( this ).toString(); } catch ( final IOException e ) { throw new Error( "this should not have happend: " + e.getMessage() ); } }
final PhylogenyWriter writer = new PhylogenyWriter(); if ( no_indendation ) { writer.setIndentPhyloxml( false ); writer.toPhyloXML( phys, 0, outfile, ForesterUtil.LINE_SEPARATOR );
public static PhylogenyWriter createPhylogenyWriter() { return new PhylogenyWriter(); }
private void writeCladeSeparator() { setSawComma( true ); if ( ( getOutputFormt() == FORMAT.NHX ) || ( getOutputFormt() == FORMAT.NH ) ) { getBuffer().append( "," ); } }
public StringBuffer toNewHampshireX( final Phylogeny tree ) throws IOException { setOutputFormt( FORMAT.NHX ); return getOutput( tree ); }
private StringBuffer createIndentation() { if ( !isIndentPhyloxml() ) { return null; } final StringBuffer sb = new StringBuffer( getNodeLevel() * 2 ); for( int i = 0; i < getNodeLevel(); ++i ) { sb.append( PhylogenyWriter.PHYLO_XML_INTENDATION_BASE ); } return sb; }
public void toNewHampshire( final Phylogeny[] trees, final boolean write_distance_to_parent, final File out_file, final String separator ) throws IOException { final StringBuffer sb = new StringBuffer(); for( final Phylogeny element : trees ) { sb.append( toNewHampshire( element, write_distance_to_parent ) ); sb.append( separator ); } writeToFile( sb, out_file ); }