Bio/SeqIO/MultiFile.pm

filter: Statementstmt 82.7% 48 / 58 Branchbran 69.2% 18 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 77.2% 78 / 101 CC 15 SCAR 15.7
CC
15
Cov
77%
next_primary_seq
12.0
_initialize
5.8
_load_file
5.1
CRAP 4.8
« Bio/Annotation/OntologyTerm.pm ↑ Summary Bio/Tools/tRNAscanSE.pm »
1 #
2 # BioPerl module for Bio::SeqIO::MultiFile
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SeqIO::MultiFile - Treating a set of files as a single input stream
17  
18 =head1 SYNOPSIS
19  
20 my $seqin = Bio::SeqIO::MultiFile->new( -format => 'Fasta',
21 -files => ['file1','file2'] );
22 while (my $seq = $seqin->next_seq) {
23 # do something with $seq
24 }
25  
26 =head1 DESCRIPTION
27  
28 Bio::SeqIO::MultiFile provides a simple way of bundling a whole
29 set of identically formatted sequence input files as a single stream.
30 File format is automatically determined by C<Bio::SeqIO>.
31  
32 =head1 FEEDBACK
33  
34 =head2 Mailing Lists
35  
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to one
38 of the Bioperl mailing lists. Your participation is much appreciated.
39  
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42  
43 =head2 Support
44  
45 Please direct usage questions or support issues to the mailing list:
46  
47 I<bioperl-l@bioperl.org>
48  
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
53  
54 =head2 Reporting Bugs
55  
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 the bugs and their resolution.
58 Bug reports can be submitted via the web:
59  
60 https://github.com/bioperl/bioperl-live/issues
61  
62 =head1 AUTHOR - Ewan Birney
63  
64 Email birney@ebi.ac.uk
65  
66 =head1 APPENDIX
67  
68 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
69  
70 =cut
71  
72  
73 # Let the code begin...
74  
75  
76 package Bio::SeqIO::MultiFile;
77 9 $Bio::SeqIO::MultiFile::VERSION = '1.7.8';
78 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 9 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82  
83 # _initialize is where the heavy stuff will happen when new is called
84  
85 2 ▶sub _initialize {
Subroutine _initialize: called CC=5 SCAR=17.6
86 2 my($self, @args) = @_;
87  
88 2 $self->SUPER::_initialize(@args);
89  
90 2 my ($file_array, $format) = $self->_rearrange([qw(FILES FORMAT)], @args);
91 2 ▶ if( !defined $file_array || ! ref $file_array ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file_array and ref $file_array) 0 2 2
Condition33%1/3
defined $file_array and ref $file_array
!ll&&!rl&&r
002
MC/DC0%0/2
defined $file_array and ref $file_array
defined $file_array ref $file_array
Truth table33%1/3
A and B
A= defined $file_arrayB= ref $file_array
ABresult
0X0
100
111
92 0 $self->throw("Must have an array files for MultiFile");
93 }
94  
95 2 $self->{'_file_array'} = [];
96 2 $self->_set_file(@$file_array);
97  
98 2 ▶ $self->format($format) if defined $format;
Branch: 1 branch
BranchTrueFalseTotal
if defined $format 1 1 2
99  
100 2 ▶ if( $self->_load_file() == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_load_file == 0) 0 2 2
101 0 $self->throw("Unable to initialise the first file");
102 }
103 }
104  
105  
106 =head2 next_seq
107  
108 Title : next_seq
109 Usage :
110 Function:
111 Example :
112 Returns :
113 Args :
114  
115 =cut
116  
117 14 ▶sub next_seq{
Subroutine next_seq: called CC=3 SCAR=11.0
Pod documented
118 14 my ($self, @args) = @_;
119 14 my $seq = $self->_current_seqio->next_seq();
120 14 ▶ if( !defined $seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $seq) { } 2 12 14
121 2 ▶ if( $self->_load_file() == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_load_file == 0) { } 1 1 2
122 1 return;
123 } else {
124 1 return $self->next_seq();
125 }
126 } else {
127 12 return $seq;
128 }
129 }
130  
131  
132 =head2 next_primary_seq
133  
134 Title : next_primary_seq
135 Usage :
136 Function:
137 Example :
138 Returns :
139 Args :
140  
141 =cut
142  
143 0 ▶sub next_primary_seq{
Subroutine next_primary_seq: not called CC=3 SCAR=24.8
Pod documented
144 0 my ($self, @args) = @_;
145 0 my $seq = $self->_current_seqio->next_primary_seq();
146 0 ▶ if( !defined $seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $seq) { } 0 0 0
147 0 ▶ if( $self->_load_file() == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_load_file == 0) { } 0 0 0
148 0 return;
149 } else {
150 0 return $self->next_primary_seq();
151 }
152 } else {
153 0 return $seq;
154 }
155 }
156  
157  
158 =head2 _load_file
159  
160 Title : _load_file
161 Usage :
162 Function:
163 Example :
164 Returns :
165 Args :
166  
167 =cut
168  
169 4 ▶sub _load_file{
Subroutine _load_file: called CC=5 SCAR=16.2
170 4 my ($self, @args) = @_;
171 4 my $file = shift @{$self->{'_file_array'}};
172 4 ▶ if( !defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 1 3 4
173 1 return 0;
174 }
175 3 my $seqio;
176 3 my $format = $self->format;
177 3 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) { } 2 1 3
178 2 $seqio = Bio::SeqIO->new( -file => $file, -format => $format );
179 } else {
180 1 $seqio = Bio::SeqIO->new( -file => $file );
181 1 ▶ $self->format($seqio->format) if not $format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 1 0 1
182 }
183  
184 # should throw an exception - but if not...
185 3 ▶ if( !defined $seqio) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seqio) 0 3 3
186 0 $self->throw("Could not build SeqIO object for $file!");
187 }
188 3 $self->_current_seqio($seqio);
189 3 return 1;
190 }
191  
192  
193 =head2 _set_file
194  
195 Title : _set_file
196 Usage :
197 Function:
198 Example :
199 Returns :
200 Args :
201  
202 =cut
203  
204 2 ▶sub _set_file{
Subroutine _set_file: called CC=1 SCAR=0.0
205 2 my ($self, @files) = @_;
206 2 push @{$self->{'_file_array'}}, @files;
207 }
208  
209  
210 =head2 _current_seqio
211  
212 Title : _current_seqio
213 Usage : $obj->_current_seqio($newval)
214 Function:
215 Example :
216 Returns : value of _current_seqio
217 Args : newvalue (optional)
218  
219 =cut
220  
221 17 ▶sub _current_seqio{
Subroutine _current_seqio: called CC=2 SCAR=6.9
222 17 my ($obj, $value) = @_;
223 17 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 3 14 17
224 3 $obj->{'_current_seqio'} = $value;
225 }
226 17 return $obj->{'_current_seqio'};
227 }
228  
229  
230 # We overload the format() method of Bio::Root::IO by a simple get/set
231  
232 6 ▶sub format{
Subroutine format: called CC=2 SCAR=6.9
Pod documented
233 6 my ($obj, $value) = @_;
234 6 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 4 6
235 2 $obj->{'_format'} = $value;
236 }
237 6 return $obj->{'_format'};
238 }
239  
240  
241 9 1;
« Bio/Annotation/OntologyTerm.pm ↑ Summary Bio/Tools/tRNAscanSE.pm »