Bioperl: SeqIO drivers

Hilmar Lapp hlapp@gmx.net
Wed, 10 May 2000 09:47:23 +0200


Ewan Birney wrote:
> Can you write a very short example about how you would extend/override
> a SeqIO system using your new code? Basicaly I am happy for it to go in
> if it look s sane and works basically like the old stuff...
> 

# install a driver for your own format, which you've put in mydriver.pm
# and the files end in .fmt, you call the format myfmt
%driver_spec = ('MODULE' => 'mydriver.pm', 'REGEXP' => "\\.fmt\$");
Bio::SeqIO->registerDriver("myfmt", %driver_spec);
# then from anywhere in the program
$seqin = Bio::SeqIO->new('-file' => 'input.fmt'); # will return an object
                                                  # of mydriver.pm

# to replace a driver for an existing format with your own:
%driver_spec = Bio::SeqIO->getDriver("fasta");
# retain the format recognition expression, just replace the module name
$driver_spec{'MODULE'} = "myfasta.pm";
# and re-install
Bio::SeqIO->registerDriver("fasta", %driver_spec);
# then from anyhwere in your program
$seqin = Bio::SeqIO->new('-file' => 'seqs.fasta'); # will now return an object
                                                   # of myfasta.pm

There is now code which initializes SeqIO such that the existing formats are
already "registered". I'm not so familiar with perl guts, but I think there's
something like a BEGIN section in a module that is executed upon 
use a_module;
anywhere. So, by this section one could even have modules registering
themselves once you include them as a use statement.

I used a hash as driver property spec because this can be extended at any
time, and you can set your own tags at runtime, which would then be accessible
to your driver module (given that you know which special tags your driver
understands).

	Hilmar

-- 
-----------------------------------------------------------------------
Hilmar Lapp                                      email: hlapp@gmx.net
NFI Vienna, IFD/Bioinformatics                   phone: +43 1 86634 631
A-1235 Vienna                                      fax: +43 1 86634 727
ROI: Bioinformatics (arrays, expression, seqs), Programming, Databases,
     Mountain Biking (hard tail, hard fork: feel the trail)
-----------------------------------------------------------------------
=========== Bioperl Project Mailing List Message Footer =======
Project URL: http://bio.perl.org/
For info about how to (un)subscribe, where messages are archived, etc:
http://www.techfak.uni-bielefeld.de/bcd/Perl/Bio/vsns-bcd-perl.html
====================================================================