[Bioperl-l] Mixed bless-ings with Bio::Seq/Bio::PrimarySeq (Bio::Seq::Meta::Array)

Chris Fields cjfields at uiuc.edu
Thu Apr 5 17:40:41 UTC 2007


Roy Chaudhuri has raised an interesting question in a bug report  
filed regarding 'bless'-ing objects into another (similar) class.   
The bug report on this is here:

http://bugzilla.open-bio.org/show_bug.cgi?id=2262

The following code (from the bug report) illustrates the problem.   
Note some of this is taken from the Bio::Seq::Meta::Array POD, though  
the example sequence object is a LocatableSeq (PrimarySeqI) and not a  
SeqI:

use Bio::SeqIO;
use Bio::Seq::Meta::Array;
# $seq isa Bio::SeqI
my $seq=Bio::SeqIO->new(-fh=>\*ARGV, -format=>'genbank')->next_seq;
# $seq is still a Bio::SeqI
bless $seq, 'Bio::Seq::Meta::Array';
Bio::SeqIO->new(-format=>'genbank')->write_seq($seq);

This produces sequence output missing sequence data, a definition,  
and other odds and ends.  $seq is first a Bio::Seq::RichSeq and is  
blessed into a Bio::Seq::Meta::Array; both times $seq remains  
Bio::SeqI.  However, Bio::Seq::Meta::Array has an odd inheritance  
tree which also makes it a Bio::PrimarySeqI and a Bio::Seq::MetaI (ick):

use base qw(Bio::LocatableSeq Bio::Seq Bio::Seq::MetaI);

Bio::LocatableSeq has a seq() method inherited from Bio::PrimarySeq,  
for instance, so using $seq->seq() invokes Bio::PrimarySeq::seq()  
instead of Bio::Seq::seq().  No problem in most cases as long as  
PrimarySeqI is blessed into another PrimarySeqI, but if one blesses a  
Bio::SeqI into a Bio::Seq::Meta::Array (as in the example) then  
PrimarySeq::seq() expects a raw sequence and gets none (since the  
data is stored internally as a PrimarySeq in a different location)  
and no sequence is output.  This happens similarly for other stored  
object data.

I'm not sure why Bio::Seq::Meta::Array is set up this way.  Do we  
want to support using 'bless $obj, Class' with Bio::SeqI/PrimarySeqI,  
or should Bio::Seq::Meta::Array be changed so that it follows one  
interface or the other?

chris



More information about the Bioperl-l mailing list