[Bioperl-l] Re: How to extend a class in bioperl?

Jason Stajich jason.stajich at duke.edu
Mon Apr 25 11:57:51 EDT 2005

You don't want those enclosing {}

This is the minimum it takes to extend an object

package AnTree;
use vars qw(@ISA);
use Bio::Tree::Tree;
@ISA = qw(Bio::Tree::Tree);

# your routines here


If you aren't adding any initialization arguments to the object you 
don't need to implement the 'new' function.

If you want TreeIO to create AnTrees instead Bio::Tree::Tree you need 
to just do this
# initialize Bio::TreeIO like normal
my $treeio = Bio::TreeIO->new(-format => 'newick', -file => 
# reset the Tree object type that is created

Jason Stajich
jason.stajich at duke.edu

On Apr 25, 2005, at 9:49 AM, Sally Li wrote:

> Hi, there,
> Thanks to Jason, Will and Brian for the help in
> storage of an object.
> Now, I have a techical question. It may be a general
> OO programming one. How to make a parent instance into
> a child instance so that it has the methods of the
> child class?
> Attached are three files for the extension of
> Bio::Tree::Tree class (AnTree.pm file), the test
> script (AnTreeProcessV.pl) and the tree file
> (testTree). My goal in this example is to make the
> instance $myTree, which is an instance of Tree, have
> the methods of AnTree so that I can use the methods
> (like, getUnsortedNodes ()). As you see, the AnTree.pm
> have the same attributes as Bio::Tree::Tree but more
> methods.
> This is the way I would like to use to extend a class.
> It is easy to manage the codes (in my opinion). I
> don't have to use the same name as Bio::Tree::Tree,
> which I used to modify a class in Bioperl.
> Thank you for help!
> Sally
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com <AnTree.pm><AnTreeProcessV.pl><testTree>

More information about the Bioperl-l mailing list