3 # BioPerl module for Bio::Index::Fastq
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Tony Cox <avc@sanger.ac.uk>
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Index::Fastq - Interface for indexing (multiple) fastq files
19 # Complete code for making an index for several
21 use Bio::Index::Fastq;
24 my $Index_File_Name = shift;
25 my $inx = Bio::Index::Fastq->new(
26 '-filename' => $Index_File_Name,
28 $inx->make_index(@ARGV);
30 # Print out several sequences present in the index
32 use Bio::Index::Fastq;
35 my $Index_File_Name = shift;
36 my $inx = Bio::Index::Fastq->new('-filename' => $Index_File_Name);
37 my $out = Bio::SeqIO->new('-format' => 'Fastq','-fh' => \*STDOUT);
39 foreach my $id (@ARGV) {
40 my $seq = $inx->fetch($id); # Returns Bio::Seq::Quality object
41 $out->write_seq($seq);
46 my $seq = $inx->get_Seq_by_id($id); #identical to fetch
50 Inherits functions for managing dbm files from Bio::Index::Abstract.pm,
51 and provides the basic funtionallity for indexing fastq files, and
52 retrieving the sequence from them. Note: for best results 'use strict'.
54 Bio::Index::Fastq supports the Bio::DB::BioSeqI interface, meaning
55 it can be used as a Sequence database for other parts of bioperl
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
70 Please direct usage questions or support issues to the mailing list:
72 I<bioperl-l@bioperl.org>
74 rather than to the module maintainer directly. Many experienced and
75 reponsive experts will be able look at the problem and quickly
76 address it. Please include a thorough description of the problem
77 with code and data examples if at all possible.
81 Report bugs to the Bioperl bug tracking system to help us keep track
82 the bugs and their resolution. Bug reports can be submitted via the
85 http://bugzilla.open-bio.org/
87 =head1 AUTHOR - Tony Cox
89 Email - avc@sanger.ac.uk
93 The rest of the documentation details each of the object
94 methods. Internal methods are usually preceded with a _
99 # Let the code begin...
102 package Bio
::Index
::Fastq
;
108 use base
qw(Bio::Index::AbstractSeq);
111 # Suggested fix by Michael G Schwern <schwern@pobox.com> to
112 # get around a clash with CPAN shell...
122 Function: The file format for this package, which is needed
123 by the SeqIO system when reading the sequence.
137 Usage : $index->_index_file( $file_name, $i )
138 Function: Specialist function to index FASTQ format files.
139 Is provided with a filename and an integer
140 by make_index in its SUPER class.
150 $i, # Index-number of file being indexed
153 my( $begin, # Offset from start of file of the start
154 # of the last found record.
159 my $id_parser = $self->id_parser;
161 open my $FASTQ, '<', $file or $self->throw("Can't open file for read : $file");
165 # $begin is the position of the first character after the '@'
166 my $begin = tell($FASTQ) - length( $_ ) + 1;
167 foreach my $id (&$id_parser($_)) {
168 $self->add_record($id, $i, $begin);
181 Usage : $index->id_parser( CODE )
182 Function: Stores or returns the code used by record_id to
183 parse the ID for record from a string. Useful
184 for (for instance) specifying a different
185 parser for different flavours of FASTQ file.
186 Returns \&default_id_parser (see below) if not
187 set. If you supply your own id_parser
188 subroutine, then it should expect a fastq
189 description line. An entry will be added to
190 the index for each string in the list returned.
191 Example : $index->id_parser( \&my_id_parser )
192 Returns : ref to CODE if called without arguments
198 my( $self, $code ) = @_;
201 $self->{'_id_parser'} = $code;
203 return $self->{'_id_parser'} || \
&default_id_parser
;
208 =head2 default_id_parser
210 Title : default_id_parser
211 Usage : $id = default_id_parser( $header )
212 Function: The default Fastq ID parser for Fastq.pm
213 Returns $1 from applying the regexp /^>\s*(\S+)/
216 Args : a fastq header line string
220 sub default_id_parser
{
221 if ($_[0] =~ /^@\s*(\S+)/) {