Bio::DB::TFBS namespace has been moved to its own distribution named after itself
[bioperl-live.git] / Bio / HandlerBaseI.pm
blob70ce39d8508471c120b3233148651ad18ed99f29
2 # BioPerl module for Bio::HandlerI
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Chris Fields
8 # Copyright Chris Fields
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::HandlerBaseI - Interface class for handler methods which interact with any
17 event-driven parsers (drivers).
19 =head1 SYNOPSIS
21 # MyHandler is a Bio::HandlerBaseI-derived class for dealing with GenBank
22 # sequence data, derived from a GenBank event-driven parser
24 # inside a parser (driver) constructor
26 $self->seqhandler($handler || MyHandler->new(-format => 'genbank'));
28 # in the driver parsing method ( such as next_seq() ) ...
30 $handler = $self->seqhandler();
32 # roll data up into hashref chunks, pass off into Handler for processing...
34 $hobj->data_handler($data);
36 # or retrieve Handler methods and pass data directly to Handler methods
38 my $hmeth = $hobj->handler_methods;
40 if ($hmeth->{ $data->{NAME} }) {
41 my $mth = $hmeth->{ $data->{NAME} }; # code ref
42 $hobj->$mth($data);
45 =head1 DESCRIPTION
47 This interface describes simple class methods used for processing data from an
48 event-based parser (a driver). This is similar in theme to an XML SAX-based
49 driver but differs in that one can optionally pass related data
50 semi-intelligently as chunks (defined in a hash reference) vs. passing as single
51 data elements in a stream. For instance, any reference-related and
52 species-related data as well as individual sequence features could be passed as
53 chunks of data to be 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 Support
106 Please direct usage questions or support issues to the mailing list:
108 I<bioperl-l@bioperl.org>
110 rather than to the module maintainer directly. Many experienced and
111 reponsive experts will be able look at the problem and quickly
112 address it. Please include a thorough description of the problem
113 with code and data examples if at all possible.
115 =head2 Reporting Bugs
117 Report bugs to the Bioperl bug tracking system to help us keep track
118 the bugs and their resolution. Bug reports can be submitted via the
119 web:
121 https://github.com/bioperl/bioperl-live/issues
123 =head1 AUTHOR - Chris Fields
125 Email cjfields at bioperl dot org
127 =head1 APPENDIX
129 The rest of the documentation details each of the object methods. Internal
130 methods are usually preceded with a _
132 =cut
134 # Let the code begin...
136 package Bio::HandlerBaseI;
137 use strict;
138 use warnings;
140 use base qw(Bio::Root::RootI);
142 my %HANDLERS = ('foo' => \&noop);
144 =head2 data_handler
146 Title : data_handler
147 Usage : $handler->data_handler($data)
148 Function: Centralized method which accepts all data chunks, then distributes
149 to the appropriate methods for processing based on the chunk name
150 from within the HandlerBaseI object.
152 One can also use
153 Returns : None
154 Args : an hash ref containing a data chunk.
156 =cut
158 sub data_handler {
159 shift->throw_not_implemented
162 =head2 handler_methods
164 Title : handler_methods
165 Usage : $handler->handler_methods('GenBank')
166 %handlers = $handler->handler_methods();
167 Function: Retrieve the handler methods used for the current format() in
168 the handler. This assumes the handler methods are already
169 described in the HandlerI-implementing class.
170 Returns : a hash reference with the data type handled and the code ref
171 associated with it.
172 Args : [optional] String representing the sequence format. If set here
173 this will also set sequence_format()
174 Throws : On unimplemented sequence format in %HANDLERS
176 =cut
178 sub handler_methods {
179 shift->throw_not_implemented
182 =head2 format
184 Title : format
185 Usage : $handler->format('GenBank')
186 $handler->format('BLAST')
187 Function: Get/Set the format for the report/record being parsed. This can be
188 used to set handlers in classes which are capable of processing
189 similar data chunks from multiple driver modules.
190 Returns : String with the sequence format
191 Args : [optional] String with the sequence format
192 Note : The format may be used to set the handlers (as in the
193 current GenericRichSeqHandler implementation)
195 =cut
197 sub format {
198 shift->throw_not_implemented
201 =head2 get_params
203 Title : get_params
204 Usage : $handler->get_params('-species')
205 Function: Convenience method used to retrieve the specified
206 parameters from the internal parameter cache
207 Returns : Hash ref containing parameters requested and data as
208 key-value pairs. Note that some parameter values may be
209 objects, arrays, etc.
210 Args : List (array) representing the parameters requested
212 =cut
214 sub get_params {
215 shift->throw_not_implemented
218 =head2 set_params
220 Title : set_params
221 Usage : $handler->set_params({
222 '-species' => $species,
223 '-accession_number' => $acc
225 Function: Convenience method used to set specific parameters
226 Returns : None
227 Args : Hash ref containing the data to be passed as key-value pairs
229 =cut
231 sub set_params {
232 shift->throw_not_implemented
235 =head2 reset_parameters
237 Title : reset_parameters
238 Usage : $handler->reset_parameters()
239 Function: Resets the internal cache of data (normally object parameters for
240 a builder or factory)
241 Returns : None
242 Args : None
244 =cut
246 sub reset_parameters {
247 shift->throw_not_implemented