Bio/SeqIO/qual.pm

filter: Statementstmt 71.7% 56 / 78 Branchbran 40.9% 18 / 44 Conditioncond 39.1% 9 / 23 MC/DCmcdc 7.1% 1 / 14 Subroutinesub 80.0% 8 / 10 Podpod 100% 4 / 4 totaltotal 55.4% 96 / 173 CC 31 SCAR 31.5
CC
31
Cov
57%
next_primary_qual
56.0
write_seq
29.7
next_seq
6.7
CRAP 23.4
« Bio/Seq/Quality.pm ↑ Summary Bio/SeqIO/embldriver.pm »
1 #
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.
5 #
6 # Copyright Chad Matsalla
7 #
8 # You may distribute this module under the same terms as perl itself
9  
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::SeqIO::qual - .qual file input/output stream
15  
16 =head1 SYNOPSIS
17  
18 Do not use this module directly. Use it via the Bio::SeqIO class
19 (see L<Bio::SeqIO> for details).
20  
21 my $in_qual = Bio::SeqIO->new(-file => $qualfile,
22 -format => 'qual',
23 -width => $width,
24 -verbose => $verbose);
25  
26 =head1 DESCRIPTION
27  
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.
30  
31 Like the fasta module, it can take an argument '-width' to change the
32 number of values per line (defaults to 50).
33  
34 =head1 FEEDBACK
35  
36 =head2 Mailing Lists
37  
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.
41  
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
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.
55  
56 =head2 Reporting Bugs
57  
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:
60  
61 https://github.com/bioperl/bioperl-live/issues
62  
63 =head1 AUTHOR Chad Matsalla
64  
65 Chad Matsalla
66 bioinformatics@dieselwurks.com
67  
68 =head1 CONTRIBUTORS
69  
70 Jason Stajich, jason@bioperl.org
71  
72 =head1 APPENDIX
73  
74 The rest of the documentation details each of the object
75 methods. Internal methods are usually preceded with a _
76  
77 =cut
78  
79 # Let the code begin...
80  
81 package Bio::SeqIO::qual;
82 2 $Bio::SeqIO::qual::VERSION = '1.7.8';
83 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶use Dumpvalue;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 2 my $dumper = Dumpvalue->new();
88  
89 2 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 2 our $WIDTH = 25;
92  
93 2 ▶sub _initialize {
Subroutine _initialize: called CC=3 SCAR=11.2
94 2 my($self,@args) = @_;
95 2 $self->SUPER::_initialize(@args);
96 2 my ($width) = $self->_rearrange([qw(WIDTH)], @args);
97 2 ▶ $width && $self->width($width);
Branch: 1 branch
BranchTrueFalseTotal
$width and $self->width($width) 0 2 2
98 2 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 2 0 2
99 2 $self->sequence_factory(Bio::Seq::SeqFactory->new
100 (-verbose => $self->verbose(),
101 -type => 'Bio::Seq::PrimaryQual'));
102 }
103 }
104  
105 =head2 next_seq()
106  
107 Title : next_seq()
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.
112  
113 =cut
114  
115 9 ▶sub next_seq {
Subroutine next_seq: called CC=6 SCAR=19.1
Pod documented
116 9 my ($self,@args) = @_;
117 9 my ($qual,$seq);
118 9 my $alphabet;
119 9 local $/ = "\n>";
120  
121 9 ▶ return unless my $entry = $self->_readline;
Branch: 1 branch
BranchTrueFalseTotal
unless my $entry = $self->_readline 1 8 9
122  
123 8 ▶ if ($entry eq '>') { # very first one
Branch: 1 branch
BranchTrueFalseTotal
if ($entry eq ">") 0 8 8
124 0 ▶ return unless $entry = $self->_readline;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry = $self->_readline 0 0 0
125 }
126  
127 # original: my ($top,$sequence) = $entry =~ /^(.+?)\n([^>]*)/s
128 8 ▶ my ($top,$sequence) = $entry =~ /^(.+?)\n([^>]*)/s
Branch: 1 branch
BranchTrueFalseTotal
() = $entry =~ /^(.+?)\n([^>]*)/s or $self->throw("Can't parse entry [$entry]") 8 0 8
129 or $self->throw("Can't parse entry [$entry]");
130 8 ▶ my ($id,$fulldesc) = $top =~ /^\s*(\S+)\s*(.*)/
Branch: 1 branch
BranchTrueFalseTotal
() = $top =~ /^\s*(\S+)\s*(.*)/ or $self->throw("Can't parse fasta header") 8 0 8
131 or $self->throw("Can't parse fasta header");
132 8 $id =~ s/^>//;
133 # create the seq object
134 8 $sequence =~ s/\n+/ /g;
135 8 return $self->sequence_factory->create
136 (-qual => $sequence,
137 -id => $id,
138 -primary_id => $id,
139 -display_id => $id,
140 -desc => $fulldesc
141 );
142 }
143  
144 =head2 _next_qual
145  
146 Title : _next_qual
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
151 Args : NONE
152 Notes : An internal method. Gets the next quality in
153 the stream.
154  
155 =cut
156  
157 0 ▶sub _next_qual {
Subroutine _next_qual: not called CC=1 SCAR=6.9
158 0 my $qual = next_primary_qual( $_[0], 1 );
159 0 return $qual;
160 }
161  
162 =head2 next_primary_qual()
163  
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
168 Args : NONE
169  
170 =cut
171  
172 0 ▶sub next_primary_qual {
Subroutine next_primary_qual: not called CC=7 SCAR=40.3
Pod documented
173 # print("CSM next_primary_qual!\n");
174 0 my( $self, $as_next_qual ) = @_;
175 0 my ($qual,$seq);
176 0 local $/ = "\n>";
177  
178 0 ▶ return unless my $entry = $self->_readline;
Branch: 1 branch
BranchTrueFalseTotal
unless my $entry = $self->_readline 0 0 0
179  
180 0 ▶ if ($entry eq '>') { # very first one
Branch: 1 branch
BranchTrueFalseTotal
if ($entry eq ">") 0 0 0
181 0 ▶ return unless $entry = $self->_readline;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry = $self->_readline 0 0 0
182 }
183  
184 0 ▶ my ($top,$sequence) = $entry =~ /^(.+?)\n([^>]*)/s
Branch: 1 branch
BranchTrueFalseTotal
() = $entry =~ /^(.+?)\n([^>]*)/s or $self->throw("Can't parse entry [$entry]") 0 0 0
185 or $self->throw("Can't parse entry [$entry]");
186 0 ▶ my ($id,$fulldesc) = $top =~ /^\s*(\S+)\s*(.*)/
Branch: 1 branch
BranchTrueFalseTotal
() = $top =~ /^\s*(\S+)\s*(.*)/ or $self->throw("Can't parse fasta header") 0 0 0
187 or $self->throw("Can't parse fasta header");
188 0 $id =~ s/^>//;
189 # create the seq object
190 0 $sequence =~ s/\n+/ /g;
191 0 ▶ if ($as_next_qual) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_next_qual) 0 0 0
192 0 $qual = Bio::Seq::PrimaryQual->new(-qual => $sequence,
193 -id => $id,
194 -primary_id => $id,
195 -display_id => $id,
196 -desc => $fulldesc
197 );
198 }
199 0 return $qual;
200 }
201  
202  
203 =head2 width
204  
205 Title : width
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)
210  
211  
212 =cut
213  
214 2 ▶sub width{
Subroutine width: called CC=3 SCAR=13.3
Pod documented
215 2 my ($self,$value) = @_;
216 2 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 2 2
217 0 $self->{'width'} = $value;
218 }
219 2 ▶ return $self->{'width'} || $WIDTH;
Condition33%1/3
$self->{'width'} || $Bio::SeqIO::qual::WIDTH
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{'width'} || $Bio::SeqIO::qual::WIDTH
$self->{'width'} $Bio::SeqIO::qual::WIDTH
Truth table33%1/3
A || B
A= $self->{'width'}B= $Bio::SeqIO::qual::WIDTH
ABresult
1X1
011
000
220 }
221  
222  
223 =head2 write_seq
224  
225 Title : write_seq
226 Usage : $obj->write_seq( -source => $source,
227 -header => "some information"
228 -oneline => 0);
229 Function: Write out a list of quality values to a fasta-style file.
230 Returns : Nothing.
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.
241  
242 =cut
243  
244 2 ▶sub write_seq {
Subroutine write_seq: called CC=16 SCAR=33.9
Pod documented
245 2 my ($self,@args) = @_;
246 2 my $width = $self->width;
247 2 my ($source, $head, $oneline) = $self->_rearrange([qw(SOURCE HEADER ONELINE)], @args);
248 2 ▶ if (!$source || ( !$source->isa('Bio::Seq::Quality') &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($source and $source->isa("Bio::Seq::Quality") || $source->isa("Bio::Seq::PrimaryQual")) 0 2 2
Condition33%2/6
$source and $source->isa("Bio::Seq::Quality") || $source->isa("Bio::Seq::PrimaryQual")
!ll&&!rl&&r
002
$source->isa("Bio::Seq::Quality") or $source->isa("Bio::Seq::PrimaryQual")
l!l&&r!l&&!r
020
MC/DC0%0/3
$source and $source->isa("Bio::Seq::Quality") || $source->isa("Bio::Seq::PrimaryQual")
$source $source->isa("Bio::Seq::Quality") $source->isa("Bio::Seq::PrimaryQual")
Truth table25%1/4
A and B or C
A= $sourceB= $source->isa("Bio::Seq::Quality")C= $source->isa("Bio::Seq::PrimaryQual")
ABCresult
0XX0
1000
11X1
1011
249 !$source->isa('Bio::Seq::PrimaryQual') )) {
250 0 $self->throw("You must pass a Bio::Seq::Quality or a Bio::Seq::PrimaryQual".
251 " object to write_seq() as a parameter named \"source\"");
252 }
253 2 ▶ my $header = ($source->can("header") && $source->header) ?
Branch: 2 branches
BranchTrueFalseTotal
$source->can('header') && $source->header ? : 1 1 2
$source->can('id') && $source->id ? : 1 0 1
Condition50%3/6
$source->can("header") and $source->header
!ll&&!rl&&r
011
$source->can("id") and $source->id
!ll&&!rl&&r
001
MC/DC50%1/2
$source->can("header") and $source->header
$source->can("header") $source->header
MC/DC0%0/2
$source->can("id") and $source->id
$source->can("id") $source->id
Truth table66%2/3
A and B
A= $source->can("header")B= $source->header
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $source->can("id")B= $source->id
ABresult
0X0
100
111
254 $source->header :
255 ($source->can("id") && $source->id) ?
256 $source->id :
257 "unknown";
258 2 my @quals = $source->qual();
259 # ::dumpValue(\@quals);
260 2 ▶ my $desc = $source->desc if $source->can('desc');
Branch: 1 branch
BranchTrueFalseTotal
if $source->can("desc") 2 0 2
261 2 ▶ $desc ||= '';
Condition50%1/2
$desc ||= ""
l!l
02
MC/DC0%0/1
$desc ||= ""
$desc
Truth table50%1/2
A
A= $desc
Aresult
11
00
262 2 $self->_print (">$header $desc\n");
263 2 my (@slice,$max,$length);
264 2 $length = $source->length();
265
266 2 ▶ if ( not(defined($oneline)) || $oneline == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $oneline or $oneline == 0) { } 2 0 2
Condition33%1/3
not defined $oneline or $oneline == 0
l!l&&r!l&&!r
200
MC/DC0%0/2
not defined $oneline or $oneline == 0
not defined $oneline $oneline == 0
Truth table33%1/3
not(A) or B
A= not defined $onelineB= $oneline == 0
ABresult
1X1
011
000
267 # $width quality values per line
268 2 ▶ for (my $count = 1; $count<=$length; $count+= $width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count <= $length) 2 2 4
269 2 ▶ if ($count+$width > $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count + $width > $length) { } 2 0 2
270 2 $max = $length;
271 } else {
272 0 $max = $count+$width-1;
273 }
274 2 my @slice = @{$source->subqual($count,$max)};
275 2 $self->_print (join(' ',@slice), "\n");
276 }
277 } else {
278 # quality values on a single line
279 0 my @slice = @{$source->qual};
280 0 $self->_print (join(' ',@slice), "\n");
281 }
282  
283 2 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 2 0 2
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
002
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write defined $self->_fh
Truth table33%1/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
ABresult
0X0
100
111
284 2 return 1;
285 }
286  
287  
288 2 1;
289  
290 __END__
« Bio/Seq/Quality.pm ↑ Summary Bio/SeqIO/embldriver.pm »