3 # BioPerl module for Bio::Tree::AlleleNode
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::Tree::AlleleNode - A Node with Alleles attached
21 use Bio::Tree::AlleleNode;
25 AlleleNodes are basic L<Bio::Tree::Node>s with the added ability to
26 add Genotypes alleles as defined by the L<Bio::PopGen::IndividualI>
27 interface. Genotypes are defined by the L<Bio::PopGen::GenotypeI>
28 interface, you will probably want to use the L<Bio::PopGen::Genotype>
31 This is implemented via containment to avoid multiple inheritance
32 problems. Their is a L<Bio::PopGen::Individual> object which handles
33 the L<Bio::PopGen::IndividualI> interface, and is accessible via the
34 L<Bio::Tree::AlleleNode::individual> method.
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to
42 the Bioperl mailing list. Your participation is much appreciated.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 of the bugs and their resolution. Bug reports can be submitted via the
64 http://bugzilla.open-bio.org/
66 =head1 AUTHOR - Jason Stajich
68 Email jason-at-bioperl-dot-org
72 The rest of the documentation details each of the object methods.
73 Internal methods are usually preceded with a _
77 This module was re-written to be a combination of
78 L<Bio::PopGen::Individual> and L<Bio::Tree::Node> primarily for use in
79 L<Bio::PopGen::Simulation::Coalescent> simulations.
83 # Let the code begin...
86 package Bio
::Tree
::AlleleNode
;
87 use vars
qw($UIDCOUNTER);
89 BEGIN { $UIDCOUNTER = 1 }
91 use Bio::PopGen::Individual;
92 use Bio::PopGen::Genotype;
94 use base qw(Bio::Tree::Node Bio::PopGen::IndividualI);
99 Usage : my $obj = Bio::Tree::AlleleNode->new();
100 Function: Builds a new Bio::Tree::AlleleNode() object
101 Returns : an instance of Bio::Tree::AlleleNode
102 Args : -unique_id => $id,
103 -genotypes => \@genotypes
104 -left => pointer to Left descendent (optional)
105 -right => pointer to Right descenent (optional)
106 -branch_length => branch length [integer] (optional)
107 -bootstrap => value bootstrap value (string)
108 -description => description of node
109 -id => human readable (unique) id for node
110 Should NOT contain the characters
115 my($class,@args) = @_;
117 my $self = $class->SUPER::new
(@args);
118 $self->individual( Bio
::PopGen
::Individual
->new(@args));
125 Usage : $obj->individual($newval)
126 Function: Get/Set Access to the underlying individual object
127 Returns : L<Bio::PopGen::Individual> object
128 Args : on set, new value (L<Bio::PopGen::Individual>)
134 my ($self,$newval) = @_;
135 if( defined $newval || ! defined $self->{'individual'} ) {
136 $newval = Bio
::PopGen
::Individual
->new() unless defined $newval;
137 $self->{'individual'} = $newval;
139 return $self->{'individual'};
142 =head2 Bio::PopGen::Individual methods
144 Methods required by L<Bio::PopGen::IndividualI>.
150 Usage : my $id = $individual->unique_id
151 Function: Unique Identifier
152 Returns : string representing unique identifier
160 $self->individual->unique_id(@_);
163 =head2 num_of_results
165 Title : num_of_results
166 Usage : my $count = $person->num_results;
167 Function: returns the count of the number of Results for a person
175 $self->individual->num_of_results(@_);
181 Usage : $individual->add_Genotype
182 Function: add a genotype value, only a single genotype
184 Returns : count of the number of genotypes associated with this individual
185 Args : @genotypes - Bio::PopGen::GenotypeI object(s) containing
186 alleles plus a marker name
192 $self->individual->add_Genotype(@_);
195 =head2 reset_Genotypes
197 Title : reset_Genotypes
198 Usage : $individual->reset_Genotypes;
199 Function: Reset the genotypes stored for this individual
208 $self->individual->reset_Genotypes(@_);
211 =head2 remove_Genotype
213 Title : remove_Genotype
214 Usage : $individual->remove_Genotype(@names)
215 Function: Removes the genotypes for the requested markers
217 Args : Names of markers
224 $self->individual->remove_Genotype(@_);
229 Title : get_Genotypes
230 Usage : my @genotypes = $ind->get_Genotypes(-marker => $markername);
231 Function: Get the genotypes for an individual, based on a criteria
232 Returns : Array of genotypes
233 Args : either none (return all genotypes) or
234 -marker => name of marker to return (exact match, case matters)
241 $self->individual->get_Genotypes(@_);
247 Usage : if( $ind->has_Marker($name) ) {}
248 Function: Boolean test to see if an Individual has a genotype
249 for a specific marker
250 Returns : Boolean (true or false)
251 Args : String representing a marker name
258 $self->individual->has_Marker(@_);
261 =head2 get_marker_names
263 Title : get_marker_names
264 Usage : my @names = $individual->get_marker_names;
265 Function: Returns the list of known marker names
266 Returns : List of strings
272 sub get_marker_names
{
274 $self->individual->get_marker_names(@_);
277 =head2 Bio::Tree::Node methods
279 Methods inherited from L<Bio::Tree::Node>.
282 =head2 add_Descendent
284 Title : add_Descendent
285 Usage : $node->add_Descendent($node);
286 Function: Adds a descendent to a node
287 Returns : number of current descendents for this node
288 Args : Bio::Node::NodeI
289 boolean flag, true if you want to ignore the fact that you are
290 adding a second node with the same unique id (typically memory
291 location reference in this implementation). default is false and
292 will throw an error if you try and overwrite an existing node.
295 =head2 each_Descendent
297 Title : each_Descendent($sortby)
298 Usage : my @nodes = $node->each_Descendent;
299 Function: all the descendents for this Node (but not their descendents
300 i.e. not a recursive fetchall)
301 Returns : Array of Bio::Tree::NodeI objects
302 Args : $sortby [optional] "height", "creation" or coderef to be used
303 to sort the order of children nodes.
306 =head2 remove_Descendent
308 Title : remove_Descendent
309 Usage : $node->remove_Descedent($node_foo);
310 Function: Removes a specific node from being a Descendent of this node
312 Args : An array of Bio::Node::NodeI objects which have be previously
313 passed to the add_Descendent call of this object.
316 =head2 remove_all_Descendents
318 Title : remove_all_Descendents
319 Usage : $node->remove_All_Descendents()
320 Function: Cleanup the node's reference to descendents and reset
321 their ancestor pointers to undef, if you don't have a reference
322 to these objects after this call they will be cleaned up - so
323 a get_nodes from the Tree object would be a safe thing to do first
329 =head2 get_all_Descendents
331 Title : get_all_Descendents
332 Usage : my @nodes = $node->get_all_Descendents;
333 Function: Recursively fetch all the nodes and their descendents
334 *NOTE* This is different from each_Descendent
335 Returns : Array or Bio::Tree::NodeI objects
340 # implemented in the interface
345 Usage : $obj->ancestor($newval)
346 Function: Set the Ancestor
347 Returns : value of ancestor
348 Args : newvalue (optional)
353 Title : branch_length
354 Usage : $obj->branch_length()
355 Function: Get/Set the branch length
356 Returns : value of branch_length
357 Args : newvalue (optional)
363 Usage : $obj->bootstrap($newval)
364 Function: Get/Set the bootstrap value
365 Returns : value of bootstrap
366 Args : newvalue (optional)
372 Usage : $obj->description($newval)
373 Function: Get/Set the description string
374 Returns : value of description
375 Args : newvalue (optional)
381 Usage : $obj->id($newval)
382 Function: The human readable identifier for the node
383 Returns : value of human readable id
384 Args : newvalue (optional)
385 Note : id cannot contain the chracters '();:'
387 "A name can be any string of printable characters except blanks,
388 colons, semicolons, parentheses, and square brackets. Because you may
389 want to include a blank in a name, it is assumed that an underscore
390 character ("_") stands for a blank; any of these in a name will be
391 converted to a blank when it is read in."
393 from L<http://evolution.genetics.washington.edu/phylip/newicktree.html>
400 Usage : my $internalid = $node->internal_id
401 Function: Returns the internal unique id for this Node
402 (a monotonically increasing number for this in-memory implementation
403 but could be a database determined unique id in other
409 =head2 Bio::Node::NodeI decorated interface implemented
411 The following methods are implemented by L<Bio::Node::NodeI> decorated
417 Usage : if( $node->is_Leaf )
418 Function: Get Leaf status
427 Usage : my $str = $node->to_string()
428 Function: For debugging, provide a node as a string
435 Usage : my $len = $node->height
436 Function: Returns the height of the tree starting at this
437 node. Height is the maximum branchlength.
438 Returns : The longest length (weighting branches with branch_length) to a leaf
441 =head2 invalidate_height
443 Title : invalidate_height
444 Usage : private helper method
445 Function: Invalidate our cached value of the node's height in the tree
455 Title : add_tag_value
456 Usage : $node->add_tag_value($tag,$value)
457 Function: Adds a tag value to a node
458 Returns : number of values stored for this tag
459 Args : $tag - tag name
460 $value - value to store for the tag
466 Usage : $node->remove_tag($tag)
467 Function: Remove the tag and all values for this tag
468 Returns : boolean representing success (0 if tag does not exist)
469 Args : $tag - tagname to remove
473 =head2 remove_all_tags
475 Title : remove_all_tags
476 Usage : $node->remove_all_tags()
477 Function: Removes all tags
486 Usage : my @tags = $node->get_all_tags()
487 Function: Gets all the tag names for this Node
488 Returns : Array of tagnames
492 =head2 get_tag_values
494 Title : get_tag_values
495 Usage : my @values = $node->get_tag_value($tag)
496 Function: Gets the values for given tag ($tag)
497 Returns : Array of values or empty list if tag does not exist
498 Args : $tag - tag name
504 Usage : $node->has_tag($tag)
505 Function: Boolean test if tag exists in the Node
507 Args : $tag - tagname