4 # BioPerl module for Bio::Index::Abstract
6 # Please direct questions and support issues to <bioperl-l@bioperl.org>
8 # Cared for by Ewan Birney <birney@sanger.ac.uk>
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Index::GenBank - Interface for indexing one or more GenBank
17 files (i.e. flat file GenBank format).
21 # Complete code for making an index for one or more GenBank files
23 use Bio::Index::GenBank;
25 my $Index_File_Name = shift;
26 my $inx = Bio::Index::GenBank->new(-filename => $Index_File_Name,
27 -write_flag => 'WRITE');
28 $inx->make_index(@ARGV);
30 # Print out sequences present in the index in gcg format
31 use Bio::Index::GenBank;
35 my $Index_File_Name = shift;
36 my $inx = Bio::Index::GenBank->new(-filename => $Index_File_Name);
37 my $seqio = Bio::SeqIO->new(-format => 'gcg');
38 foreach my $id (@ARGV) {
39 my $seq = $inx->fetch($id); # Returns Bio::Seq object
40 $seqio->write_seq($seq);
45 my $seq1 = $inx->get_Seq_by_id($locus);
46 my $seq2 = $inx->get_Seq_by_acc($acc);
50 By default the index that is created uses the LOCUS, ACCESSION, and
51 VERSION identifiers as keys. Inherits functions for managing dbm
52 files from Bio::Index::Abstract.pm, and provides the basic
53 functionality for indexing GenBank files, and retrieving the
54 sequence from them. For best results 'use strict'.
56 You can also set or customize the unique key used to retrieve by
57 writing your own function and calling the id_parser() method.
60 $inx->id_parser(\&get_id);
62 $inx->make_index($file_name);
64 # here is where the retrieval key is specified
67 $line =~ /clone="(\S+)"/;
75 User feedback is an integral part of the evolution of this and other
76 Bioperl modules. Send your comments and suggestions preferably to one
77 of the Bioperl mailing lists. Your participation is much appreciated.
79 bioperl-l@bioperl.org - General discussion
80 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
84 Please direct usage questions or support issues to the mailing list:
86 L<bioperl-l@bioperl.org>
88 rather than to the module maintainer directly. Many experienced and
89 reponsive experts will be able look at the problem and quickly
90 address it. Please include a thorough description of the problem
91 with code and data examples if at all possible.
95 Report bugs to the Bioperl bug tracking system to help us keep track
96 the bugs and their resolution. Bug reports can be submitted via
99 http://bugzilla.open-bio.org/
101 =head1 AUTHOR - Ewan Birney
103 Email - birney@ebi.ac.uk
107 The rest of the documentation details each of the object methods.
108 Internal methods are usually preceded with a _
112 # Let's begin the code...
114 package Bio
::Index
::GenBank
;
120 use base
qw(Bio::Index::AbstractSeq);
123 return '__GenBank_FLAT__'; # What kind of index are we?
133 Usage : $index->_index_file($file_name, $i)
134 Function: Specialized function to index GenBank format files.
135 Is provided with a filename and an integer
136 by make_index in its SUPER class.
146 $i # Index-number of file being indexed
151 my $id_parser = $self->id_parser;
153 open my $GENBANK, '<', $file or
154 $self->throw("Can't open file for read : $file");
159 $begin = tell($GENBANK) - length($_);
161 for my $id (&$id_parser($_)) {
162 next if exists $done_ids{$id};
163 $self->add_record($id, $i, $begin) if $id;
177 Usage : $index->id_parser( CODE )
178 Function: Stores or returns the code used by record_id to
179 parse the ID for record from a string.
180 Returns \&default_id_parser (see below) if not
181 set. An entry will be added to
182 the index for each string in the list returned.
183 Example : $index->id_parser( \&my_id_parser )
184 Returns : reference to CODE if called without arguments
190 my ($self,$code) = @_;
193 $self->{'_id_parser'} = $code;
195 return $self->{'_id_parser'} || \
&default_id_parser
;
198 =head2 default_id_parser
200 Title : default_id_parser
201 Usage : $id = default_id_parser($line)
202 Function: The default parser for GenBank.pm
203 Returns : Array of specified ids
210 sub default_id_parser
{
213 if ( $line =~ /^LOCUS\s+(\S+)/ ) {
215 } elsif ( $line =~ /^ACCESSION\s+(.*)/ ) {
216 for my $acc ( split(/\s+/,$1) ) {
219 } elsif ( /^VERSION\s+(.*)/) {
221 for my $acc ( split(/\s+/,$1) ) {
232 Usage : Internal function for indexing system
233 Function: Provides file format for this database
241 my ($self,@args) = @_;