1 # BioPerl module for Bio::Annotation::Tree
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 # Cared for by Weigang Qiu <weigang at genectr.hunter.cuny.edu>
7 # Based on the Bio::Annotation::DBLink by Ewan Birney
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Annotation::Tree - Provide a tree as an annotation to a Bio::AnnotatableI
20 # Read a tree and an alignment
22 $treeio=Bio::TreeIO->new(-file=>'foo.dnd', -format=>'newic');
23 $tree=$treeio->next_tree;
24 $alnio=Bio::AlignIO->new(-file=>'foo.aln', -format=>'clustalw');
25 $aln=$alnio->next_aln;
27 # Construct a tree annotation
28 $ann_tree = Bio::Annotation::Tree->new (-tree_id => 'mytree',
32 # Add the tree annotation to AlignI
33 $ac = Bio::Annotation::Collection->new();
34 $ac->add_Annotation('tree', $ann_tree);
35 $aln->annotation($ac);
38 # The above procedures are sensible only if
39 # the tree is generated from the alignment. However,
40 # currently no effort has been made to check the consistency
41 # between the tree OTU names and the sequence names
45 Provides a Bio::AnnotationI object which contains a Bio::Tree::TreeI, which can
46 be added to a Bio::AnnotationCollectionI, which in turn be attached to a
47 Bio::AnnotatableI (typically a Bio::AlignI object)
51 Weigang Qiu - weigang at genectr.hunter.cuny.edu
60 The rest of the documentation details each of the object
61 methods. Internal methods are usually preceded with a '_'
65 # Let the code begin...
67 package Bio
::Annotation
::Tree
;
71 use base
qw(Bio::Root::Root Bio::AnnotationI Bio::TreeIO);
75 my($class,@args) = @_;
77 my $self = $class->SUPER::new
(@args);
79 my ($tree_id, $tree_obj, $tag) =
80 $self->_rearrange([ qw(
86 defined $tag && $self->tagname($tag);
87 defined $tree_id && $self->tree_id($tree_id);
88 defined $tree_obj && $self->tree($tree_obj);
91 # other possible variables to store
95 # defined $program && $self->program($program);
96 # defined $method && $self->method($method);
97 # defined $freq && $self->freq($tree_freq);
101 =head1 AnnotationI implementing functions
108 Usage : $ann_tree->as_text();
109 Function: output tree as a string
110 Returns : a newic tree file
118 my $tree = $self->tree || $self->throw("Tree object absent");
119 my $treeio = Bio
::TreeIO
->new();
120 $treeio->write_tree($tree);
126 Usage : my $str = $ann->display_text();
127 Function: returns a string. Unlike as_text(), this method returns a string
128 formatted as would be expected for te specific implementation.
130 One can pass a callback as an argument which allows custom text
131 generation; the callback is passed the current instance and any text
135 Args : [optional] callback
140 my $DEFAULT_CB = sub { $_[0]->as_text || ''};
143 my ($self, $cb) = @_;
145 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
154 Usage : my $hashtree = $value->hash_tree
155 Function: For supporting the AnnotationI interface just returns the value
156 as a hashref with the key 'value' pointing to the value
157 Returns : hashrf to tree
165 $h->{'value'} = $self->tree();
172 Usage : $obj->tagname($newval)
173 Function: Get/set the tagname for this annotation value.
174 Setting this is optional. If set, it obviates the need to
175 provide a tag to Bio::AnnotationCollectionI when adding
176 this object. When obtaining an AnnotationI object from the
177 collection, the collection will set the value to the tag
178 under which it was stored unless the object has a tag
180 Returns : value of tagname (a scalar)
181 Args : new value (a scalar, optional)
187 my ($self,$value) = @_;
188 if( defined $value) {
189 $self->{'tagname'} = $value;
191 return $self->{'tagname'};
194 =head1 Specific accessors for Tree
199 Usage : $obj->tree_id($newval)
200 Function: Get/set a name for the tree
201 Returns : value of tagname (a scalar)
202 Args : new value (a scalar, optional)
209 return $self->{'tree_id'} = shift if defined($_[0]);
210 return $self->{'tree_id'};
216 Usage : $obj->tree($newval)
217 Function: Get/set tree
219 Args : new value (a tree ref, optional)
226 return $self->{'tree'} = shift if defined($_[0]);
227 return $self->{'tree'};