import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.Confidence;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
import org.forester.phylogeny.factories.PhylogenyFactory;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
else {
PhylogenyMethods.setBootstrapConfidence( node, Confidence.CONFIDENCE_DEFAULT_VALUE );
}
- node.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
+ node.setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
}
} // moveBranchLengthsToBootstrap()
final static int show_vector_data = 23;
final static int show_taxonomy_images = 24;
final static int show_properties = 25;
+ final static int write_confidence_values_sd = 26;
// ------------------
// Click-to options
// ------------------
String default_config_filename = Constants.DEFAULT_CONFIGURATION_FILE_NAME;
final static String display_options[][] = {
{ "Phylogram", "display", "?" }, { "Node Name", "display", "yes" }, { "Taxonomy Code", "display", "yes" },
- { "Annotation", "nodisplay", "no" }, { "Confidence Value", "display", "?" }, { "Event", "display", "?" },
+ { "Annotation", "nodisplay", "no" }, { "Confidence Values", "display", "?" }, { "Event", "display", "?" },
{ "Taxonomy Colorize", "display", "no" }, { "Colorize Branches", "display", "no" },
{ "Use Branch-Widths", "display", "no" }, { "Show Custom Nodes", "display", "yes" },
{ "Domains", "nodisplay", "no" }, { "Binary Characters", "nodisplay", "no" },
{ "Taxonomy Common", "display", "no" }, { "Annotation Colorize", "nodisplay", "no" },
{ "Prot/Gene Symbol", "display", "yes" }, { "Rollover", "display", "yes" },
{ "Relation Confidence", "display", "no" }, { "Vector Data", "display", "no" },
- { "Taxonomy Images", "display", "no" }, { "Properties", "display", "no" } };
+ { "Taxonomy Images", "display", "no" }, { "Properties", "display", "no" },
+ { "Confidence StdDev", "display", "no" } };
final static String clickto_options[][] = {
{ "Display Node Data", "display" }, { "Collapse/Uncollapse", "display" }, { "Root/Reroot", "display" },
{ "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, { "Colorize Subtree", "display" },
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.964 beta BG";
- final static String PRG_DATE = "2011.12.08";
+ final static String VERSION = "0.965 beta T2P";
+ final static String PRG_DATE = "2011.12.14";
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" };
private JCheckBox _show_node_names;
private JCheckBox _show_taxo_code;
private JCheckBox _write_confidence;
+ private JCheckBox _write_confidence_sd;
private JCheckBox _show_events;
private JCheckBox _color_acc_species;
private JCheckBox _color_branches_cb;
addJCheckBox( getWriteConfidenceCb(), ch_panel );
add( ch_panel );
break;
+ case Configuration.write_confidence_values_sd:
+ _write_confidence_sd = new JCheckBox( title );
+ addJCheckBox( getWriteConfidenceSDCb(), ch_panel );
+ add( ch_panel );
+ break;
case Configuration.write_events:
_show_events = new JCheckBox( title );
addJCheckBox( getShowEventsCb(), ch_panel );
return _write_confidence;
}
+ public JCheckBox getWriteConfidenceSDCb() {
+ return _write_confidence_sd;
+ }
+
private void init() {
_draw_phylogram = new ArrayList<Boolean>();
setSpeciesColors( new HashMap<String, Color>() );
return ( ( _show_binary_characters != null ) && _show_binary_characters.isSelected() );
}
- boolean isShowBootstrapValues() {
+ boolean isShowConfidenceValues() {
return ( ( getWriteConfidenceCb() != null ) && getWriteConfidenceCb().isSelected() );
}
+ boolean isShowConfidenceSDValues() {
+ return ( ( getWriteConfidenceSDCb() != null ) && getWriteConfidenceSDCb().isSelected() );
+ }
+
boolean isShowDomainArchitectures() {
return ( ( _show_domain_architectures != null ) && _show_domain_architectures.isSelected() );
}
getWriteConfidenceCb().setSelected( state );
}
break;
+ case Configuration.write_confidence_values_sd:
+ if ( getWriteConfidenceSDCb() != null ) {
+ getWriteConfidenceSDCb().setSelected( state );
+ }
+ break;
case Configuration.write_events:
if ( getShowEventsCb() != null ) {
getShowEventsCb().setSelected( state );
_configuration.getDisplayTitle( Configuration.write_confidence_values ) );
setCheckbox( Configuration.write_confidence_values,
_configuration.doCheckOption( Configuration.write_confidence_values ) );
+ addCheckbox( Configuration.write_confidence_values_sd,
+ _configuration.getDisplayTitle( Configuration.write_confidence_values_sd ) );
+ setCheckbox( Configuration.write_confidence_values_sd,
+ _configuration.doCheckOption( Configuration.write_confidence_values_sd ) );
}
if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
import org.forester.phylogeny.data.Identifier;
import org.forester.phylogeny.data.MultipleUris;
import org.forester.phylogeny.data.PhylogenyData;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Point;
import org.forester.phylogeny.data.Reference;
import org.forester.phylogeny.data.Sequence;
top.add( category );
addSubelementEditable( category, NodePanel.NODE_NAME, phylogeny_node.getName(), PHYLOXML_TAG.NODE_NAME );
String bl = "";
- if ( phylogeny_node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( phylogeny_node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
bl = ForesterUtil.FORMATTER_6.format( phylogeny_node.getDistanceToParent() );
}
addSubelementEditable( category, NodePanel.NODE_BRANCH_LENGTH, bl, PHYLOXML_TAG.NODE_BRANCH_LENGTH );
break;
case NODE_BRANCH_LENGTH:
if ( ForesterUtil.isEmpty( value ) ) {
- getMyNode().setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
+ getMyNode().setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
}
else {
try {
}
else {
final String type = getMyNode().getBranchData().getConfidences().get( number ).getType();
- getMyNode().getBranchData().getConfidences().set( number, new Confidence( confidence, type ) );
+ final double sd = getMyNode().getBranchData().getConfidences().get( number ).getStandardDeviation();
+ getMyNode().getBranchData().getConfidences().set( number, new Confidence( confidence, type, sd ) );
}
break;
case CONFIDENCE_TYPE:
}
else {
final double v = getMyNode().getBranchData().getConfidences().get( number ).getValue();
- getMyNode().getBranchData().getConfidences().set( number, new Confidence( v, value ) );
+ final double sd = getMyNode().getBranchData().getConfidences().get( number ).getStandardDeviation();
+ getMyNode().getBranchData().getConfidences().set( number, new Confidence( v, value, sd ) );
}
break;
case TAXONOMY_CODE:
import org.forester.phylogeny.data.Distribution;
import org.forester.phylogeny.data.Event;
import org.forester.phylogeny.data.PhylogenyData;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Point;
import org.forester.phylogeny.data.PropertiesMap;
import org.forester.phylogeny.data.Property;
final DefaultMutableTreeNode category = new DefaultMutableTreeNode( name );
top.add( category );
addSubelement( category, NODE_NAME, phylogeny_node.getName() );
- if ( phylogeny_node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( phylogeny_node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
addSubelement( category,
NODE_BRANCH_LENGTH,
ForesterUtil.FORMATTER_6.format( phylogeny_node.getDistanceToParent() ) );
import org.forester.phylogeny.data.NodeVisualization.NodeFill;
import org.forester.phylogeny.data.NodeVisualization.NodeShape;
import org.forester.phylogeny.data.PhylogenyData;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.PropertiesMap;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Sequence;
final boolean to_graphics_file ) {
String conf_str = "";
final List<Confidence> confidences = node.getBranchData().getConfidences();
- if ( confidences.size() == 1 ) {
- final double value = node.getBranchData().getConfidence( 0 ).getValue();
- if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
- return;
- }
- conf_str = FORMATTER_CONFIDENCE.format( value );
- }
- else if ( confidences.size() > 1 ) {
- boolean one_ok = false;
- boolean not_first = false;
- Collections.sort( confidences );
- final StringBuilder sb = new StringBuilder();
- for( final Confidence confidence : confidences ) {
- final double value = confidence.getValue();
- if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
- if ( value >= getOptions().getMinConfidenceValue() ) {
- one_ok = true;
- }
- if ( not_first ) {
- sb.append( "/" );
- }
- else {
- not_first = true;
+ // if ( confidences.size() == 1 ) {
+ // final double value = node.getBranchData().getConfidence( 0 ).getValue();
+ // if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) {
+ // return;
+ // }
+ // conf_str = FORMATTER_CONFIDENCE.format( value );
+ // }
+ // else if ( confidences.size() > 1 ) {
+ boolean one_ok = false;
+ boolean not_first = false;
+ Collections.sort( confidences );
+ final StringBuilder sb = new StringBuilder();
+ for( final Confidence confidence : confidences ) {
+ final double value = confidence.getValue();
+ if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
+ if ( value >= getOptions().getMinConfidenceValue() ) {
+ one_ok = true;
+ }
+ if ( not_first ) {
+ sb.append( "/" );
+ }
+ else {
+ not_first = true;
+ }
+ sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
+ .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
+ if ( getControlPanel().isShowConfidenceSDValues() ) {
+ if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
+ sb.append( "(" );
+ sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getStandardDeviation(),
+ getOptions()
+ .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
+ sb.append( ")" );
}
- sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions()
- .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
}
}
+ //}
if ( one_ok ) {
conf_str = sb.toString();
}
if ( getOptions().isShowBranchLengthValues()
&& ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
|| ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
- && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) ) {
+ && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
paintBranchLength( g, node, to_pdf, to_graphics_file );
}
if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
++_external_node_index;
}
// Confidence values
- if ( getControlPanel().isShowBootstrapValues()
+ if ( getControlPanel().isShowConfidenceValues()
&& !node.isExternal()
&& !node.isRoot()
&& ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
getOptions()
.getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
+ if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
+ _popup_buffer.append( " (sd=" );
+ _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
+ .getStandardDeviation(), getOptions()
+ .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
+ _popup_buffer.append( ")" );
+ }
}
}
if ( node.getNodeData().isHasProperties() ) {
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.Accession;
import org.forester.phylogeny.data.Annotation;
+import org.forester.phylogeny.data.Confidence;
import org.forester.phylogeny.data.DomainArchitecture;
import org.forester.phylogeny.data.Event;
import org.forester.phylogeny.data.Identifier;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.PropertiesMap;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Sequence;
.compile( "^[A-Z0-9]+$" );
public final static Pattern NUMBERS_ONLY_PATTERN = Pattern
.compile( "^[0-9]+$" );
+ public final static Pattern MB_PROB_PATTERN = Pattern
+ .compile( "prob=([^,]+)" );
+ public final static Pattern MB_PROB_SD_PATTERN = Pattern
+ .compile( "prob_stddev=([^,]+)" );
+ public final static Pattern MB_BL_PATTERN = Pattern
+ .compile( "length_median=([^,]+)" );
public NHXParser() {
init();
saw_colon = false;
}
}
- if ( in_open_bracket && c == ']' ) {
+ if ( in_open_bracket && ( c == ']' ) ) {
in_open_bracket = false;
}
// \n\t is always ignored,
// comment consisting just of "[]":
saw_open_bracket = false;
}
- else if ( c == '(' && !in_open_bracket ) {
+ else if ( ( c == '(' ) && !in_open_bracket ) {
processOpenParen();
}
- else if ( c == ')' && !in_open_bracket ) {
+ else if ( ( c == ')' ) && !in_open_bracket ) {
processCloseParen();
}
- else if ( c == ',' && !in_open_bracket ) {
+ else if ( ( c == ',' ) && !in_open_bracket ) {
processComma();
}
else {
while ( it.hasNext() ) {
final PhylogenyNode n = it.next();
PhylogenyMethods.setBootstrapConfidence( n, n.getDistanceToParent() );
- n.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
+ n.setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
}
}
final PhylogenyNode node_to_annotate,
final PhylogenyMethods.TAXONOMY_EXTRACTION taxonomy_extraction,
final boolean replace_underscores ) throws NHXFormatException {
- System.out.println( s );
- System.out.println();
if ( ( taxonomy_extraction != PhylogenyMethods.TAXONOMY_EXTRACTION.NO ) && replace_underscores ) {
throw new IllegalArgumentException( "cannot extract taxonomies and replace under scores at the same time" );
}
if ( replace_underscores ) {
s = s.replaceAll( "_+", " " );
}
- int ob = 0;
- int cb = 0;
- String a = "";
- String b = "";
- StringTokenizer t = null;
boolean is_nhx = false;
- ob = s.indexOf( "[" );
- cb = s.indexOf( "]" );
+ final int ob = s.indexOf( "[" );
if ( ob > -1 ) {
- a = "";
- b = "";
+ String b = "";
is_nhx = true;
+ final int cb = s.indexOf( "]" );
if ( cb < 0 ) {
throw new NHXFormatException( "error in NHX formatted data: no closing \"]\" in \"" + s + "\"" );
}
if ( numbers_only.matches() ) {
b = ":" + NHXtags.SUPPORT + bracketed;
}
+ else if ( s.indexOf( "prob=" ) > -1 ) {
+ processMrBayes3Data( s, node_to_annotate );
+ }
}
- a = s.substring( 0, ob );
- s = a + b;
+ s = s.substring( 0, ob ) + b;
if ( ( s.indexOf( "[" ) > -1 ) || ( s.indexOf( "]" ) > -1 ) ) {
throw new NHXFormatException( "error in NHX formatted data: more than one \"]\" or \"[\"" );
}
}
- t = new StringTokenizer( s, ":" );
+ final StringTokenizer t = new StringTokenizer( s, ":" );
if ( t.countTokens() > 0 ) {
if ( !s.startsWith( ":" ) ) {
node_to_annotate.setName( t.nextToken() );
}
while ( t.hasMoreTokens() ) {
s = t.nextToken();
- System.out.println( "=>" + s );
- System.out.println();
if ( s.startsWith( org.forester.io.parsers.nhx.NHXtags.SPECIES_NAME ) ) {
if ( !node_to_annotate.getNodeData().isHasTaxonomy() ) {
node_to_annotate.getNodeData().setTaxonomy( new Taxonomy() );
node_to_annotate.getNodeData().getSequence().setName( s.substring( 2 ) );
}
else if ( s.indexOf( '=' ) < 0 ) {
- if ( node_to_annotate.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( node_to_annotate.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
throw new NHXFormatException( "error in NHX formatted data: more than one distance to parent:"
+ "\"" + s + "\"" );
}
}
}
+ private static void processMrBayes3Data( final String s, final PhylogenyNode node_to_annotate )
+ throws NHXFormatException {
+ double sd = -1;
+ final Matcher mb_prob_sd_matcher = MB_PROB_SD_PATTERN.matcher( s );
+ if ( mb_prob_sd_matcher.find() ) {
+ try {
+ sd = Double.parseDouble( mb_prob_sd_matcher.group( 1 ) );
+ }
+ catch ( final NumberFormatException e ) {
+ throw new NHXFormatException( "failed to parse probability standard deviation (Mr Bayes output) from \""
+ + s + "\"" );
+ }
+ }
+ final Matcher mb_prob_matcher = MB_PROB_PATTERN.matcher( s );
+ if ( mb_prob_matcher.find() ) {
+ double prob = -1;
+ try {
+ prob = Double.parseDouble( mb_prob_matcher.group( 1 ) );
+ }
+ catch ( final NumberFormatException e ) {
+ throw new NHXFormatException( "failed to parse probability (Mr Bayes output) from \"" + s + "\"" );
+ }
+ if ( prob >= 0.0 ) {
+ if ( sd >= 0.0 ) {
+ node_to_annotate.getBranchData()
+ .addConfidence( new Confidence( prob, "posterior probability", sd ) );
+ }
+ else {
+ node_to_annotate.getBranchData().addConfidence( new Confidence( prob, "posterior probability" ) );
+ }
+ }
+ }
+ final Matcher mb_bl_matcher = MB_BL_PATTERN.matcher( s );
+ if ( mb_bl_matcher.find() ) {
+ double bl = -1;
+ try {
+ bl = Double.parseDouble( mb_bl_matcher.group( 1 ) );
+ }
+ catch ( final NumberFormatException e ) {
+ throw new NHXFormatException( "failed to parse median branch length (Mr Bayes output) from \"" + s
+ + "\"" );
+ }
+ if ( bl >= 0.0 ) {
+ node_to_annotate.setDistanceToParent( bl );
+ }
+ }
+ }
+
/**
* Parses String s in the format r.g.b (e.g. "12.34.234" ) into red, green,
* and blue and returns the corresponding Color.
import org.forester.phylogeny.data.Distribution;
import org.forester.phylogeny.data.Event;
import org.forester.phylogeny.data.Identifier;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.PropertiesMap;
import org.forester.phylogeny.data.Property;
import org.forester.phylogeny.data.Reference;
final XmlElement element = xml_element.getChildElement( i );
final String qualified_name = element.getQualifiedName();
if ( qualified_name.equals( PhyloXmlMapping.BRANCH_LENGTH ) ) {
- if ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
throw new PhylogenyParserException( "ill advised attempt to set distance twice for the same clade (probably via element and via attribute)" );
}
node.setDistanceToParent( element.getValueAsDouble() );
public static final String BINARY_CHARACTERS_LOST_COUNT_ATTR = "lost_count";
public static final String BRANCH_LENGTH = "branch_length";
public static final String CONFIDENCE = "confidence";
+ public static final String CONFIDENCE_SD_ATTR = "stddev";
public static final String CONFIDENCE_TYPE_ATTR = "type";
public static final String COLOR = "color";
public static final String COLOR_RED = "red";
if ( element.isHasAttribute( PhyloXmlMapping.CONFIDENCE_TYPE_ATTR ) ) {
confidence.setType( element.getAttribute( PhyloXmlMapping.CONFIDENCE_TYPE_ATTR ) );
}
+ if ( element.isHasAttribute( PhyloXmlMapping.CONFIDENCE_SD_ATTR ) ) {
+ try {
+ confidence.setStandardDeviation( Double.parseDouble( element
+ .getAttribute( PhyloXmlMapping.CONFIDENCE_SD_ATTR ) ) );
+ }
+ catch ( final NumberFormatException ex ) {
+ throw new PhylogenyParserException( "attempt to parse ["
+ + element.getAttribute( PhyloXmlMapping.CONFIDENCE_SD_ATTR + "] into double" ) );
+ }
+ }
return confidence;
}
if ( !ForesterUtil.isEmpty( node.getName() ) ) {
PhylogenyDataUtil.appendElement( w, PhyloXmlMapping.NODE_NAME, node.getName(), indentation );
}
- if ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
PhylogenyDataUtil.appendElement( w, PhyloXmlMapping.BRANCH_LENGTH, String.valueOf( ForesterUtil.round( node
.getDistanceToParent(), PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ), indentation );
}
import org.forester.phylogeny.data.BranchData;
import org.forester.phylogeny.data.Confidence;
import org.forester.phylogeny.data.Identifier;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Sequence;
import org.forester.phylogeny.data.SequenceRelation;
import org.forester.phylogeny.data.SequenceRelation.SEQUENCE_RELATION_TYPE;
new_node.setParent( sibling_parent );
sibling.setParent( new_node );
sibling_parent.setChildNode( sibling_index, new_node );
- final double new_dist = sibling.getDistanceToParent() == PhylogenyNode.DISTANCE_DEFAULT ? PhylogenyNode.DISTANCE_DEFAULT
+ final double new_dist = sibling.getDistanceToParent() == PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ? PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT
: sibling.getDistanceToParent() / 2;
new_node.setDistanceToParent( new_dist );
sibling.setDistanceToParent( new_dist );
b.setBranchData( ( BranchData ) a.getBranchDataDirectly().copy() );
}
// New root is always placed in the middle of the branch:
- if ( a.getDistanceToParent() == PhylogenyNode.DISTANCE_DEFAULT ) {
- b.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
+ if ( a.getDistanceToParent() == PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
+ b.setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
}
else {
if ( distance_n_to_parent >= 0.0 ) {
if ( c.getNumberOfDescendants() == 2 ) {
final PhylogenyNode node = c.getChildNode( 1 - b.getChildNodeIndex( c ) );
node.setParent( b );
- if ( ( c.getDistanceToParent() == PhylogenyNode.DISTANCE_DEFAULT )
- && ( node.getDistanceToParent() == PhylogenyNode.DISTANCE_DEFAULT ) ) {
- node.setDistanceToParent( PhylogenyNode.DISTANCE_DEFAULT );
+ if ( ( c.getDistanceToParent() == PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT )
+ && ( node.getDistanceToParent() == PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
+ node.setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
}
else {
node.setDistanceToParent( ( c.getDistanceToParent() >= 0.0 ? c.getDistanceToParent() : 0.0 )
import org.forester.phylogeny.data.Confidence;
import org.forester.phylogeny.data.DomainArchitecture;
import org.forester.phylogeny.data.Identifier;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Sequence;
import org.forester.phylogeny.data.Taxonomy;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
else if ( b >= 0.0 ) {
return b;
}
- return PhylogenyNode.DISTANCE_DEFAULT;
+ return PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT;
}
// Helper for getUltraParalogousNodes( PhylogenyNode ).
import org.forester.io.parsers.nhx.NHXParser;
import org.forester.phylogeny.data.BranchData;
import org.forester.phylogeny.data.NodeData;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.iterators.ChildNodeIteratorForward;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.phylogeny.iterators.PreorderTreeIterator;
public class PhylogenyNode implements PhylogenyNodeI, Comparable<PhylogenyNode> {
- /** Value of -99.0 is used as default value. */
- public final static double DISTANCE_DEFAULT = -1024.0;
- private static int _node_count = 0;
+ private static int _node_count = 0;
private byte _indicator;
private int _id;
private int _sum_ext_nodes;
_x = 0;
_y = 0;
//_node_name = "";
- _distance_parent = PhylogenyNode.DISTANCE_DEFAULT;
+ _distance_parent = PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT;
_collapse = false;
_link = null;
_branch_data = null;
sb.append( data );
}
}
- if ( ( getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) && write_distance_to_parent ) {
+ if ( ( getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) && write_distance_to_parent ) {
sb.append( ":" );
sb.append( getDistanceToParent() );
}
sb.append( name );
}
}
- if ( getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
sb.append( ":" );
sb.append( getDistanceToParent() );
}
public class Confidence implements PhylogenyData, Comparable<Confidence> {
- public final static double CONFIDENCE_DEFAULT_VALUE = -9999.0;
- private double _value;
- private String _type;
+ public final static int CONFIDENCE_DEFAULT_VALUE = -9999;
+ private double _value;
+ private double _sd;
+ private String _type;
public Confidence() {
init();
public Confidence( final double value, final String type ) {
setValue( value );
setType( type );
+ setStandardDeviation( CONFIDENCE_DEFAULT_VALUE );
+ }
+
+ public Confidence( final double value, final String type, final double sd ) {
+ setValue( value );
+ setType( type );
+ setStandardDeviation( sd );
}
@Override
sb.append( "] " );
}
sb.append( ForesterUtil.FORMATTER_6.format( getValue() ) );
+ if ( getStandardDeviation() != CONFIDENCE_DEFAULT_VALUE ) {
+ sb.append( " (sd=" );
+ sb.append( getStandardDeviation() );
+ sb.append( ")" );
+ }
return sb;
}
@Override
public PhylogenyData copy() {
- return new Confidence( getValue(), getType() );
+ return new Confidence( getValue(), getType(), getStandardDeviation() );
}
public String getType() {
return _value;
}
+ public double getStandardDeviation() {
+ return _sd;
+ }
+
public void init() {
setValue( CONFIDENCE_DEFAULT_VALUE );
setType( "" );
+ setStandardDeviation( CONFIDENCE_DEFAULT_VALUE );
}
@Override
_value = value;
}
+ public void setStandardDeviation( final double sd ) {
+ _sd = sd;
+ }
+
@Override
public StringBuffer toNHX() {
final StringBuffer sb = new StringBuffer();
}
writer.write( ForesterUtil.LINE_SEPARATOR );
writer.write( indentation );
- PhylogenyDataUtil.appendElement( writer,
- PhyloXmlMapping.CONFIDENCE,
- String.valueOf( ForesterUtil
- .round( getValue(),
- PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ),
- PhyloXmlMapping.CONFIDENCE_TYPE_ATTR,
- ForesterUtil.isEmpty( getType() ) ? "unknown" : getType() );
+ if ( getStandardDeviation() != CONFIDENCE_DEFAULT_VALUE ) {
+ PhylogenyDataUtil
+ .appendElement( writer,
+ PhyloXmlMapping.CONFIDENCE,
+ String.valueOf( ForesterUtil
+ .round( getValue(), PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ),
+ PhyloXmlMapping.CONFIDENCE_TYPE_ATTR,
+ ForesterUtil.isEmpty( getType() ) ? "unknown" : getType(),
+ PhyloXmlMapping.CONFIDENCE_SD_ATTR,
+ String.valueOf( ForesterUtil
+ .round( getStandardDeviation(),
+ PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ) );
+ }
+ else {
+ PhylogenyDataUtil
+ .appendElement( writer,
+ PhyloXmlMapping.CONFIDENCE,
+ String.valueOf( ForesterUtil
+ .round( getValue(), PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ),
+ PhyloXmlMapping.CONFIDENCE_TYPE_ATTR,
+ ForesterUtil.isEmpty( getType() ) ? "unknown" : getType() );
+ }
}
@Override
public final class PhylogenyDataUtil {
+ /** Value of -99.0 is used as default value. */
+ public final static double BRANCH_LENGTH_DEFAULT = -1024.0;
+
public static void appendClose( final Writer w, final String element_name ) throws IOException {
w.write( "</" );
w.write( element_name );
public static void appendElement( final Writer w,
final String element_name,
+ final String value,
+ final String attribute1_name,
+ final String attribute1_value,
+ final String attribute2_name,
+ final String attribute2_value ) throws IOException {
+ appendOpen( w, element_name, attribute1_name, attribute1_value, attribute2_name, attribute2_value );
+ w.write( replaceIllegalXmlCharacters( value ) );
+ appendClose( w, element_name );
+ }
+
+ public static void appendElement( final Writer w,
+ final String element_name,
final String attribute1_name,
final String attribute1_value,
final String attribute2_name,
import org.forester.phylogeny.data.Event;
import org.forester.phylogeny.data.Identifier;
import org.forester.phylogeny.data.PhylogenyData;
+import org.forester.phylogeny.data.PhylogenyDataUtil;
import org.forester.phylogeny.data.Polygon;
import org.forester.phylogeny.data.PropertiesMap;
import org.forester.phylogeny.data.Property;
if ( !n3.getName().equals( "n3" ) ) {
return false;
}
- if ( n3.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
return false;
}
if ( n3.isDuplication() ) {
if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
return false;
}
- if ( n1.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
return false;
}
if ( n2.getName().compareTo( "" ) != 0 ) {
if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
return false;
}
- if ( n2.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) {
+ if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
return false;
}
final PhylogenyNode n00 = PhylogenyNode
private static boolean testNHXParsingMB() {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final Phylogeny p1 = factory.create( "(1[&prob=1.000000000000000e+00,prob_stddev=0.000000000000000e+00,"
+ final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
+ "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
+ "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
+ "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
- + "5.026800000000000e-02}],2[&prob=1.000000000000000e+00,prob_stddev=0.000000000000000e+00,"
+ + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
+ "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
+ "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
+ "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
+ "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
- System.out.println( p1.getNode( "1" ).getDistanceToParent() );
- System.exit( -1 );
return false;
}
- // if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
- // return false;
- // }
+ if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
+ return false;
+ }
+ if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
+ 0.1100000000000000e+00 ) ) {
+ return false;
+ }
+ if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
+ return false;
+ }
+ if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
+ return false;
+ }
+ final Phylogeny p2 = factory
+ .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
+ + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
+ + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
+ + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
+ + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
+ + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
+ + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
+ + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
+ + "7.369400000000000e-02}])",
+ new NHXParser() )[ 0 ];
+ if ( p2.getNode( "1" ) == null ) {
+ return false;
+ }
+ if ( p2.getNode( "2" ) == null ) {
+ return false;
+ }
}
catch ( final Exception e ) {
e.printStackTrace( System.out );