~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to Bio/SeqIO.pm

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
                           -format => 'EMBL');
29
29
 
30
30
    while ( my $seq = $in->next_seq() ) {
31
 
            $out->write_seq($seq);
 
31
        $out->write_seq($seq);
32
32
    }
33
33
 
34
34
  # Now, to actually get at the sequence object, use the standard Bio::Seq
98
98
    # read from standard input or the input filenames
99
99
 
100
100
    while ( $seq = <$stream> ) {
101
 
          # do something with $seq
 
101
        # do something with $seq
102
102
    }
103
103
 
104
104
and
131
131
   $seqIO = Bio::SeqIO->new(-fh   => \*FILEHANDLE, -format=>$format);
132
132
   $seqIO = Bio::SeqIO->new(-format => $format);
133
133
 
134
 
The new() class method constructs a new Bio::SeqIO object.  The
 
134
The new() class method constructs a new Bio::SeqIO object. The
135
135
returned object can be used to retrieve or print Seq objects. new()
136
136
accepts the following parameters:
137
137
 
170
170
  use Bio::SeqIO;
171
171
  use IO::String;
172
172
  my $in  = Bio::SeqIO->new(-file => "emblfile",
173
 
                            -format => 'EMBL');
 
173
                            -format => 'EMBL');
174
174
  while ( my $seq = $in->next_seq() ) {
175
175
      # the output handle is reset for every file
176
176
      my $stringio = IO::String->new($string);
177
177
      my $out = Bio::SeqIO->new(-fh => $stringio,
178
 
                                -format => 'fasta');
 
178
                                -format => 'fasta');
179
179
      # output goes into $string
180
180
      $out->write_seq($seq);
181
181
      # modify $string
227
227
                           -flush  => 0); # go as fast as we can!
228
228
  while($seq = $gb->next_seq) { $fa->write_seq($seq) }
229
229
 
 
230
=item -seqfactory
 
231
 
 
232
Provide a Bio::Factory::SequenceFactoryI object. See the sequence_factory() method.
 
233
 
 
234
=item -locfactory
 
235
 
 
236
Provide a Bio::Factory::LocationFactoryI object. See the location_factory() method.
 
237
 
 
238
=item -objbuilder
 
239
 
 
240
Provide a Bio::Factory::ObjectBuilderI object. See the object_builder() method.
230
241
 
231
242
=back
232
243
 
312
323
package Bio::SeqIO;
313
324
 
314
325
use strict;
 
326
use warnings;
315
327
 
316
328
use Bio::Factory::FTLocationFactory;
317
329
use Bio::Seq::SeqBuilder;
318
330
use Bio::Tools::GuessSeqFormat;
319
331
use Symbol;
320
332
 
321
 
use base qw(Bio::Root::Root Bio::Root::IO Bio::Factory::SequenceStreamI);
 
333
use parent qw(Bio::Root::Root Bio::Root::IO Bio::Factory::SequenceStreamI);
322
334
 
323
335
my %valid_alphabet_cache;
324
336
 
 
337
 
325
338
=head2 new
326
339
 
327
340
 Title   : new
328
 
 Usage   : $stream = Bio::SeqIO->new(-file => $filename,
329
 
                                     -format => 'Format')
 
341
 Usage   : $stream = Bio::SeqIO->new(-file => 'sequences.fasta',
 
342
                                     -format => 'fasta');
330
343
 Function: Returns a new sequence stream
331
344
 Returns : A Bio::SeqIO stream initialised with the appropriate format
332
345
 Args    : Named parameters:
333
 
             -file => $filename
334
 
             -fh => filehandle to attach to
 
346
             -file   => filename
 
347
             -fh     => filehandle to attach to
335
348
             -format => format
336
349
 
337
 
           Additional arguments may be used to set factories and
338
 
           builders involved in the sequence object creation. None of
339
 
           these must be provided, they all have reasonable defaults.
340
 
             -seqfactory   the Bio::Factory::SequenceFactoryI object
341
 
             -locfactory   the Bio::Factory::LocationFactoryI object
342
 
             -objbuilder   the Bio::Factory::ObjectBuilderI object
 
350
           Additional arguments may be used. They all have reasonable defaults
 
351
           and are thus optional.
 
352
             -alphabet   => 'dna', 'rna', or 'protein'
 
353
             -flush      => 0 or 1 (default, flush filehandles after each write)
 
354
             -seqfactory => sequence factory
 
355
             -locfactory => location factory
 
356
             -objbuilder => object builder
343
357
 
344
358
See L<Bio::SeqIO::Handler>
345
359
 
348
362
my $entry = 0;
349
363
 
350
364
sub new {
351
 
        my ($caller,@args) = @_;
352
 
        my $class = ref($caller) || $caller;
353
 
 
354
 
        # or do we want to call SUPER on an object if $caller is an
355
 
        # object?
356
 
        if( $class =~ /Bio::SeqIO::(\S+)/ ) {
357
 
                my ($self) = $class->SUPER::new(@args);
358
 
                $self->_initialize(@args);
359
 
                return $self;
360
 
        } else {
361
 
 
362
 
                my %param = @args;
363
 
                @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
364
 
 
365
 
                unless( defined $param{-file} ||
366
 
                        defined $param{-fh}   ||
367
 
                        defined $param{-string} ) {
368
 
                    $class->throw("file argument provided, but with an undefined value") 
369
 
                        if exists $param{'-file'};
370
 
                    $class->throw("fh argument provided, but with an undefined value") 
371
 
                        if exists $param{'-fh'};
372
 
                    $class->throw("string argument provided, but with an undefined value") 
373
 
                        if exists($param{'-string'});
374
 
                    # $class->throw("No file, fh, or string argument provided"); # neither defined
375
 
                }
376
 
 
377
 
        my $format = $param{'-format'} ||
378
 
            $class->_guess_format( $param{-file} || $ARGV[0] );
 
365
    my ($caller,@args) = @_;
 
366
    my $class = ref($caller) || $caller;
 
367
 
 
368
    # or do we want to call SUPER on an object if $caller is an
 
369
    # object?
 
370
    if( $class =~ /Bio::SeqIO::(\S+)/ ) {
 
371
        my ($self) = $class->SUPER::new(@args);
 
372
        $self->_initialize(@args);
 
373
        return $self;
 
374
    } else {
 
375
 
 
376
        my %param = @args;
 
377
        @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
 
378
 
 
379
        unless( defined $param{-file} ||
 
380
                defined $param{-fh}   ||
 
381
                defined $param{-string} ) {
 
382
            $class->throw("file argument provided, but with an undefined value") 
 
383
                if exists $param{'-file'};
 
384
            $class->throw("fh argument provided, but with an undefined value") 
 
385
                if exists $param{'-fh'};
 
386
            $class->throw("string argument provided, but with an undefined value") 
 
387
                if exists($param{'-string'});
 
388
            # $class->throw("No file, fh, or string argument provided"); # neither defined
 
389
        }
 
390
 
 
391
        my $format = $param{'-format'} ||
 
392
            $class->_guess_format( $param{-file} || $ARGV[0] );
379
393
        
380
 
        if( ! $format ) {
381
 
            if ($param{-file}) {
382
 
                $format = Bio::Tools::GuessSeqFormat->new(-file => $param{-file}||$ARGV[0] )->guess;
383
 
            } elsif ($param{-fh}) {
384
 
                $format = Bio::Tools::GuessSeqFormat->new(-fh => $param{-fh}||$ARGV[0] )->guess;
385
 
            }
386
 
        }
387
 
    # changed 1-3-11; no need to print out an empty string (only way this
388
 
    # exception is triggered) - cjfields
389
 
    $class->throw("Could not guess format from file/fh") unless $format;
390
 
        $format = "\L$format";  # normalize capitalization to lower case
391
 
 
392
 
    if ($format =~ /-/) {
393
 
        ($format, my $variant) = split('-', $format, 2);
394
 
        push @args, (-variant => $variant);
395
 
    }
396
 
        return unless( $class->_load_format_module($format) );
397
 
        return "Bio::SeqIO::$format"->new(@args);
 
394
        if( ! $format ) {
 
395
            if ($param{-file}) {
 
396
                $format = Bio::Tools::GuessSeqFormat->new(-file => $param{-file}||$ARGV[0] )->guess;
 
397
            } elsif ($param{-fh}) {
 
398
                $format = Bio::Tools::GuessSeqFormat->new(-fh => $param{-fh}||$ARGV[0] )->guess;
 
399
            }
 
400
        }
 
401
        # changed 1-3-11; no need to print out an empty string (only way this
 
402
        # exception is triggered) - cjfields
 
403
        $class->throw("Could not guess format from file/fh") unless $format;
 
404
        $format = "\L$format";  # normalize capitalization to lower case
 
405
 
 
406
        if ($format =~ /-/) {
 
407
            ($format, my $variant) = split('-', $format, 2);
 
408
            push @args, (-variant => $variant);
 
409
        }
 
410
 
 
411
 
 
412
        return unless( $class->_load_format_module($format) );
 
413
        return "Bio::SeqIO::$format"->new(@args);
398
414
    }
399
415
}
400
416
 
 
417
 
401
418
=head2 newFh
402
419
 
403
420
 Title   : newFh
404
421
 Usage   : $fh = Bio::SeqIO->newFh(-file=>$filename,-format=>'Format')
405
 
 Function: does a new() followed by an fh()
 
422
 Function: Does a new() followed by an fh()
406
423
 Example : $fh = Bio::SeqIO->newFh(-file=>$filename,-format=>'Format')
407
424
           $sequence = <$fh>;   # read a sequence object
408
425
           print $fh $sequence; # write a sequence object
414
431
=cut
415
432
 
416
433
sub newFh {
417
 
  my $class = shift;
418
 
  return unless my $self = $class->new(@_);
419
 
  return $self->fh;
 
434
    my $class = shift;
 
435
    return unless my $self = $class->new(@_);
 
436
    return $self->fh;
420
437
}
421
438
 
 
439
 
422
440
=head2 fh
423
441
 
424
442
 Title   : fh
425
443
 Usage   : $obj->fh
426
 
 Function:
 
444
 Function: Get or set the IO filehandle
427
445
 Example : $fh = $obj->fh;      # make a tied filehandle
428
446
           $sequence = <$fh>;   # read a sequence object
429
447
           print $fh $sequence; # write a sequence object
432
450
 
433
451
=cut
434
452
 
435
 
 
436
453
sub fh {
437
 
  my $self = shift;
438
 
  my $class = ref($self) || $self;
439
 
  my $s = Symbol::gensym;
440
 
  tie $$s,$class,$self;
441
 
  return $s;
 
454
    my $self = shift;
 
455
    my $class = ref($self) || $self;
 
456
    my $s = Symbol::gensym;
 
457
    tie $$s,$class,$self;
 
458
    return $s;
442
459
}
443
460
 
 
461
 
444
462
# _initialize is chained for all SeqIO classes
445
463
 
446
464
sub _initialize {
447
 
        my($self, @args) = @_;
448
 
 
449
 
        # flush is initialized by the Root::IO init
450
 
 
451
 
        my ($seqfact,$locfact,$objbuilder, $alphabet) =
452
 
          $self->_rearrange([qw(SEQFACTORY
453
 
                              LOCFACTORY
454
 
                              OBJBUILDER
455
 
                  ALPHABET)
456
 
                                                          ], @args);
457
 
 
458
 
        $locfact = Bio::Factory::FTLocationFactory->new(-verbose => $self->verbose)
459
 
          if ! $locfact;
460
 
        $objbuilder = Bio::Seq::SeqBuilder->new(-verbose => $self->verbose)
461
 
          unless $objbuilder;
462
 
        $self->sequence_builder($objbuilder);
463
 
        $self->location_factory($locfact);
464
 
 
465
 
        # note that this should come last because it propagates the sequence
466
 
        # factory to the sequence builder
467
 
        $seqfact && $self->sequence_factory($seqfact);
 
465
    my($self, @args) = @_;
 
466
 
 
467
    # flush is initialized by the Root::IO init
 
468
 
 
469
    my ($seqfact,$locfact,$objbuilder, $alphabet) =
 
470
        $self->_rearrange([qw(SEQFACTORY
 
471
                              LOCFACTORY
 
472
                              OBJBUILDER
 
473
                              ALPHABET)
 
474
                                         ], @args);
 
475
 
 
476
    $locfact = Bio::Factory::FTLocationFactory->new(-verbose => $self->verbose)
 
477
        if ! $locfact;
 
478
    $objbuilder = Bio::Seq::SeqBuilder->new(-verbose => $self->verbose)
 
479
        unless $objbuilder;
 
480
    $self->sequence_builder($objbuilder);
 
481
    $self->location_factory($locfact);
 
482
 
 
483
    # note that this should come last because it propagates the sequence
 
484
    # factory to the sequence builder
 
485
    $seqfact && $self->sequence_factory($seqfact);
468
486
        
469
487
    #bug 2160
470
488
    $alphabet && $self->alphabet($alphabet);
471
489
 
472
 
 
473
 
        # initialize the IO part
474
 
        $self->_initialize_io(@args);
 
490
    # initialize the IO part
 
491
    $self->_initialize_io(@args);
475
492
}
476
493
 
 
494
 
477
495
=head2 next_seq
478
496
 
479
497
 Title   : next_seq
506
524
   $self->throw("Sorry, you cannot read from a generic Bio::SeqIO object.");
507
525
}
508
526
 
 
527
 
509
528
=head2 write_seq
510
529
 
511
530
 Title   : write_seq
522
541
}
523
542
 
524
543
 
 
544
=head2 format
 
545
 
 
546
 Title   : format
 
547
 Usage   : $format = $stream->format()
 
548
 Function: Get the sequence format
 
549
 Returns : sequence format, e.g. fasta, fastq
 
550
 Args    : none
 
551
 
 
552
=cut
 
553
 
 
554
# format() method inherited from Bio::Root::IO
 
555
 
 
556
 
525
557
=head2 alphabet
526
558
 
527
559
 Title   : alphabet
538
570
   my ($self, $value) = @_;
539
571
 
540
572
   if ( defined $value) {
541
 
                $value = lc $value;
542
 
                unless ($valid_alphabet_cache{$value}) {
543
 
                        # instead of hard-coding the allowed values once more, we check by
544
 
                        # creating a dummy sequence object
545
 
                        eval {
546
 
                                require Bio::PrimarySeq;
547
 
                                my $seq = Bio::PrimarySeq->new('-verbose' => $self->verbose,
548
 
                                                                                                                 '-alphabet' => $value);
549
 
                        };
550
 
                        if ($@) {
551
 
                                $self->throw("Invalid alphabet: $value\n. See Bio::PrimarySeq for allowed values.");
552
 
                        }
553
 
                        $valid_alphabet_cache{$value} = 1;
554
 
                }
555
 
                $self->{'alphabet'} = $value;
 
573
        $value = lc $value;
 
574
        unless ($valid_alphabet_cache{$value}) {
 
575
            # instead of hard-coding the allowed values once more, we check by
 
576
            # creating a dummy sequence object
 
577
            eval {
 
578
                require Bio::PrimarySeq;
 
579
                my $seq = Bio::PrimarySeq->new('-verbose' => $self->verbose,
 
580
                                                         '-alphabet' => $value);
 
581
            };
 
582
            if ($@) {
 
583
                $self->throw("Invalid alphabet: $value\n. See Bio::PrimarySeq for allowed values.");
 
584
            }
 
585
            $valid_alphabet_cache{$value} = 1;
 
586
        }
 
587
        $self->{'alphabet'} = $value;
556
588
   }
557
589
   return $self->{'alphabet'};
558
590
}
559
591
 
 
592
 
560
593
=head2 _load_format_module
561
594
 
562
595
 Title   : _load_format_module
569
602
=cut
570
603
 
571
604
sub _load_format_module {
572
 
        my ($self, $format) = @_;
573
 
        my $module = "Bio::SeqIO::" . $format;
574
 
        my $ok;
 
605
    my ($self, $format) = @_;
 
606
    my $module = "Bio::SeqIO::" . $format;
 
607
    my $ok;
575
608
 
576
 
        eval {
577
 
                $ok = $self->_load_module($module);
578
 
        };
579
 
        if ( $@ ) {
580
 
                print STDERR <<END;
 
609
    eval {
 
610
        $ok = $self->_load_module($module);
 
611
    };
 
612
    if ( $@ ) {
 
613
        print STDERR <<END;
581
614
$self: $format cannot be found
582
615
Exception $@
583
616
For more information about the SeqIO system please see the SeqIO docs.
584
617
This includes ways of checking for formats at compile time, not run time
585
618
END
586
 
                ;
587
 
        }
588
 
        return $ok;
 
619
        ;
 
620
    }
 
621
    return $ok;
589
622
}
590
623
 
 
624
 
591
625
=head2 _concatenate_lines
592
626
 
593
627
 Title   : _concatenate_lines
604
638
=cut
605
639
 
606
640
sub _concatenate_lines {
607
 
        my ($self, $s1, $s2) = @_;
608
 
 
609
 
        $s1 .= " " if($s1 && ($s1 !~ /-$/) && $s2);
610
 
        return ($s1 ? $s1 : "") . ($s2 ? $s2 : "");
 
641
    my ($self, $s1, $s2) = @_;
 
642
    $s1 .= " " if($s1 && ($s1 !~ /-$/) && $s2);
 
643
    return ($s1 ? $s1 : "") . ($s2 ? $s2 : "");
611
644
}
612
645
 
 
646
 
613
647
=head2 _filehandle
614
648
 
615
649
 Title   : _filehandle
626
660
    return $self->_fh(@args);
627
661
}
628
662
 
 
663
 
629
664
=head2 _guess_format
630
665
 
631
666
 Title   : _guess_format
643
678
sub _guess_format {
644
679
   my $class = shift;
645
680
   return unless $_ = shift;
646
 
   return 'abi'     if /\.ab[i1]$/i;
647
 
   return 'ace'     if /\.ace$/i;
648
 
   return 'alf'     if /\.alf$/i;
649
 
   return 'bsml'    if /\.(bsm|bsml)$/i;
650
 
   return 'ctf'     if /\.ctf$/i;
651
 
   return 'embl'    if /\.(embl|ebl|emb|dat)$/i;
652
 
        return 'entrezgene' if /\.asn$/i;
653
 
   return 'exp'     if /\.exp$/i;
654
 
   return 'fasta'   if /\.(fasta|fast|fas|seq|fa|fsa|nt|aa|fna|faa)$/i;
655
 
   return 'fastq'   if /\.fastq$/i;
656
 
   return 'gcg'     if /\.gcg$/i;
657
 
   return 'genbank' if /\.(gb|gbank|genbank|gbk|gbs)$/i;
658
 
   return 'phd'     if /\.(phd|phred)$/i;
659
 
   return 'pir'     if /\.pir$/i;
660
 
   return 'pln'     if /\.pln$/i;
661
 
   return 'qual'    if /\.qual$/i;
662
 
   return 'raw'     if /\.txt$/i;
663
 
   return 'scf'     if /\.scf$/i;
664
 
   return 'swiss'   if /\.(swiss|sp)$/i;
 
681
   return 'abi'        if /\.ab[i1]$/i;
 
682
   return 'ace'        if /\.ace$/i;
 
683
   return 'alf'        if /\.alf$/i;
 
684
   return 'bsml'       if /\.(bsm|bsml)$/i;
 
685
   return 'ctf'        if /\.ctf$/i;
 
686
   return 'embl'       if /\.(embl|ebl|emb|dat)$/i;
 
687
   return 'entrezgene' if /\.asn$/i;
 
688
   return 'exp'        if /\.exp$/i;
 
689
   return 'fasta'      if /\.(fasta|fast|fas|seq|fa|fsa|nt|aa|fna|faa)$/i;
 
690
   return 'fastq'      if /\.fastq$/i;
 
691
   return 'gcg'        if /\.gcg$/i;
 
692
   return 'genbank'    if /\.(gb|gbank|genbank|gbk|gbs)$/i;
 
693
   return 'phd'        if /\.(phd|phred)$/i;
 
694
   return 'pir'        if /\.pir$/i;
 
695
   return 'pln'        if /\.pln$/i;
 
696
   return 'qual'       if /\.qual$/i;
 
697
   return 'raw'        if /\.txt$/i;
 
698
   return 'scf'        if /\.scf$/i;
 
699
   return 'swiss'      if /\.(swiss|sp)$/i;
665
700
 
666
701
   # from Strider 1.4 Release Notes: The file name extensions used by
667
702
   # Strider 1.4 are ".xdna", ".xdgn", ".xrna" and ".xprt" for DNA,
668
703
   # DNA Degenerate, RNA and Protein Sequence Files, respectively
669
 
   return 'strider' if /\.(xdna|xdgn|xrna|xprt)$/i;
 
704
   return 'strider'    if /\.(xdna|xdgn|xrna|xprt)$/i;
670
705
 
671
 
   return 'ztr'     if /\.ztr$/i;
 
706
   return 'ztr'        if /\.ztr$/i;
672
707
}
673
708
 
 
709
 
674
710
sub DESTROY {
675
 
        my $self = shift;
676
 
        $self->close();
 
711
    my $self = shift;
 
712
    $self->close();
677
713
}
678
714
 
 
715
 
679
716
sub TIEHANDLE {
680
 
        my ($class,$val) = @_;
681
 
        return bless {'seqio' => $val}, $class;
 
717
    my ($class,$val) = @_;
 
718
    return bless {'seqio' => $val}, $class;
682
719
}
683
720
 
 
721
 
684
722
sub READLINE {
685
 
        my $self = shift;
686
 
        return $self->{'seqio'}->next_seq() unless wantarray;
687
 
        my (@list, $obj);
688
 
        push @list, $obj while $obj = $self->{'seqio'}->next_seq();
689
 
        return @list;
 
723
    my $self = shift;
 
724
    return $self->{'seqio'}->next_seq() unless wantarray;
 
725
    my (@list, $obj);
 
726
    push @list, $obj while $obj = $self->{'seqio'}->next_seq();
 
727
    return @list;
690
728
}
691
729
 
 
730
 
692
731
sub PRINT {
693
 
        my $self = shift;
694
 
        $self->{'seqio'}->write_seq(@_);
 
732
    my $self = shift;
 
733
    $self->{'seqio'}->write_seq(@_);
695
734
}
696
735
 
 
736
 
697
737
=head2 sequence_factory
698
738
 
699
739
 Title   : sequence_factory
704
744
 
705
745
=cut
706
746
 
707
 
sub sequence_factory{
708
 
   my ($self,$obj) = @_;
 
747
sub sequence_factory {
 
748
   my ($self, $obj) = @_;
709
749
   if( defined $obj ) {
710
 
                if( ! ref($obj) || ! $obj->isa('Bio::Factory::SequenceFactoryI') ) {
711
 
                        $self->throw("Must provide a valid Bio::Factory::SequenceFactoryI object to ".ref($self)."::sequence_factory()");
712
 
                }
713
 
                $self->{'_seqio_seqfactory'} = $obj;
714
 
                my $builder = $self->sequence_builder();
715
 
                if($builder && $builder->can('sequence_factory') &&
716
 
                        (! $builder->sequence_factory())) {
717
 
                        $builder->sequence_factory($obj);
718
 
                }
 
750
        if( ! ref($obj) || ! $obj->isa('Bio::Factory::SequenceFactoryI') ) {
 
751
            $self->throw("Must provide a valid Bio::Factory::SequenceFactoryI object to ".ref($self)."::sequence_factory()");
 
752
        }
 
753
        $self->{'_seqio_seqfactory'} = $obj;
 
754
        my $builder = $self->sequence_builder();
 
755
        if($builder && $builder->can('sequence_factory') &&
 
756
            (! $builder->sequence_factory())) {
 
757
            $builder->sequence_factory($obj);
 
758
        }
719
759
   }
720
760
   $self->{'_seqio_seqfactory'};
721
761
}
722
762
 
 
763
 
723
764
=head2 object_factory
724
765
 
725
766
 Title   : object_factory
732
773
=cut
733
774
 
734
775
sub object_factory{
735
 
        return shift->sequence_factory(@_);
 
776
    return shift->sequence_factory(@_);
736
777
}
737
778
 
 
779
 
738
780
=head2 sequence_builder
739
781
 
740
782
 Title   : sequence_builder
741
783
 Usage   : $seqio->sequence_builder($seqfactory)
742
784
 Function: Get/Set the Bio::Factory::ObjectBuilderI used to build sequence
743
 
           objects.
 
785
           objects. This applies to rich sequence formats only, e.g. genbank
 
786
           but not fasta.
744
787
 
745
788
           If you do not set the sequence object builder yourself, it
746
789
           will in fact be an instance of L<Bio::Seq::SeqBuilder>, and
751
794
 
752
795
=cut
753
796
 
754
 
sub sequence_builder{
755
 
        my ($self,$obj) = @_;
756
 
        if( defined $obj ) {
757
 
                if( ! ref($obj) || ! $obj->isa('Bio::Factory::ObjectBuilderI') ) {
758
 
                        $self->throw("Must provide a valid Bio::Factory::ObjectBuilderI object to ".ref($self)."::sequence_builder()");
759
 
                }
760
 
                $self->{'_object_builder'} = $obj;
761
 
        }
762
 
        $self->{'_object_builder'};
 
797
sub sequence_builder {
 
798
    my ($self, $obj) = @_;
 
799
    if( defined $obj ) {
 
800
        if( ! ref($obj) || ! $obj->isa('Bio::Factory::ObjectBuilderI') ) {
 
801
            $self->throw("Must provide a valid Bio::Factory::ObjectBuilderI object to ".ref($self)."::sequence_builder()");
 
802
        }
 
803
        $self->{'_object_builder'} = $obj;
 
804
    }
 
805
    $self->{'_object_builder'};
763
806
}
764
807
 
 
808
 
765
809
=head2 location_factory
766
810
 
767
811
 Title   : location_factory
774
818
 
775
819
=cut
776
820
 
777
 
sub location_factory{
778
 
        my ($self,$obj) = @_;
779
 
        if( defined $obj ) {
780
 
                if( ! ref($obj) || ! $obj->isa('Bio::Factory::LocationFactoryI') ) {
781
 
                        $self->throw("Must provide a valid Bio::Factory::LocationFactoryI" .
782
 
                                                         " object to ".ref($self)."->location_factory()");
783
 
                }
784
 
                $self->{'_seqio_locfactory'} = $obj;
785
 
        }
786
 
        $self->{'_seqio_locfactory'};
 
821
sub location_factory {
 
822
    my ($self,$obj) = @_;
 
823
    if( defined $obj ) {
 
824
        if( ! ref($obj) || ! $obj->isa('Bio::Factory::LocationFactoryI') ) {
 
825
            $self->throw("Must provide a valid Bio::Factory::LocationFactoryI" .
 
826
                             " object to ".ref($self)."->location_factory()");
 
827
        }
 
828
        $self->{'_seqio_locfactory'} = $obj;
 
829
    }
 
830
    $self->{'_seqio_locfactory'};
787
831
}
788
832
 
789
833
1;