import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import org.forester.archaeopteryx.TreePanelUtil;
import org.forester.io.parsers.FastaParser;
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
import org.forester.phylogeny.iterators.PreorderTreeIterator;
import org.forester.util.BasicDescriptiveStatistics;
import org.forester.util.DescriptiveStatistics;
-import org.forester.util.FailedConditionCheckException;
import org.forester.util.ForesterUtil;
import org.forester.util.TaxonomyUtil;
}
/**
+ * For external nodes the level is 0.
+ *
+ * @param node
+ * @return
+ */
+ public static int calculateLevel( final PhylogenyNode node ) {
+ if ( node.isExternal() ) {
+ return 0;
+ }
+ int level = 0;
+ for( PhylogenyNode ext : node.getAllExternalDescendants() ) {
+ int counter = 0;
+ while ( ext != node ) {
+ ext = ext.getParent();
+ ++counter;
+ }
+ if ( counter > level ) {
+ level = counter;
+ }
+ }
+ return level;
+ }
+
+ /**
* Calculates the distance between PhylogenyNodes node1 and node2.
*
*
return node1;
}
- public static short calculateMaxBranchesToLeaf( final PhylogenyNode node ) {
- if ( node.isExternal() ) {
- return 0;
- }
- short max = 0;
- for( PhylogenyNode d : node.getAllExternalDescendants() ) {
- short steps = 0;
- while ( d != node ) {
- if ( d.isCollapse() ) {
- steps = 0;
- }
- else {
- steps++;
- }
- d = d.getParent();
- }
- if ( max < steps ) {
- max = steps;
- }
- }
- return max;
- }
-
public static int calculateMaxDepth( final Phylogeny phy ) {
int max = 0;
for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
}
return max;
}
-
+
public static String[] obtainPresentRanksSorted( final Phylogeny phy ) {
final Set<String> present_ranks = new HashSet<String>();
for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
}
}
}
- final String ordered_ranks[] = new String[present_ranks.size() + 1];
+ final String ordered_ranks[] = new String[ present_ranks.size() + 1 ];
int c = 0;
for( final String rank : TaxonomyUtil.RANKS ) {
- if ( present_ranks.contains( rank ) ) {
- ordered_ranks[ c++ ] = rank;
- }
+ if ( present_ranks.contains( rank ) ) {
+ ordered_ranks[ c++ ] = rank;
+ }
}
ordered_ranks[ c ] = "off";
return ordered_ranks;
return descs;
}
+ public static List<PhylogenyNode> getAllDescendantsOfGivenLevel( final PhylogenyNode node, final int level ) {
+ final List<PhylogenyNode> descs = new ArrayList<PhylogenyNode>();
+ final Set<Long> encountered = new HashSet<Long>();
+ if ( !node.isExternal() ) {
+ final List<PhylogenyNode> exts = node.getAllExternalDescendants();
+ for( PhylogenyNode current : exts ) {
+ if ( calculateLevel( current ) == level ) {
+ descs.add( current );
+ }
+ while ( current != node ) {
+ current = current.getParent();
+ if ( encountered.contains( current.getId() ) ) {
+ continue;
+ }
+ if ( calculateLevel( current ) == level ) {
+ descs.add( current );
+ }
+ encountered.add( current.getId() );
+ }
+ }
+ }
+ return descs;
+ }
+
/**
*
* Convenience method
return nodes_to_delete;
}
- final static public void transferInternalNamesToBootstrapSupport( final Phylogeny phy ) {
+ final static public void transferInternalNamesToConfidenceValues( final Phylogeny phy,
+ final String confidence_type ) {
final PhylogenyNodeIterator it = phy.iteratorPostorder();
while ( it.hasNext() ) {
final PhylogenyNode n = it.next();
+ e.getLocalizedMessage() );
}
if ( value >= 0.0 ) {
- n.getBranchData().addConfidence( new Confidence( value, "bootstrap" ) );
+ n.getBranchData().addConfidence( new Confidence( value, confidence_type ) );
n.setName( "" );
}
}
n.getNodeData().getTaxonomy().setIdentifier( new Identifier( name ) );
break;
}
+ case CLADE_NAME:
+ n.setName( name );
+ break;
default: {
throw new IllegalArgumentException( "don't know what to do with " + field );
}
}
public final static void collapseToDepth( final Phylogeny phy, final int depth ) {
- if ( phy.getNumberOfExternalNodes() < 3 ) {
+ if ( phy.getNumberOfExternalNodes() < 3 ) {
return;
}
collapseToDepthHelper( phy.getRoot(), 0, depth );
}
}
-
-
public final static void collapseToRank( final Phylogeny phy, final int rank ) {
if ( phy.getNumberOfExternalNodes() < 3 ) {
return;
else {
if ( TaxonomyUtil.RANK_TO_INT.get( current_rank ) >= target_rank ) {
n.setCollapse( true );
-
final PhylogenyNodeIterator it = new PreorderTreeIterator( n );
while ( it.hasNext() ) {
it.next().setCollapse( true );
collapseToRankHelper( desc, target_rank );
}
}
-
+
public final static PhylogenyNode getFirstExternalNode( final PhylogenyNode node ) {
PhylogenyNode n = node;
while ( n.isInternal() ) {
}
return n;
}
-
+
public final static PhylogenyNode getLastExternalNode( final PhylogenyNode node ) {
PhylogenyNode n = node;
while ( n.isInternal() ) {
}
return false;
}
-
}