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
16 Bio::SeqIO::MultiFile - Treating a set of files as a single input stream
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
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>.
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
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.
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
68 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
73 # Let the code begin...
76 package Bio
::SeqIO
::MultiFile
;
80 use base
qw(Bio::SeqIO);
83 # _initialize is where the heavy stuff will happen when new is called
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");
118 my ($self, @args) = @_;
119 my $seq = $self->_current_seqio->next_seq();
120 if( !defined $seq ) {
121 if( $self->_load_file() == 0) {
124 return $self->next_seq();
132 =head2 next_primary_seq
134 Title : next_primary_seq
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) {
150 return $self->next_primary_seq();
170 my ($self, @args) = @_;
171 my $file = shift @
{$self->{'_file_array'}};
172 if( !defined $file ) {
176 my $format = $self->format;
178 $seqio = Bio
::SeqIO
->new( -file
=> $file, -format
=> $format );
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);
205 my ($self, @files) = @_;
206 push @
{$self->{'_file_array'}}, @files;
210 =head2 _current_seqio
212 Title : _current_seqio
213 Usage : $obj->_current_seqio($newval)
216 Returns : value of _current_seqio
217 Args : newvalue (optional)
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
233 my ($obj, $value) = @_;
234 if( defined $value) {
235 $obj->{'_format'} = $value;
237 return $obj->{'_format'};