Cluster/SequenceFamily.pm

filter: Statementstmt 83.7% 77 / 92 Branchbran 58.8% 20 / 34 Conditioncond 41.6% 5 / 12 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 83.3% 15 / 18 Podpod 100% 15 / 15 totaltotal 75.5% 133 / 176 CC 23 SCAR 15.5
CC
23
Cov
74%
get_members
8.8
new
7.9
alignment
6.0
CRAP 4.7
« Cluster/UniGene.pm ↑ Summary Cluster/ClusterFactory.pm »
1 #
2 # BioPerl module for Bio::Cluster::SequenceFamily
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
7 #
8 # Copyright Shawn Hoon
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Cluster::SequenceFamily - Sequence Family object
17  
18 =head1 SYNOPSIS
19  
20 use Bio::SeqIO;
21 use Bio::Cluster::SequenceFamily;
22 use File::Spec;
23  
24 my $file = File::Spec->catfile('t','data','swiss.dat');
25 my $seqio= Bio::SeqIO->new(-format => 'swiss',
26 -file => $file);
27 my @mem;
28 while(my $seq = $seqio->next_seq){
29 push @mem, $seq;
30 }
31  
32 #create the family
33 my $family = Bio::Cluster::SequenceFamily->new(
34 -family_id=>"Family_1",
35 -description=>"Family Description Here",
36 -annotation_score=>"100",
37 -members=>\@mem);
38  
39 #access the family
40  
41 foreach my $mem ($family->get_members){
42 print $mem->display_id."\t".$mem->desc."\n";
43 }
44  
45 #select members if members have a Bio::Species Object
46  
47 my @mem = $family->get_members(-binomial=>"Homo sapiens");
48 @mem = $family->get_members(-ncbi_taxid => 9606);
49 @mem = $family->get_members(-common_name=>"Human");
50 @mem = $family->get_members(-species=>"sapiens");
51 @mem = $family->get_members(-genus=>"Homo");
52  
53 =head1 DESCRIPTION
54  
55 This is a simple Family object that may hold any group of object. For more
56 specific families, one should derive from FamilyI.
57  
58 =head1 FEEDBACK
59  
60 Email bioperl-l@bioperl.org for support and feedback.
61  
62 =head2 Mailing Lists
63  
64 User feedback is an integral part of the evolution of this and other
65 Bioperl modules. Send your comments and suggestions preferably to one
66 of the Bioperl mailing lists. Your participation is much appreciated.
67  
68 bioperl-l@bioperl.org - General discussion
69 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
70  
71 =head2 Support
72  
73 Please direct usage questions or support issues to the mailing list:
74  
75 I<bioperl-l@bioperl.org>
76  
77 rather than to the module maintainer directly. Many experienced and
78 reponsive experts will be able look at the problem and quickly
79 address it. Please include a thorough description of the problem
80 with code and data examples if at all possible.
81  
82 =head2 Reporting Bugs
83  
84 Report bugs to the Bioperl bug tracking system to help us keep track
85 the bugs and their resolution. Bug reports can be submitted via the
86 web:
87  
88 https://github.com/bioperl/bioperl-live/issues
89  
90 =head1 AUTHOR - Shawn Hoon
91  
92 Email shawnh@fugu-sg.org
93  
94 =head1 APPENDIX
95  
96 The rest of the documentation details each of the object
97 methods. Internal methods are usually preceded with a "_".
98  
99 =cut
100  
101 # Let the code begin...
102  
103  
104 package Bio::Cluster::SequenceFamily;
105 2 $Bio::Cluster::SequenceFamily::VERSION = '1.7.3';
106 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 2 ▶use base qw(Bio::Root::Root Bio::Cluster::FamilyI);
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 =head2 new
111  
112 Title : new
113 Usage : my $family = Bio::Cluster::SequenceFamily->new(
114 -family_id=>"Family_1",
115 -description=>"Family Description Here",
116 -annotation_score=>"100",
117 -members=>\@mem);
118 Function: Constructor for SequenceFamily object
119 Returns : Bio::Cluster::SequenceFamily object
120  
121 See L<Bio::Cluster::SequenceFamily>.
122  
123 =cut
124  
125 1 ▶sub new {
Subroutine new: called CC=7 SCAR=20.6
Pod documented
126 1 my ($class,@args) = @_;
127 1 my $self = $class->SUPER::new(@args);
128 1 my ($id,$description,$version,$annot_score,
129 $family_score,$members) = $self->_rearrange([qw(FAMILY_ID DESCRIPTION VERSION
130 ANNOTATION_SCORE
131 FAMILY_SCORE MEMBERS)],@args);
132 1 $self->{'_members'} = [];
133 1 ▶ $id && $self->family_id($id);
Branch: 1 branch
BranchTrueFalseTotal
$id and $self->family_id($id) 1 0 1
134 1 ▶ $description && $self->description($description);
Branch: 1 branch
BranchTrueFalseTotal
$description and $self->description($description) 1 0 1
135 1 ▶ $version && $self->version($version);
Branch: 1 branch
BranchTrueFalseTotal
$version and $self->version($version) 1 0 1
136 1 ▶ $annot_score && $self->annotation_score($annot_score);
Branch: 1 branch
BranchTrueFalseTotal
$annot_score and $self->annotation_score($annot_score) 1 0 1
137 1 ▶ $family_score && $self->family_score($family_score);
Branch: 1 branch
BranchTrueFalseTotal
$family_score and $self->family_score($family_score) 1 0 1
138 1 ▶ $members && $self->add_members($members);
Branch: 1 branch
BranchTrueFalseTotal
$members and $self->add_members($members) 1 0 1
139  
140 1 return $self;
141 }
142  
143 =head2 version
144  
145 Title : version
146 Usage : $family->version("1.0");
147 Function: get/set for version
148 Returns : a string version of the family generated.
149  
150 =cut
151  
152 2 ▶sub version{
Subroutine version: called CC=2 SCAR=6.9
Pod documented
153 2 my ($self,$value) = @_;
154 2 ▶ if($value){
Branch: 1 branch
BranchTrueFalseTotal
if ($value) 1 1 2
155 1 $self->{'_version'} =$value;
156 }
157 2 return $self->{'_version'};
158 }
159  
160 =head2 annotation_score
161  
162 Title : annotation_score
163 Usage : $family->annotation_score(100);
164 Function: get/set for annotation_score which
165 represent the confidence in which the
166 consensus description has been assigned
167 to the family.
168 Returns : Bio::SimpleAlign
169  
170 See L<Bio::SimpleAlign>
171  
172 =cut
173  
174 2 ▶sub annotation_score{
Subroutine annotation_score: called CC=2 SCAR=6.9
Pod documented
175 2 my ($self,$score) = @_;
176 2 ▶ if($score){
Branch: 1 branch
BranchTrueFalseTotal
if ($score) 1 1 2
177 1 $self->{'_annotation_score'} = $score;
178 }
179 2 return $self->{'_annotation_score'};
180 }
181  
182 =head2 alignment
183  
184 Title : alignment
185 Usage : $family->alignment($align);
186 Function: get/set for an alignment object representing
187 the multiple alignment of the members of the family.
188 Returns : Bio::SimpleAlign
189  
190 See L<Bio::SimpleAlign>
191  
192 =cut
193  
194 0 ▶sub alignment {
Subroutine alignment: not called CC=2 SCAR=17.9
Pod documented
195 0 my ($self,$align) = @_;
196 0 ▶ if($align){
Branch: 1 branch
BranchTrueFalseTotal
if ($align) 0 0 0
197 0 $self->{'_alignment'} = $align;
198 }
199 0 return $self->{'_alignment'};
200 }
201  
202 =head2 tree
203  
204 Title : tree
205 Usage : $family->tree($tree);
206 Function: get/set for an tree object representing
207 the phylogenetic tree of the family.
208 Returns : Bio::Tree
209  
210 See L<Bio::Tree>
211  
212 =cut
213  
214 0 ▶sub tree {
Subroutine tree: not called CC=2 SCAR=17.9
Pod documented
215 0 my ($self,$tree) = @_;
216 0 ▶ if($tree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree) 0 0 0
217 0 $self->{'_tree'} = $tree;
218 }
219 0 return $self->{'_tree'};
220 }
221  
222 =head1 L<Bio::Cluster::FamilyI> methods
223  
224 =cut
225  
226 =head2 family_score
227  
228 Title : family_score
229 Usage : Bio::Cluster::FamilyI->family_score(95);
230 Function: get/set for the score of algorithm used to generate
231 the family if present
232  
233 This is aliased to cluster_score().
234  
235 Returns : the score
236 Args : the score
237  
238 =cut
239  
240 2 ▶sub family_score {
Subroutine family_score: called CC=1 SCAR=0.0
Pod documented
241 2 return shift->cluster_score(@_);
242 }
243  
244  
245 =head2 family_id
246  
247 Title : family_id
248 Usage : $family->family_id("Family_1");
249 Function: get/set for family id
250  
251 This is aliased to display_id().
252  
253 Returns : a string specifying identifier of the family
254  
255 =cut
256  
257 2 ▶sub family_id{
Subroutine family_id: called CC=1 SCAR=0.0
Pod documented
258 2 return shift->display_id(@_);
259 }
260  
261 =head1 L<Bio::ClusterI> methods
262  
263 =cut
264  
265 =head2 display_id
266  
267 Title : display_id
268 Usage :
269 Function: Get/set the display name or identifier for the cluster
270 Returns : a string
271 Args : optional, on set the display ID ( a string)
272  
273 =cut
274  
275 2 ▶sub display_id{
Subroutine display_id: called CC=2 SCAR=6.9
Pod documented
276 2 my ($self,$id) = @_;
277 2 ▶ if($id){
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 1 1 2
278 1 $self->{'_cluster_id'} = $id;
279 }
280 2 return $self->{'_cluster_id'};
281 }
282  
283 =head2 description
284  
285 Title : description
286 Usage : $fam->description("POLYUBIQUITIN")
287 Function: get/set for the consensus description of the cluster
288 Returns : the description string
289 Args : Optional the description string
290  
291 =cut
292  
293 2 ▶sub description{
Subroutine description: called CC=2 SCAR=6.9
Pod documented
294 2 my ($self,$desc) = @_;
295 2 ▶ if($desc){
Branch: 1 branch
BranchTrueFalseTotal
if ($desc) 1 1 2
296 1 $self->{'_description'} = $desc;
297 }
298 2 return $self->{'_description'};
299 }
300  
301 =head2 get_members
302  
303 Title : get_members
304 Usage : Valid criteria:
305 -common_name
306 -binomial
307 -ncbi_taxid
308 -organelle
309 -genus
310 $family->get_members(-common_name =>"human");
311 $family->get_members(-species =>"homo sapiens");
312 $family->get_members(-ncbi_taxid => 9606);
313 For now, multiple critieria are ORed.
314  
315 Will return all members if no criteria are provided.
316  
317 Function: get members using methods from L<Bio::Species>
318 the phylogenetic tree of the family.
319 Returns : an array of objects that are member of this family.
320  
321 =cut
322  
323 2 ▶sub get_members {
Subroutine get_members: called CC=7 SCAR=21.8
Pod documented
324 2 my $self = shift;
325 0 ▶ return @{$self->{'_members'}} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
326  
327 ## since the logic behind the checks is OR, we keep the ids in an hash for
328 ## performance (skip the test if it's already there) and to avoid repats
329 2 my %match;
330 2 my %filter = @_;
331 2 foreach my $key (keys %filter) {
332 2 (my $method = $key) =~ s/^-//;
333 8 %match = (%match, map { $_ => $_ } grep {
334 ! $match{$_} && $_->species &&
335 ($_->species->can($method) ||
336 $self->throw("$method is an invalid criteria")) &&
337 14 ▶ $_->species->$method() eq $filter{$key}
Condition41%5/12
!$match{$_} && $_->species && ($_->species->can($method) || $self->throw("$method is an invalid criteria")) && $_->species->$method eq $filter{$key}
!ll&&!rl&&r
068
not $match{$_} and $_->species and $_->species->can($method) || $self->throw("$method is an invalid criteria")
!ll&&!rl&&r
0014
not $match{$_} and $_->species
!ll&&!rl&&r
0014
$_->species->can($method) or $self->throw("$method is an invalid criteria")
l!l&&r!l&&!r
1400
MC/DC20%1/5
!$match{$_} && $_->species && ($_->species->can($method) || $self->throw("$method is an invalid criteria")) && $_->species->$method eq $filter{$key}
not $match{$_} $_->species $_->species->can($method) $self->throw("$method is an invalid criteria") $_->species->$method eq $filter{$key}
Truth table28%2/7
not(A) and B and C or D && E
A= not $match{$_}B= $_->speciesC= $_->species->can($method)D= $self->throw("$method is an invalid criteria")E= $_->species->$method eq $filter{$key}
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
338 2 } @{$self->{'_members'}});
339 }
340 2 return map {$match{$_}} keys (%match);
341 }
342  
343 =head2 size
344  
345 Title : size
346 Usage : $fam->size();
347 Function: get/set for the size of the family,
348 calculated from the number of members
349 Returns : the size of the family
350 Args :
351  
352 =cut
353  
354 3 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod documented
355 3 my ($self) = @_;
356 3 return scalar(@{$self->{'_members'}});
357 }
358  
359 =head2 cluster_score
360  
361 Title : cluster_score
362 Usage : $fam->cluster_score(100);
363 Function: get/set for cluster_score which
364 represent the score in which the clustering
365 algorithm assigns to this cluster.
366 Returns : a number
367  
368 =cut
369  
370 3 ▶sub cluster_score{
Subroutine cluster_score: called CC=2 SCAR=6.9
Pod documented
371 3 my ($self,$score) = @_;
372 3 ▶ if($score){
Branch: 1 branch
BranchTrueFalseTotal
if ($score) 1 2 3
373 1 $self->{'_cluster_score'} = $score;
374 }
375 3 return $self->{'_cluster_score'};
376 }
377  
378  
379 =head1 Implementation specific methods
380  
381 These are mostly for adding/removing/changing.
382  
383 =cut
384  
385 =head2 add_members
386  
387 Title : add_members
388 Usage : $fam->add_member([$seq1,$seq1]);
389 Function: add members to a family
390 Returns :
391 Args : the member(s) to add, as an array or arrayref
392  
393 =cut
394  
395 3 ▶sub add_members{
Subroutine add_members: called CC=3 SCAR=11.0
Pod documented
396 3 my ($self,@mems) = @_;
397  
398 3 ▶ if (@mems) {
Branch: 1 branch
BranchTrueFalseTotal
if (@mems) 3 0 3
399 3 my $mem = shift(@mems);
400 3 ▶ if(ref($mem) eq "ARRAY"){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mem eq 'ARRAY') { } 1 2 3
401 1 push @{$self->{'_members'}},@{$mem};
402 } else {
403 2 push @{$self->{'_members'}},$mem;
404 }
405 3 push @{$self->{'_members'}}, @mems;
406 }
407 3 return 1;
408 }
409  
410 =head2 remove_members
411  
412 Title : remove_members
413 Usage : $fam->remove_members();
414 Function: remove all members from a family
415 Returns : the previous array of members
416 Args : none
417  
418 =cut
419  
420 1 ▶sub remove_members{
Subroutine remove_members: called CC=1 SCAR=0.0
Pod documented
421 1 my ($self) = @_;
422 1 my $mems = $self->{'_members'};
423 1 $self->{'_members'} = [];
424 1 return @$mems;
425 }
426  
427 #####################################################################
428 # aliases for naming consistency or other reasons #
429 #####################################################################
430  
431 2 *flush_members = \&remove_members;
432 2 *add_member = \&add_members;
433  
434 =head2 members
435  
436 Title : members
437 Usage : $members = $fam->members([$seq1,$seq1]);
438 Function: Deprecated. Use add_members() or get_members() instead
439  
440 =cut
441  
442 0 ▶sub members{
Subroutine members: not called CC=2 SCAR=17.9
Pod documented
443 0 my $self = shift;
444 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
445 # this is in set mode
446 0 $self->warn("setting members() in ".ref($self)." is deprecated.\n".
447 "Use add_members() instead.");
448 0 return $self->add_members(@_);
449 } else {
450 # get mode
451 0 $self->warn("members() in ".ref($self)." is deprecated.\n".
452 "Use get_members() instead.");
453 0 return $self->get_members();
454 }
455 }
456  
457 2 1;
« Cluster/UniGene.pm ↑ Summary Cluster/ClusterFactory.pm »