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;
- private boolean _write_conf_values_in_branckets_in_nh;
+ 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 );
- setWriteConfidenceValuesInBracketsInNH( false );
+ 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 boolean write_conf_values_in_branckets_in_nh ) throws IOException {
+ final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException {
setOutputFormt( FORMAT.NH );
- setWriteConfidenceValuesInBracketsInNH( write_conf_values_in_branckets_in_nh );
+ setNhConversionSupportStyle( svs );
setSimpleNH( simple_nh );
setWriteDistanceToParentInNH( nh_write_distance_to_parent );
return getOutput( tree );
public void toNewHampshire( final Phylogeny tree,
final boolean simple_nh,
final boolean write_distance_to_parent,
- final boolean use_brackets_for_confidence,
+ final NH_CONVERSION_SUPPORT_VALUE_STYLE svs,
final File out_file ) throws IOException {
- writeToFile( toNewHampshire( tree, simple_nh, write_distance_to_parent, use_brackets_for_confidence ), out_file );
+ writeToFile( toNewHampshire( tree, simple_nh, write_distance_to_parent, svs ), out_file );
}
public void toNewHampshire( final Phylogeny[] trees,
writeToFile( sb, out_file );
}
- public void toNexus( final File out_file, final Phylogeny tree, final boolean write_conf_values_in_branckets_in_nh )
+ 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, write_conf_values_in_branckets_in_nh );
+ writeNexusTreesBlock( writer, trees, svs );
writer.flush();
writer.close();
}
- public StringBuffer toNexus( final Phylogeny tree, final boolean write_conf_values_in_branckets_in_nh )
- 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, write_conf_values_in_branckets_in_nh );
+ writeNexusTreesBlock( writer, trees, svs );
writer.flush();
writer.close();
return string_writer.getBuffer();
else if ( getOutputFormt() == FORMAT.NH ) {
getBuffer().append( node.toNewHampshire( isSimpleNH(),
isWriteDistanceToParentInNH(),
- isWriteConfidenceValuesInBracketsInNH() ) );
+ getNhConversionSupportStyle() ) );
}
}
- private boolean isWriteConfidenceValuesInBracketsInNH() {
- return _write_conf_values_in_branckets_in_nh;
+ private NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportStyle() {
+ return _nh_conversion_support_style;
}
- private void setWriteConfidenceValuesInBracketsInNH( final boolean write_conf_values_in_branckets_in_nh ) {
- _write_conf_values_in_branckets_in_nh = write_conf_values_in_branckets_in_nh;
+ 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 {
public static void writeNexusTreesBlock( final Writer writer,
final List<Phylogeny> trees,
- final boolean write_conf_values_in_branckets_in_nh ) throws IOException {
+ 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, write_conf_values_in_branckets_in_nh ) );
+ writer.write( phylogeny.toNewHampshire( false, svs ) );
writer.write( ForesterUtil.LINE_SEPARATOR );
i++;
}
import java.util.Vector;
import org.forester.io.writers.PhylogenyWriter;
+import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
import org.forester.phylogeny.data.BranchData;
import org.forester.phylogeny.data.Confidence;
import org.forester.phylogeny.data.Identifier;
} // swapChildren( PhylogenyNode )
public String toNewHampshire() {
- return toNewHampshire( false, false );
+ return toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
}
- public String toNewHampshire( final boolean simple_nh, final boolean write_conf_values_in_branckets_in_nh ) {
+ public String toNewHampshire( final boolean simple_nh,
+ final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_style ) {
try {
- return new PhylogenyWriter().toNewHampshire( this, simple_nh, true, write_conf_values_in_branckets_in_nh )
+ return new PhylogenyWriter().toNewHampshire( this, simple_nh, true, nh_conversion_support_style )
.toString();
}
catch ( final IOException e ) {
}
}
- public String toNexus( final boolean write_conf_values_in_branckets_in_nh ) {
+ public String toNexus( final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) {
try {
- return new PhylogenyWriter().toNexus( this, write_conf_values_in_branckets_in_nh ).toString();
+ return new PhylogenyWriter().toNexus( this, svs ).toString();
}
catch ( final IOException e ) {
throw new Error( "this should not have happend: " + e.getMessage() );
// ---------------------------------------------------------
final public String toNewHampshire( final boolean simple_nh,
final boolean write_distance_to_parent,
- final boolean write_support_values_in_brackets ) {
+ final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) {
final StringBuilder sb = new StringBuilder();
String data = "";
- if ( !ForesterUtil.isEmpty( getName() ) ) {
+ if ( ( svs == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) && !isExternal() ) {
+ if ( getBranchData().isHasConfidences()
+ && ( getBranchData().getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) {
+ data = String.valueOf( getBranchData().getConfidence( 0 ).getValue() );
+ }
+ }
+ else if ( !ForesterUtil.isEmpty( getName() ) ) {
data = getName();
}
else if ( getNodeData().isHasTaxonomy() ) {
sb.append( ":" );
sb.append( getDistanceToParent() );
}
- if ( write_support_values_in_brackets && !isExternal() && getBranchData().isHasConfidences()
+ if ( ( svs == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) && !isExternal()
+ && getBranchData().isHasConfidences()
&& ( getBranchData().getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) {
sb.append( "[" );
sb.append( getBranchData().getConfidence( 0 ).getValue() );
import org.forester.phylogeny.PhylogenyBranch;
import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
+import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
import org.forester.phylogeny.data.BinaryCharacters;
import org.forester.phylogeny.data.BranchWidth;
import org.forester.phylogeny.data.Confidence;
if ( p50.getNode( "A" ) == null ) {
return false;
}
- if ( !p50.toNewHampshire( false, true ).equals( "((A,B)ab:2.0[88.0],C);" ) ) {
+ if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
+ .equals( "((A,B)ab:2.0[88.0],C);" ) ) {
return false;
}
- if ( !p50.toNewHampshire( false, false ).equals( "((A,B)ab:2.0,C);" ) ) {
+ if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
+ return false;
+ }
+ if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
+ .equals( "((A,B)88.0:2.0,C);" ) ) {
return false;
}
final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];