2 # BioPerl module for Bio::Index::EMBL
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Ewan Birney <birney@sanger.ac.uk>
8 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
14 Bio::Index::EMBL - Interface for indexing (multiple) EMBL/Swissprot
15 .dat files (i.e. flat file EMBL/Swissprot format).
19 # Complete code for making an index for several
24 my $Index_File_Name = shift;
25 my $inx = Bio::Index::EMBL->new(-filename => $Index_File_Name,
26 -write_flag => 'WRITE');
27 $inx->make_index(@ARGV);
29 # Print out several sequences present in the index
34 my $Index_File_Name = shift;
35 my $inx = Bio::Index::EMBL->new(-filename => $Index_File_Name);
36 my $out = Bio::SeqIO->new(-format => 'Fasta',-fh => \*STDOUT);
38 foreach my $id (@ARGV) {
39 my $seq = $inx->fetch($id); # Returns Bio::Seq object
40 $out->write_seq($seq);
45 my $seq1 = $inx->get_Seq_by_id($id);
46 my $seq2 = $inx->get_Seq_by_acc($acc);
50 Inherits functions for managing dbm files from Bio::Index::Abstract.pm,
51 and provides the basic funtionallity for indexing EMBL files, and
52 retrieving the sequence from them. Heavily snaffled from James Gilbert
53 and his Fasta system. Note: for best results 'use strict'.
55 The keys are the identifiers in the ID and AC lines.
61 User feedback is an integral part of the evolution of this and other
62 Bioperl modules. Send your comments and suggestions preferably to one
63 of the Bioperl mailing lists. Your participation is much appreciated.
65 bioperl-l@bioperl.org - General discussion
66 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
72 Please direct usage questions or support issues to the mailing list:
74 I<bioperl-l@bioperl.org>
76 rather than to the module maintainer directly. Many experienced and
77 reponsive experts will be able look at the problem and quickly
78 address it. Please include a thorough description of the problem
79 with code and data examples if at all possible.
83 Report bugs to the Bioperl bug tracking system to help us keep track
84 the bugs and their resolution. Bug reports can be submitted via the
87 https://redmine.open-bio.org/projects/bioperl/
89 =head1 AUTHOR - Ewan Birney
91 Email - birney@sanger.ac.uk
95 The rest of the documentation details each of the object
96 methods. Internal methods are usually preceded with a _
101 # Let's begin the code...
104 package Bio
::Index
::EMBL
;
109 use base
qw(Bio::Index::AbstractSeq);
112 return '__EMBL_FLAT__'; # What kind of index are we?
123 Usage : $index->_index_file( $file_name, $i )
124 Function: Specialist function to index EMBL format files.
125 Is provided with a filename and an integer
126 by make_index in its SUPER class.
136 $i # Index-number of file being indexed
139 my( $begin, # Offset from start of file of the start
140 # of the last found record.
141 $id, # ID of last found record.
142 @accs, # accession of last record. Also put into the index
147 open my $EMBL, '<', $file or $self->throw("Can't open file for read : $file");
149 # In Windows, text files have '\r\n' as line separator, but when reading in
150 # text mode Perl will only show the '\n'. This means that for a line "ABC\r\n",
151 # "length $_" will report 4 although the line is 5 bytes in length.
152 # We assume that all lines have the same line separator and only read current line.
153 my $init_pos = tell($EMBL);
154 my $curr_line = <$EMBL>;
155 my $pos_diff = tell($EMBL) - $init_pos;
156 my $correction = $pos_diff - length $curr_line;
157 seek $EMBL, $init_pos, 0; # Rewind position to proceed to read the file
164 if( ! defined $id ) {
165 $self->throw("Got to a end of entry line for an EMBL flat file with no parsed ID. Considering this a problem!");
169 $self->warn("For id [$id] in embl flat file, got no accession number. Storing id index anyway");
172 $self->add_record($id, $i, $begin);
174 foreach my $acc (@accs) {
176 $self->add_record($acc, $i, $begin);
179 } elsif (/^ID\s+(\S+)/) {
181 # not sure if I like this. Assummes tell is in bytes.
182 # we could tell before each line and save it.
183 $begin = tell($EMBL) - length( $_ ) - $correction;
185 } elsif (/^AC\s+(.*)?/) {
186 push @accs , split (/[; ]+/, $1);
199 Usage : Internal function for indexing system
200 Function: Provides file format for this database
209 my ($self,@args) = @_;