2 # BioPerl module for Bio::Seq::BaseSeqProcessor
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Hilmar Lapp <hlapp at gmx.net>
8 # Copyright Hilmar Lapp
10 # You may distribute this module under the same terms as perl itself
13 # (c) Hilmar Lapp, hlapp at gmx.net, 2002.
14 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
16 # You may distribute this module under the same terms as perl itself.
17 # Refer to the Perl Artistic License (see the license accompanying this
18 # software package, or see http://www.perl.com/language/misc/Artistic.html)
19 # for the terms under which you may use, modify, and redistribute this module.
21 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
22 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 # POD documentation - main docs before the code
30 Bio::Seq::BaseSeqProcessor - Base implementation for a SequenceProcessor
34 # you need to derive your own processor from this one
38 This provides just a basic framework for implementations of
39 L<Bio::Factory::SequenceProcessorI>.
41 Essentially what it does is support a parameter to new() to set
42 sequence factory and source stream, and a next_seq() implementation
43 that will use a queue to be filled by a class overriding
50 User feedback is an integral part of the evolution of this and other
51 Bioperl modules. Send your comments and suggestions preferably to
52 the Bioperl mailing list. Your participation is much appreciated.
54 bioperl-l@bioperl.org - General discussion
55 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
59 Please direct usage questions or support issues to the mailing list:
61 I<bioperl-l@bioperl.org>
63 rather than to the module maintainer directly. Many experienced and
64 reponsive experts will be able look at the problem and quickly
65 address it. Please include a thorough description of the problem
66 with code and data examples if at all possible.
70 Report bugs to the Bioperl bug tracking system to help us keep track
71 of the bugs and their resolution. Bug reports can be submitted via the
74 https://github.com/bioperl/bioperl-live/issues
76 =head1 AUTHOR - Hilmar Lapp
78 Email hlapp at gmx.net
82 The rest of the documentation details each of the object methods.
83 Internal methods are usually preceded with a _
88 # Let the code begin...
91 package Bio
::Seq
::BaseSeqProcessor
;
95 # Object preamble - inherits from Bio::Root::Root
98 use base
qw(Bio::Root::Root Bio::Factory::SequenceProcessorI);
103 Usage : my $obj = Bio::Seq::BaseSeqProcessor->new();
104 Function: Builds a new Bio::Seq::BaseSeqProcessor object
105 Returns : an instance of Bio::Seq::BaseSeqProcessor
106 Args : Named parameters. Currently supported are
107 -seqfactory the Bio::Factory::SequenceFactoryI object to use
108 -source_stream the Bio::Factory::SequenceStreamI object to
115 my($class,@args) = @_;
117 my $self = $class->SUPER::new
(@args);
120 $self->_rearrange([qw(SOURCE_STREAM SEQFACTORY)], @args);
122 $self->{'_queue'} = [];
123 $self->sequence_factory($fact) if $fact;
124 $self->source_stream($stream) if $stream;
129 =head1 L<Bio::Factory::SequenceProcessorI> methods
135 Title : source_stream
136 Usage : $obj->source_stream($newval)
137 Function: Get/set the source sequence stream for this sequence
141 Returns : A Bio::Factory::SequenceStreamI compliant object
142 Args : on set, new value (a Bio::Factory::SequenceStreamI compliant
153 my $fact = $stream->sequence_factory();
154 $self->sequence_factory($fact)
155 unless $self->sequence_factory() || (! $fact);
156 return $self->{'source_stream'} = $stream;
158 return $self->{'source_stream'};
161 =head1 L<Bio::Factory::SequenceStreamI> methods
168 Usage : $seq = stream->next_seq
169 Function: Reads the next sequence object from the stream and returns it.
171 This implementation will obtain objects from the source
172 stream as necessary and pass them to process_seq() for
173 processing. This method will return the objects one at a
174 time that process_seq() returns.
176 Returns : a Bio::Seq sequence object
179 See L<Bio::Factory::SequenceStreamI::next_seq>
187 # if the queue is empty, fetch next from source and process it
188 if(@
{$self->{'_queue'}} == 0) {
190 while($seq = $self->source_stream->next_seq()) {
191 @seqs = $self->process_seq($seq);
192 # we may get zero seqs returned
195 push(@
{$self->{'_queue'}}, @seqs) if @seqs;
197 # take next from the queue of seqs
198 $seq = shift(@
{$self->{'_queue'}});
205 Usage : $stream->write_seq($seq)
206 Function: Writes the result(s) of processing the sequence object into
209 You need to override this method in order not to alter
210 (process) sequence objects before output.
212 Returns : 1 for success and 0 for error. The method stops attempting
213 to write objects after the first error returned from the
214 source stream. Otherwise the return value is the value
215 returned from the source stream from writing the last
216 object resulting from processing the last sequence object
219 Args : Bio::SeqI object, or an array of such objects
224 my ($self, @seqs) = @_;
226 foreach my $seq (@seqs) {
227 foreach my $processed ($self->process_seq($seq)) {
228 $ret = $self->source_stream->write_seq($seq);
235 =head2 sequence_factory
237 Title : sequence_factory
238 Usage : $seqio->sequence_factory($seqfactory)
239 Function: Get the Bio::Factory::SequenceFactoryI
240 Returns : Bio::Factory::SequenceFactoryI
246 sub sequence_factory
{
249 return $self->{'sequence_factory'} = shift if @_;
250 return $self->{'sequence_factory'};
253 =head2 object_factory
255 Title : object_factory
256 Usage : $obj->object_factory($newval)
257 Function: This is an alias to sequence_factory with a more generic name.
259 Returns : a L<Bio::Factory::ObjectFactoryI> compliant object
260 Args : on set, new value (a L<Bio::Factory::ObjectFactoryI>
261 compliant object or undef, optional)
267 return shift->sequence_factory(@_);
274 Function: Closes the stream. We override this here in order to cascade
275 to the source stream.
285 return $self->source_stream() ?
$self->source_stream->close(@_) : 1;
288 =head1 To be overridden by a derived class
296 Function: This is the method that is supposed to do the actual
297 processing. It needs to be overridden to do what you want
300 Generally, you do not have to override or implement any other
301 method to derive your own sequence processor.
303 The implementation provided here just returns the unaltered
304 input sequence and hence is not very useful other than
305 serving as a neutral default processor.
308 Returns : An array of zero or more Bio::PrimarySeqI (or derived
309 interface) compliant object as the result of processing the
311 Args : A Bio::PrimarySeqI (or derived interface) compliant object
318 my ($self,$seq) = @_;