Bio-Community
view release on metacpan or search on metacpan
lib/Bio/Community.pm view on Meta::CPAN
}
####
# TODO: get_member_by_rel_ab
# get_member_by_abs_ab
# get_member_by_count
####
=head2 get_richness
Function: Report the community richness or number of different types of members.
This is a form of alpha diversity.
Usage : my $alpha_richness = $community->get_richness();
Args : none
Returns : integer for the richness
=cut
method get_richness () {
$self->_reset if $self->_has_changed;
if (not defined $self->_richness) {
# Try to calculate the richness from the abundance ranks if available
my $num_members = scalar( @{$self->_ranks_arr_weighted} ) ||
scalar( @{$self->_ranks_arr_unweighted} ) ;
# If rank abundance are not available, calculate richness manually
if ($num_members == 0) {
while ($self->next_member('_get_alpha_richness_ite')) {
$num_members++;
}
}
# Save richness for later re-use
$self->_richness($num_members);
}
return $self->_richness;
}
=head2 get_count
Function: Fetch the abundance or count of a member
Usage : my $count = $community->get_count($member);
Args : a Bio::Community::Member object
Returns : An integer for the count of this member, including zero if the member
was not present in the community.
=cut
#method get_count (Bio::Community::Member $member) {
method get_count ($member) {
return $self->_counts->{$member->id} || 0;
}
=head2 get_rel_ab
Function: Determine the relative abundance (in percent) of a member in the
community.
Usage : my $rel_ab = $community->get_rel_ab($member);
Args : a Bio::Community::Member object
Returns : an integer between 0 and 100 for the relative abundance of this member
=cut
#method get_rel_ab (Bio::Community::Member $member) {
method get_rel_ab ($member) {
my $rel_ab = 0;
my ($weight , $total_count ) = $self->use_weights ?
($member->get_weights_prod, $self->_weighted_count ) :
(1 , $self->get_members_count) ;
if ($total_count) {
$rel_ab = $self->get_count($member) * 100 / ($weight * $total_count);
}
return $rel_ab;
}
=head2 get_abs_ab
Function: Determine the absolute abundance of a member in the community, i.e.,
its C<get_rel_ab()> multiplied by its C<get_members_abundance()>.
Usage : my $abs_ab = $community->get_abs_ab($member);
Args : a Bio::Community::Member object
Returns : a number for the absolute abundance of this member
=cut
#method get_abs_ab (Bio::Community::Member $member) {
method get_abs_ab ($member) {
return $self->get_rel_ab($member) / 100 * $self->get_members_abundance;
}
=head2 get_rank
Function: Determine the abundance rank of a member in the community. The
organism with the highest relative abundance has rank 1, the second-
most abundant has rank 2, etc.
Usage : my $rank = $community->get_rank($member);
Args : a Bio::Community::Member object
Returns : integer for the abundance rank of this member or undef if the member
was not found
=cut
#method get_rank (Bio::Community::Member $member) {
method get_rank ($member) {
$self->_reset if $self->_has_changed;
my $member_id = $member->id;
if ( $self->get_member_by_id($member_id) ) { # If the member exists
if ( $self->use_weights && (scalar @{$self->_ranks_arr_weighted} == 0) ) {
# Calculate relative abundance based ranks if ranks do not already exist
$self->_calc_ranks();
}
if ( (not $self->use_weights) && (scalar @{$self->_ranks_arr_unweighted} == 0) ) {
# Calculate relative abundance based ranks if ranks do not already exist
$self->_calc_ranks();
( run in 0.875 second using v1.01-cache-2.11-cpan-39bf76dae61 )