Bio/SeqIO/raw.pm

filter: Statementstmt 72.9% 35 / 48 Branchbran 50.0% 11 / 22 Conditioncond 45.4% 5 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 75.0% 6 / 8 Podpod 100% 3 / 3 totaltotal 62.2% 61 / 98 CC 18 SCAR 24.6
CC
18
Cov
63%
write_qual
30.0
write_seq
13.0
next_seq
4.0
CRAP 11.7
« Bio/Index/AbstractSeq.pm ↑ Summary Bio/AlignIO.pm »
1 #-----------------------------------------------------------------------------
2 # PACKAGE : Bio::SeqIO::raw
3 # AUTHOR : Ewan Birney <birney@ebi.ac.uk>
4 # CREATED : Feb 16 1999
5 #
6 # Copyright (c) 1997-9 bioperl, Ewan Birney. All Rights Reserved.
7 # This module is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 #
10 # _History_
11 #
12 # Ewan Birney <birney@ebi.ac.uk> developed the SeqIO
13 # schema and the first prototype modules.
14 #
15 # This code is based on his Bio::SeqIO::Fasta module with
16 # the necessary minor tweaks necessary to get it to read
17 # and write raw formatted sequences made by
18 # chris dagdigian <dag@sonsorol.org>
19 #
20 # October 18, 1999 Largely rewritten by Lincoln Stein
21 #
22 # Copyright Ewan Birney
23 #
24 # You may distribute this module under the same terms as perl itself
25  
26 # POD documentation - main docs before the code
27  
28 =head1 NAME
29  
30 Bio::SeqIO::raw - raw sequence file input/output stream
31  
32 =head1 SYNOPSIS
33  
34 Do not use this module directly. Use it via the L<Bio::SeqIO> class.
35  
36 =head1 DESCRIPTION
37  
38 This object can transform Bio::Seq objects to and from raw flat
39 file databases.
40  
41 =head1 FEEDBACK
42  
43 =head2 Mailing Lists
44  
45 User feedback is an integral part of the evolution of this and other
46 Bioperl modules. Send your comments and suggestions preferably to one
47 of the Bioperl mailing lists. Your participation is much appreciated.
48  
49 bioperl-l@bioperl.org - General discussion
50 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
51  
52 =head2 Support
53  
54 Please direct usage questions or support issues to the mailing list:
55  
56 I<bioperl-l@bioperl.org>
57  
58 rather than to the module maintainer directly. Many experienced and
59 reponsive experts will be able look at the problem and quickly
60 address it. Please include a thorough description of the problem
61 with code and data examples if at all possible.
62  
63 =head2 Reporting Bugs
64  
65 Report bugs to the Bioperl bug tracking system to help us keep track
66 the bugs and their resolution.
67 Bug reports can be submitted via the web:
68  
69 https://github.com/bioperl/bioperl-live/issues
70  
71 =head1 AUTHORS
72  
73 Ewan Birney E<lt>birney@ebi.ac.ukE<gt>
74 Lincoln Stein E<lt>lstein@cshl.orgE<gt>
75  
76 =head1 CONTRIBUTORS
77  
78 Jason Stajich E<lt>jason@bioperl.org<gt>
79  
80 =head1 APPENDIX
81  
82 The rest of the documentation details each of the object methods.
83 Internal methods are usually preceded with a _
84  
85 =cut
86  
87  
88 # Let the code begin...
89  
90 package Bio::SeqIO::raw;
91 3 $Bio::SeqIO::raw::VERSION = '1.7.8';
92 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 3 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 3 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 3 our %variant = ( 'multiple' => undef, # default
99 'single' => undef );
100  
101 10 ▶sub _initialize {
Subroutine _initialize: called CC=4 SCAR=13.9
102 10 my($self,@args) = @_;
103 10 $self->SUPER::_initialize(@args);
104 10 my ($variant) = $self->_rearrange([qw(VARIANT)], @args);
105 10 ▶ $variant ||= 'multiple';
Condition100%2/2
$variant ||= "multiple"
l!l
28
MC/DC100%1/1
$variant ||= "multiple"
$variant
Truth table100%2/2
A
A= $variant
Aresult
11
00
106 10 $self->variant($variant);
107 10 ▶ $self->{record_separator} = $variant eq 'single' ? undef : $/;
Branch: 1 branch
BranchTrueFalseTotal
$variant eq 'single' ? : 2 8 10
108 10 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->sequence_factory) 10 0 10
109 10 $self->sequence_factory(Bio::Seq::SeqFactory->new
110 (-verbose => $self->verbose(),
111 -type => 'Bio::Seq'));
112 }
113 10 $self->variant;
114 }
115  
116 =head2 next_seq
117  
118 Title : next_seq
119 Usage : $seq = $stream->next_seq()
120 Function: returns the next sequence in the stream
121 Returns : Bio::Seq object
122 Args :
123  
124  
125 =cut
126  
127 19 ▶sub next_seq{
Subroutine next_seq: called CC=4 SCAR=13.9
Pod documented
128 19 my ($self,@args) = @_;
129 ## When its 1 sequence per line with no formatting at all,
130 ## grabbing it should be easy :)
131
132 ## adding an option to assume the file is one sequence
133 19 local $/ = $self->{record_separator};
134 19 my $nextline = $self->_readline();
135 19 ▶ return unless defined $nextline;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nextline 2 17 19
136
137 17 my $sequence = uc($nextline);
138 17 $sequence =~ s/\W//g;
139 17 ▶ return unless $sequence;
Branch: 1 branch
BranchTrueFalseTotal
unless $sequence 1 16 17
140 16 ▶ return $self->sequence_factory->create(-seq => $sequence) if $sequence;
Branch: 1 branch
BranchTrueFalseTotal
if $sequence 16 0 16
141 }
142  
143 =head2 write_seq
144  
145 Title : write_seq
146 Usage : $stream->write_seq($seq)
147 Function: writes the $seq object into the stream
148 Returns : 1 for success and 0 for error
149 Args : Array of Bio::PrimarySeqI objects
150  
151  
152 =cut
153  
154 5 ▶sub write_seq {
Subroutine write_seq: called CC=8 SCAR=25.7
Pod documented
155 5 my ($self,@seq) = @_;
156 5 foreach my $seq (@seq) {
157 5 ▶ $self->throw("Must provide a valid Bio::PrimarySeqI object")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI") 0 5 5
Condition33%2/6
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
005
defined $seq and ref $seq
!ll&&!rl&&r
005
MC/DC0%0/3
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
defined $seq ref $seq $seq->isa("Bio::PrimarySeqI")
Truth table25%1/4
A and B and C
A= defined $seqB= ref $seqC= $seq->isa("Bio::PrimarySeqI")
ABCresult
0XX0
10X0
1100
1111
158 unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI');
159 5 ▶ $self->_print($seq->seq, "\n") or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_print($seq->seq, "\n") or return 5 0 5
160 }
161 5 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 5 0 5
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
005
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
162 5 return 1;
163 }
164  
165 =head2 write_qual
166  
167 Title : write_qual
168 Usage : $stream->write_qual($seq)
169 Function: writes the $seq object into the stream
170 Returns : 1 for success and 0 for error
171 Args : Bio::Seq::Quality object
172  
173  
174 =cut
175  
176 0 ▶sub write_qual {
Subroutine write_qual: not called CC=5 SCAR=34.0
Pod documented
177 0 my ($self,@seq) = @_;
178 0 my @qual = ();
179 0 foreach (@seq) {
180 0 ▶ unless ($_->isa("Bio::Seq::Quality")){
Branch: 1 branch
BranchTrueFalseTotal
unless ($_->isa("Bio::Seq::Quality")) 0 0 0
181 0 warn("You cannot write raw qualities without supplying a Bio::Seq::".
182 "Quality object! You passed a ".ref($_)."\n");
183 0 next;
184 }
185 0 @qual = @{$_->qual};
186 0 ▶ if(scalar(@qual) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @qual == 0) 0 0 0
187 0 $qual[0] = "\n";
188 }
189 0 ▶ $self->_print (join " ", @qual,"\n") or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_print(join(" ", @qual, "\n")) or return 0 0 0
190 }
191 0 return 1;
192 }
193  
194 =head2 variant
195  
196 Title : variant
197 Usage : $format = $obj->variant();
198 Function: Get and set method for the sequence variant. For raw sequence, this
199 indicates whether to treat the input as multiple sequences (the
200 default) or as a single sequence.
201  
202 Current values accepted are:
203  
204 'single' single sequence
205 'multiple' multiple sequences (default)
206 Returns : string
207 Args : new value, string
208  
209 =cut
210  
211 # variant() method inherited from Bio::Root::IO
212  
213 # private method for testing record separator
214  
215 0 ▶sub _separator {
Subroutine _separator: not called CC=1 SCAR=6.9
216 0 shift->{record_separator};
217 }
218  
219 3 1;
« Bio/Index/AbstractSeq.pm ↑ Summary Bio/AlignIO.pm »