4 # BioPerl module for Bio::Index::Qual
6 # Copied almost verbatim from James Gilbert's Bio::Index::Fasta
8 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
14 Bio::Index::Qual - Interface for indexing (multiple) fasta qual files
18 # Complete code for making an index for several
23 my $Index_File_Name = shift;
24 my $inx = Bio::Index::Qual->new(
25 '-filename' => $Index_File_Name,
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::Qual->new('-filename' => $Index_File_Name);
36 my $out = Bio::SeqIO->new('-format' => 'qual','-fh' => \*STDOUT);
38 foreach my $id (@ARGV) {
39 my $seq = $inx->fetch($id); # Returns Bio::Seq object
40 $out->write_seq($seq);
45 my $seq = $inx->get_Seq_by_id($id); #identical to fetch
49 Inherits functions for managing dbm files from Bio::Index::Abstract.pm,
50 and provides the basic funtionallity for indexing qual files, and
51 retrieving the sequence from them. For best results 'use strict'.
53 Bio::Index::Qual supports the Bio::DB::BioSeqI interface, meaning
54 it can be used as a Sequence database for other parts of bioperl
56 Additional example code is available in scripts/index/*PLS and in
57 the Bioperl Tutorial (L<http://www.bioperl.org/wiki/Bptutorial.pl>).
59 Note that by default the key for the sequence will be the first continuous
60 string after the 'E<gt>' in the qual header. If you want to use a specific
61 substring of the qual header you must use the id_parser() method.
63 You can also set or customize the unique key used to retrieve by
64 writing your own function and calling the id_parser() method.
67 $inx->id_parser(\&get_id);
69 $inx->make_index($file_name);
71 # here is where the retrieval key is specified
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to one
84 of the Bioperl mailing lists. Your participation is much appreciated.
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
91 Report bugs to the Bioperl bug tracking system to help us keep track
92 the bugs and their resolution. Bug reports can be submitted via the
95 http://bugzilla.open-bio.org/
97 =head1 AUTHOR - James Gilbert, Mark Johnson
99 Email - jgrg@sanger.ac.uk, mjohnson@watson.wustl.edu
103 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
108 # Let the code begin...
111 package Bio
::Index
::Qual
;
117 use base
qw(Bio::Index::AbstractSeq);
120 # Suggested fix by Michael G Schwern <schwern@pobox.com> to
121 # get around a clash with CPAN shell...
132 Function: The file format for this package, which is needed
133 by the SeqIO system when reading the sequence.
147 Usage : $index->_index_file( $file_name, $i )
148 Function: Specialist function to index QUAL format files.
149 Is provided with a filename and an integer
150 by make_index in its SUPER class.
160 $i, # Index-number of file being indexed
163 my( $begin, # Offset from start of file of the start
164 # of the last found record.
169 my $id_parser = $self->id_parser;
171 open my $QUAL, '<', $file or $self->throw("Can't open file for read : $file");
176 # $begin is the position of the first character after the '>'
177 my $offset = ( $^O
=~ /mswin/i ) ?
0 : 1;
178 my $begin = tell($QUAL) - length( $_ ) + $offset;
180 foreach my $id (&$id_parser($_)) {
181 $self->add_record($id, $i, $begin);
193 Usage : $index->id_parser( CODE )
194 Function: Stores or returns the code used by record_id to
195 parse the ID for record from a string. Useful
196 for (for instance) specifying a different
197 parser for different flavours of Qual file.
198 Returns \&default_id_parser (see below) if not
199 set. If you supply your own id_parser
200 subroutine, then it should expect a qual
201 description line. An entry will be added to
202 the index for each string in the list returned.
203 Example : $index->id_parser( \&my_id_parser )
204 Returns : ref to CODE if called without arguments
210 my( $self, $code ) = @_;
213 $self->{'_id_parser'} = $code;
215 return $self->{'_id_parser'} || \
&default_id_parser
;
220 =head2 default_id_parser
222 Title : default_id_parser
223 Usage : $id = default_id_parser( $header )
224 Function: The default Qual ID parser for Qual.pm
225 Returns $1 from applying the regexp /^>\s*(\S+)/
228 Args : a qual header line string
232 sub default_id_parser
{
233 if ($_[0] =~ /^>\s*(\S+)/) {