This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Inheritance Question In Bioperl

I am writing a Perl application that processes a lot of GFF3 data. I'm using BioPerl's GFF3 parser (Bio::Tools::GFF) which returns objects of type Bio::SeqFeature::Generic. I have written a class (let's call it My::Feature) that extends the Bio::SeqFeature::Generic class a bit with some methods that make it easier to work with the objects.

My question is how to create an object of this new type from an existing Bio::SeqFeature::Generic object. I want to continue to use the BioPerl GFF3 parser to do all the hard work, but that parser gives me Bio::SeqFeature::Generic objects. Once I have one of these objects, how could I convert it into a My::Feature object?

Thanks.

PS. Maybe I'm asking the wrong question. Maybe I should be asking if there is a way for the Bio::Tools::GFF parser to return My::Feature objects.

perl bioperl

1 answer

This is not so much a Bioperl question as an inheritance one.

You will need to write a constructor which takes a BSF::G and returns your object. It will look something like

sub new_from_generic {
    my $class = shift;
    my $generic = shift;
    my $self = bless($generic, $class); # to change its type
    ...
    return $self;
}

Note that the whole reblessing thing assumes that you are actually inheriting from BSF::G. While I'm not a huge fan of inheritance vs. containment, in this case, you're probably best off doing so, since so many of the BioPerl modules use the Bio::Seq::I interface.

As far getting them generic Bio::Tools::GFF to return your subclass, you'd also need to wrap or subclass it to convert the BSF::G output before handing them off. Honestly, I'd suggest just wrapping it unless you're making heavy use of the various parts of the GFF package, instead of just using it as a loader.

Log in to answer this question.