Bio-Community
view release on metacpan or search on metacpan
lib/Bio/Community/Member.pm view on Meta::CPAN
The identifier for this community member. An ID is necessary and sufficient to
identify a community member, but additional information can be attached to a
member.
my $obj1 = Bio::Community::Member->new( -id => 153 );
my $obj2 = $obj1;
my $obj3 = Bio::Community::Member->new( -id => 153 );
my $obj4 = Bio::Community::Member->new( -id => 6123 );
my $obj5 = Bio::Community::Member->new( ); # automatically assigned ID
In the above example, $obj1, $obj2 and $obj3 represent the same member, while
$obj4 represents a different member, and $obj5 yet another member.
=back
=head1 AUTHOR
Florent Angly L<florent.angly@gmail.com>
=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::Member object
Usage : my $member = Bio::Community::Member->new( );
Args : -id, -desc, -taxon, -seqs, -weights
Returns : a new Bio::Community::Member object
=cut
package Bio::Community::Member;
use Moose;
use MooseX::NonMoose;
use MooseX::StrictConstructor;
use namespace::autoclean;
use Method::Signatures;
use Bio::Community::Types;
extends 'Bio::Root::Root';
with 'Bio::Community::Role::Described' , # -desc
'Bio::Community::Role::Classified', # -taxon
'Bio::Community::Role::Sequenced' , # -seqs
'Bio::Community::Role::Weighted' ; # -weights
use constant PREFIX => 'bc';
my $max_num = 0;
# First ID is 'bc1'
my $id_re = '^'.PREFIX.'(\d+)$';
$id_re = qr/$id_re/;
my $mod_re = qr/^Bio::Community/;
=head2 id
Function: my $description = $member->id();
Usage : Get or set the ID for the member. If an ID is not provided, a unique
ID prefixed with 'bc' is generated, e.g. 'bc1', 'bc2', etc. This
makes it easy to distinguish IDs assigned by Bio::Community::Member
from IDs obtained from other sources, e.g. Greengenes taxa ID or
QIIME arbitrary OTU ID. Use of the 'bc' prefix is restricted to the
L<Bio::Community::Member> module; please refrain from using it yourself.
Args : A string
Returns : A string
=cut
has id => (
is => 'rw',
isa => 'Str',
required => 0,
init_arg => '-id',
lazy => 0,
predicate => '_has_id',
trigger => \&_auto_id, # only when setting the ID
);
method BUILD ($args) {
# Ensure that a default ID is assigned if needed after object construction
$self->_auto_id( $self->id );
}
method _auto_id ($id?, $old_id?) {
# Validate given ID or assign a new ID automatically
if (not defined $id) {
# Assign a new ID
#$self->id( PREFIX.$max_num++ ); # warns because of call to _register_id
$self->{id} = PREFIX.++$max_num
} else {
# Validate ID
( run in 0.598 second using v1.01-cache-2.11-cpan-39bf76dae61 )