Bio::Tools::CodonTable::is_start_codon: check in case of ambiguous codons (#266)
[bioperl-live.git] / lib / Bio / SeqIO / MultiFile.pm
blobbc6bf1c3a42e4572877ead1e3a1f52db4a383ca6
2 # BioPerl module for Bio::SeqIO::MultiFile
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
8 # Copyright Ewan Birney
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::SeqIO::MultiFile - Treating a set of files as a single input stream
18 =head1 SYNOPSIS
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
26 =head1 DESCRIPTION
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>.
32 =head1 FEEDBACK
34 =head2 Mailing Lists
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.
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43 =head2 Support
45 Please direct usage questions or support issues to the mailing list:
47 I<bioperl-l@bioperl.org>
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.
54 =head2 Reporting Bugs
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:
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR - Ewan Birney
64 Email birney@ebi.ac.uk
66 =head1 APPENDIX
68 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
70 =cut
73 # Let the code begin...
76 package Bio::SeqIO::MultiFile;
78 use strict;
80 use base qw(Bio::SeqIO);
83 # _initialize is where the heavy stuff will happen when new is called
85 sub _initialize {
86 my($self, @args) = @_;
88 $self->SUPER::_initialize(@args);
90 my ($file_array, $format) = $self->_rearrange([qw(FILES FORMAT)], @args);
91 if( !defined $file_array || ! ref $file_array ) {
92 $self->throw("Must have an array files for MultiFile");
95 $self->{'_file_array'} = [];
96 $self->_set_file(@$file_array);
98 $self->format($format) if defined $format;
100 if( $self->_load_file() == 0 ) {
101 $self->throw("Unable to initialise the first file");
106 =head2 next_seq
108 Title : next_seq
109 Usage :
110 Function:
111 Example :
112 Returns :
113 Args :
115 =cut
117 sub next_seq{
118 my ($self, @args) = @_;
119 my $seq = $self->_current_seqio->next_seq();
120 if( !defined $seq ) {
121 if( $self->_load_file() == 0) {
122 return;
123 } else {
124 return $self->next_seq();
126 } else {
127 return $seq;
132 =head2 next_primary_seq
134 Title : next_primary_seq
135 Usage :
136 Function:
137 Example :
138 Returns :
139 Args :
141 =cut
143 sub next_primary_seq{
144 my ($self, @args) = @_;
145 my $seq = $self->_current_seqio->next_primary_seq();
146 if( !defined $seq ) {
147 if( $self->_load_file() == 0) {
148 return;
149 } else {
150 return $self->next_primary_seq();
152 } else {
153 return $seq;
158 =head2 _load_file
160 Title : _load_file
161 Usage :
162 Function:
163 Example :
164 Returns :
165 Args :
167 =cut
169 sub _load_file{
170 my ($self, @args) = @_;
171 my $file = shift @{$self->{'_file_array'}};
172 if( !defined $file ) {
173 return 0;
175 my $seqio;
176 my $format = $self->format;
177 if ($format) {
178 $seqio = Bio::SeqIO->new( -file => $file, -format => $format );
179 } else {
180 $seqio = Bio::SeqIO->new( -file => $file );
181 $self->format($seqio->format) if not $format;
184 # should throw an exception - but if not...
185 if( !defined $seqio) {
186 $self->throw("Could not build SeqIO object for $file!");
188 $self->_current_seqio($seqio);
189 return 1;
193 =head2 _set_file
195 Title : _set_file
196 Usage :
197 Function:
198 Example :
199 Returns :
200 Args :
202 =cut
204 sub _set_file{
205 my ($self, @files) = @_;
206 push @{$self->{'_file_array'}}, @files;
210 =head2 _current_seqio
212 Title : _current_seqio
213 Usage : $obj->_current_seqio($newval)
214 Function:
215 Example :
216 Returns : value of _current_seqio
217 Args : newvalue (optional)
219 =cut
221 sub _current_seqio{
222 my ($obj, $value) = @_;
223 if( defined $value) {
224 $obj->{'_current_seqio'} = $value;
226 return $obj->{'_current_seqio'};
230 # We overload the format() method of Bio::Root::IO by a simple get/set
232 sub format{
233 my ($obj, $value) = @_;
234 if( defined $value) {
235 $obj->{'_format'} = $value;
237 return $obj->{'_format'};