Permalink
Browse files

Little changes and fixes

  • Loading branch information...
1 parent 57993e1 commit 2a8084cf1a0d124af1c05d59e801a8d909e8e952 @fangly fangly committed Apr 19, 2012
Showing with 20 additions and 26 deletions.
  1. +8 −8 lib/Bio/Community.pm
  2. +1 −0 lib/Bio/Community/Tools/Distance.pm
  3. +5 −12 lib/Bio/Community/Tools/Sampler.pm
  4. +6 −6 lib/Bio/Community/Types.pm
View
@@ -33,8 +33,10 @@ Bio::Community - A biological community
=head1 DESCRIPTION
-A Bio::Community is composed of Bio::Community::Member objects at a specified
-abundance.
+The Bio::Community module represent communities of biological organisms. It is
+composed of Bio::Community::Member objects at a specified abundance. Each member
+can represent a species (e.g. an elephant, a bacterium) or a proxy for a species,
+such as a DNA sequence.
=head1 FEEDBACK
@@ -341,9 +343,10 @@ method get_member_by_id (Int $member_id) {
=head2 get_member_by_rank
Title : get_member_by_rank
- Function: Fetch a member based on its abundance rank
+ Function: Fetch a member based on its abundance rank. A smaller rank corresponds
+ to a larger relative abundance.
Usage : my $member = $community->get_member_by_rank(1);
- Args : positive integer for the member rank
+ Args : strictly positive integer for the member rank
Returns : a Bio::Community::Member object or undef if member was not found
=cut
@@ -471,10 +474,7 @@ method _calc_ranks {
# 1/ Get abundance of all members and sort them
my $members = [ $self->all_members ];
- my $rel_abs = [ ];
- for my $member (@$members) {
- push @$rel_abs, $self->get_rel_ab($member);
- }
+ my $rel_abs = [ map { $self->get_rel_ab($_) } @$members ];
# 2/ Save ranks in an array
($rel_abs, $members) = _two_array_sort($rel_abs, $members);
@@ -139,6 +139,7 @@ has type => (
=cut
####after new => sub { # prevents inlining
+#### or maybe try BUILD
method get_distance () {
my $dist;
my $type = $self->type;
@@ -26,15 +26,6 @@ Bio::Community::Tools::Sampler - Sample organisms according to their abundance
Pick individuals at random from a community
-=head1 CONSTRUCTOR
-
-=head2 Bio::Community::Tools::Sampler->new()
-
- my $member = Bio::Community::Member->new();
-
-The new() class method constructs a new Bio::Community::Tools::Sampler object and
-accepts the following parameters:
-
=head1 OBJECT METHODS
=head1 FEEDBACK
@@ -83,7 +74,7 @@ methods. Internal methods are usually preceded with a _
Title : new
Function: Create a new Bio::Community::Tool::Sampler object
Usage : my $sampler = Bio::Community::Tool::Sampler->new( );
- Args :
+ Args : -community (see below)
Returns : a new Bio::Community::Tools::Sampler object
=cut
@@ -149,7 +140,7 @@ has _members => (
=head2 get_rand_member
Title : get_rand_member
- Function: Get a random member from a community
+ Function: Get a random member from a community (sample with replacement).
Usage : my $member = $sampler->get_rand_member();
Args : None
Returns : A Bio::Community::Member object
@@ -164,12 +155,14 @@ method get_rand_member () {
return ${$self->_members}[$index];
}
+### TODO: option to sample without replacement!
+
=head2 get_rand_community
Title : get_rand_community
Function: Create a community from random members of a community
- Usage : my $ = $sampler->get_rand_member();
+ Usage : my $community = $sampler->get_rand_community(1000);
Args : Number of members
Returns : A Bio::Community object
View
@@ -60,22 +60,22 @@ use namespace::autoclean;
subtype 'PositiveNum'
=> as 'Num'
=> where { $_ >= 0 }
- => message { "Only positive numbers accepted, but got '$_'" };
+ => message { "Only positive numbers accepted, but got '".($_||'')."'" };
subtype 'StrictlyPositiveNum'
=> as 'PositiveNum'
=> where { $_ > 0 }
- => message { "Only strictly positive numbers accepted, but got '$_'" };
+ => message { "Only strictly positive numbers accepted, but got '".($_||'')."'" };
subtype 'PositiveInt'
=> as 'Int'
=> where { $_ >= 0 }
- => message { "Only positive integers accepted, but got '$_'" };
+ => message { "Only positive integers accepted, but got '".($_||'')."'" };
subtype 'StrictlyPositiveInt'
=> as 'PositiveInt'
=> where { $_ > 0 }
- => message { "Only strictly positive integers accepted, but got '$_'" };
+ => message { "Only strictly positive integers accepted, but got '".($_||'')."'" };
# A Count should be a positive integer but to make things easier. We sometimes
@@ -88,14 +88,14 @@ subtype 'Count'
subtype 'NumericSort'
=> as 'Int'
=> where { ($_ >= -1) && ($_ <= 1) }
- => message { "This only accepts 0 (off), 1 (increasing) or -1 (decreasing), but got '$_'" };
+ => message { "This only accepts 0 (off), 1 (increasing) or -1 (decreasing), but got '".($_||'')."'" };
# Type of abundance: count, percentage, fraction
subtype 'AbundanceType'
=> as 'Str'
=> where { $_ =~ m/^(count|percentage|fraction)$/ }
- => message { "This only accepts 'count', 'percentage', or 'fraction', but got '$_'" };
+ => message { "This only accepts 'count', 'percentage', or 'fraction', but got '".($_||'')."'" };
# Rank: a strictly positive integer
subtype 'AbundanceRank'

0 comments on commit 2a8084c

Please sign in to comment.