* seq_inds is not defined for Model-based HSPs
[bioperl-live.git] / Bio / HandlerBaseI.pm
blob87140d9fd7c82ed2da42dac25fd9e3a4f98c8c4d
1 # $Id$
3 # BioPerl module for Bio::HandlerI
5 # Cared for by Chris Fields
7 # Copyright Chris Fields
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::HandlerBaseI - Interface class for handler methods which interact with any
16 event-driven parsers (drivers).
18 =head1 SYNOPSIS
20 # MyHandler is a Bio::HandlerBaseI-derived class for dealing with GenBank
21 # sequence data, derived from a GenBank event-driven parser
23 # inside a parser (driver) constructor
25 $self->seqhandler($handler || MyHandler->new(-format => 'genbank'));
27 # in the driver parsing method ( such as next_seq() ) ...
29 $handler = $self->seqhandler();
31 # roll data up into hashref chunks, pass off into Handler for processing...
33 $hobj->data_handler($data);
35 # or retrieve Handler methods and pass data directly to Handler methods
37 my $hmeth = $hobj->handler_methods;
39 if ($hmeth->{ $data->{NAME} }) {
40 my $mth = $hmeth->{ $data->{NAME} }; # code ref
41 $hobj->$mth($data);
44 =head1 DESCRIPTION
46 This interface describes simple class methods used for processing data
47 from an event-based parser (a driver). This is similar in theme to an
48 XML SAX-based driver but differs in that one can optionally pass
49 related data semi- intelligently as chunks (defined in a hash
50 reference) vs. passing as single data elements in a stream. For
51 instance, any reference-related and species-related data as well as
52 individual sequence features could be passed as chunks of data to be
53 processed in part or as a whole (from Data::Dumper output):
55 Annotation Data (References):
57 $VAR1 = {
58 'NAME' => 'REFERENCE',
59 'DATA' => '1 (bases 1 to 10001)'
60 'AUTHORS' => 'International Human Genome Sequencing Consortium.'
61 'TITLE' => 'The DNA sequence of Homo sapiens'
62 'JOURNAL' => 'Unpublished (2003)'
65 Sequence features (source seqfeature):
67 $VAR1 = {
68 'mol_type' => 'genomic DNA',
69 'LOCATION' => '<1..>10001',
70 'NAME' => 'FEATURES',
71 'FEATURE_KEY' => 'source',
72 'note' => 'Accession AL451081 sequenced by The Sanger Centre',
73 'db_xref' => 'taxon:9606',
74 'clone' => 'RP11-302I18',
75 'organism' => 'Homo sapiens'
78 These would be 'handled' accordingly by methods specified in a
79 HandlerI-based class. The data in a chunk is intentionally left vague
80 here since this may vary from implementation to implementation and can
81 be somewhat open to interpretation. A data chunk in a sequence record,
82 for instance, will be different than a data chunk in a BLAST
83 report. This also allows one the flexibility to pass data as more
84 XML-like small bits, as huge chunks, or even as indexed locations in a
85 file (such as when using a "pull" parser, like a Bio::PullParserI).
87 For an sequence-based implementation see
88 Bio::SeqIO::RichSeq::GenericRichSeqHandler, which handles any GenBank,
89 UniProt, and EMBL data from their respective driver modules
90 (Bio::SeqIO::gbdriver, Bio::SeqIO::swissdriver, and
91 Bio::SeqIO::embldriver).
93 =head1 FEEDBACK
95 =head2 Mailing Lists
97 User feedback is an integral part of the evolution of this and other
98 Bioperl modules. Send your comments and suggestions preferably to one
99 of the Bioperl mailing lists. Your participation is much appreciated.
101 bioperl-l@bioperl.org - General discussion
102 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
104 =head2 Reporting Bugs
106 Report bugs to the Bioperl bug tracking system to help us keep track
107 the bugs and their resolution. Bug reports can be submitted via the
108 web:
110 http://bugzilla.open-bio.org/
112 =head1 AUTHOR - Chris Fields
114 Email cjfields at uiuc dot edu
116 =head1 APPENDIX
118 The rest of the documentation details each of the object methods. Internal
119 methods are usually preceded with a _
121 =cut
123 # Let the code begin...
125 package Bio::HandlerBaseI;
126 use strict;
127 use warnings;
129 use base qw(Bio::Root::RootI);
131 my %HANDLERS = ('foo' => \&noop);
133 =head2 data_handler
135 Title : data_handler
136 Usage : $handler->data_handler($data)
137 Function: Centralized method which accepts all data chunks, then distributes
138 to the appropriate methods for processing based on the chunk name
139 from within the HandlerBaseI object.
141 One can also use
142 Returns : None
143 Args : an hash ref containing a data chunk.
145 =cut
147 sub data_handler {
148 shift->throw_not_implemented
151 =head2 handler_methods
153 Title : handler_methods
154 Usage : $handler->handler_methods('GenBank')
155 %handlers = $handler->handler_methods();
156 Function: Retrieve the handler methods used for the current format() in
157 the handler. This assumes the handler methods are already
158 described in the HandlerI-implementing class.
159 Returns : a hash reference with the data type handled and the code ref
160 associated with it.
161 Args : [optional] String representing the sequence format. If set here
162 this will also set sequence_format()
163 Throws : On unimplemented sequence format in %HANDLERS
165 =cut
167 sub handler_methods {
168 shift->throw_not_implemented
171 =head2 format
173 Title : format
174 Usage : $handler->format('GenBank')
175 $handler->format('BLAST')
176 Function: Get/Set the format for the report/record being parsed. This can be
177 used to set handlers in classes which are capable of processing
178 similar data chunks from multiple driver modules.
179 Returns : String with the sequence format
180 Args : [optional] String with the sequence format
181 Note : The format may be used to set the handlers (as in the
182 current GenericRichSeqHandler implementation)
184 =cut
186 sub format {
187 shift->throw_not_implemented
190 =head2 get_params
192 Title : get_params
193 Usage : $handler->get_params('-species')
194 Function: Convenience method used to retrieve the specified
195 parameters from the internal parameter cache
196 Returns : Hash ref containing parameters requested and data as
197 key-value pairs. Note that some parameter values may be
198 objects, arrays, etc.
199 Args : List (array) representing the parameters requested
201 =cut
203 sub get_params {
204 shift->throw_not_implemented
207 =head2 set_params
209 Title : set_params
210 Usage : $handler->set_params({
211 '-species' => $species,
212 '-accession_number' => $acc
214 Function: Convenience method used to set specific parameters
215 Returns : None
216 Args : Hash ref containing the data to be passed as key-value pairs
218 =cut
220 sub set_params {
221 shift->throw_not_implemented
224 =head2 reset_parameters
226 Title : reset_parameters
227 Usage : $handler->reset_parameters()
228 Function: Resets the internal cache of data (normally object parameters for
229 a builder or factory)
230 Returns : None
231 Args : None
233 =cut
235 sub reset_parameters {
236 shift->throw_not_implemented