Bio-Variation

 view release on metacpan or  search on metacpan

lib/Bio/Variation/IO.pm  view on Meta::CPAN

  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution.  Bug reports can be submitted via the
web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHOR - Heikki Lehvaslaiho

Email:  heikki-at-bioperl-dot-org

=head1 APPENDIX

The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _

=cut

# Let the code begin...

package Bio::Variation::IO;
$Bio::Variation::IO::VERSION = '1.7.5';
use strict;


use base qw(Bio::SeqIO Bio::Root::IO);

=head2 new

 Title   : new
 Usage   : $stream = Bio::Variation::IO->new(-file => $filename, -format => 'Format')
 Function: Returns a new seqstream
 Returns : A Bio::Variation::IO::Handler initialised with the appropriate format
 Args    : -file => $filename
           -format => format
           -fh => filehandle to attach to

=cut


sub new {
   my ($class, %param) = @_;
   my ($format);

   @param{ map { lc $_ } keys %param } = values %param;  # lowercase keys
   $format = $param{'-format'}
             || $class->_guess_format( $param{-file} || $ARGV[0] )
             || 'flat';
   $format = "\L$format"; # normalize capitalization to lower case

   return unless $class->_load_format_module($format);
   return "Bio::Variation::IO::$format"->new(%param);
}


=head2 format

 Title   : format
 Usage   : $format = $stream->format()
 Function: Get the variation format
 Returns : variation format
 Args    : none

=cut

# format() method inherited from Bio::Root::IO


sub _load_format_module {
  my ($class, $format) = @_;
  my $module = "Bio::Variation::IO::" . $format;
  my $ok;  
  eval {
      $ok = $class->_load_module($module);
  };
  if ( $@ ) {
    print STDERR <<END;
$class: $format cannot be found
Exception $@
For more information about the IO system please see the IO docs.
This includes ways of checking for formats at compile time, not run time
END
  ;
  }
  return $ok;
}

=head2 next

 Title   : next
 Usage   : $seqDiff = $stream->next
 Function: reads the next $seqDiff object from the stream
 Returns : a Bio::Variation::SeqDiff object
 Args    :

=cut

sub next {
   my ($self, $seq) = @_;
   $self->throw("Sorry, you cannot read from a generic Bio::Variation::IO object.");
}

sub next_seq {
   my ($self, $seq) = @_;
   $self->throw("These are not sequence objects. Use method 'next' instead of 'next_seq'.");
   $self->next($seq);
}

=head2 write

 Title   : write
 Usage   : $stream->write($seq)
 Function: writes the $seq object into the stream
 Returns : 1 for success and 0 for error
 Args    : Bio::Variation::SeqDiff object

=cut

sub write {
    my ($self, $seq) = @_;
    $self->throw("Sorry, you cannot write to a generic Bio::Variation::IO object.");
}

sub write_seq {
   my ($self, $seq) = @_;
   $self->warn("These are not sequence objects. Use method 'write' instead of 'write_seq'.");
   $self->write($seq);
}

=head2 _guess_format

 Title   : _guess_format
 Usage   : $obj->_guess_format($filename)
 Function:
 Example :
 Returns : guessed format of filename (lower case)
 Args    :

=cut

sub _guess_format {
   my $class = shift;
   return unless $_ = shift;
   return 'flat'     if /\.dat$/i;
   return 'xml'     if /\.xml$/i;
}


1;



( run in 1.486 second using v1.01-cache-2.11-cpan-39bf76dae61 )