1 # BioPerl module for Bio::Index::Fastq
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 # Cared for by Tony Cox <avc@sanger.ac.uk>
7 # You may distribute this module under the same terms as perl itself
9 # POD documentation - main docs before the code
13 Bio::Index::Fastq - Interface for indexing (multiple) fastq files
17 # Complete code for making an index for several
19 use Bio::Index::Fastq;
22 my $Index_File_Name = shift;
23 my $inx = Bio::Index::Fastq->new(
24 '-filename' => $Index_File_Name,
26 $inx->make_index(@ARGV);
28 # Print out several sequences present in the index
30 use Bio::Index::Fastq;
33 my $Index_File_Name = shift;
34 my $inx = Bio::Index::Fastq->new('-filename' => $Index_File_Name);
35 my $out = Bio::SeqIO->new('-format' => 'Fastq','-fh' => \*STDOUT);
37 foreach my $id (@ARGV) {
38 my $seq = $inx->fetch($id); # Returns Bio::Seq::Quality object
39 $out->write_seq($seq);
44 my $seq = $inx->get_Seq_by_id($id); #identical to fetch
48 Inherits functions for managing dbm files from Bio::Index::Abstract.pm,
49 and provides the basic funtionallity for indexing fastq files, and
50 retrieving the sequence from them. Note: for best results 'use strict'.
52 Bio::Index::Fastq supports the Bio::DB::BioSeqI interface, meaning
53 it can be used as a Sequence database for other parts of bioperl
59 User feedback is an integral part of the evolution of this and other
60 Bioperl modules. Send your comments and suggestions preferably to one
61 of the Bioperl mailing lists. Your participation is much appreciated.
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
68 Please direct usage questions or support issues to the mailing list:
70 I<bioperl-l@bioperl.org>
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via the
83 http://bugzilla.open-bio.org/
85 =head1 AUTHOR - Tony Cox
87 Email - avc@sanger.ac.uk
91 The rest of the documentation details each of the object
92 methods. Internal methods are usually preceded with a _
97 # Let the code begin...
100 package Bio
::Index
::Fastq
;
106 use base
qw(Bio::Index::AbstractSeq);
109 # Suggested fix by Michael G Schwern <schwern@pobox.com> to
110 # get around a clash with CPAN shell...
120 Function: The file format for this package, which is needed
121 by the SeqIO system when reading the sequence.
135 Usage : $index->_index_file( $file_name, $i )
136 Function: Specialist function to index FASTQ format files.
137 Is provided with a filename and an integer
138 by make_index in its SUPER class.
148 $i, # Index-number of file being indexed
151 my( $begin, # Offset from start of file of the start
152 # of the last found record.
157 my $id_parser = $self->id_parser;
159 open my $FASTQ, '<', $file or $self->throw("Can't open file for read : $file");
163 my $begin = tell($FASTQ) - length( $_ );
164 foreach my $id (&$id_parser($_)) {
165 $self->add_record($id, $i, $begin);
178 Usage : $index->id_parser( CODE )
179 Function: Stores or returns the code used by record_id to
180 parse the ID for record from a string. Useful
181 for (for instance) specifying a different
182 parser for different flavours of FASTQ file.
183 Returns \&default_id_parser (see below) if not
184 set. If you supply your own id_parser
185 subroutine, then it should expect a fastq
186 description line. An entry will be added to
187 the index for each string in the list returned.
188 Example : $index->id_parser( \&my_id_parser )
189 Returns : ref to CODE if called without arguments
195 my( $self, $code ) = @_;
198 $self->{'_id_parser'} = $code;
200 return $self->{'_id_parser'} || \
&default_id_parser
;
205 =head2 default_id_parser
207 Title : default_id_parser
208 Usage : $id = default_id_parser( $header )
209 Function: The default Fastq ID parser for Fastq.pm
210 Returns $1 from applying the regexp /^>\s*(\S+)/
213 Args : a fastq header line string
217 sub default_id_parser
{
218 if ($_[0] =~ /^@\s*(\S+)/) {