import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.forester.io.parsers.nhx.NHXParser;
import org.forester.io.writers.PhylogenyWriter;
new_node.setParent( sibling_parent );
sibling.setParent( new_node );
sibling_parent.setChildNode( sibling_index, new_node );
- final double new_dist = sibling.getDistanceToParent() == PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ? PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT
- : sibling.getDistanceToParent() / 2;
+ final double new_dist = sibling.getDistanceToParent() == PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT
+ ? PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT : sibling.getDistanceToParent() / 2;
new_node.setDistanceToParent( new_dist );
sibling.setDistanceToParent( new_dist );
externalNodesHaveChanged();
else {
double max = -Double.MAX_VALUE;
for( int i = 0; i < n.getNumberOfDescendants(); ++i ) {
- final double l = calculateSubtreeHeight( n.getChildNode( i ), take_collapse_into_account );
+ final double l = calculateSubtreeHeight( n.getChildNode( i ), take_collapse_into_account );
if ( l > max ) {
max = l;
}
}
- return max + ( n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0) ;
+ return max + ( n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0 );
}
}
if ( p.getNumberOfDescendants() == 2 ) {
final int pi = p.getChildNodeIndex();
if ( removed_node.isFirstChildNode() ) {
- p.getChildNode( 1 ).setDistanceToParent( PhylogenyMethods.addPhylogenyDistances( p
- .getDistanceToParent(), p.getChildNode( 1 ).getDistanceToParent() ) );
+ p.getChildNode( 1 )
+ .setDistanceToParent( PhylogenyMethods.addPhylogenyDistances( p.getDistanceToParent(),
+ p.getChildNode( 1 )
+ .getDistanceToParent() ) );
pp.setChildNode( pi, p.getChildNode( 1 ) );
}
else {
- p.getChildNode( 0 ).setDistanceToParent( PhylogenyMethods.addPhylogenyDistances( p
- .getDistanceToParent(), p.getChildNode( 0 ).getDistanceToParent() ) );
+ p.getChildNode( 0 )
+ .setDistanceToParent( PhylogenyMethods.addPhylogenyDistances( p.getDistanceToParent(),
+ p.getChildNode( 0 )
+ .getDistanceToParent() ) );
pp.setChildNode( pi, p.getChildNode( 0 ) );
}
}
return _external_nodes_set;
}
-
/**
* Returns the first external PhylogenyNode.
*/
*
* @return the height for rooted, tree-shaped phylogenies
*/
- public double calculateHeight(final boolean take_collapse_into_account) {
+ public double calculateHeight( final boolean take_collapse_into_account ) {
if ( isEmpty() ) {
return 0.0;
}
return nodes;
}
+ public List<PhylogenyNode> getNodes( final Pattern p ) {
+ if ( isEmpty() ) {
+ return null;
+ }
+ final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
+ for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
+ final PhylogenyNode n = iter.next();
+ if ( n.getName() != null ) {
+ final Matcher m = p.matcher( n.getName() );
+ if ( m.find() ) {
+ nodes.add( n );
+ }
+ }
+ }
+ return nodes;
+ }
+
public List<PhylogenyNode> getNodesViaSequenceName( final String seq_name ) {
if ( isEmpty() ) {
return null;
taxIdList = map.get( node );
if ( node.isDuplication() && isContains( taxIdList, taxonomyCodeRangeList ) ) {
if ( node.getChildNode1() == prev ) {
- v.addAll( getNodeByTaxonomyID( searchNodeSpeciesId, node.getChildNode2()
- .getAllExternalDescendants() ) );
+ v.addAll( getNodeByTaxonomyID( searchNodeSpeciesId,
+ node.getChildNode2().getAllExternalDescendants() ) );
}
else {
- v.addAll( getNodeByTaxonomyID( searchNodeSpeciesId, node.getChildNode1()
- .getAllExternalDescendants() ) );
+ v.addAll( getNodeByTaxonomyID( searchNodeSpeciesId,
+ node.getChildNode1().getAllExternalDescendants() ) );
}
}
}
public Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> getRelevantSequenceRelationTypes() {
if ( _relevant_sequence_relation_types == null ) {
- _relevant_sequence_relation_types = new Vector<SEQUENCE_RELATION_TYPE>();
+ _relevant_sequence_relation_types = new Vector<SequenceRelation.SEQUENCE_RELATION_TYPE>();
}
return _relevant_sequence_relation_types;
}
return true;
}
+ public boolean isCompletelyBinaryAllow3ChildrenAtRoot() {
+ if ( isEmpty() ) {
+ return false;
+ }
+ for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
+ final PhylogenyNode node = iter.next();
+ if ( node.isRoot() ) {
+ if ( node.isInternal()
+ && ( ( node.getNumberOfDescendants() != 2 ) && ( node.getNumberOfDescendants() != 3 ) ) ) {
+ return false;
+ }
+ }
+ else {
+ if ( node.isInternal() && ( node.getNumberOfDescendants() != 2 ) ) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
/**
* Checks whether a Phylogeny object is deleted (or empty).
*
}
else {
node.setDistanceToParent( ( c.getDistanceToParent() >= 0.0 ? c.getDistanceToParent() : 0.0 )
- + ( node.getDistanceToParent() >= 0.0 ? node.getDistanceToParent() : 0.0 ) );
+ + ( node.getDistanceToParent() >= 0.0 ? node.getDistanceToParent() : 0.0 ) );
}
if ( c.getBranchDataDirectly() != null ) {
node.setBranchData( ( BranchData ) c.getBranchDataDirectly().copy() );
*/
public void setRooted( final boolean b ) {
_rooted = b;
- } // setRooted( boolean )
+ }
public void setSequenceRelationQueries( final Collection<Sequence> sequencesByName ) {
_sequenceRelationQueries = sequencesByName;