[Bioperl-l] Bio::FeatureIO::gff bug?

Chris Fields cjfields at uiuc.edu
Tue Sep 25 10:14:04 EDT 2007

On Sep 25, 2007, at 5:00 AM, Sendu Bala wrote:

> Hilmar Lapp wrote:
>> On Sep 24, 2007, at 9:35 AM, Chris Fields wrote:
>>> I think that'll work fine.  The other option would be call a
>>> print_gff_header() function within write_feature() with the  
>>> intent to
>>> print the header only once, using a flag or similar:
>>> if (!$self->header_printed) {
>>>      $self->print_gff_header;
>>>      $self->header_printed(1);
>>> }
>> I'd lean toward this or a similar approach too. Writing stuff out  
>> in the
>> constructor doesn't feel like the best design.
> I'd argue that the alternative is just inefficient with no  
> compensating
> benefit. You have something that must only be done once, and a method
> (_initialize) that is only called once. The constructor is used to set
> up the file, getting it into a state ready to add features. This
> involves opening it for writing with the correct filename and setting
> the desired GFF version. Why wouldn't it also output what ever else  
> was
> necessary it initialize the file?

It's great to have someone picking this up, so anything that works is  
fine by me, to tell the truth.  I'll state my piece, though, and  
stand out of the way.

In my opinion there are a couple of compensating benefits.  One is  
long-term maintenance, primarily being all calls to generate output  
are contained within the write_features method and are thus easier to  
find and more maintainable.  The logic goes, if there were a bug I  
would expect to find output in a write_* method or a method called  
from within write_* method, not in the constructor or something  
called from the constructor, like _initialize().  I've always been  
told the constructor in any OO language is typically limited to  
setting state data and behavior, not generating new data (i.e.  
generating output).

Related to that, the other benefit is expected behavior when calling  
a method.  I don't know of cases in other IO classes in Bioperl which  
generate output when a new() instance is created; output is expected  
specifically when calling a particular write_* method.  Therefore I  
wouldn't expect any output be generated until write_feature() were  
called (or calling similarly named methods where output would be  
expected, like a print_* method).

Saying all that, I'm probably not the best one to bang the 'best  
practices' drum right now as I haven't had time to finish up several  
modules I've been working on!  Speaking of (going back to work...)

> Also, what do we expect should happen when we use Bioperl to create a
> GFF file and don't write any features to it? Should it be an empty  
> file,
> or should it contain whatever GFF information the user had managed to
> supply (the version)?

As mentioned above, I would expect no output generated at all unless  
explicitly calling write_features(), just like any of the other IOs;  
the header info would be generated then.  BioPerl has traditionally  
been for whatever works though, which is fine by me.


More information about the Bioperl-l mailing list