2 # BioPerl module for Bio::Index::Swissprot
4 # You may distribute this module under the same terms as perl itself
6 # POD documentation - main docs before the code
10 Bio::Index::Swissprot - Interface for indexing one or more
15 # Make an index for one or more Swissprot files:
17 use Bio::Index::Swissprot;
20 my $index_file_name = shift;
21 my $inx = Bio::Index::Swissprot->new(
22 -filename => $index_file_name,
24 $inx->make_index(@ARGV);
26 # Print out several sequences present in the index in Genbank
29 use Bio::Index::Swissprot;
33 my $out = Bio::SeqIO->new( -format => 'genbank',
35 my $index_file_name = shift;
36 my $inx = Bio::Index::Swissprot->new(-filename => $index_file_name);
38 foreach my $id (@ARGV) {
39 my $seq = $inx->fetch($id); # Returns a 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 By default the index that is created uses the AC and ID identifiers
51 as keys. This module inherits functions for managing dbm files from
52 Bio::Index::Abstract.pm, and provides the basic functionality
53 for indexing Swissprot files and retrieving Sequence objects from
54 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($index_file_name);
64 # here is where the retrieval key is specified
67 $line =~ /^KW\s+([A-Z]+)/i;
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 I<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 Also lorenz@ist.org, bosborne at alum.mit.edu
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
::Swissprot
;
120 use base
qw(Bio::Index::AbstractSeq);
123 return '__Swissprot_FLAT__'; # What kind of index are we?
133 Usage : $index->_index_file( $file_name, $i )
134 Function: Specialist function to index Swissprot format files.
135 Is provided with a filename and an integer
136 by make_index in its SUPER class.
144 # $file is file name, $i is number of file being indexed
145 my( $self, $file, $i ) = @_;
147 # Offset from start of file
150 my $id_parser = $self->id_parser;
152 open my $SWISSPROT,'<',$file or $self->throw("Can't read file: $file");
155 while (<$SWISSPROT>) {
157 $begin = tell($SWISSPROT) - length( $_ );
159 for my $id (&$id_parser($_)) {
160 next if exists $done_ids{$id};
161 $self->add_record($id, $i, $begin) if $id;
175 Usage : $index->id_parser( CODE )
176 Function: Stores or returns the code used by record_id to
177 parse the ID for record from a string.
178 Returns \&default_id_parser (see below) if not
179 set. An entry will be added to
180 the index for each string in the list returned.
181 Example : $index->id_parser( \&my_id_parser )
182 Returns : ref to CODE if called without arguments
188 my( $self, $code ) = @_;
191 $self->{'_id_parser'} = $code;
193 return $self->{'_id_parser'} || \
&default_id_parser
;
196 =head2 default_id_parser
198 Title : default_id_parser
199 Usage : $id = default_id_parser( $line )
200 Function: The default parser for Swissprot.pm
201 Returns $1 from applying the regexp /^ID\s*(\S+)/
202 or /^AC\s+([A-Z0-9]+)/ to the current line.
208 sub default_id_parser
{
210 if ($line =~ /^ID\s*(\S+)/) {
213 elsif ($line =~ /^AC\s+([A-Z0-9]+)/) {
221 Usage : Internal function for indexing system
222 Function: Provides file format for this database