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
;
94 # Object preamble - inherits from Bio::Root::Root
97 use base
qw(Bio::Root::Root Bio::Factory::SequenceProcessorI);
102 Usage : my $obj = Bio::Seq::BaseSeqProcessor->new();
103 Function: Builds a new Bio::Seq::BaseSeqProcessor object
104 Returns : an instance of Bio::Seq::BaseSeqProcessor
105 Args : Named parameters. Currently supported are
106 -seqfactory the Bio::Factory::SequenceFactoryI object to use
107 -source_stream the Bio::Factory::SequenceStreamI object to
114 my($class,@args) = @_;
116 my $self = $class->SUPER::new
(@args);
119 $self->_rearrange([qw(SOURCE_STREAM SEQFACTORY)], @args);
121 $self->{'_queue'} = [];
122 $self->sequence_factory($fact) if $fact;
123 $self->source_stream($stream) if $stream;
128 =head1 L<Bio::Factory::SequenceProcessorI> methods
134 Title : source_stream
135 Usage : $obj->source_stream($newval)
136 Function: Get/set the source sequence stream for this sequence
140 Returns : A Bio::Factory::SequenceStreamI compliant object
141 Args : on set, new value (a Bio::Factory::SequenceStreamI compliant
152 my $fact = $stream->sequence_factory();
153 $self->sequence_factory($fact)
154 unless $self->sequence_factory() || (! $fact);
155 return $self->{'source_stream'} = $stream;
157 return $self->{'source_stream'};
160 =head1 L<Bio::Factory::SequenceStreamI> methods
167 Usage : $seq = stream->next_seq
168 Function: Reads the next sequence object from the stream and returns it.
170 This implementation will obtain objects from the source
171 stream as necessary and pass them to process_seq() for
172 processing. This method will return the objects one at a
173 time that process_seq() returns.
175 Returns : a Bio::Seq sequence object
178 See L<Bio::Factory::SequenceStreamI::next_seq>
186 # if the queue is empty, fetch next from source and process it
187 if(@
{$self->{'_queue'}} == 0) {
189 while($seq = $self->source_stream->next_seq()) {
190 @seqs = $self->process_seq($seq);
191 # we may get zero seqs returned
194 push(@
{$self->{'_queue'}}, @seqs) if @seqs;
196 # take next from the queue of seqs
197 $seq = shift(@
{$self->{'_queue'}});
204 Usage : $stream->write_seq($seq)
205 Function: Writes the result(s) of processing the sequence object into
208 You need to override this method in order not to alter
209 (process) sequence objects before output.
211 Returns : 1 for success and 0 for error. The method stops attempting
212 to write objects after the first error returned from the
213 source stream. Otherwise the return value is the value
214 returned from the source stream from writing the last
215 object resulting from processing the last sequence object
218 Args : Bio::SeqI object, or an array of such objects
223 my ($self, @seqs) = @_;
225 foreach my $seq (@seqs) {
226 foreach my $processed ($self->process_seq($seq)) {
227 $ret = $self->source_stream->write_seq($seq);
234 =head2 sequence_factory
236 Title : sequence_factory
237 Usage : $seqio->sequence_factory($seqfactory)
238 Function: Get the Bio::Factory::SequenceFactoryI
239 Returns : Bio::Factory::SequenceFactoryI
245 sub sequence_factory
{
248 return $self->{'sequence_factory'} = shift if @_;
249 return $self->{'sequence_factory'};
252 =head2 object_factory
254 Title : object_factory
255 Usage : $obj->object_factory($newval)
256 Function: This is an alias to sequence_factory with a more generic name.
258 Returns : a L<Bio::Factory::ObjectFactoryI> compliant object
259 Args : on set, new value (a L<Bio::Factory::ObjectFactoryI>
260 compliant object or undef, optional)
266 return shift->sequence_factory(@_);
273 Function: Closes the stream. We override this here in order to cascade
274 to the source stream.
284 return $self->source_stream() ?
$self->source_stream->close(@_) : 1;
287 =head1 To be overridden by a derived class
295 Function: This is the method that is supposed to do the actual
296 processing. It needs to be overridden to do what you want
299 Generally, you do not have to override or implement any other
300 method to derive your own sequence processor.
302 The implementation provided here just returns the unaltered
303 input sequence and hence is not very useful other than
304 serving as a neutral default processor.
307 Returns : An array of zero or more Bio::PrimarySeqI (or derived
308 interface) compliant object as the result of processing the
310 Args : A Bio::PrimarySeqI (or derived interface) compliant object
317 my ($self,$seq) = @_;