+ private final static String obtainLabel( final Set<String> labels_set, final PhylogenyNode n ) throws RIOException {
+ String label;
+ if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
+ label = n.getNodeData().getSequence().getName();
+ }
+ else if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
+ label = n.getNodeData().getSequence().getSymbol();
+ }
+ else if ( n.getNodeData().isHasSequence()
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
+ label = n.getNodeData().getSequence().getGeneName();
+ }
+ else if ( !ForesterUtil.isEmpty( n.getName() ) ) {
+ label = n.getName();
+ }
+ else {
+ throw new RIOException( "node " + n + " has no appropriate label" );
+ }
+ if ( labels_set.contains( label ) ) {
+ throw new RIOException( "label " + label + " is not unique" );
+ }
+ return label;
+ }
+
+ private final static Phylogeny[] parseGeneTrees( final File gene_trees_file ) throws FileNotFoundException,
+ IOException {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( gene_trees_file, true );
+ if ( p instanceof NHXParser ) {
+ final NHXParser nhx = ( NHXParser ) p;
+ nhx.setReplaceUnderscores( false );
+ nhx.setIgnoreQuotes( true );
+ nhx.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE );
+ }
+ else if ( p instanceof NexusPhylogeniesParser ) {
+ final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) p;
+ nex.setReplaceUnderscores( false );
+ nex.setIgnoreQuotes( true );
+ nex.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE );
+ }
+ return factory.create( gene_trees_file, p );
+ }
+
+ private final static void removeSingleDescendentsNodes( final Phylogeny species_tree, final boolean verbose ) {
+ final int o = PhylogenyMethods.countNumberOfOneDescendantNodes( species_tree );
+ if ( o > 0 ) {
+ if ( verbose ) {
+ System.out.println( "warning: species tree has " + o
+ + " internal nodes with only one descendent which are therefore going to be removed" );
+ }
+ PhylogenyMethods.deleteInternalNodesWithOnlyOneDescendent( species_tree );
+ }
+ }
+
+ private final static void updateCounts( final IntMatrix m, final int counter, final Phylogeny g )
+ throws RIOException {
+ PhylogenyMethods.preOrderReId( g );
+ final HashMap<String, PhylogenyNode> map = PhylogenyMethods.createNameToExtNodeMap( g );
+ for( int x = 0; x < m.size(); ++x ) {
+ final String mx = m.getLabel( x );
+ final PhylogenyNode nx = map.get( mx );
+ if ( nx == null ) {
+ throw new RIOException( "node \"" + mx + "\" not present in gene tree #" + counter );
+ }
+ String my;
+ PhylogenyNode ny;
+ for( int y = 0; y < m.size(); ++y ) {
+ my = m.getLabel( y );
+ ny = map.get( my );
+ if ( ny == null ) {
+ throw new RIOException( "node \"" + my + "\" not present in gene tree #" + counter );
+ }
+ if ( !PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( nx, ny ).isDuplication() ) {
+ m.inreaseByOne( x, y );
+ }
+ }
+ }
+ }
+