blib/lib/Bio/Community/Member.pm

filter: Statementstmt 100% 51 / 51 Branchbran 75.0% 9 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 93.9% 78 / 83 CC 9 SCAR 12.6
CC
9
Cov
94%
_auto_id
7.0
BUILD
3.1
BEGIN
1.0
CRAP 3.5
« blib/lib/Bio/Community/Meta.pm ↑ Summary blib/lib/Bio/Community/Role/PRNG.pm »
1 # BioPerl module for Bio::Community::Member
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Copyright 2011-2014 Florent Angly <florent.angly@gmail.com>
6 #
7 # You may distribute this module under the same terms as perl itself
8  
9  
10 =head1 NAME
11  
12 Bio::Community::Member - The basic constituent of a biological community
13  
14 =head1 SYNOPSIS
15  
16 use Bio::Community::Member;
17  
18 my $member1 = Bio::Community::Member->new( -id => 2, -desc => 'Homo sapiens' );
19 print "Got member ".$member1->desc." (ID ".$member1->id.")\n";
20  
21 my $member2 = Bio::Community::Member->new( );
22 my $member2_id = $member2->id;
23  
24 =head1 DESCRIPTION
25  
26 A Bio::Community::Member represents an organism, individual, species, amplicon
27 sequence, shotgun sequence or anything you like.
28  
29 =head1 CONSTRUCTOR
30  
31 =head2 Bio::Community::Member->new()
32  
33 my $member = Bio::Community::Member->new();
34  
35 The new() class method constructs a new Bio::Community::Member object and
36 accepts the following parameters:
37  
38 =head1 OBJECT METHODS
39  
40 =item id
41  
42 The identifier for this community member. An ID is necessary and sufficient to
43 identify a community member, but additional information can be attached to a
44 member.
45  
46 my $obj1 = Bio::Community::Member->new( -id => 153 );
47 my $obj2 = $obj1;
48 my $obj3 = Bio::Community::Member->new( -id => 153 );
49 my $obj4 = Bio::Community::Member->new( -id => 6123 );
50 my $obj5 = Bio::Community::Member->new( ); # automatically assigned ID
51  
52 In the above example, $obj1, $obj2 and $obj3 represent the same member, while
53 $obj4 represents a different member, and $obj5 yet another member.
54  
55 =back
56  
57 =head1 AUTHOR
58  
59 Florent Angly L<florent.angly@gmail.com>
60  
61 =head1 SUPPORT AND BUGS
62  
63 User feedback is an integral part of the evolution of this and other Bioperl
64 modules. Please direct usage questions or support issues to the mailing list,
65 L<bioperl-l@bioperl.org>, rather than to the module maintainer directly. Many
66 experienced and reponsive experts will be able look at the problem and quickly
67 address it. Please include a thorough description of the problem with code and
68 data examples if at all possible.
69  
70 If you have found a bug, please report it on the BioPerl bug tracking system
71 to help us keep track the bugs and their resolution:
72 L<https://redmine.open-bio.org/projects/bioperl/>
73  
74 =head1 COPYRIGHT
75  
76 Copyright 2011-2014 by Florent Angly <florent.angly@gmail.com>
77  
78 This library is free software; you can redistribute it and/or modify
79 it under the same terms as Perl itself, either Perl version 5.10.1 or,
80 at your option, any later version of Perl 5 you may have available.
81  
82 =head1 APPENDIX
83  
84 The rest of the documentation details each of the object
85 methods. Internal methods are usually preceded with a _
86  
87 =head2 new
88  
89 Function: Create a new Bio::Community::Member object
90 Usage : my $member = Bio::Community::Member->new( );
91 Args : -id, -desc, -taxon, -seqs, -weights
92 Returns : a new Bio::Community::Member object
93  
94 =cut
95  
96  
97 package Bio::Community::Member;
98  
99 22 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 22 ▶use MooseX::NonMoose;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 22 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 22 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 22 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 22 ▶use Bio::Community::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 22 extends 'Bio::Root::Root';
107  
108 22 with 'Bio::Community::Role::Described' , # -desc
109 'Bio::Community::Role::Classified', # -taxon
110 'Bio::Community::Role::Sequenced' , # -seqs
111 'Bio::Community::Role::Weighted' ; # -weights
112  
113  
114 22 ▶use constant PREFIX => 'bc';
Subroutine BEGIN: called CC=1 SCAR=0.0
115 22 my $max_num = 0;
116 # First ID is 'bc1'
117  
118 22 my $id_re = '^'.PREFIX.'(\d+)$';
119 22 $id_re = qr/$id_re/;
120  
121 22 my $mod_re = qr/^Bio::Community/;
122  
123  
124 =head2 id
125  
126 Function: my $description = $member->id();
127 Usage : Get or set the ID for the member. If an ID is not provided, a unique
128 ID prefixed with 'bc' is generated, e.g. 'bc1', 'bc2', etc. This
129 makes it easy to distinguish IDs assigned by Bio::Community::Member
130 from IDs obtained from other sources, e.g. Greengenes taxa ID or
131 QIIME aritrary OTU ID. Use of the 'bc' prefix is restricted to the
132 L<Bio::Community::Member> module; please refrain from using it yourself.
133 Args : A string
134 Returns : A string
135  
136 =cut
137  
138 22 has id => (
139 is => 'rw',
140 isa => 'Str',
141 required => 0,
142 init_arg => '-id',
143 lazy => 0,
144 predicate => '_has_id',
145 trigger => \&_auto_id, # only when setting the ID
146 );
147  
148  
149 22 ▶method BUILD ($args) {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BUILD: called CC=3 SCAR=11.2
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 379 379
if scalar @_ > 1 0 379 379
150 # Ensure that a default ID is assigned if needed after object construction
151 379 $self->_auto_id( $self->id );
152 }
153  
154  
155 22 ▶method _auto_id ($id?, $old_id?) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _auto_id: called CC=7 SCAR=19.5
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 654 654
156 # Validate given ID or assign a new ID automatically
157 654 ▶ if (not defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $id) { } 115 539 654
158 # Assign a new ID
159 #$self->id( PREFIX.$max_num++ ); # warns because of call to _register_id
160 115 $self->{id} = PREFIX.++$max_num
161 } else {
162 # Validate ID
163 539 ▶ if ( ($id =~ $id_re) && ((caller(0))[0] !~ $mod_re) && ((caller(1))[0] !~ $mod_re) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /$id_re/ and not +(&CORE::GLOBAL::caller(0))[0] =~ /$mod_re/ and not +(&CORE::GLOBAL::caller(1))[0] =~ /$mod_re/) 2 537 539
Condition83%5/6
$id =~ /$id_re/ and not +(&CORE::GLOBAL::caller(0))[0] =~ /$mod_re/ and not +(&CORE::GLOBAL::caller(1))[0] =~ /$mod_re/
!ll&&!rl&&r
53702
$id =~ /$id_re/ and not +(&CORE::GLOBAL::caller(0))[0] =~ /$mod_re/
!ll&&!rl&&r
53522
MC/DC66%2/3
$id =~ /$id_re/ and not +(&CORE::GLOBAL::caller(0))[0] =~ /$mod_re/ and not +(&CORE::GLOBAL::caller(1))[0] =~ /$mod_re/
$id =~ /$id_re/ not +(&CORE::GLOBAL::caller(0))[0] =~ /$mod_re/ not +(&CORE::GLOBAL::caller(1))[0] =~ /$mod_re/
Truth table75%3/4
A and not(B) and not(C)
A= $id =~ /$id_re/B= not +(&CORE::GLOBAL::caller(0))[0] =~ /$mod_re/C= not +(&CORE::GLOBAL::caller(1))[0] =~ /$mod_re/
ABCresult
0XX0
10X0
1100
1111
164 # Check validity of 'bcXX' IDs not requested by Bio::Community* modules
165 2 my $num = $1;
166 2 ▶ if ($num > $max_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > $max_num) { } 1 1 2
167 1 $max_num = $num;
168 } else {
169 1 $self->warn("Request to assign ID $id to member but we are at ID ".
170 PREFIX."$max_num already. ID might not be unique!");
171 }
172 }
173 }
174 654 return 1;
175 }
176  
177  
178 =head2 desc
179  
180 Usage : my $description = $member->desc();
181 Function: Get or set a description for this object.
182 See L<Bio::Community::Role::Described>.
183 Args : A string
184 Returns : A string
185  
186 =head2 taxon
187  
188 Usage : my $taxon = $member->taxon();
189 Function: Get or set a taxon (or species) for this object.
190 See L<Bio::Community::Role::Classified>.
191 Args : A Bio::Taxon object
192 Returns : A Bio::Taxon object
193  
194 =head2 seqs
195  
196 Usage : my $seqs = $member->seqs();
197 Function: Get or set some sequences for this object.
198 See L<Bio::Community::Role::Sequenced>.
199 Args : An arrayref of Bio::SeqI objects
200 Returns : An arrayref of Bio::SeqI objects
201  
202 =head2 weights
203  
204 Usage : my $weights = $member->weights();
205 Function: Get or set some weights for this object. Weights represent how biased
206 the sampling of this organism is. For example, when random shotgun
207 sequencing microorganisms in the environment, the relative abundance
208 of reads in the sequence library is not proportional to the relative
209 abundance of the genomes because larger genomes contribute
210 disproportionalely more reads than small genomes. In such a case, you
211 could set the weight to the length of the genome. See
212 L<Bio::Community::Role::Weighted>. Also see get_count() and get_rel_ab()
213 in L<Bio::Community>.
214 Args : An arrayref of positive integers
215 Returns : An arrayref of positive integers
216  
217 =cut
218  
219  
220 ####
221 # TODO:
222 # For on the fly attributes: http://stackoverflow.com/questions/3996067/how-can-i-flexibly-add-data-to-moose-objects
223 # For flexible attributes: https://github.com/cjfields/biome/blob/master/lib/Biome/Role/Identifiable.pm
224 ####
225  
226  
227 22 __PACKAGE__->meta->make_immutable;
228  
229 22 1;
« blib/lib/Bio/Community/Meta.pm ↑ Summary blib/lib/Bio/Community/Role/PRNG.pm »