Bio-Community
view release on metacpan or search on metacpan
lib/Bio/Community/IO.pm view on Meta::CPAN
-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
$self->_initialize_io(%$args);
return 1;
}
=head2 next_member
Usage : my ($member, $count) = $in->next_member;
Function: Get the next member from the community and its abundance. This
function is implemented by the Bio::Community::IO::Driver used to
parse the given file format.
Args : None
Returns : An array containing:
A Bio::Community::Member object (or undef)
A positive number (or undef)
=cut
method next_member () {
$self->throw_not_implemented;
}
=head2 next_community
Usage : my $community = $in->next_community;
Function: Get the next community. Note that communities without members are
skipped.
Args : None
Returns : A Bio::Community object
or
undef if there were no communities left
=cut
method next_community () {
my $community;
if (not defined $self->_meta) {
$self->_next_metacommunity_init( );
( run in 0.988 second using v1.01-cache-2.11-cpan-39bf76dae61 )