@Override public PhylogenyData copy() { return new Confidence( getValue(), getType(), getStandardDeviation() ); }
@Override public String toString() { return asText().toString(); } }
public Confidence() { init(); }
public void init() { setValue( CONFIDENCE_DEFAULT_VALUE ); setType( "" ); setStandardDeviation( CONFIDENCE_DEFAULT_VALUE ); }
@Override public boolean isEqual( final PhylogenyData confidence ) { if ( confidence == null ) { return false; } if ( !( confidence instanceof Confidence ) ) { return false; } final Confidence s = ( Confidence ) confidence; if ( s.getValue() != getValue() ) { return false; } if ( !s.getType().equals( getType() ) ) { return false; } return true; }
@Override public StringBuffer asText() { final StringBuffer sb = new StringBuffer(); if ( !ForesterUtil.isEmpty( getType() ) ) { sb.append( "[" ); sb.append( getType() ); sb.append( "] " ); } sb.append( ForesterUtil.FORMATTER_6.format( getValue() ) ); if ( getStandardDeviation() != CONFIDENCE_DEFAULT_VALUE ) { sb.append( " (sd=" ); sb.append( getStandardDeviation() ); sb.append( ")" ); } return sb; }
private static boolean testDataObjects() { try { final Confidence s0 = new Confidence(); final Confidence s1 = new Confidence(); if ( !s0.isEqual( s1 ) ) { return false; final Confidence s2 = new Confidence( 0.23, "bootstrap" ); final Confidence s3 = new Confidence( 0.23, "bootstrap" ); if ( s2.isEqual( s1 ) ) { return false; if ( !s2.isEqual( s3 ) ) { return false; final Confidence s4 = ( Confidence ) s3.copy(); if ( !s4.isEqual( s3 ) ) { return false; s3.asSimpleText(); s3.asText();
@Override public PhylogenyData parse( final XmlElement element ) throws PhyloXmlDataFormatException { final Confidence confidence = new Confidence(); confidence.setValue( element.getValueAsDouble() ); 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 PhyloXmlDataFormatException( "attempt to parse [" + element.getAttribute( PhyloXmlMapping.CONFIDENCE_SD_ATTR + "] into double" ) ); } } return confidence; }
/** * Convenience method. * Sets value for the first confidence value (created if not present, values overwritten otherwise). */ public static void setConfidence( final PhylogenyNode node, final double confidence_value, final String type ) { Confidence c = null; if ( node.getBranchData().getNumberOfConfidences() > 0 ) { c = node.getBranchData().getConfidence( 0 ); } else { c = new Confidence(); node.getBranchData().addConfidence( c ); } c.setType( type ); c.setValue( confidence_value ); }
@Override public StringBuffer asSimpleText() { return new StringBuffer().append( ForesterUtil.FORMATTER_6.format( getValue() ) ); }
private final static Confidence obtainConfidence( final PhylogenyNode n, final String confidence_type ) { final List<Confidence> confidences = n.getBranchData().getConfidences(); Confidence match = null; for( final Confidence confidence : confidences ) { if ( confidence.getType().equals( confidence_type ) ) { if ( match != null ) { throw new IllegalArgumentException( "confidence [" + confidence_type + "] is not unique" ); } match = confidence; } } if ( match == null ) { match = new Confidence( 0, confidence_type ); confidences.add( match ); } return match; } }
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; return false; if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) { return false;
if ( sd >= 0.0 ) { node_to_annotate.getBranchData() .addConfidence( new Confidence( prob, "posterior probability", sd ) ); node_to_annotate.getBranchData().addConfidence( new Confidence( prob, "posterior probability" ) );
/** * Returns a deep copy of this Phylogeny. * <p> * (The resulting Phylogeny has its references in the external nodes * corrected, if they are lacking/obsolete in this.) */ public Phylogeny copy( final PhylogenyNode source ) { final Phylogeny tree = new Phylogeny(); if ( isEmpty() ) { tree.init(); return tree; } tree._rooted = _rooted; tree._name = new String( _name ); tree._description = new String( _description ); tree._type = new String( _type ); tree._rerootable = _rerootable; tree._distance_unit = new String( _distance_unit ); if ( _confidence != null ) { tree._confidence = ( Confidence ) _confidence.copy(); } if ( _identifier != null ) { tree._identifier = ( Identifier ) _identifier.copy(); } tree.setAllowMultipleParents( isAllowMultipleParents() ); tree._root = PhylogenyMethods.copySubTree( source ); return tree; }
final static public boolean isHasAtLeastOneBranchWithSupportSD( final Phylogeny phy ) { final PhylogenyNodeIterator it = phy.iteratorPostorder(); while ( it.hasNext() ) { final PhylogenyNode n = it.next(); if ( n.getBranchData().isHasConfidences() ) { final List<Confidence> c = n.getBranchData().getConfidences(); for( final Confidence confidence : c ) { if ( confidence.getStandardDeviation() > 0 ) { return true; } } } } return false; }
@Override public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { if ( getValue() == CONFIDENCE_DEFAULT_VALUE ) { return; } writer.write( ForesterUtil.LINE_SEPARATOR ); writer.write( indentation ); if ( getStandardDeviation() != CONFIDENCE_DEFAULT_VALUE ) { PhylogenyDataUtil .appendElement( writer, PhyloXmlMapping.CONFIDENCE, FORMATTER.format( 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, FORMATTER.format( ForesterUtil .round( getValue(), PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ), PhyloXmlMapping.CONFIDENCE_TYPE_ATTR, ForesterUtil.isEmpty( getType() ) ? "unknown" : getType() ); } }
public Confidence( final double value, final String type, final double sd ) { setValue( value ); setType( type ); setStandardDeviation( sd ); }