Bio-Community

 view release on metacpan or  search on metacpan

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

=head1 SUPPORT AND BUGS

User feedback is an integral part of the evolution of this and other Bioperl
modules. Please direct usage questions or support issues to the mailing list, 
L<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.

If you have found a bug, please report it on the BioPerl bug tracking system
to help us keep track the bugs and their resolution:
L<https://redmine.open-bio.org/projects/bioperl/>

=head1 COPYRIGHT

Copyright 2011-2014 by Florent Angly <florent.angly@gmail.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.1 or,
at your option, any later version of Perl 5 you may have available.

=head1 APPENDIX

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

=head2 new

 Function: Create a new Bio::Community::IO object
 Usage   : # Reading a file
           my $in = Bio::Community::IO->new( -file => 'community.txt' );
           # Writing a file
           my $out = Bio::Community::IO->new( -file => '>community.txt',
                                              -format => 'generic'       );
 Args    : -file : Path of a community file. See file() in Bio::Root::IO.
           -format : Format of the file, either 'generic', 'biom', 'gaas',
               'qiime' or 'unifrac'. This is optional when reading a community
               file because the format is automatically detected by the
               Bio::Community::IO::FormatGuesser module. See also format() in
               Bio::Root::IO.
           -weight_files : Arrayref of files (or filehandles) that contain
               weights to assign to members. See weight_files().
           -weight_assign : When using files of weights, define what to do for
               community members that do not have weights. See weight_assign().
           -taxonomy: Given a Bio::DB::Taxonomy object, try to place the community
               members in this taxonomy. See taxonomy().
           -skip_empty_communities: Skip communities with no members. See
               skip_empty_communities()
           See the documentation for _initialize_io() in Bio::Root::IO for other
           accepted constructors like -fh, -string, -input, or -url.
 Returns : A Bio::Community::IO object

=cut


package Bio::Community::IO;

use Moose;
use Moose::Util qw/does_role/;
use MooseX::NonMoose;
use namespace::autoclean;
use Module::Runtime;
use Method::Signatures;
use Bio::Community;
use Bio::Community::Meta;
use Bio::Community::Types;
use Bio::Community::IO::FormatGuesser;
use Bio::Community::TaxonomyUtils
   qw(split_lineage_string get_taxon_lineage get_lineage_string clean_lineage_arr);

extends 'Bio::Root::Root',
        'Bio::Root::IO';


has '_meta' => (
   is => 'rw',
   #isa => undef, # Bio::Community::Meta
   required => 0,
   init_arg => undef,
   default => undef,
   lazy => 1,
);


# Overriding new... Is there a better alternative?

func new ($class, @args) {
   my $real_class = Scalar::Util::blessed($class) || $class;

   # These all come from the same base, Moose::Object, so this is fine
   my $params = $real_class->BUILDARGS(@args);
   my $format = delete $params->{'-format'};
   if (not defined $format) {
      # Try to guess format
      my $guesser = Bio::Community::IO::FormatGuesser->new();
      if ($params->{'-file'}) {
         $guesser->file( $params->{'-file'} );
      } elsif ($params->{'-fh'}) {
         $guesser->fh( $params->{'-fh'} );
      }
      $format = $guesser->guess;
   }
   if (not defined $format) {
      $real_class->throw("Could not automatically detect input format.");
   }

   # Use the real driver class here
   $real_class = __PACKAGE__.'::Driver::'.$format;
   Module::Runtime::use_module($real_class);
   $class->throw("Module $real_class does not implement a community IO stream")
       unless $real_class->does('Bio::Community::Role::IO');

   $params = $real_class->BUILDARGS(%$params);
   my $self = Class::MOP::Class->initialize($real_class)->new_object($params);

   return $self;
}


method BUILD ($args) {
   # Start IOs



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