35
# usually you won't instantiate this yourself -- a SeqIO object
36
# will have one already
35
# usually you won't instantiate this yourself - a SeqIO object -
36
# you will have one already
37
37
my $seqin = Bio::SeqIO->new(-fh => \*STDIN, -format => "genbank");
38
38
my $builder = $seqin->sequence_builder();
69
69
easy-to-use configurator of the parsing flow.
71
71
Configuring the parsing process may be for you if you need much less
72
information, or much less sequences, than the stream actually
72
information, or much less sequence, than the stream actually
73
73
contains. Configuration can in both cases speed up the parsing time
74
74
considerably, because unwanted sections or the rest of unwanted
75
sequences are skipped over by the parser.
75
sequences are skipped over by the parser. This configuration could
76
also conserve memory if you're running out of available RAM.
77
78
See the methods of the class-specific implementation section for
78
79
further documentation of what can be configured.
85
86
Bioperl modules. Send your comments and suggestions preferably to
86
87
the Bioperl mailing list. Your participation is much appreciated.
88
bioperl-l@bioperl.org - General discussion
89
http://bioperl.org/MailList.shtml - About the mailing lists
89
bioperl-l@bioperl.org - General discussion
90
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
91
92
=head2 Reporting Bugs
93
94
Report bugs to the Bioperl bug tracking system to help us keep track
94
95
of the bugs and their resolution. Bug reports can be submitted via
97
bioperl-bugs@bioperl.org
98
http://bugzilla.bioperl.org/
98
http://bugzilla.open-bio.org/
100
100
=head1 AUTHOR - Hilmar Lapp
102
102
Email hlapp at gmx.net
106
Additional contributors names and emails here
110
106
The rest of the documentation details each of the object methods.
119
115
package Bio::Seq::SeqBuilder;
123
118
# Object preamble - inherits from Bio::Root::Root
126
use Bio::Factory::ObjectBuilderI;
128
@ISA = qw(Bio::Root::Root Bio::Factory::ObjectBuilderI);
121
use base qw(Bio::Root::Root Bio::Factory::ObjectBuilderI);
130
123
my %slot_param_map = ("add_SeqFeature" => "features",
140
133
Returns : an instance of Bio::Seq::SeqBuilder
147
139
my($class,@args) = @_;
149
141
my $self = $class->SUPER::new(@args);
151
143
$self->{'wanted_slots'} = [];
152
144
$self->{'unwanted_slots'} = [];
153
145
$self->{'object_conds'} = [];
189
my ($self,$slot) = @_;
181
my ($self,$slot) = @_;
192
$slot = substr($slot,1) if substr($slot,0,1) eq '-';
193
if($self->want_all()) {
184
$slot = substr($slot,1) if substr($slot,0,1) eq '-';
185
if($self->want_all()) {
194
186
foreach ($self->get_unwanted_slots()) {
195
# this always overrides in want-all mode
196
return 0 if($slot eq $_);
187
# this always overrides in want-all mode
188
return 0 if($slot eq $_);
198
190
if(! exists($self->{'_objskel'})) {
199
$self->{'_objskel'} = $self->sequence_factory->create_object();
191
$self->{'_objskel'} = $self->sequence_factory->create_object();
201
193
if(exists($param_slot_map{$slot})) {
202
$ok = $self->{'_objskel'}->can($param_slot_map{$slot});
194
$ok = $self->{'_objskel'}->can($param_slot_map{$slot});
204
$ok = $self->{'_objskel'}->can($slot);
196
$ok = $self->{'_objskel'}->can($slot);
206
198
return $ok if $ok;
207
199
# even if the object 'cannot' do this slot, it might have been
208
200
# added to the list of wanted slot, so carry on
210
foreach ($self->get_wanted_slots()) {
202
foreach ($self->get_wanted_slots()) {
219
211
=head2 add_slot_value
255
247
starting with a dash, and each element at an odd index is
256
248
the value of the preceding name.
261
252
sub add_slot_value{
262
my ($self,$slot,@args) = @_;
253
my ($self,$slot,@args) = @_;
264
my $h = $self->{'_objhash'};
266
# multiple named parameter variant of calling?
267
if((@args > 1) && (@args % 2) && (substr($slot,0,1) eq '-')) {
268
unshift(@args, $slot);
270
my $key = shift(@args);
271
$h->{$key} = shift(@args);
274
if($slot eq 'add_SeqFeature') {
275
$slot = '-'.$slot_param_map{$slot};
276
$h->{$slot} = [] unless $h->{$slot};
277
push(@{$h->{$slot}}, @args);
255
my $h = $self->{'_objhash'};
257
# multiple named parameter variant of calling?
258
if((@args > 1) && (@args % 2) && (substr($slot,0,1) eq '-')) {
259
unshift(@args, $slot);
261
my $key = shift(@args);
262
$h->{$key} = shift(@args);
279
$slot = '-'.$slot unless substr($slot,0,1) eq '-';
280
$h->{$slot} = $args[0];
265
if($slot eq 'add_SeqFeature') {
266
$slot = '-'.$slot_param_map{$slot};
267
$h->{$slot} = [] unless $h->{$slot};
268
push(@{$h->{$slot}}, @args);
270
$slot = '-'.$slot unless substr($slot,0,1) eq '-';
271
$h->{$slot} = $args[0];
286
277
=head2 want_object
303
294
the present object, and FALSE otherwise.
313
foreach my $cond ($self->get_object_conditions()) {
314
$ok = &$cond($self->{'_objhash'});
317
delete $self->{'_objhash'} unless $ok;
303
foreach my $cond ($self->get_object_conditions()) {
304
$ok = &$cond($self->{'_objhash'});
307
delete $self->{'_objhash'} unless $ok;
321
311
=head2 make_object
338
328
Returns : the object that was built
348
if(exists($self->{'_objhash'}) && %{$self->{'_objhash'}}) {
349
$obj = $self->sequence_factory->create_object(%{$self->{'_objhash'}});
351
$self->{'_objhash'} = {}; # reset
337
if(exists($self->{'_objhash'}) && %{$self->{'_objhash'}}) {
338
$obj = $self->sequence_factory->create_object(%{$self->{'_objhash'}});
340
$self->{'_objhash'} = {}; # reset
355
344
=head1 Implementation specific methods
408
397
Args : an array of slot names (strings)
413
401
sub add_wanted_slot{
414
my ($self,@slots) = @_;
402
my ($self,@slots) = @_;
416
my $myslots = $self->{'wanted_slots'};
417
foreach my $slot (@slots) {
418
if(! grep { $slot eq $_; } @$myslots) {
419
push(@$myslots, $slot);
404
my $myslots = $self->{'wanted_slots'};
405
foreach my $slot (@slots) {
406
if(! grep { $slot eq $_; } @$myslots) {
407
push(@$myslots, $slot);
425
413
=head2 remove_wanted_slots
432
420
Returns : the previous list of wanted slot names
438
425
sub remove_wanted_slots{
440
my @slots = $self->get_wanted_slots();
441
$self->{'wanted_slots'} = [];
427
my @slots = $self->get_wanted_slots();
428
$self->{'wanted_slots'} = [];
445
432
=head2 get_unwanted_slots
470
456
Args : an array of slot names (strings)
475
460
sub add_unwanted_slot{
476
my ($self,@slots) = @_;
461
my ($self,@slots) = @_;
478
my $myslots = $self->{'unwanted_slots'};
479
foreach my $slot (@slots) {
480
if(! grep { $slot eq $_; } @$myslots) {
481
push(@$myslots, $slot);
463
my $myslots = $self->{'unwanted_slots'};
464
foreach my $slot (@slots) {
465
if(! grep { $slot eq $_; } @$myslots) {
466
push(@$myslots, $slot);
487
472
=head2 remove_unwanted_slots
494
479
Returns : the previous list of unwanted slot names
500
484
sub remove_unwanted_slots{
502
my @slots = $self->get_unwanted_slots();
503
$self->{'unwanted_slots'} = [];
486
my @slots = $self->get_unwanted_slots();
487
$self->{'unwanted_slots'} = [];
551
534
Args : on set, new value (a scalar or undef, optional)
559
return $self->{'want_all'} = shift if @_;
560
return $self->{'want_all'};
541
return $self->{'want_all'} = shift if @_;
542
return $self->{'want_all'};
563
545
=head2 get_object_conditions
579
561
Returns : a list of closures
585
566
sub get_object_conditions{
588
return @{$self->{'object_conds'}};
569
return @{$self->{'object_conds'}};
591
572
=head2 add_object_condition
609
590
Args : the list of conditions
614
594
sub add_object_condition{
615
my ($self,@conds) = @_;
595
my ($self,@conds) = @_;
617
if(grep { ref($_) ne 'CODE'; } @conds) {
618
$self->throw("conditions against which to validate an object ".
619
"must be anonymous code blocks");
621
push(@{$self->{'object_conds'}}, @conds);
597
if(grep { ref($_) ne 'CODE'; } @conds) {
598
$self->throw("conditions against which to validate an object ".
599
"must be anonymous code blocks");
601
push(@{$self->{'object_conds'}}, @conds);
625
605
=head2 remove_object_conditions
632
612
Returns : The list of previously set conditions (an array of closures)
638
617
sub remove_object_conditions{
640
my @conds = $self->get_object_conditions();
641
$self->{'object_conds'} = [];
619
my @conds = $self->get_object_conditions();
620
$self->{'object_conds'} = [];
645
624
=head1 Methods to control what type of object is built
657
636
Args : on set, new value (a Bio::Factory::SequenceFactoryI
658
637
implementing object or undef, optional)
663
641
sub sequence_factory{
667
delete $self->{'_objskel'};
668
return $self->{'sequence_factory'} = shift;
670
return $self->{'sequence_factory'};
645
delete $self->{'_objskel'};
646
return $self->{'sequence_factory'} = shift;
648
return $self->{'sequence_factory'};