| 1 | # | ||
| 2 | # BioPerl module for FAST::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 | FAST::Bio::Cluster::SequenceFamily - Sequence Family object | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | use FAST::Bio::SeqIO; | ||
| 21 | use FAST::Bio::Cluster::SequenceFamily; | ||
| 22 | use File::Spec; | ||
| 23 | |||
| 24 | my $file = File::Spec->catfile('t','data','swiss.dat'); | ||
| 25 | my $seqio= FAST::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 = FAST::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 FAST::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://redmine.open-bio.org/projects/bioperl/ | ||
| 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 FAST::Bio::Cluster::SequenceFamily; | ||
| 105 | |||
| 106 | use strict; | ||
| 107 | |||
| 108 | use base qw(FAST::Bio::Root::Root FAST::Bio::Cluster::FamilyI); | ||
| 109 | |||
| 110 | |||
| 111 | =head2 new | ||
| 112 | |||
| 113 | Title : new | ||
| 114 | Usage : my $family = FAST::Bio::Cluster::SequenceFamily->new( | ||
| 115 | -family_id=>"Family_1", | ||
| 116 | -description=>"Family Description Here", | ||
| 117 | -annotation_score=>"100", | ||
| 118 | -members=>\@mem); | ||
| 119 | Function: Constructor for SequenceFamily object | ||
| 120 | Returns : FAST::Bio::Cluster::SequenceFamily object | ||
| 121 | |||
| 122 | See L<FAST::Bio::Cluster::SequenceFamily>. | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | sub new { | ||
| 127 | my ($class,@args) = @_; | ||
| 128 | my $self = $class->SUPER::new(@args); | ||
| 129 | my ($id,$description,$version,$annot_score, | ||
| 130 | $family_score,$members) = $self->_rearrange([qw(FAMILY_ID DESCRIPTION VERSION | ||
| 131 | ANNOTATION_SCORE | ||
| 132 | FAMILY_SCORE MEMBERS)],@args); | ||
| 133 | $self->{'_members'} = []; | ||
| 134 | $id && $self->family_id($id); | ||
| 135 | $description && $self->description($description); | ||
| 136 | $version && $self->version($version); | ||
| 137 | $annot_score && $self->annotation_score($annot_score); | ||
| 138 | $family_score && $self->family_score($family_score); | ||
| 139 | $members && $self->add_members($members); | ||
| 140 | |||
| 141 | return $self; | ||
| 142 | |||
| 143 | } | ||
| 144 | |||
| 145 | =head2 version | ||
| 146 | |||
| 147 | Title : version | ||
| 148 | Usage : $family->version("1.0"); | ||
| 149 | Function: get/set for version | ||
| 150 | Returns : a string version of the family generated. | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | sub version{ | ||
| 155 | my ($self,$value) = @_; | ||
| 156 | if($value){ | ||
| 157 | $self->{'_version'} =$value; | ||
| 158 | } | ||
| 159 | return $self->{'_version'}; | ||
| 160 | } | ||
| 161 | |||
| 162 | =head2 annotation_score | ||
| 163 | |||
| 164 | Title : annotation_score | ||
| 165 | Usage : $family->annotation_score(100); | ||
| 166 | Function: get/set for annotation_score which | ||
| 167 | represent the confidence in which the | ||
| 168 | consensus description has been assigned | ||
| 169 | to the family. | ||
| 170 | Returns : FAST::Bio::SimpleAlign | ||
| 171 | |||
| 172 | See L<FAST::Bio::SimpleAlign> | ||
| 173 | |||
| 174 | =cut | ||
| 175 | |||
| 176 | sub annotation_score{ | ||
| 177 | my ($self,$score) = @_; | ||
| 178 | if($score){ | ||
| 179 | $self->{'_annotation_score'} = $score; | ||
| 180 | } | ||
| 181 | return $self->{'_annotation_score'}; | ||
| 182 | } | ||
| 183 | |||
| 184 | =head2 alignment | ||
| 185 | |||
| 186 | Title : alignment | ||
| 187 | Usage : $family->alignment($align); | ||
| 188 | Function: get/set for an alignment object representing | ||
| 189 | the multiple alignment of the members of the family. | ||
| 190 | Returns : FAST::Bio::SimpleAlign | ||
| 191 | |||
| 192 | See L<FAST::Bio::SimpleAlign> | ||
| 193 | |||
| 194 | =cut | ||
| 195 | |||
| 196 | sub alignment { | ||
| 197 | my ($self,$align) = @_; | ||
| 198 | if($align){ | ||
| 199 | $self->{'_alignment'} = $align; | ||
| 200 | } | ||
| 201 | return $self->{'_alignment'}; | ||
| 202 | } | ||
| 203 | |||
| 204 | =head2 tree | ||
| 205 | |||
| 206 | Title : tree | ||
| 207 | Usage : $family->tree($tree); | ||
| 208 | Function: get/set for an tree object representing | ||
| 209 | the phylogenetic tree of the family. | ||
| 210 | Returns : FAST::Bio::Tree | ||
| 211 | |||
| 212 | See L<FAST::Bio::Tree> | ||
| 213 | |||
| 214 | =cut | ||
| 215 | |||
| 216 | sub tree { | ||
| 217 | my ($self,$tree) = @_; | ||
| 218 | if($tree) { | ||
| 219 | $self->{'_tree'} = $tree; | ||
| 220 | } | ||
| 221 | return $self->{'_tree'}; | ||
| 222 | } | ||
| 223 | |||
| 224 | =head1 L<FAST::Bio::Cluster::FamilyI> methods | ||
| 225 | |||
| 226 | =cut | ||
| 227 | |||
| 228 | =head2 family_score | ||
| 229 | |||
| 230 | Title : family_score | ||
| 231 | Usage : FAST::Bio::Cluster::FamilyI->family_score(95); | ||
| 232 | Function: get/set for the score of algorithm used to generate | ||
| 233 | the family if present | ||
| 234 | |||
| 235 | This is aliased to cluster_score(). | ||
| 236 | |||
| 237 | Returns : the score | ||
| 238 | Args : the score | ||
| 239 | |||
| 240 | =cut | ||
| 241 | |||
| 242 | sub family_score { | ||
| 243 | return shift->cluster_score(@_); | ||
| 244 | } | ||
| 245 | |||
| 246 | |||
| 247 | =head2 family_id | ||
| 248 | |||
| 249 | Title : family_id | ||
| 250 | Usage : $family->family_id("Family_1"); | ||
| 251 | Function: get/set for family id | ||
| 252 | |||
| 253 | This is aliased to display_id(). | ||
| 254 | |||
| 255 | Returns : a string specifying identifier of the family | ||
| 256 | |||
| 257 | =cut | ||
| 258 | |||
| 259 | sub family_id{ | ||
| 260 | return shift->display_id(@_); | ||
| 261 | } | ||
| 262 | |||
| 263 | =head1 L<FAST::Bio::ClusterI> methods | ||
| 264 | |||
| 265 | =cut | ||
| 266 | |||
| 267 | =head2 display_id | ||
| 268 | |||
| 269 | Title : display_id | ||
| 270 | Usage : | ||
| 271 | Function: Get/set the display name or identifier for the cluster | ||
| 272 | Returns : a string | ||
| 273 | Args : optional, on set the display ID ( a string) | ||
| 274 | |||
| 275 | =cut | ||
| 276 | |||
| 277 | sub display_id{ | ||
| 278 | my ($self,$id) = @_; | ||
| 279 | if($id){ | ||
| 280 | $self->{'_cluster_id'} = $id; | ||
| 281 | } | ||
| 282 | return $self->{'_cluster_id'}; | ||
| 283 | } | ||
| 284 | |||
| 285 | =head2 description | ||
| 286 | |||
| 287 | Title : description | ||
| 288 | Usage : $fam->description("POLYUBIQUITIN") | ||
| 289 | Function: get/set for the consensus description of the cluster | ||
| 290 | Returns : the description string | ||
| 291 | Args : Optional the description string | ||
| 292 | |||
| 293 | =cut | ||
| 294 | |||
| 295 | sub description{ | ||
| 296 | my ($self,$desc) = @_; | ||
| 297 | if($desc){ | ||
| 298 | $self->{'_description'} = $desc; | ||
| 299 | } | ||
| 300 | return $self->{'_description'}; | ||
| 301 | } | ||
| 302 | |||
| 303 | =head2 get_members | ||
| 304 | |||
| 305 | Title : get_members | ||
| 306 | Usage : Valid criteria: | ||
| 307 | -common_name | ||
| 308 | -binomial | ||
| 309 | -ncbi_taxid | ||
| 310 | -organelle | ||
| 311 | -genus | ||
| 312 | $family->get_members(-common_name =>"human"); | ||
| 313 | $family->get_members(-species =>"homo sapiens"); | ||
| 314 | $family->get_members(-ncbi_taxid => 9606); | ||
| 315 | For now, multiple critieria are ORed. | ||
| 316 | |||
| 317 | Will return all members if no criteria are provided. | ||
| 318 | |||
| 319 | Function: get members using methods from L<FAST::Bio::Species> | ||
| 320 | the phylogenetic tree of the family. | ||
| 321 | Returns : an array of objects that are member of this family. | ||
| 322 | |||
| 323 | =cut | ||
| 324 | |||
| 325 | sub get_members { | ||
| 326 | my $self = shift; | ||
| 327 | my @ret; | ||
| 328 | |||
| 329 | if(@_) { | ||
| 330 | my %hash = @_; | ||
| 331 | foreach my $mem ( @{$self->{'_members'}} ) { | ||
| 332 | foreach my $key ( keys %hash){ | ||
| 333 | my $method = $key; | ||
| 334 | $method=~s/-//g; | ||
| 335 | if($mem->can('species')){ | ||
| 336 | my $species = $mem->species; | ||
| 337 | $species->can($method) || | ||
| 338 | $self->throw("$method is an invalid criteria"); | ||
| 339 | if($species->$method() eq $hash{$key} ){ | ||
| 340 | push @ret, $mem; | ||
| 341 | } | ||
| 342 | } | ||
| 343 | } | ||
| 344 | } | ||
| 345 | return @ret; | ||
| 346 | } | ||
| 347 | return @{$self->{'_members'}}; | ||
| 348 | } | ||
| 349 | |||
| 350 | =head2 size | ||
| 351 | |||
| 352 | Title : size | ||
| 353 | Usage : $fam->size(); | ||
| 354 | Function: get/set for the size of the family, | ||
| 355 | calculated from the number of members | ||
| 356 | Returns : the size of the family | ||
| 357 | Args : | ||
| 358 | |||
| 359 | =cut | ||
| 360 | |||
| 361 | sub size { | ||
| 362 | my ($self) = @_; | ||
| 363 | |||
| 364 | return scalar(@{$self->{'_members'}}); | ||
| 365 | |||
| 366 | } | ||
| 367 | |||
| 368 | =head2 cluster_score | ||
| 369 | |||
| 370 | Title : cluster_score | ||
| 371 | Usage : $fam->cluster_score(100); | ||
| 372 | Function: get/set for cluster_score which | ||
| 373 | represent the score in which the clustering | ||
| 374 | algorithm assigns to this cluster. | ||
| 375 | Returns : a number | ||
| 376 | |||
| 377 | =cut | ||
| 378 | |||
| 379 | sub cluster_score{ | ||
| 380 | my ($self,$score) = @_; | ||
| 381 | if($score){ | ||
| 382 | $self->{'_cluster_score'} = $score; | ||
| 383 | } | ||
| 384 | return $self->{'_cluster_score'}; | ||
| 385 | } | ||
| 386 | |||
| 387 | |||
| 388 | =head1 Implementation specific methods | ||
| 389 | |||
| 390 | These are mostly for adding/removing/changing. | ||
| 391 | |||
| 392 | =cut | ||
| 393 | |||
| 394 | =head2 add_members | ||
| 395 | |||
| 396 | Title : add_members | ||
| 397 | Usage : $fam->add_member([$seq1,$seq1]); | ||
| 398 | Function: add members to a family | ||
| 399 | Returns : | ||
| 400 | Args : the member(s) to add, as an array or arrayref | ||
| 401 | |||
| 402 | =cut | ||
| 403 | |||
| 404 | sub add_members{ | ||
| 405 | my ($self,@mems) = @_; | ||
| 406 | |||
| 407 | if (@mems) { | ||
| 408 | my $mem = shift(@mems); | ||
| 409 | if(ref($mem) eq "ARRAY"){ | ||
| 410 | push @{$self->{'_members'}},@{$mem}; | ||
| 411 | } else { | ||
| 412 | push @{$self->{'_members'}},$mem; | ||
| 413 | } | ||
| 414 | push @{$self->{'_members'}}, @mems; | ||
| 415 | } | ||
| 416 | return 1; | ||
| 417 | } | ||
| 418 | |||
| 419 | =head2 remove_members | ||
| 420 | |||
| 421 | Title : remove_members | ||
| 422 | Usage : $fam->remove_members(); | ||
| 423 | Function: remove all members from a family | ||
| 424 | Returns : the previous array of members | ||
| 425 | Args : none | ||
| 426 | |||
| 427 | =cut | ||
| 428 | |||
| 429 | sub remove_members{ | ||
| 430 | my ($self) = @_; | ||
| 431 | my $mems = $self->{'_members'}; | ||
| 432 | $self->{'_members'} = []; | ||
| 433 | return @$mems; | ||
| 434 | } | ||
| 435 | |||
| 436 | ##################################################################### | ||
| 437 | # aliases for naming consistency or other reasons # | ||
| 438 | ##################################################################### | ||
| 439 | |||
| 440 | *flush_members = \&remove_members; | ||
| 441 | *add_member = \&add_members; | ||
| 442 | |||
| 443 | =head2 members | ||
| 444 | |||
| 445 | Title : members | ||
| 446 | Usage : $members = $fam->members([$seq1,$seq1]); | ||
| 447 | Function: Deprecated. Use add_members() or get_members() instead | ||
| 448 | |||
| 449 | =cut | ||
| 450 | |||
| 451 | sub members{ | ||
| 452 | my $self = shift; | ||
| 453 | if(@_) { | ||
| 454 | # this is in set mode | ||
| 455 | $self->warn("setting members() in ".ref($self)." is deprecated.\n". | ||
| 456 | "Use add_members() instead."); | ||
| 457 | return $self->add_members(@_); | ||
| 458 | } else { | ||
| 459 | # get mode | ||
| 460 | $self->warn("members() in ".ref($self)." is deprecated.\n". | ||
| 461 | "Use get_members() instead."); | ||
| 462 | return $self->get_members(); | ||
| 463 | } | ||
| 464 | } | ||
| 465 | |||
| 466 | 1; |