import java.util.TreeMap;
import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.io.parsers.util.PhylogenyParserException;
import org.forester.phylogeny.data.BranchColor;
return trees;
}
+ public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final List<File> files )
+ throws IOException {
+ final List<Phylogeny> tree_list = new ArrayList<Phylogeny>();
+ for( final File file : files ) {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny[] trees = factory.create( file, parser );
+ if ( ( trees == null ) || ( trees.length == 0 ) ) {
+ throw new PhylogenyParserException( "Unable to parse phylogeny from file: " + file );
+ }
+ tree_list.addAll( Arrays.asList( trees ) );
+ }
+ return tree_list.toArray( new Phylogeny[ tree_list.size() ] );
+ }
+
final static public void transferInternalNodeNamesToConfidence( final Phylogeny phy ) {
final PhylogenyNodeIterator it = phy.iteratorPostorder();
while ( it.hasNext() ) {
}
final static public void transferNodeNameToField( final Phylogeny phy,
- final PhylogenyMethods.PhylogenyNodeField field ) {
+ final PhylogenyMethods.PhylogenyNodeField field,
+ final boolean external_only ) throws PhyloXmlDataFormatException {
final PhylogenyNodeIterator it = phy.iteratorPostorder();
while ( it.hasNext() ) {
final PhylogenyNode n = it.next();
+ if ( external_only && n.isInternal() ) {
+ continue;
+ }
final String name = n.getName().trim();
if ( !ForesterUtil.isEmpty( name ) ) {
switch ( field ) {
case TAXONOMY_CODE:
- //temp hack
- // if ( name.length() > 5 ) {
- // n.setName( "" );
- // if ( !n.getNodeData().isHasTaxonomy() ) {
- // n.getNodeData().setTaxonomy( new Taxonomy() );
- // }
- // n.getNodeData().getTaxonomy().setScientificName( name );
- // break;
- // }
- //
n.setName( "" );
setTaxonomyCode( n, name );
break;
.setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
break;
}
+ case TAXONOMY_ID: {
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ n.getNodeData().getTaxonomy().setIdentifier( new Identifier( name ) );
+ break;
+ }
}
}
}
return stats;
}
- public static DescriptiveStatistics calculatConfidenceStatistics( final Phylogeny phy ) {
+ public static DescriptiveStatistics calculatBranchLengthStatistics( final Phylogeny phy ) {
final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
final PhylogenyNode n = iter.next();
- if ( !n.isExternal() ) {
+ if ( !n.isRoot() && ( n.getDistanceToParent() >= 0.0 ) ) {
+ stats.addValue( n.getDistanceToParent() );
+ }
+ }
+ return stats;
+ }
+
+ public static List<DescriptiveStatistics> calculatConfidenceStatistics( final Phylogeny phy ) {
+ final List<DescriptiveStatistics> stats = new ArrayList<DescriptiveStatistics>();
+ for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
+ final PhylogenyNode n = iter.next();
+ if ( !n.isExternal() && !n.isRoot() ) {
if ( n.getBranchData().isHasConfidences() ) {
- stats.addValue( n.getBranchData().getConfidence( 0 ).getValue() );
+ for( int i = 0; i < n.getBranchData().getConfidences().size(); ++i ) {
+ final Confidence c = n.getBranchData().getConfidences().get( i );
+ if ( ( i > ( stats.size() - 1 ) ) || ( stats.get( i ) == null ) ) {
+ stats.add( i, new BasicDescriptiveStatistics() );
+ }
+ if ( !ForesterUtil.isEmpty( c.getType() ) ) {
+ if ( !ForesterUtil.isEmpty( stats.get( i ).getDescription() ) ) {
+ if ( !stats.get( i ).getDescription().equalsIgnoreCase( c.getType() ) ) {
+ throw new IllegalArgumentException( "support values in node [" + n.toString()
+ + "] appear inconsistently ordered" );
+ }
+ }
+ stats.get( i ).setDescription( c.getType() );
+ }
+ stats.get( i ).addValue( ( ( c != null ) && ( c.getValue() >= 0 ) ) ? c.getValue() : 0 );
+ }
}
}
}
if ( !node.getNodeData().isHasTaxonomy() ) {
return "";
}
- if ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
- return node.getNodeData().getTaxonomy().getTaxonomyCode();
- }
else if ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) {
return node.getNodeData().getTaxonomy().getScientificName();
}
+ if ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
+ return node.getNodeData().getTaxonomy().getTaxonomyCode();
+ }
else {
return node.getNodeData().getTaxonomy().getCommonName();
}
double blue = 0.0;
int n = 0;
if ( node.isInternal() ) {
- for( final PhylogenyNodeIterator iterator = node.iterateChildNodesForward(); iterator.hasNext(); ) {
- final PhylogenyNode child_node = iterator.next();
+ //for( final PhylogenyNodeIterator iterator = node.iterateChildNodesForward(); iterator.hasNext(); ) {
+ for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
+ final PhylogenyNode child_node = node.getChildNode( i );
final Color child_color = getBranchColorValue( child_node );
if ( child_color != null ) {
++n;
*
* @param node
* @param taxonomy_code
+ * @throws PhyloXmlDataFormatException
*/
- public static void setTaxonomyCode( final PhylogenyNode node, final String taxonomy_code ) {
+ public static void setTaxonomyCode( final PhylogenyNode node, final String taxonomy_code )
+ throws PhyloXmlDataFormatException {
if ( !node.getNodeData().isHasTaxonomy() ) {
node.getNodeData().setTaxonomy( new Taxonomy() );
}
SEQUENCE_SYMBOL,
SEQUENCE_NAME,
TAXONOMY_ID_UNIPROT_1,
- TAXONOMY_ID_UNIPROT_2;
+ TAXONOMY_ID_UNIPROT_2,
+ TAXONOMY_ID;
}
public static enum TAXONOMY_EXTRACTION {