2 # Copyright (c) 1997-9 bioperl, Chad Matsalla. All Rights Reserved.
3 # This module is free software; you can redistribute it and/or
4 # modify it under the same terms as Perl itself.
6 # Copyright Chad Matsalla
8 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
14 Bio::SeqIO::qual - .qual file input/output stream
18 Do not use this module directly. Use it via the Bio::SeqIO class
19 (see L<Bio::SeqIO> for details).
21 my $in_qual = Bio::SeqIO->new(-file => $qualfile,
24 -verbose => $verbose);
28 This object can transform .qual (similar to fasta) objects to and from
29 Bio::Seq::Quality objects. See L<Bio::Seq::Quality> for details.
31 Like the fasta module, it can take an argument '-width' to change the
32 number of values per line (defaults to 50).
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to one
40 of the Bioperl mailing lists. Your participation is much appreciated.
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 Please direct usage questions or support issues to the mailing list:
49 I<bioperl-l@bioperl.org>
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 the bugs and their resolution. Bug reports can be submitted via the web:
61 https://github.com/bioperl/bioperl-live/issues
63 =head1 AUTHOR Chad Matsalla
66 bioinformatics@dieselwurks.com
70 Jason Stajich, jason@bioperl.org
74 The rest of the documentation details each of the object
75 methods. Internal methods are usually preceded with a _
79 # Let the code begin...
81 package Bio
::SeqIO
::qual
;
84 use Bio
::Seq
::SeqFactory
;
87 my $dumper = Dumpvalue
->new();
89 use base
qw(Bio::SeqIO);
95 $self->SUPER::_initialize
(@args);
96 my ($width) = $self->_rearrange([qw(WIDTH)], @args);
97 $width && $self->width($width);
98 if( ! defined $self->sequence_factory ) {
99 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
100 (-verbose
=> $self->verbose(),
101 -type
=> 'Bio::Seq::PrimaryQual'));
108 Usage : $scf = $stream->next_seq()
109 Function: returns the next scf sequence in the stream
110 Returns : Bio::Seq::PrimaryQual object
111 Notes : Get the next quality sequence from the stream.
116 my ($self,@args) = @_;
121 return unless my $entry = $self->_readline;
123 if ($entry eq '>') { # very first one
124 return unless $entry = $self->_readline;
127 # original: my ($top,$sequence) = $entry =~ /^(.+?)\n([^>]*)/s
128 my ($top,$sequence) = $entry =~ /^(.+?)\n([^>]*)/s
129 or $self->throw("Can't parse entry [$entry]");
130 my ($id,$fulldesc) = $top =~ /^\s*(\S+)\s*(.*)/
131 or $self->throw("Can't parse fasta header");
133 # create the seq object
134 $sequence =~ s/\n+/ /g;
135 return $self->sequence_factory->create
147 Usage : $seq = $stream->_next_qual() (but do not do
148 that. Use $stream->next_seq() instead)
149 Function: returns the next quality in the stream
150 Returns : Bio::Seq::PrimaryQual object
152 Notes : An internal method. Gets the next quality in
158 my $qual = next_primary_qual
( $_[0], 1 );
162 =head2 next_primary_qual()
164 Title : next_primary_qual()
165 Usage : $seq = $stream->next_primary_qual()
166 Function: returns the next sequence in the stream
167 Returns : Bio::PrimaryQual object
172 sub next_primary_qual
{
173 # print("CSM next_primary_qual!\n");
174 my( $self, $as_next_qual ) = @_;
178 return unless my $entry = $self->_readline;
180 if ($entry eq '>') { # very first one
181 return unless $entry = $self->_readline;
184 my ($top,$sequence) = $entry =~ /^(.+?)\n([^>]*)/s
185 or $self->throw("Can't parse entry [$entry]");
186 my ($id,$fulldesc) = $top =~ /^\s*(\S+)\s*(.*)/
187 or $self->throw("Can't parse fasta header");
189 # create the seq object
190 $sequence =~ s/\n+/ /g;
192 $qual = Bio
::Seq
::PrimaryQual
->new(-qual
=> $sequence,
206 Usage : $obj->width($newval)
207 Function: Get/Set the number of values per line for FASTA-like output
208 Returns : value of width
209 Args : newvalue (optional)
215 my ($self,$value) = @_;
216 if( defined $value) {
217 $self->{'width'} = $value;
219 return $self->{'width'} || $WIDTH;
226 Usage : $obj->write_seq( -source => $source,
227 -header => "some information"
229 Function: Write out a list of quality values to a fasta-style file.
231 Args : Requires a reference to a Bio::Seq::Quality object or a
232 PrimaryQual object as the -source. Option 1: information
233 for the header. Option 2: whether the quality score should
234 be on a single line or not
235 Notes : If no -header is provided, $obj->id() will be used where
236 $obj is a reference to either a Quality object or a
237 PrimaryQual object. If $source->id() fails, "unknown" will
238 be the header. If the Quality object has $source->length()
239 of "DIFFERENT" (read the pod, luke), write_seq will use the
240 length of the PrimaryQual object within the Quality object.
245 my ($self,@args) = @_;
246 my $width = $self->width;
247 my ($source, $head, $oneline) = $self->_rearrange([qw(SOURCE HEADER ONELINE)], @args);
248 if (!$source || ( !$source->isa('Bio::Seq::Quality') &&
249 !$source->isa('Bio::Seq::PrimaryQual') )) {
250 $self->throw("You must pass a Bio::Seq::Quality or a Bio::Seq::PrimaryQual".
251 " object to write_seq() as a parameter named \"source\"");
253 my $header = ($source->can("header") && $source->header) ?
255 ($source->can("id") && $source->id) ?
258 my @quals = $source->qual();
259 # ::dumpValue(\@quals);
260 my $desc = $source->desc if $source->can('desc');
262 $self->_print (">$header $desc\n");
263 my (@slice,$max,$length);
264 $length = $source->length();
266 if ( not(defined($oneline)) || $oneline == 0) {
267 # $width quality values per line
268 for (my $count = 1; $count<=$length; $count+= $width) {
269 if ($count+$width > $length) {
272 $max = $count+$width-1;
274 my @slice = @
{$source->subqual($count,$max)};
275 $self->_print (join(' ',@slice), "\n");
278 # quality values on a single line
279 my @slice = @
{$source->qual};
280 $self->_print (join(' ',@slice), "\n");
283 $self->flush if $self->_flush_on_write && defined $self->_fh;