3 # BioPerl module for Bio::TreeIO::cluster
5 # Contributed by Guillaume Rousse <Guillaume-dot-Rousse-at-inria-dot-fr>
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::TreeIO::cluster - A TreeIO driver module for parsing Algorithm::Cluster::treecluster() output
19 # do not use this module directly
21 use Algorithm::Cluster;
22 my ($result, $linkdist) = Algorithm::Cluster::treecluster(
25 my $treeio = Bio::TreeIO->new(
28 -linkdist => $linkdist,
31 my $tree = $treeio->next_tree;
35 This is a driver module for parsing Algorithm::Cluster::treecluster() output.
41 User feedback is an integral part of the evolution of this and other
42 Bioperl modules. Send your comments and suggestions preferably to
43 the Bioperl mailing list. Your participation is much appreciated.
45 bioperl-l@bioperl.org - General discussion
46 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
50 Report bugs to the Bioperl bug tracking system to help us keep track
51 of the bugs and their resolution. Bug reports can be submitted via
54 http://bugzilla.open-bio.org/
56 =head1 AUTHOR - Guillaume Rousse
58 Email Guillaume-dot-Rousse-at-inria-dot-fr
62 Jason Stajich - jason-at-bioperl-dot-org
66 The rest of the documentation details each of the object methods.
67 Internal methods are usually preceded with a _
72 # Let the code begin...
75 package Bio
::TreeIO
::cluster
;
78 use Bio
::Event
::EventGeneratorI
;
81 use base
qw(Bio::TreeIO);
86 Usage : my $obj = Bio::TreeIO::cluster->new();
87 Function: Builds a new Bio::TreeIO::cluster object for reading Algorithm::Cluster::treecluster output
88 Returns : Bio::TreeIO::cluster
89 Args :-result => Algorithm::Cluster result
90 -linkdist => distance between links
91 -labels => node labels
97 ($self->{_result
},$self->{_linkdist
},
98 $self->{_labels
}) = $self->_rearrange([qw
99 (RESULT LINKDIST LABELS
)],
101 $self->SUPER::_initialize
(@_);
107 Usage : my $tree = $treeio->next_tree
108 Function: Gets the next tree in the stream
109 Returns : Bio::Tree::TreeI
117 if( ! $self->{_result
} ){
118 $self->warn("Must provide value 'result' and 'linkdist' and 'labels' when initializing a TreeIO::cluster object");
121 $self->_eventHandler->start_document();
123 # build tree from the root
124 $self->_eventHandler->start_element({Name
=> 'tree'});
125 $self->_recurse(-1, 0);
126 $self->_recurse(-1, 1);
127 $self->_eventHandler->end_element({Name
=> 'tree'});
129 return $self->_eventHandler->end_document;
133 my ($self, $line, $column) = @_;
135 my $id = $self->{_result
}->[$line]->[$column];
138 $self->debug("leaf $id\n");
139 $self->debug("distance $self->{_linkdist}->[$line]\n");
140 $self->debug("label $self->{_labels}->[$id]\n");
141 $self->_eventHandler->start_element({Name
=> 'node'});
142 $self->_eventHandler->start_element({Name
=> 'branch_length'});
143 $self->_eventHandler->characters($self->{_linkdist
}->[$line]);
144 $self->_eventHandler->end_element({Name
=> 'branch_length'});
145 $self->_eventHandler->start_element({Name
=> 'id'});
146 $self->_eventHandler->characters($self->{_labels
}->[$id]);
147 $self->_eventHandler->end_element({Name
=> 'id'});
148 $self->_eventHandler->start_element({Name
=> 'leaf'});
149 $self->_eventHandler->characters(1);
150 $self->_eventHandler->end_element({Name
=> 'leaf'});
151 $self->_eventHandler->end_element({Name
=> 'node'});
154 $self->debug("internal node $id\n");
155 $self->debug("distance $self->{_linkdist}->[$line]\n");
156 $self->_eventHandler->start_element({Name
=> 'node'});
157 $self->_eventHandler->start_element({Name
=> 'branch_length'});
158 $self->_eventHandler->characters($self->{_linkdist
}->[$line]);
159 $self->_eventHandler->end_element({Name
=> 'branch_length'});
160 $self->_eventHandler->start_element({Name
=> 'leaf'});
161 $self->_eventHandler->characters(0);
162 $self->_eventHandler->end_element({Name
=> 'leaf'});
163 $self->_eventHandler->start_element({Name
=> 'tree'});
164 my $child_id = - ($id + 1);
165 $self->_recurse($child_id, 0);
166 $self->_recurse($child_id, 1);
167 $self->_eventHandler->end_element({Name
=> 'tree'});
168 $self->_eventHandler->end_element({Name
=> 'node'});
177 Function: Sorry not possible with this format
185 $_[0]->throw("Sorry the format 'cluster' can only be used as an input format");