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
;
79 use base
qw(Bio::SeqIO);
82 # _initialize is where the heavy stuff will happen when new is called
85 my($self, @args) = @_;
87 $self->SUPER::_initialize
(@args);
89 my ($file_array, $format) = $self->_rearrange([qw(FILES FORMAT)], @args);
90 if( !defined $file_array || ! ref $file_array ) {
91 $self->throw("Must have an array files for MultiFile");
94 $self->{'_file_array'} = [];
95 $self->_set_file(@
$file_array);
97 $self->format($format) if defined $format;
99 if( $self->_load_file() == 0 ) {
100 $self->throw("Unable to initialise the first file");
117 my ($self, @args) = @_;
118 my $seq = $self->_current_seqio->next_seq();
119 if( !defined $seq ) {
120 if( $self->_load_file() == 0) {
123 return $self->next_seq();
131 =head2 next_primary_seq
133 Title : next_primary_seq
142 sub next_primary_seq
{
143 my ($self, @args) = @_;
144 my $seq = $self->_current_seqio->next_primary_seq();
145 if( !defined $seq ) {
146 if( $self->_load_file() == 0) {
149 return $self->next_primary_seq();
169 my ($self, @args) = @_;
170 my $file = shift @
{$self->{'_file_array'}};
171 if( !defined $file ) {
175 my $format = $self->format;
177 $seqio = Bio
::SeqIO
->new( -file
=> $file, -format
=> $format );
179 $seqio = Bio
::SeqIO
->new( -file
=> $file );
180 $self->format($seqio->format) if not $format;
183 # should throw an exception - but if not...
184 if( !defined $seqio) {
185 $self->throw("Could not build SeqIO object for $file!");
187 $self->_current_seqio($seqio);
204 my ($self, @files) = @_;
205 push @
{$self->{'_file_array'}}, @files;
209 =head2 _current_seqio
211 Title : _current_seqio
212 Usage : $obj->_current_seqio($newval)
215 Returns : value of _current_seqio
216 Args : newvalue (optional)
221 my ($obj, $value) = @_;
222 if( defined $value) {
223 $obj->{'_current_seqio'} = $value;
225 return $obj->{'_current_seqio'};
229 # We overload the format() method of Bio::Root::IO by a simple get/set
232 my ($obj, $value) = @_;
233 if( defined $value) {
234 $obj->{'_format'} = $value;
236 return $obj->{'_format'};