// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.phylogeny;
private Confidence _confidence;
private Identifier _identifier;
private boolean _rerootable;
- private HashMap<Integer, PhylogenyNode> _id_to_node_map;
+ private HashMap<Long, PhylogenyNode> _id_to_node_map;
private List<PhylogenyNode> _external_nodes_set;
private Collection<Sequence> _sequenceRelationQueries;
private Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> _relevant_sequence_relation_types;
* Finds the PhylogenyNode of this Phylogeny which has a matching ID number.
* @return PhylogenyNode with matching ID, null if not found
*/
- public PhylogenyNode getNode( final int id ) throws NoSuchElementException {
+ public PhylogenyNode getNode( final long id ) throws NoSuchElementException {
if ( isEmpty() ) {
throw new NoSuchElementException( "attempt to get node in an empty phylogeny" );
}
return nodes;
}
+ public List<PhylogenyNode> getNodesViaSequenceSymbol( final String seq_name ) {
+ 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.getNodeData().isHasSequence() && n.getNodeData().getSequence().getSymbol().equals( seq_name ) ) {
+ nodes.add( n );
+ }
+ }
+ return nodes;
+ }
+
public List<PhylogenyNode> getNodesViaTaxonomyCode( final String taxonomy_code ) {
if ( isEmpty() ) {
return null;
return c;
}
+ public int getNumberOfInternalNodes() {
+ if ( isEmpty() ) {
+ return 0;
+ }
+ int c = 0;
+ for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
+ if ( iter.next().isInternal() ) {
+ ++c;
+ }
+ }
+ if ( !isRooted() ) {
+ --c;
+ }
+ return c;
+ }
+
/**
* Returns the sum of external Nodes of this Phylogeny (int).
*/
return;
}
_id_to_node_map = null;
- int max = 0;
+ long max = 0;
for( final PhylogenyNodeIterator it = iteratorPreorder(); it.hasNext(); ) {
final PhylogenyNode node = it.next();
if ( node.isRoot() ) {
* @param id
* ID (int) of PhylogenyNode of this Phylogeny
*/
- public void reRoot( final int id ) {
+ public void reRoot( final long id ) {
reRoot( getNode( id ) );
}
/**
- * Places the root of this Phylogeny on Branch b. The new root is always
- * placed on the middle of the branch b.
- *
- */
- public void reRoot( final PhylogenyBranch b ) {
- final PhylogenyNode n1 = b.getFirstNode();
- final PhylogenyNode n2 = b.getSecondNode();
- if ( n1.isExternal() ) {
- reRoot( n1 );
- }
- else if ( n2.isExternal() ) {
- reRoot( n2 );
- }
- else if ( ( n2 == n1.getChildNode1() ) || ( n2 == n1.getChildNode2() ) ) {
- reRoot( n2 );
- }
- else if ( ( n1 == n2.getChildNode1() ) || ( n1 == n2.getChildNode2() ) ) {
- reRoot( n1 );
- }
- else if ( ( n1.getParent() != null ) && n1.getParent().isRoot()
- && ( ( n1.getParent().getChildNode1() == n2 ) || ( n1.getParent().getChildNode2() == n2 ) ) ) {
- reRoot( n1 );
- }
- else {
- throw new IllegalArgumentException( "reRoot( Branch b ): b is not a branch." );
- }
- }
-
- /**
* Places the root of this Phylogeny on the parent branch PhylogenyNode n.
* The new root is always placed on the middle of the branch.
* <p>
_identifier = identifier;
}
- public void setIdToNodeMap( final HashMap<Integer, PhylogenyNode> idhash ) {
+ public void setIdToNodeMap( final HashMap<Long, PhylogenyNode> idhash ) {
_id_to_node_map = idhash;
}
public void setRoot( final PhylogenyNode n ) {
_root = n;
- } // setRoot( PhylogenyNode )
+ }
/**
* Sets whether this Phylogeny is rooted or not.
return;
} // unRoot()
- private HashMap<Integer, PhylogenyNode> getIdToNodeMap() {
+ private HashMap<Long, PhylogenyNode> getIdToNodeMap() {
return _id_to_node_map;
}
if ( isEmpty() ) {
return;
}
- setIdToNodeMap( new HashMap<Integer, PhylogenyNode>() );
+ setIdToNodeMap( new HashMap<Long, PhylogenyNode>() );
for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
getIdToNodeMap().put( node.getId(), node );