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
16 Bio::HandlerBaseI - Interface class for handler methods which interact with any
17 event-driven parsers (drivers).
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
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):
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):
68 'mol_type' => 'genomic DNA',
69 'LOCATION' => '<1..>10001',
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).
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
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
121 https://redmine.open-bio.org/projects/bioperl/
123 =head1 AUTHOR - Chris Fields
125 Email cjfields at bioperl dot org
129 The rest of the documentation details each of the object methods. Internal
130 methods are usually preceded with a _
134 # Let the code begin...
136 package Bio
::HandlerBaseI
;
140 use base
qw(Bio::Root::RootI);
142 my %HANDLERS = ('foo' => \
&noop
);
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.
154 Args : an hash ref containing a data chunk.
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
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
178 sub handler_methods
{
179 shift->throw_not_implemented
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)
198 shift->throw_not_implemented
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
215 shift->throw_not_implemented
221 Usage : $handler->set_params({
222 '-species' => $species,
223 '-accession_number' => $acc
225 Function: Convenience method used to set specific parameters
227 Args : Hash ref containing the data to be passed as key-value pairs
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)
246 sub reset_parameters
{
247 shift->throw_not_implemented