Bio::Tree AnnotatableNode
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::Tree::AnnotatableNode - A Tree Node with support for annotation
Package variables
No package variables defined.
Included modules
Bio::Annotation::Collection
Bio::Seq
Inherit
Bio::AnnotatableI Bio::Tree::Node
Synopsis
    use Bio::Tree::AnnotatableNode;
my $nodeA = Bio::Tree::AnnotatableNode->new();
my $nodeL = Bio::Tree::AnnotatableNode->new();
my $nodeR = Bio::Tree::AnnotatableNode->new();
my $node = Bio::Tree::AnnotatableNode->new(); $node->add_Descendents($nodeL); $node->add_Descendents($nodeR); print "node is not a leaf \n" if( $node->is_leaf); # $node is-a Bio::AnnotatableI, hence: my $ann_coll = $node->annotation(); # $ann_coll is-a Bio::AnnotationCollectionI, hence: my @all_anns = $ann_coll->get_Annotations(); # do something with the annotation objects
Description
Makes a Tree Node with Annotations, suitable for building a Tree. See
Bio::Tree::Node for a full list of functionality.
Methods
newDescriptionCode
DESTROY
No description
Code
annotationDescriptionCode
add_tag_valueDescriptionCode
remove_tagDescriptionCode
remove_all_tagsDescriptionCode
get_all_tagsDescriptionCode
get_tag_valuesDescriptionCode
has_tagDescriptionCode
to_string_callbackDescriptionCode
to_string
No description
Code
sequenceDescriptionCode
has_sequenceDescriptionCode
Methods description
newcode    nextTop
 Title   : new
Usage : my $obj = Bio::Tree::AnnotatableNode->new();
Function: Builds a new Bio::Tree::AnnotatableNode object
Returns : Bio::Tree::AnnotatableNode
Args : -tostring => code reference to the tostring callback function (optional)
annotationcodeprevnextTop
 Title   : annotation
Usage : $ann = $node->annotation or
$node->annotation($ann)
Function: Gets or sets the annotation
Returns : Bio::AnnotationCollectionI object
Args : None or Bio::AnnotationCollectionI object
See Bio::AnnotationCollectionI and Bio::Annotation::Collection
for more information
add_tag_valuecodeprevnextTop
 Title   : add_tag_value
Usage : $node->add_tag_value($tag,$value)
Function: Adds a tag value to a node
Returns : number of values stored for this tag
Args : $tag - tag name
$value - value to store for the tag
remove_tagcodeprevnextTop
 Title   : remove_tag
Usage : $node->remove_tag($tag)
Function: Remove the tag and all values for this tag
Returns : boolean representing success (0 if tag does not exist)
Args : $tag - tagname to remove
remove_all_tagscodeprevnextTop
 Title   : remove_all_tags
Usage : $node->remove_all_tags()
Function: Removes all tags
Returns : None
Args : None
get_all_tagscodeprevnextTop
 Title   : get_all_tags
Usage : my @tags = $node->get_all_tags()
Function: Gets all the tag names for this Node
Returns : Array of tagnames
Args : None
get_tag_valuescodeprevnextTop
 Title   : get_tag_values
Usage : my @values = $node->get_tag_value($tag)
Function: Gets the values for given tag ($tag)
Returns : Array of values or empty list if tag does not exist
Args : $tag - tag name
has_tagcodeprevnextTop
 Title   : has_tag
Usage : $node->has_tag($tag)
Function: Boolean test if tag exists in the Node
Returns : Boolean
Args : $tag - tagname
to_string_callbackcodeprevnextTop
 Title   : to_string_callback
Usage : $node->to_string_callback(\&func)
Function: get/set callback for to_string
Returns : code reference for the to_string callback function
Args : \&func - code reference to be set as the callback function
sequencecodeprevnextTop
 Title   : sequence
Usage : $ann = $node->sequence or
$node->sequence($seq)
Function: Gets or sets the sequence
Returns : array reference of Bio::SeqI objects
Args : None or Bio::SeqI object
See Bio::SeqI and Bio::Seq
for more information
has_sequencecodeprevnextTop
 Title   : has_sequence
Usage : if( $node->has_sequence) { # do something }
Function: tells if node has sequence attached
Returns : Boolean for whether or not node has Bio::SeqI attached.
Args : None
Methods code
newdescriptionprevnextTop
sub new {
  my ($class,@args) = @_;
  my $self = $class->SUPER::new(@args);
  my $to_string_cb = $self->_rearrange([qw(TOSTRING)], @args);
  if ($to_string_cb) {
    $self->to_string_callback($to_string_cb);
  }
  return $self;
}
DESTROYdescriptionprevnextTop
sub DESTROY {
    my ($self) = @_;
    # try to insure that everything is cleaned up
$self->SUPER::DESTROY();
}
annotationdescriptionprevnextTop
sub annotation {
  my ($self,$value) = @_;
  if( defined $value ) {
    $self->throw("object of class ".ref($value)." does not implement ".
        "Bio::AnnotationCollectionI. Too bad.")      unless $value->isa("Bio::AnnotationCollectionI");
    $self->{'_annotation'} = $value;
  } 
  elsif( ! defined $self->{'_annotation'}) 
  {
    $self->{'_annotation'} = Bio::Annotation::Collection->new();
  }
  return $self->{'_annotation'};
}
add_tag_valuedescriptionprevnextTop
sub add_tag_value {
  my ($self,$tag,$value) = @_;
  if( ! defined $tag || ! defined $value ) {
    $self->warn("cannot call add_tag_value with an undefined value");
  }
  my $ac = $self->annotation();
  my $sv = Bio::Annotation::SimpleValue->new(-value => $value);
  $ac->add_Annotation($tag, $sv); 
  return scalar $ac->get_Annotations($tag);
}
remove_tagdescriptionprevnextTop
sub remove_tag {
  my ($self,$tag) = @_;
  my $ac = $self->annotation();
  if( @{$ac->get_Annotations($tag)} ) {
    $ac->remove_Annotations($tag);
    return 1;
  }
  return 0;
}
remove_all_tagsdescriptionprevnextTop
sub remove_all_tags {
  my ($self) = @_;
  my $ac = $self->annotation();
  $ac->remove_Annotations();
  return;
}
get_all_tagsdescriptionprevnextTop
sub get_all_tags {
  my ($self) = @_;
  my $ac = $self->annotation();
  my @tags = sort $ac->get_all_annotation_keys(); 
  # how to restrict it to SimpleValues?
return @tags;
}
get_tag_valuesdescriptionprevnextTop
sub get_tag_values {
  my ($self,$tag) = @_;
  my $ac = $self->annotation();
  my @values = map {$_->value()} $ac->get_Annotations($tag);
  return @values;
}
has_tagdescriptionprevnextTop
sub has_tag {
  my ($self,$tag) = @_;
  my $ac = $self->annotation();
  return ( scalar $ac->get_Annotations($tag) > 0);
}
to_string_callbackdescriptionprevnextTop
sub to_string_callback {
    # get/set callback, using $DEFAULT_CB if nothing is set
my ($self, $foo) = @_; if ($foo) { # $foo is callback code ref, self as first arg (so you have access to object data)
$self->{'_to_string_cb'} = $foo; } else { if (! defined $self->{'_to_string_cb'}) { $self->{'_to_string_cb'} =\& Bio::Tree::NodeI::to_string; } } return $self->{'_to_string_cb'};
}
to_stringdescriptionprevnextTop
sub to_string {
  my ($self) = @_;
  my $cb = $self->to_string_callback();
  return $cb->($self);
}
sequencedescriptionprevnextTop
sub sequence {
  my ($self,$value) = @_;
  if( defined $value ) {
    $self->throw("object of class ".ref($value)." does not implement ".
        "Bio::SeqI. Too bad.")      unless $value->isa("Bio::SeqI");
    push (@{$self->{'_sequence'}}, $value);
  } 
  #elsif( ! defined $self->{'_sequence'}) 
#{
# $self->{'_sequence'} = Bio::Seq->new();
#}
return $self->{'_sequence'};
}
has_sequencedescriptionprevnextTop
sub has_sequence {
  my ($self) = @_;
  return $self->{'_sequence'} && @{$self->{'_sequence'}};
}


1;
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
  bioperl-l@bioperl.org                  - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support Top
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:
  https://redmine.open-bio.org/projects/bioperl/
AUTHOR - Mira HanTop
Email mirhan@indiana.edu
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Methods for implementing Bio::AnnotatableITop
Methods for implementing tag access through Annotation::SimpleValueTop
Methods for implementing to_stringTop
Methods for accessing Bio::SeqTop