package org.forester.phylogeny;
import java.awt.Color;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
+import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
+import org.forester.io.parsers.util.PhylogenyParserException;
import org.forester.phylogeny.data.BranchColor;
import org.forester.phylogeny.data.BranchWidth;
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;
+import org.forester.phylogeny.factories.PhylogenyFactory;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.util.BasicDescriptiveStatistics;
import org.forester.util.DescriptiveStatistics;
return !obtainLCA( node1, node2 ).isDuplication();
}
+ public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException {
+ 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 );
+ }
+ return trees;
+ }
+
+ final static public void transferInternalNodeNamesToConfidence( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( !n.isExternal() && !n.getBranchData().isHasConfidences() ) {
+ if ( !ForesterUtil.isEmpty( n.getName() ) ) {
+ double d = -1.0;
+ try {
+ d = Double.parseDouble( n.getName() );
+ }
+ catch ( final Exception e ) {
+ d = -1.0;
+ }
+ if ( d >= 0.0 ) {
+ n.getBranchData().addConfidence( new Confidence( d, "" ) );
+ n.setName( "" );
+ }
+ }
+ }
+ }
+ }
+
+ final static public void transferInternalNamesToBootstrapSupport( final Phylogeny phy ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ if ( !n.isExternal() && !ForesterUtil.isEmpty( n.getName() ) ) {
+ double value = -1;
+ try {
+ value = Double.parseDouble( n.getName() );
+ }
+ catch ( final NumberFormatException e ) {
+ throw new IllegalArgumentException( "failed to parse number from [" + n.getName() + "]: "
+ + e.getLocalizedMessage() );
+ }
+ if ( value >= 0.0 ) {
+ n.getBranchData().addConfidence( new Confidence( value, "bootstrap" ) );
+ n.setName( "" );
+ }
+ }
+ }
+ }
+
+ final static public void sortNodeDescendents( final PhylogenyNode node, final DESCENDANT_SORT_PRIORITY pri ) {
+ class PhylogenyNodeSortTaxonomyPriority implements Comparator<PhylogenyNode> {
+
+ @Override
+ public int compare( final PhylogenyNode n1, final PhylogenyNode n2 ) {
+ if ( n1.getNodeData().isHasTaxonomy() && n2.getNodeData().isHasTaxonomy() ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getScientificName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getScientificName() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getScientificName().toLowerCase()
+ .compareTo( n2.getNodeData().getTaxonomy().getScientificName().toLowerCase() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getTaxonomyCode() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getTaxonomyCode()
+ .compareTo( n2.getNodeData().getTaxonomy().getTaxonomyCode() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getCommonName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getCommonName() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getCommonName().toLowerCase()
+ .compareTo( n2.getNodeData().getTaxonomy().getCommonName().toLowerCase() );
+ }
+ }
+ if ( n1.getNodeData().isHasSequence() && n2.getNodeData().isHasSequence() ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getName() ) ) ) {
+ return n1.getNodeData().getSequence().getName().toLowerCase()
+ .compareTo( n2.getNodeData().getSequence().getName().toLowerCase() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getSymbol() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getSymbol() ) ) ) {
+ return n1.getNodeData().getSequence().getSymbol()
+ .compareTo( n2.getNodeData().getSequence().getSymbol() );
+ }
+ if ( ( n1.getNodeData().getSequence().getAccession() != null )
+ && ( n2.getNodeData().getSequence().getAccession() != null )
+ && !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getAccession().getValue() )
+ && !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getAccession().getValue() ) ) {
+ return n1.getNodeData().getSequence().getAccession().getValue()
+ .compareTo( n2.getNodeData().getSequence().getAccession().getValue() );
+ }
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getName() ) ) && ( !ForesterUtil.isEmpty( n2.getName() ) ) ) {
+ return n1.getName().toLowerCase().compareTo( n2.getName().toLowerCase() );
+ }
+ return 0;
+ }
+ }
+ class PhylogenyNodeSortSequencePriority implements Comparator<PhylogenyNode> {
+
+ @Override
+ public int compare( final PhylogenyNode n1, final PhylogenyNode n2 ) {
+ if ( n1.getNodeData().isHasSequence() && n2.getNodeData().isHasSequence() ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getName() ) ) ) {
+ return n1.getNodeData().getSequence().getName().toLowerCase()
+ .compareTo( n2.getNodeData().getSequence().getName().toLowerCase() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getSymbol() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getSymbol() ) ) ) {
+ return n1.getNodeData().getSequence().getSymbol()
+ .compareTo( n2.getNodeData().getSequence().getSymbol() );
+ }
+ if ( ( n1.getNodeData().getSequence().getAccession() != null )
+ && ( n2.getNodeData().getSequence().getAccession() != null )
+ && !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getAccession().getValue() )
+ && !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getAccession().getValue() ) ) {
+ return n1.getNodeData().getSequence().getAccession().getValue()
+ .compareTo( n2.getNodeData().getSequence().getAccession().getValue() );
+ }
+ }
+ if ( n1.getNodeData().isHasTaxonomy() && n2.getNodeData().isHasTaxonomy() ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getScientificName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getScientificName() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getScientificName().toLowerCase()
+ .compareTo( n2.getNodeData().getTaxonomy().getScientificName().toLowerCase() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getTaxonomyCode() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getTaxonomyCode()
+ .compareTo( n2.getNodeData().getTaxonomy().getTaxonomyCode() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getCommonName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getCommonName() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getCommonName().toLowerCase()
+ .compareTo( n2.getNodeData().getTaxonomy().getCommonName().toLowerCase() );
+ }
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getName() ) ) && ( !ForesterUtil.isEmpty( n2.getName() ) ) ) {
+ return n1.getName().toLowerCase().compareTo( n2.getName().toLowerCase() );
+ }
+ return 0;
+ }
+ }
+ class PhylogenyNodeSortNodeNamePriority implements Comparator<PhylogenyNode> {
+
+ @Override
+ public int compare( final PhylogenyNode n1, final PhylogenyNode n2 ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getName() ) ) && ( !ForesterUtil.isEmpty( n2.getName() ) ) ) {
+ return n1.getName().toLowerCase().compareTo( n2.getName().toLowerCase() );
+ }
+ if ( n1.getNodeData().isHasTaxonomy() && n2.getNodeData().isHasTaxonomy() ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getScientificName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getScientificName() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getScientificName().toLowerCase()
+ .compareTo( n2.getNodeData().getTaxonomy().getScientificName().toLowerCase() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getTaxonomyCode() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getTaxonomyCode()
+ .compareTo( n2.getNodeData().getTaxonomy().getTaxonomyCode() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getTaxonomy().getCommonName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getTaxonomy().getCommonName() ) ) ) {
+ return n1.getNodeData().getTaxonomy().getCommonName().toLowerCase()
+ .compareTo( n2.getNodeData().getTaxonomy().getCommonName().toLowerCase() );
+ }
+ }
+ if ( n1.getNodeData().isHasSequence() && n2.getNodeData().isHasSequence() ) {
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getName() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getName() ) ) ) {
+ return n1.getNodeData().getSequence().getName().toLowerCase()
+ .compareTo( n2.getNodeData().getSequence().getName().toLowerCase() );
+ }
+ if ( ( !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getSymbol() ) )
+ && ( !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getSymbol() ) ) ) {
+ return n1.getNodeData().getSequence().getSymbol()
+ .compareTo( n2.getNodeData().getSequence().getSymbol() );
+ }
+ if ( ( n1.getNodeData().getSequence().getAccession() != null )
+ && ( n2.getNodeData().getSequence().getAccession() != null )
+ && !ForesterUtil.isEmpty( n1.getNodeData().getSequence().getAccession().getValue() )
+ && !ForesterUtil.isEmpty( n2.getNodeData().getSequence().getAccession().getValue() ) ) {
+ return n1.getNodeData().getSequence().getAccession().getValue()
+ .compareTo( n2.getNodeData().getSequence().getAccession().getValue() );
+ }
+ }
+ return 0;
+ }
+ }
+ Comparator<PhylogenyNode> c;
+ switch ( pri ) {
+ case SEQUENCE:
+ c = new PhylogenyNodeSortSequencePriority();
+ break;
+ case NODE_NAME:
+ c = new PhylogenyNodeSortNodeNamePriority();
+ break;
+ default:
+ c = new PhylogenyNodeSortTaxonomyPriority();
+ }
+ final List<PhylogenyNode> descs = node.getDescendants();
+ Collections.sort( descs, c );
+ int i = 0;
+ for( final PhylogenyNode desc : descs ) {
+ node.setChildNode( i++, desc );
+ }
+ }
+
+ final static public void transferNodeNameToField( final Phylogeny phy,
+ final PhylogenyMethods.PhylogenyNodeField field ) {
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ 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;
+ case TAXONOMY_SCIENTIFIC_NAME:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ n.getNodeData().getTaxonomy().setScientificName( name );
+ break;
+ case TAXONOMY_COMMON_NAME:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ n.getNodeData().getTaxonomy().setCommonName( name );
+ break;
+ case SEQUENCE_SYMBOL:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasSequence() ) {
+ n.getNodeData().setSequence( new Sequence() );
+ }
+ n.getNodeData().getSequence().setSymbol( name );
+ break;
+ case SEQUENCE_NAME:
+ n.setName( "" );
+ if ( !n.getNodeData().isHasSequence() ) {
+ n.getNodeData().setSequence( new Sequence() );
+ }
+ n.getNodeData().getSequence().setName( name );
+ break;
+ case TAXONOMY_ID_UNIPROT_1: {
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ String id = name;
+ final int i = name.indexOf( '_' );
+ if ( i > 0 ) {
+ id = name.substring( 0, i );
+ }
+ else {
+ n.setName( "" );
+ }
+ n.getNodeData().getTaxonomy()
+ .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
+ break;
+ }
+ case TAXONOMY_ID_UNIPROT_2: {
+ if ( !n.getNodeData().isHasTaxonomy() ) {
+ n.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ String id = name;
+ final int i = name.indexOf( '_' );
+ if ( i > 0 ) {
+ id = name.substring( i + 1, name.length() );
+ }
+ else {
+ n.setName( "" );
+ }
+ n.getNodeData().getTaxonomy()
+ .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
+ break;
+ }
+ }
+ }
+ }
+ }
+
static double addPhylogenyDistances( final double a, final double b ) {
if ( ( a >= 0.0 ) && ( b >= 0.0 ) ) {
return a + b;
else if ( b >= 0.0 ) {
return b;
}
- return PhylogenyNode.DISTANCE_DEFAULT;
+ return PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT;
}
// Helper for getUltraParalogousNodes( PhylogenyNode ).
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 );
+ }
}
}
}
}
}
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match && node.getNodeData().isHasSequence()
&& match( node.getNodeData().getSequence().getName(), query, case_sensitive, partial ) ) {
match = true;
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match && node.getNodeData().isHasSequence()
&& match( node.getNodeData().getSequence().getSymbol(), query, case_sensitive, partial ) ) {
match = true;
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match
+ && node.getNodeData().isHasSequence()
&& ( node.getNodeData().getSequence().getAccession() != null )
&& match( node.getNodeData().getSequence().getAccession().getValue(),
query,
partial ) ) {
match = true;
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match && node.getNodeData().isHasSequence()
&& ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
final DomainArchitecture da = node.getNodeData().getSequence().getDomainArchitecture();
I: for( int i = 0; i < da.getNumberOfDomains(); ++i ) {
}
}
}
+ if ( !match && ( node.getNodeData().getBinaryCharacters() != null ) ) {
+ Iterator<String> it = node.getNodeData().getBinaryCharacters().getPresentCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), query, case_sensitive, partial ) ) {
+ match = true;
+ break I;
+ }
+ }
+ it = node.getNodeData().getBinaryCharacters().getGainedCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), query, case_sensitive, partial ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
if ( match ) {
nodes.add( node );
}
}
}
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match && node.getNodeData().isHasSequence()
&& match( node.getNodeData().getSequence().getName(), query, case_sensitive, partial ) ) {
match = true;
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match && node.getNodeData().isHasSequence()
&& match( node.getNodeData().getSequence().getSymbol(), query, case_sensitive, partial ) ) {
match = true;
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match
+ && node.getNodeData().isHasSequence()
&& ( node.getNodeData().getSequence().getAccession() != null )
&& match( node.getNodeData().getSequence().getAccession().getValue(),
query,
partial ) ) {
match = true;
}
- else if ( node.getNodeData().isHasSequence()
+ if ( !match && node.getNodeData().isHasSequence()
&& ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
final DomainArchitecture da = node.getNodeData().getSequence().getDomainArchitecture();
I: for( int i = 0; i < da.getNumberOfDomains(); ++i ) {
}
}
}
+ if ( !match && ( node.getNodeData().getBinaryCharacters() != null ) ) {
+ Iterator<String> it = node.getNodeData().getBinaryCharacters().getPresentCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), query, case_sensitive, partial ) ) {
+ match = true;
+ break I;
+ }
+ }
+ it = node.getNodeData().getBinaryCharacters().getGainedCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), query, case_sensitive, partial ) ) {
+ match = true;
+ break I;
+ }
+ }
+ // final String[] bcp_ary = node.getNodeData().getBinaryCharacters()
+ // .getPresentCharactersAsStringArray();
+ // I: for( final String bc : bcp_ary ) {
+ // if ( match( bc, query, case_sensitive, partial ) ) {
+ // match = true;
+ // break I;
+ // }
+ // }
+ // final String[] bcg_ary = node.getNodeData().getBinaryCharacters()
+ // .getGainedCharactersAsStringArray();
+ // I: for( final String bc : bcg_ary ) {
+ // if ( match( bc, query, case_sensitive, partial ) ) {
+ // match = true;
+ // break I;
+ // }
+ // }
+ }
if ( !match ) {
all_matched = false;
break;
}
return nodes_to_delete.size();
}
+
+ /**
+ * Arranges the order of childern for each node of this Phylogeny in such a
+ * way that either the branch with more children is on top (right) or on
+ * bottom (left), dependent on the value of boolean order.
+ *
+ * @param order
+ * decides in which direction to order
+ * @param pri
+ */
+ public static void orderAppearance( final PhylogenyNode n,
+ final boolean order,
+ final boolean order_ext_alphabetically,
+ final DESCENDANT_SORT_PRIORITY pri ) {
+ if ( n.isExternal() ) {
+ return;
+ }
+ else {
+ PhylogenyNode temp = null;
+ if ( ( n.getNumberOfDescendants() == 2 )
+ && ( n.getChildNode1().getNumberOfExternalNodes() != n.getChildNode2().getNumberOfExternalNodes() )
+ && ( ( n.getChildNode1().getNumberOfExternalNodes() < n.getChildNode2().getNumberOfExternalNodes() ) == order ) ) {
+ temp = n.getChildNode1();
+ n.setChild1( n.getChildNode2() );
+ n.setChild2( temp );
+ }
+ else if ( order_ext_alphabetically ) {
+ boolean all_ext = true;
+ for( final PhylogenyNode i : n.getDescendants() ) {
+ if ( !i.isExternal() ) {
+ all_ext = false;
+ break;
+ }
+ }
+ if ( all_ext ) {
+ PhylogenyMethods.sortNodeDescendents( n, pri );
+ }
+ }
+ for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
+ orderAppearance( n.getChildNode( i ), order, order_ext_alphabetically, pri );
+ }
+ }
+ }
+
+ public static enum PhylogenyNodeField {
+ CLADE_NAME,
+ TAXONOMY_CODE,
+ TAXONOMY_SCIENTIFIC_NAME,
+ TAXONOMY_COMMON_NAME,
+ SEQUENCE_SYMBOL,
+ SEQUENCE_NAME,
+ TAXONOMY_ID_UNIPROT_1,
+ TAXONOMY_ID_UNIPROT_2;
+ }
+
+ public static enum TAXONOMY_EXTRACTION {
+ NO, YES, PFAM_STYLE_ONLY;
+ }
+
+ public static enum DESCENDANT_SORT_PRIORITY {
+ TAXONOMY, SEQUENCE, NODE_NAME;
+ }
}