Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Seq/BaseSeqProcessor.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 # $Id: BaseSeqProcessor.pm,v 1.2 2002/11/02 21:04:19 lapp Exp $ | |
2 # | |
3 # BioPerl module for Bio::Seq::BaseSeqProcessor | |
4 # | |
5 # Cared for by Hilmar Lapp <hlapp at gmx.net> | |
6 # | |
7 # Copyright Hilmar Lapp | |
8 # | |
9 # You may distribute this module under the same terms as perl itself | |
10 | |
11 # | |
12 # (c) Hilmar Lapp, hlapp at gmx.net, 2002. | |
13 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002. | |
14 # | |
15 # You may distribute this module under the same terms as perl itself. | |
16 # Refer to the Perl Artistic License (see the license accompanying this | |
17 # software package, or see http://www.perl.com/language/misc/Artistic.html) | |
18 # for the terms under which you may use, modify, and redistribute this module. | |
19 # | |
20 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | |
21 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | |
22 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
23 # | |
24 | |
25 # POD documentation - main docs before the code | |
26 | |
27 =head1 NAME | |
28 | |
29 Bio::Seq::BaseSeqProcessor - Base implementation for a SequenceProcessor | |
30 | |
31 =head1 SYNOPSIS | |
32 | |
33 # you need to derive your own processor from this one | |
34 | |
35 =head1 DESCRIPTION | |
36 | |
37 This provides just a basic framework for implementations of | |
38 L<Bio::Factory::SequenceProcessorI>. | |
39 | |
40 Essentially what it does is support a parameter to new() to set | |
41 sequence factory and source stream, and a next_seq() implementation | |
42 that will use a queue to be filled by a class overriding | |
43 process_seq(). | |
44 | |
45 =head1 FEEDBACK | |
46 | |
47 =head2 Mailing Lists | |
48 | |
49 User feedback is an integral part of the evolution of this and other | |
50 Bioperl modules. Send your comments and suggestions preferably to | |
51 the Bioperl mailing list. Your participation is much appreciated. | |
52 | |
53 bioperl-l@bioperl.org - General discussion | |
54 http://bioperl.org/MailList.shtml - About the mailing lists | |
55 | |
56 =head2 Reporting Bugs | |
57 | |
58 Report bugs to the Bioperl bug tracking system to help us keep track | |
59 of the bugs and their resolution. Bug reports can be submitted via | |
60 email or the web: | |
61 | |
62 bioperl-bugs@bioperl.org | |
63 http://bioperl.org/bioperl-bugs/ | |
64 | |
65 =head1 AUTHOR - Hilmar Lapp | |
66 | |
67 Email hlapp at gmx.net | |
68 | |
69 Describe contact details here | |
70 | |
71 =head1 CONTRIBUTORS | |
72 | |
73 Additional contributors names and emails here | |
74 | |
75 =head1 APPENDIX | |
76 | |
77 The rest of the documentation details each of the object methods. | |
78 Internal methods are usually preceded with a _ | |
79 | |
80 =cut | |
81 | |
82 | |
83 # Let the code begin... | |
84 | |
85 | |
86 package Bio::Seq::BaseSeqProcessor; | |
87 use vars qw(@ISA); | |
88 use strict; | |
89 | |
90 # Object preamble - inherits from Bio::Root::Root | |
91 | |
92 use Bio::Root::Root; | |
93 use Bio::Factory::SequenceProcessorI; | |
94 | |
95 @ISA = qw(Bio::Root::Root Bio::Factory::SequenceProcessorI); | |
96 | |
97 =head2 new | |
98 | |
99 Title : new | |
100 Usage : my $obj = new Bio::Seq::BaseSeqProcessor(); | |
101 Function: Builds a new Bio::Seq::BaseSeqProcessor object | |
102 Returns : an instance of Bio::Seq::BaseSeqProcessor | |
103 Args : Named parameters. Currently supported are | |
104 -seqfactory the Bio::Factory::SequenceFactoryI object to use | |
105 -source_stream the Bio::Factory::SequenceStreamI object to | |
106 which we are chained | |
107 | |
108 | |
109 =cut | |
110 | |
111 sub new { | |
112 my($class,@args) = @_; | |
113 | |
114 my $self = $class->SUPER::new(@args); | |
115 | |
116 my ($stream,$fact) = | |
117 $self->_rearrange([qw(SOURCE_STREAM SEQFACTORY)], @args); | |
118 | |
119 $self->{'_queue'} = []; | |
120 $self->sequence_factory($fact) if $fact; | |
121 $self->source_stream($stream) if $stream; | |
122 | |
123 return $self; | |
124 } | |
125 | |
126 =head1 L<Bio::Factory::SequenceProcessorI> methods | |
127 | |
128 =cut | |
129 | |
130 =head2 source_stream | |
131 | |
132 Title : source_stream | |
133 Usage : $obj->source_stream($newval) | |
134 Function: Get/set the source sequence stream for this sequence | |
135 processor. | |
136 | |
137 Example : | |
138 Returns : A Bio::Factory::SequenceStreamI compliant object | |
139 Args : on set, new value (a Bio::Factory::SequenceStreamI compliant | |
140 object) | |
141 | |
142 | |
143 =cut | |
144 | |
145 sub source_stream{ | |
146 my $self = shift; | |
147 | |
148 if(@_) { | |
149 my $stream = shift; | |
150 my $fact = $stream->sequence_factory(); | |
151 $self->sequence_factory($fact) | |
152 unless $self->sequence_factory() || (! $fact); | |
153 return $self->{'source_stream'} = $stream; | |
154 } | |
155 return $self->{'source_stream'}; | |
156 } | |
157 | |
158 =head1 L<Bio::Factory::SequenceStreamI> methods | |
159 | |
160 =cut | |
161 | |
162 =head2 next_seq | |
163 | |
164 Title : next_seq | |
165 Usage : $seq = stream->next_seq | |
166 Function: Reads the next sequence object from the stream and returns it. | |
167 | |
168 This implementation will obtain objects from the source | |
169 stream as necessary and pass them to process_seq() for | |
170 processing. This method will return the objects one at a | |
171 time that process_seq() returns. | |
172 | |
173 Returns : a Bio::Seq sequence object | |
174 Args : none | |
175 | |
176 See L<Bio::Factory::SequenceStreamI::next_seq> | |
177 | |
178 =cut | |
179 | |
180 sub next_seq{ | |
181 my $self = shift; | |
182 my $seq; | |
183 | |
184 # if the queue is empty, fetch next from source and process it | |
185 if(@{$self->{'_queue'}} == 0) { | |
186 my @seqs = (); | |
187 while($seq = $self->source_stream->next_seq()) { | |
188 @seqs = $self->process_seq($seq); | |
189 # we may get zero seqs returned | |
190 last if @seqs; | |
191 } | |
192 push(@{$self->{'_queue'}}, @seqs) if @seqs; | |
193 } | |
194 # take next from the queue of seqs | |
195 $seq = shift(@{$self->{'_queue'}}); | |
196 return $seq; | |
197 } | |
198 | |
199 =head2 write_seq | |
200 | |
201 Title : write_seq | |
202 Usage : $stream->write_seq($seq) | |
203 Function: writes the $seq object into the stream | |
204 | |
205 This implementation passes the sequences to the source | |
206 stream unaltered. You need to override this in order to | |
207 have sequence objects altered before output. | |
208 | |
209 Returns : 1 for success and 0 for error | |
210 Args : Bio::Seq object | |
211 | |
212 =cut | |
213 | |
214 sub write_seq{ | |
215 return shift->source_stream->write_seq(@_); | |
216 } | |
217 | |
218 =head2 sequence_factory | |
219 | |
220 Title : sequence_factory | |
221 Usage : $seqio->sequence_factory($seqfactory) | |
222 Function: Get the Bio::Factory::SequenceFactoryI | |
223 Returns : Bio::Factory::SequenceFactoryI | |
224 Args : none | |
225 | |
226 | |
227 =cut | |
228 | |
229 sub sequence_factory{ | |
230 my $self = shift; | |
231 | |
232 return $self->{'sequence_factory'} = shift if @_; | |
233 return $self->{'sequence_factory'}; | |
234 } | |
235 | |
236 =head2 object_factory | |
237 | |
238 Title : object_factory | |
239 Usage : $obj->object_factory($newval) | |
240 Function: This is an alias to sequence_factory with a more generic name. | |
241 Example : | |
242 Returns : a L<Bio::Factory::ObjectFactoryI> compliant object | |
243 Args : on set, new value (a L<Bio::Factory::ObjectFactoryI> | |
244 compliant object or undef, optional) | |
245 | |
246 | |
247 =cut | |
248 | |
249 sub object_factory{ | |
250 return shift->sequence_factory(@_); | |
251 } | |
252 | |
253 =head2 close | |
254 | |
255 Title : close | |
256 Usage : | |
257 Function: Closes the stream. We override this here in order to cascade | |
258 to the source stream. | |
259 Example : | |
260 Returns : | |
261 Args : none | |
262 | |
263 | |
264 =cut | |
265 | |
266 sub close{ | |
267 my $self = shift; | |
268 return $self->source_stream() ? $self->source_stream->close(@_) : 1; | |
269 } | |
270 | |
271 =head1 To be overridden by a derived class | |
272 | |
273 =cut | |
274 | |
275 =head2 process_seq | |
276 | |
277 Title : process_seq | |
278 Usage : | |
279 Function: This is the method that is supposed to do the actual | |
280 processing. It needs to be overridden to do what you want | |
281 it to do. | |
282 | |
283 Generally, you do not have to override or implement any other | |
284 method to derive your own sequence processor. | |
285 | |
286 The implementation provided here just returns the unaltered | |
287 input sequence and hence is not very useful other than | |
288 serving as a neutral default processor. | |
289 | |
290 Example : | |
291 Returns : An array of zero or more Bio::PrimarySeqI (or derived | |
292 interface) compliant object as the result of processing the | |
293 input sequence. | |
294 Args : A Bio::PrimarySeqI (or derived interface) compliant object | |
295 to be processed. | |
296 | |
297 | |
298 =cut | |
299 | |
300 sub process_seq{ | |
301 my ($self,$seq) = @_; | |
302 | |
303 return ($seq); | |
304 } | |
305 | |
306 1; |