Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Cluster/SequenceFamily.pm @ 0:1f6dce3d34e0
Uploaded
| author | mahtabm |
|---|---|
| date | Thu, 11 Apr 2013 02:01:53 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1f6dce3d34e0 |
|---|---|
| 1 # $Id: SequenceFamily.pm,v 1.4 2002/12/01 00:34:58 jason Exp $ | |
| 2 # | |
| 3 # BioPerl module for Bio::Cluster::SequenceFamily | |
| 4 # | |
| 5 # Cared for by Shawn Hoon <shawnh@fugu-sg.org> | |
| 6 # | |
| 7 # Copyright Shawn Hoon | |
| 8 # | |
| 9 # You may distribute this module under the same terms as perl itself | |
| 10 | |
| 11 # POD documentation - main docs before the code | |
| 12 | |
| 13 =head1 NAME | |
| 14 | |
| 15 Bio::Cluster::SequenceFamily - Sequence Family object | |
| 16 | |
| 17 =head1 SYNOPSIS | |
| 18 | |
| 19 use Bio::Cluster::SequenceFamily | |
| 20 | |
| 21 use Bio::SeqIO; | |
| 22 use Bio::Cluster::SequenceFamily; | |
| 23 | |
| 24 my $file = Bio::Root::IO->catfile('t','data','swiss.dat'); | |
| 25 my $seqio= new Bio::SeqIO('-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(-family_id=>"Family_1", | |
| 34 -description=>"Family Description Here", | |
| 35 -annotation_score=>"100", | |
| 36 -members=>\@mem); | |
| 37 | |
| 38 #access the family | |
| 39 | |
| 40 foreach my $mem ($family->get_members){ | |
| 41 print $mem->display_id."\t".$mem->desc."\n"; | |
| 42 } | |
| 43 | |
| 44 #select members if members have a Bio::Species Object | |
| 45 | |
| 46 my @mem = $family->get_members(-binomial=>"Homo sapiens"); | |
| 47 @mem = $family->get_members(-ncbi_taxid => 9606); | |
| 48 @mem = $family->get_members(-common_name=>"Human"); | |
| 49 @mem = $family->get_members(-species=>"sapiens"); | |
| 50 @mem = $family->get_members(-genus=>"Homo"); | |
| 51 | |
| 52 | |
| 53 | |
| 54 =head1 DESCRIPTION | |
| 55 | |
| 56 This is a simple Family object that may hold any group of object. For more | |
| 57 specific families, one should derive from FamilyI. | |
| 58 | |
| 59 =head1 FEEDBACK | |
| 60 | |
| 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://bio.perl.org/MailList.html - About the mailing lists | |
| 70 | |
| 71 =head2 Reporting Bugs | |
| 72 | |
| 73 Report bugs to the Bioperl bug tracking system to help us keep track | |
| 74 the bugs and their resolution. Bug reports can be submitted via email | |
| 75 or the web: | |
| 76 | |
| 77 bioperl-bugs@bioperl.org | |
| 78 http://bugzilla.bioperl.org/ | |
| 79 | |
| 80 =head1 AUTHOR - Shawn Hoon | |
| 81 | |
| 82 Email shawnh@fugu-sg.org | |
| 83 | |
| 84 | |
| 85 =head1 APPENDIX | |
| 86 | |
| 87 | |
| 88 The rest of the documentation details each of the object | |
| 89 methods. Internal methods are usually preceded with a "_". | |
| 90 | |
| 91 =cut | |
| 92 | |
| 93 # Let the code begin... | |
| 94 | |
| 95 | |
| 96 package Bio::Cluster::SequenceFamily; | |
| 97 | |
| 98 use strict; | |
| 99 use vars qw(@ISA); | |
| 100 | |
| 101 | |
| 102 use Bio::Root::Root; | |
| 103 use Bio::Cluster::FamilyI; | |
| 104 | |
| 105 @ISA = qw(Bio::Root::Root Bio::Cluster::FamilyI); | |
| 106 | |
| 107 | |
| 108 =head2 new | |
| 109 | |
| 110 Title : new | |
| 111 Usage : my $family = Bio::Cluster::SequenceFamily->new(-family_id=>"Family_1", | |
| 112 -description=>"Family Description Here", | |
| 113 -annotation_score=>"100", | |
| 114 -members=>\@mem); | |
| 115 Function: Constructor for SequenceFamily object | |
| 116 Returns : L<Bio::Cluster::SequenceFamily> object | |
| 117 | |
| 118 =cut | |
| 119 | |
| 120 sub new { | |
| 121 my ($class,@args) = @_; | |
| 122 my $self = $class->SUPER::new(@args); | |
| 123 my ($id,$description,$version,$annot_score, | |
| 124 $family_score,$members) = $self->_rearrange([qw(FAMILY_ID DESCRIPTION VERSION | |
| 125 ANNOTATION_SCORE | |
| 126 FAMILY_SCORE MEMBERS)],@args); | |
| 127 $self->{'_members'} = []; | |
| 128 $id && $self->family_id($id); | |
| 129 $description && $self->description($description); | |
| 130 $version && $self->version($version); | |
| 131 $annot_score && $self->annotation_score($annot_score); | |
| 132 $family_score && $self->family_score($family_score); | |
| 133 $members && $self->add_members($members); | |
| 134 | |
| 135 return $self; | |
| 136 | |
| 137 } | |
| 138 | |
| 139 =head2 version | |
| 140 | |
| 141 Title : version | |
| 142 Usage : $family->version("1.0"); | |
| 143 Function: get/set for version | |
| 144 Returns : a string version of the family generated. | |
| 145 | |
| 146 =cut | |
| 147 | |
| 148 sub version{ | |
| 149 my ($self,$value) = @_; | |
| 150 if($value){ | |
| 151 $self->{'_version'} =$value; | |
| 152 } | |
| 153 return $self->{'_version'}; | |
| 154 } | |
| 155 | |
| 156 =head2 annotation_score | |
| 157 | |
| 158 Title : annotation_score | |
| 159 Usage : $family->annotation_score(100); | |
| 160 Function: get/set for annotation_score which | |
| 161 represent the confidence in which the | |
| 162 consensus description has been assigned | |
| 163 to the family. | |
| 164 Returns : L<Bio::SimpleAlign> | |
| 165 | |
| 166 =cut | |
| 167 | |
| 168 sub annotation_score{ | |
| 169 my ($self,$score) = @_; | |
| 170 if($score){ | |
| 171 $self->{'_annotation_score'} = $score; | |
| 172 } | |
| 173 return $self->{'_annotation_score'}; | |
| 174 } | |
| 175 | |
| 176 =head2 alignment | |
| 177 | |
| 178 Title : alignment | |
| 179 Usage : $family->alignment($align); | |
| 180 Function: get/set for an alignment object representing | |
| 181 the multiple alignment of the members of the family. | |
| 182 Returns : L<Bio::SimpleAlign> | |
| 183 | |
| 184 =cut | |
| 185 | |
| 186 sub alignment { | |
| 187 my ($self,$align) = @_; | |
| 188 if($align){ | |
| 189 $self->{'_alignment'} = $align; | |
| 190 } | |
| 191 return $self->{'_alignment'}; | |
| 192 } | |
| 193 | |
| 194 =head2 tree | |
| 195 | |
| 196 Title : tree | |
| 197 Usage : $family->tree($tree); | |
| 198 Function: get/set for an tree object representing | |
| 199 the phylogenetic tree of the family. | |
| 200 Returns : L<Bio::Tree> | |
| 201 | |
| 202 =cut | |
| 203 | |
| 204 sub tree { | |
| 205 my ($self,$tree) = @_; | |
| 206 if($tree) { | |
| 207 $self->{'_tree'} = $tree; | |
| 208 } | |
| 209 return $self->{'_tree'}; | |
| 210 } | |
| 211 | |
| 212 =head1 L<Bio::Cluster::FamilyI> methods | |
| 213 | |
| 214 =cut | |
| 215 | |
| 216 =head2 family_score | |
| 217 | |
| 218 Title : family_score | |
| 219 Usage : Bio::Cluster::FamilyI->family_score(95); | |
| 220 Function: get/set for the score of algorithm used to generate | |
| 221 the family if present | |
| 222 | |
| 223 This is aliased to cluster_score(). | |
| 224 | |
| 225 Returns : the score | |
| 226 Args : the score | |
| 227 | |
| 228 =cut | |
| 229 | |
| 230 sub family_score { | |
| 231 return shift->cluster_score(@_); | |
| 232 } | |
| 233 | |
| 234 | |
| 235 =head2 family_id | |
| 236 | |
| 237 Title : family_id | |
| 238 Usage : $family->family_id("Family_1"); | |
| 239 Function: get/set for family id | |
| 240 | |
| 241 This is aliased to display_id(). | |
| 242 | |
| 243 Returns : a string specifying identifier of the family | |
| 244 | |
| 245 =cut | |
| 246 | |
| 247 sub family_id{ | |
| 248 return shift->display_id(@_); | |
| 249 } | |
| 250 | |
| 251 =head1 L<Bio::ClusterI> methods | |
| 252 | |
| 253 =cut | |
| 254 | |
| 255 =head2 display_id | |
| 256 | |
| 257 Title : display_id | |
| 258 Usage : | |
| 259 Function: Get/set the display name or identifier for the cluster | |
| 260 Returns : a string | |
| 261 Args : optional, on set the display ID ( a string) | |
| 262 | |
| 263 =cut | |
| 264 | |
| 265 sub display_id{ | |
| 266 my ($self,$id) = @_; | |
| 267 if($id){ | |
| 268 $self->{'_cluster_id'} = $id; | |
| 269 } | |
| 270 return $self->{'_cluster_id'}; | |
| 271 } | |
| 272 | |
| 273 =head2 description | |
| 274 | |
| 275 Title : description | |
| 276 Usage : $fam->description("POLYUBIQUITIN") | |
| 277 Function: get/set for the consensus description of the cluster | |
| 278 Returns : the description string | |
| 279 Args : Optional the description string | |
| 280 | |
| 281 =cut | |
| 282 | |
| 283 sub description{ | |
| 284 my ($self,$desc) = @_; | |
| 285 if($desc){ | |
| 286 $self->{'_description'} = $desc; | |
| 287 } | |
| 288 return $self->{'_description'}; | |
| 289 } | |
| 290 | |
| 291 =head2 get_members | |
| 292 | |
| 293 Title : get_members | |
| 294 Usage : Valid criteria: | |
| 295 -common_name | |
| 296 -binomial | |
| 297 -ncbi_taxid | |
| 298 -organelle | |
| 299 -genus | |
| 300 $family->get_members(-common_name =>"human"); | |
| 301 $family->get_members(-species =>"homo sapiens"); | |
| 302 $family->get_members(-ncbi_taxid => 9606); | |
| 303 For now, multiple critieria are ORed. | |
| 304 | |
| 305 Will return all members if no criteria are provided. | |
| 306 | |
| 307 Function: get members using methods from L<Bio::Species> | |
| 308 the phylogenetic tree of the family. | |
| 309 Returns : an array of objects that are member of this family. | |
| 310 | |
| 311 =cut | |
| 312 | |
| 313 sub get_members { | |
| 314 my $self = shift; | |
| 315 my @ret; | |
| 316 | |
| 317 if(@_) { | |
| 318 my %hash = @_; | |
| 319 foreach my $mem ( @{$self->{'_members'}} ) { | |
| 320 foreach my $key ( keys %hash){ | |
| 321 my $method = $key; | |
| 322 $method=~s/-//g; | |
| 323 if($mem->can('species')){ | |
| 324 my $species = $mem->species; | |
| 325 $species->can($method) || | |
| 326 $self->throw("$method is an invalid criteria"); | |
| 327 if($species->$method() eq $hash{$key} ){ | |
| 328 push @ret, $mem; | |
| 329 } | |
| 330 } | |
| 331 } | |
| 332 } | |
| 333 return @ret; | |
| 334 } | |
| 335 return @{$self->{'_members'}}; | |
| 336 } | |
| 337 | |
| 338 =head2 size | |
| 339 | |
| 340 Title : size | |
| 341 Usage : $fam->size(); | |
| 342 Function: get/set for the size of the family, | |
| 343 calculated from the number of members | |
| 344 Returns : the size of the family | |
| 345 Args : | |
| 346 | |
| 347 =cut | |
| 348 | |
| 349 sub size { | |
| 350 my ($self) = @_; | |
| 351 | |
| 352 return scalar(@{$self->{'_members'}}); | |
| 353 | |
| 354 } | |
| 355 | |
| 356 =head2 cluster_score | |
| 357 | |
| 358 Title : cluster_score | |
| 359 Usage : $fam->cluster_score(100); | |
| 360 Function: get/set for cluster_score which | |
| 361 represent the score in which the clustering | |
| 362 algorithm assigns to this cluster. | |
| 363 Returns : a number | |
| 364 | |
| 365 =cut | |
| 366 | |
| 367 sub cluster_score{ | |
| 368 my ($self,$score) = @_; | |
| 369 if($score){ | |
| 370 $self->{'_cluster_score'} = $score; | |
| 371 } | |
| 372 return $self->{'_cluster_score'}; | |
| 373 } | |
| 374 | |
| 375 | |
| 376 =head1 Implementation specific methods | |
| 377 | |
| 378 These are mostly for adding/removing/changing. | |
| 379 | |
| 380 =cut | |
| 381 | |
| 382 =head2 add_members | |
| 383 | |
| 384 Title : add_members | |
| 385 Usage : $fam->add_member([$seq1,$seq1]); | |
| 386 Function: add members to a family | |
| 387 Returns : | |
| 388 Args : the member(s) to add, as an array or arrayref | |
| 389 | |
| 390 =cut | |
| 391 | |
| 392 sub add_members{ | |
| 393 my ($self,@mems) = @_; | |
| 394 | |
| 395 my $mem = shift(@mems); | |
| 396 if(ref($mem) eq "ARRAY"){ | |
| 397 push @{$self->{'_members'}},@{$mem}; | |
| 398 } else { | |
| 399 push @{$self->{'_members'}},$mem; | |
| 400 } | |
| 401 push @{$self->{'_members'}}, @mems; | |
| 402 | |
| 403 return 1; | |
| 404 } | |
| 405 | |
| 406 =head2 remove_members | |
| 407 | |
| 408 Title : remove_members | |
| 409 Usage : $fam->remove_members(); | |
| 410 Function: remove all members from a family | |
| 411 Returns : the previous array of members | |
| 412 Args : none | |
| 413 | |
| 414 =cut | |
| 415 | |
| 416 sub remove_members{ | |
| 417 my ($self) = @_; | |
| 418 my $mems = $self->{'_members'}; | |
| 419 $self->{'_members'} = []; | |
| 420 return @$mems; | |
| 421 } | |
| 422 | |
| 423 ##################################################################### | |
| 424 # aliases for naming consistency or other reasons # | |
| 425 ##################################################################### | |
| 426 | |
| 427 *flush_members = \&remove_members; | |
| 428 *add_member = \&add_members; | |
| 429 | |
| 430 sub members{ | |
| 431 my $self = shift; | |
| 432 if(@_) { | |
| 433 # this is in set mode | |
| 434 $self->warn("setting members() in ".ref($self)." is deprecated.\n". | |
| 435 "Use add_members() instead."); | |
| 436 return $self->add_members(@_); | |
| 437 } else { | |
| 438 # get mode | |
| 439 $self->warn("members() in ".ref($self)." is deprecated.\n". | |
| 440 "Use get_members() instead."); | |
| 441 return $self->get_members(); | |
| 442 } | |
| 443 } | |
| 444 | |
| 445 1; |
