[Bioperl-l] general design of the IO system

Jason Stajich jason at cgt.duhs.duke.edu
Tue Mar 30 11:49:51 EST 2004


In the new method seeing the format as defined by
-format => 'fasta'
then gets mapped to a modulename 'Bio::SeqIO::fasta' and it calls new on
this module, basically like this
 my $mod = 'Bio::SeqIO::fasta';
 return $mod->new( @args );

So Bio::SeqIO::fasta new is called, then it delegates to its superclass
(Bio::SeqIO).  But this time around things are different because $class is
now different.

When the inherited Bio::SeqIO::new is called there is a test for classname
if( $class =~ /Bio::SeqIO::(\S+)/ ) {
        my ($self) = $class->SUPER::new(@args);
        $self->_initialize(@args);
        return $self;
}

There is a set of subsequent hierarchical _initialize calls made as well.

All of this is in place so that we can
 - Inherit from Bio::Root::Root
 - have initialization arguments be handled by superclasses so that a
   method signature is respected and a superclass implementer doesn't have
   to add a bunch of copy+paste code every time we add a new
   initialization parameter to all the subclasses.

This is the forced way of doing OO in Perl unfortunately.

Yes it is a little bit inefficient, but the biggest hit we take seems
to be is Bio::Root::Root _rearrange method being recalled many times and
its conversions of arrays to hashes.

-jason
On Tue, 30 Mar 2004, Steffen Grossmann wrote:

> Dear all,
>
> I am at the moment having a hard time trying to understand the basic
> design of the IO system.
>
> For example, in Bio::SeqIO I don't understand the trick which makes an
> object created with Bio::SeqIO->new look like a Bio::SeqIO object but
> behave like a, e.g., Bio::SeqIO::fasta object.
>
> Actually, the 'new' method in Bio::SeqIO looks circular to me.
>
> Please, if one of you wizards could explain this to me or give me a hint
> where to find the design documented?
>
> Thanks a lot!
>
> Steffen
>
>

--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu


More information about the Bioperl-l mailing list