comparison variant_effect_predictor/Bio/EnsEMBL/Compara/MemberSet.pm @ 0:21066c0abaf5 draft

Uploaded
author willmclaren
date Fri, 03 Aug 2012 10:04:48 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:21066c0abaf5
1 =head1 LICENSE
2
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
4 Genome Research Limited. All rights reserved.
5
6 This software is distributed under a modified Apache license.
7 For license details, please see
8
9 http://www.ensembl.org/info/about/code_licence.html
10
11 =head1 CONTACT
12
13 Please email comments or questions to the public Ensembl
14 developers list at <dev@ensembl.org>.
15
16 Questions may also be sent to the Ensembl help desk at
17 <helpdesk@ensembl.org>.
18
19 =head1 AUTHORSHIP
20
21 Ensembl Team. Individual contributions can be found in the CVS log.
22
23 =cut
24
25 =head1 NAME
26
27 MemberSet - A superclass for pairwise or multiple relationships, base of
28 Bio::EnsEMBL::Compara::Family, Bio::EnsEMBL::Compara::Homology and
29 Bio::EnsEMBL::Compara::Domain.
30
31 =head1 DESCRIPTION
32
33 A superclass for pairwise and multiple relationships
34
35 Currently the Member objects are used in the GeneTree structure
36 to represent the leaves of the trees. Each leaf contains an aligned
37 sequence, which is represented as an Member object.
38
39 =head1 INHERITANCE TREE
40
41 Bio::EnsEMBL::Compara::MemberSet
42
43 =head1 METHODS
44
45 =cut
46
47 package Bio::EnsEMBL::Compara::MemberSet;
48
49 use strict;
50 use Scalar::Util qw(weaken);
51 use Bio::EnsEMBL::Utils::Argument;
52 use Bio::EnsEMBL::Utils::Scalar qw(:all);
53 use Bio::EnsEMBL::Utils::Exception;
54 use Bio::EnsEMBL::Compara::Attribute;
55 use Bio::EnsEMBL::Compara::Member;
56
57
58 ####################################
59 # #
60 # Constructor, getters / setters #
61 # #
62 ####################################
63
64
65 =head2 new
66
67 Arg [-DBID] :
68 int - internal ID for this object
69 Arg [-ADAPTOR]:
70 Bio::EnsEMBL::Compara::DBSQL::MemberSetAdaptor - the object adaptor
71 Arg [-STABLE_ID] :
72 string - the stable identifier of this object
73 Arg [-VERSION] :
74 int - the version of the stable identifier of this object
75 Arg [-METHOD_LINK_SPECIES_SET_ID] :
76 int - the internal ID for the MethodLinkSpeciesSet object
77 Arg [-DESCRIPTION]:
78 string - the description for the object
79 Example : $family = Bio::EnsEMBL::Compara::MemberSet->new(...);
80 Description: Creates a new MemberSet object
81 Returntype : Bio::EnsEMBL::Compara::MemberSet
82 Exceptions : none
83 Caller : subclass->new
84 Status : Stable
85
86 =cut
87
88 sub new {
89 my ($class, @args) = @_;
90
91 my $self = bless {}, $class;
92
93 if (scalar @args) {
94 #do this explicitly.
95 my ($dbid, $stable_id, $version, $method_link_species_set_id, $description, $adaptor)
96 = rearrange([qw(DBID STABLE_ID VERSION METHOD_LINK_SPECIES_SET_ID DESCRIPTION ADAPTOR)], @args);
97
98 $dbid && $self->dbID($dbid);
99 $stable_id && $self->stable_id($stable_id);
100 $version && $self->version($version);
101 $description && $self->description($description);
102 $method_link_species_set_id && $self->method_link_species_set_id($method_link_species_set_id);
103 $adaptor && $self->adaptor($adaptor);
104 }
105
106 return $self;
107 }
108
109 =head2 new_fast
110
111 Arg [1] : hash reference $hashref
112 Example : none
113 Description: This is an ultra fast constructor which requires knowledge of
114 the objects internals to be used.
115 Returntype :
116 Exceptions : none
117 Caller :
118 Status : Stable
119
120 =cut
121
122 sub new_fast {
123 my ($class, $hashref) = @_;
124
125 return bless $hashref, $class;
126 }
127
128 =head2 dbID
129
130 Arg [1] : int $dbID (optional)
131 Example :
132 Description: Getter/setter for the internal ID of this relation
133 Returntype : int
134 Exceptions : none
135 Caller : general
136 Status : Stable
137
138 =cut
139
140 sub dbID {
141 my $self = shift;
142 $self->{'_dbID'} = shift if(@_);
143 return $self->{'_dbID'};
144 }
145
146 =head2 stable_id
147
148 Arg [1] : string $stable_id (optional)
149 Example :
150 Description: Getter/setter for the stable ID of this relation
151 Returntype : string
152 Exceptions : none
153 Caller : general
154 Status : Stable
155
156 =cut
157
158 sub stable_id {
159 my $self = shift;
160 $self->{'_stable_id'} = shift if(@_);
161 return $self->{'_stable_id'};
162 }
163
164 =head2 version
165
166 Arg [1] : string $version (optional)
167 Example :
168 Description: Getter/setter for the version number of the stable ID
169 Returntype : int
170 Exceptions : none
171 Caller : general
172 Status : Stable
173
174 =cut
175
176 sub version {
177 my $self = shift;
178 $self->{'_version'} = shift if(@_);
179 return $self->{'_version'};
180 }
181
182 =head2 description
183
184 Arg [1] : string $description (optional)
185 Example :
186 Description: Getter/setter for the description corresponding to this relation
187 Returntype : string
188 Exceptions : none
189 Caller : general
190 Status : Stable
191
192 =cut
193
194 sub description {
195 my $self = shift;
196 $self->{'_description'} = shift if(@_);
197 return $self->{'_description'};
198 }
199
200 =head2 method_link_species_set
201
202 Arg [1] : MethodLinkSpeciesSet object (optional)
203 Example :
204 Description: getter/setter method for the MethodLinkSpeciesSet for this relation.
205 Can lazy-load the method_link_species_set from the method_link_species_set_id
206 if that one is set and the adaptor is set.
207 Returntype : Bio::EnsEMBL::Compara::MethodLinkSpeciesSet
208 Exceptions : throws if setting to an unsuitable object
209 Caller : general
210 Status : Stable
211
212 =cut
213
214 sub method_link_species_set {
215 my $self = shift;
216
217 if(@_) {
218 my $mlss = shift;
219 assert_ref($mlss, 'Bio::EnsEMBL::Compara::MethodLinkSpeciesSet');
220 $self->{'_method_link_species_set'} = $mlss;
221 $self->{'_method_link_species_set_id'} = $mlss->dbID;
222
223 } elsif (defined $self->{'_method_link_species_set_id'}) {
224 #lazy load from method_link_species_set_id
225 if ((not defined $self->{'_method_link_species_set'})
226 or ($self->{'_method_link_species_set'}->dbID ne $self->{'_method_link_species_set_id'})) {
227 my $mlssa = $self->adaptor->db->get_MethodLinkSpeciesSetAdaptor;
228 my $mlss = $mlssa->fetch_by_dbID($self->method_link_species_set_id);
229 $self->{'_method_link_species_set'} = $mlss;
230 }
231 }
232
233 return $self->{'_method_link_species_set'};
234 }
235
236 =head2 method_link_species_set_id
237
238 Arg [1] : integer (optional)
239 Example :
240 Description: getter/setter method for the internal ID of the MethodLinkSpeciesSet
241 for this relation.
242 Returntype : integer
243 Exceptions : none
244 Caller : general
245 Status : Stable
246
247 =cut
248
249 sub method_link_species_set_id {
250 my $self = shift;
251
252 $self->{'_method_link_species_set_id'} = shift if (@_);
253 return $self->{'_method_link_species_set_id'};
254 }
255
256 =head2 method_link_type
257
258 DEPRECATED. Use method_link_species_set()->method()->type() instead. This is not a setter any more.
259
260 =cut
261
262 sub method_link_type { # DEPRECATED
263 my $self = shift;
264 deprecate('Use method_link_species_set()->method()->type() instead. This is not a setter any more.');
265 return $self->method_link_species_set->method->type() if defined $self->{'_method_link_species_set_id'};
266 }
267
268
269 =head2 method_link_id
270
271 DEPRECATED. Use method_link_species_set()->method()->dbID() instead. This is not a setter any more.
272
273 =cut
274
275 sub method_link_id { # DEPRECATED
276 my $self = shift;
277 deprecate('Use method_link_species_set()->method()->dbID() instead. This is not a setter any more.');
278 return $self->method_link_species_set->method->dbID if defined $self->{'_method_link_species_set_id'};
279 }
280
281 =head2 adaptor
282
283 Arg [1] : string $adaptor (optional)
284 corresponding to a perl module
285 Example :
286 Description: getter/setter method for the adaptor for this relation. Usually
287 this will be either GeneTreeAdaptor, FamilyAdaptor, or
288 HomologyAdaptor
289 Returntype : Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor object
290 Exceptions : none
291 Caller : general
292 Status : Stable
293
294 =cut
295
296 sub adaptor {
297 my $self = shift;
298 $self->{'_adaptor'} = shift if(@_);
299 return $self->{'_adaptor'};
300 }
301
302
303
304 ###########################
305 # #
306 # Member content #
307 # #
308 ###########################
309
310 =head2 member_class
311
312 Description: Returns the type of member used in the set
313 Returntype : String: Bio::EnsEMBL::Compara::Member
314 Caller : general
315 Status : Stable
316
317 =cut
318
319 sub member_class {
320 return 'Bio::EnsEMBL::Compara::Member';
321 }
322
323
324 =head2 deep_copy
325
326 Description: Returns a copy of $self. All the members are themselves copied
327 Returntype : Bio::EnsEMBL::Compara::MemberSet
328 Caller : general
329 Status : Stable
330
331 =cut
332
333 sub deep_copy {
334 my $self = shift;
335 my $copy = {};
336 bless $copy, ref($self);
337
338 foreach my $attr (qw(_dbID _adaptor _version _stable_id _description _method_link_species_set_id)) {
339 $copy->{$attr} = $self->{$attr};
340 }
341
342 foreach my $member (@{$self->get_all_Members}) {
343 $copy->add_Member($member->copy());
344 }
345
346 return $copy;
347 }
348
349
350 =head2 add_Member
351
352 Arg [1] : Member
353 Example :
354 Description: Add a new Member to this set
355 Returntype : none
356 Exceptions : Throws if input objects don't check
357 Caller : general
358 Status : Stable
359
360 =cut
361
362 sub add_Member {
363 my ($self, $member) = @_;
364
365 assert_ref($member, $self->member_class);
366 my $source_name = $member->source_name();
367 my $taxon_id = $member->taxon_id();
368 my $genome_db_id = $member->genome_db_id();
369 #print "adding $source_name: ", $member->dbID, "\n";
370
371 if (defined $self->{'_this_one_first'} && $self->{'_this_one_first'} eq $member->stable_id) {
372 unshift @{$self->{'_member_array'}}, $member ;
373 unshift @{$self->{'_members_by_source'}{$source_name}}, $member;
374 unshift @{$self->{'_members_by_source_taxon'}{"${source_name}_${taxon_id}"}}, $member;
375 if(defined $genome_db_id) {
376 unshift @{$self->{_members_by_source_genome_db}{"${source_name}_${genome_db_id}"}}, $member;
377 unshift @{$self->{_members_by_genome_db}{$genome_db_id}}, $member;
378 }
379 } else {
380 push @{$self->{'_member_array'}}, $member ;
381 push @{$self->{'_members_by_source'}{$source_name}}, $member;
382 push @{$self->{'_members_by_source_taxon'}{"${source_name}_${taxon_id}"}}, $member;
383 if(defined $genome_db_id) {
384 push @{$self->{_members_by_source_genome_db}{"${source_name}_${genome_db_id}"}}, $member;
385 push @{$self->{_members_by_genome_db}{$genome_db_id}}, $member;
386 }
387 }
388
389 $member->{'set'} = $self;
390 weaken($member->{'set'});
391 }
392
393 sub add_Member_Attribute { # DEPRECATED
394 my ($self, $member_attribute) = @_;
395 my ($member, $attr) = @{$member_attribute};
396
397 my $am = Bio::EnsEMBL::Compara::Member::copy($member);
398 bless $am, $self->member_class;
399 foreach my $key (keys %Bio::EnsEMBL::Compara::Attribute::ok_field) {
400 $am->$key($attr->$key) if defined $attr->key;
401 }
402 $self->add_Member($am);
403 }
404
405
406 sub _tranform_array_to_Member_Attributes {
407 my ($self, $array) = @_;
408 my @all_ma;
409 foreach my $member (@$array) {
410 my $attribute = new Bio::EnsEMBL::Compara::Attribute;
411 foreach my $key (keys %Bio::EnsEMBL::Compara::Attribute::ok_field) {
412 $attribute->$key($member->can($key) ? $member->$key : undef);
413 }
414 push @all_ma, [$member, $attribute];
415 }
416 return \@all_ma;
417 }
418
419
420 =head2 get_all_Members
421
422 Arg [1] : None
423 Example :
424 Description:
425 Returntype : array reference of Bio::EnsEMBL::Compara::Member
426 Exceptions :
427 Caller :
428
429 =cut
430
431 sub get_all_Members {
432 my ($self) = @_;
433
434 unless (defined $self->{'_member_array'}) {
435
436 my $am_adaptor = $self->adaptor->db->get_MemberAdaptor();
437 my $members = $am_adaptor->fetch_all_by_MemberSet($self);
438
439 $self->{'_member_array'} = [];
440 $self->{'_members_by_source'} = {};
441 $self->{'_members_by_source_taxon'} = {};
442 $self->{'_members_by_source_genome_db'} = {};
443 $self->{'_members_by_genome_db'} = {};
444 foreach my $member (@{$members}) {
445 $self->add_Member($member);
446 }
447 }
448 return $self->{'_member_array'};
449 }
450
451
452
453 =head2 get_all_GeneMember
454
455 Arg [1] : None
456 Example :
457 Description:
458 Returntype : array reference of Bio::EnsEMBL::Compara::Member
459 Exceptions :
460 Caller : public
461
462 =cut
463
464 sub get_all_GeneMembers {
465 my ($self) = @_;
466
467 my $members = [];
468 foreach my $aligned_member (@{$self->get_all_Members}) {
469 push @$members, $aligned_member->gene_member if defined $aligned_member->gene_member;
470 }
471
472 return $members;
473 }
474 =head2 gene_list
475
476 Example : my $pair = $homology->gene_list
477 Description: return the pair of members for the homology
478 Returntype : array ref of (2) Bio::EnsEMBL::Compara::Member objects
479 Caller : general
480
481 =cut
482
483
484 sub gene_list { # DEPRECATED
485 my $self = shift;
486 return $self->get_all_GeneMembers
487 }
488
489
490 sub get_all_Member_Attribute { # DEPRECATED
491 my $self = shift;
492 return $self->_tranform_array_to_Member_Attributes($self->get_all_Members);
493 }
494
495
496 #################################
497 # #
498 # Members per category #
499 # #
500 #################################
501
502 =head2 get_Member_by_source
503
504 Arg [1] : string $source_name
505 e.g. "ENSEMBLPEP"
506 Example :
507 Description:
508 Returntype : array reference of Bio::EnsEMBL::Compara::Member
509 Exceptions :
510 Caller : public
511
512 =cut
513
514 sub get_Member_by_source {
515 my ($self, $source_name) = @_;
516 throw("Should give defined source_name as arguments\n") unless (defined $source_name);
517 my ($scope, $key) = ('_members_by_source', $source_name);
518 return $self->_get_Member($scope, $key);
519 }
520
521 =head2 get_Member_by_source_taxon
522
523 Arg [1] : string $source_name
524 Arg [2] : int $taxon_id
525 Example : $domain->get_Member_by_source_taxon('ENSEMBLPEP',9606)
526 Description:
527 Returntype : array reference of Bio::EnsEMBL::Compara::Member
528 Exceptions :
529 Caller : public
530
531 =cut
532
533 sub get_Member_by_source_taxon {
534 my ($self, $source_name, $taxon_id) = @_;
535 throw("Should give defined source_name and taxon_id as arguments\n") unless (defined $source_name && defined $taxon_id);
536 my ($scope, $key) = ('_members_by_source_taxon', "${source_name}_${taxon_id}");
537 return $self->_get_Member($scope, $key);
538 }
539
540 =head2 get_Member_by_GenomeDB
541
542 Arg [1] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
543 Example : $domain->get_Member_by_GenomeDB($genome_db)
544 Description: Returns all [Member] entries linked to this GenomeDB.
545 This will only return EnsEMBL based entries since UniProtKB
546 entries are not linked to a GenomeDB.
547 Returntype : array reference of Bio::EnsEMBL::Compara::Member
548 Exceptions : If input is undefined & genome db is not of expected type
549 Caller : public
550
551 =cut
552
553 sub get_Member_by_GenomeDB {
554 my ($self, $genome_db) = @_;
555 throw("Should give defined genome_db as an argument\n") unless defined $genome_db;
556 assert_ref($genome_db, 'Bio::EnsEMBL::Compara::GenomeDB');
557 my ($scope, $key) = ('_members_by_genome_db', $genome_db->dbID());
558 return $self->_get_Member($scope, $key);
559 }
560
561 =head2 get_Member_by_source_GenomeDB
562
563 Arg [1] : string $source_name
564 Arg [2] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
565 Example : $domain->get_Member_by_source_taxon('ENSEMBLPEP', $genome_db)
566 Description: Returns all [Member] entries linked to this GenomeDB
567 and the given source_name. This will only return EnsEMBL based
568 entries since UniProtKB entries are not linked to a GenomeDB.
569 Returntype : array reference of Bio::EnsEMBL::Compara::Member
570 Exceptions : If input is undefined & genome db is not of expected type
571 Caller : public
572
573 =cut
574
575 sub get_Member_by_source_GenomeDB {
576 my ($self, $source_name, $genome_db) = @_;
577 throw("Should give defined source_name & genome_db as arguments\n") unless defined $source_name && $genome_db;
578 assert_ref($genome_db, 'Bio::EnsEMBL::Compara::GenomeDB');
579 my ($scope, $key) = ('_members_by_source_genome_db', "${source_name}_".$genome_db->dbID());
580 return $self->_get_Member($scope, $key);
581 }
582
583 =head2 _get_Member
584
585 Arg [1] : string $scope
586 Arg [2] : string $key
587 Example : $domain->_get_Member('_members_by_source', 'ENSEMBLPEP')
588 Description: Used as the generic reference point for all
589 get_Memeber_by* methods. The method searches the given
590 scope & if the values cannot be found will initalize that value
591 to an empty array reference.
592 Returntype : array reference of Bio::EnsEMBL::Compara::Member
593 Exceptions : None.
594 Caller : internal
595
596 =cut
597
598 sub _get_Member {
599 my ($self, $scope, $key) = @_;
600 $self->get_all_Members();
601 $self->{$scope}->{$key} = [] unless defined $self->{$scope}->{$key};
602 return $self->{$scope}->{$key};
603 }
604
605
606 =head2 get_Member_Attribute_by_source
607
608 Arg [1] : string $source_name
609 e.g. "ENSEMBLPEP"
610 Example :
611 Description:
612 Returntype : array reference of Bio::EnsEMBL::Compara::Member and attribute
613 Exceptions :
614 Caller : public
615
616 =cut
617
618 sub get_Member_Attribute_by_source { # DEPRECATED
619 my ($self, $source_name) = @_;
620 throw("Should give defined source_name as arguments\n") unless (defined $source_name);
621 my ($attribute_scope, $key) = ('_members_by_source', $source_name);
622 return $self->_get_Member_Attribute($attribute_scope, $key);
623 }
624
625 =head2 get_Member_Attribute_by_source_taxon
626
627 Arg [1] : string $source_name
628 Arg [2] : int $taxon_id
629 Example : $domain->get_Member_by_source_taxon('ENSEMBLPEP',9606)
630 Description:
631 Returntype : array reference of Bio::EnsEMBL::Compara::Member
632 Exceptions :
633 Caller : public
634
635 =cut
636
637 sub get_Member_Attribute_by_source_taxon { # DEPRECATED
638 my ($self, $source_name, $taxon_id) = @_;
639 throw("Should give defined source_name and taxon_id as arguments\n") unless (defined $source_name && defined $taxon_id);
640 my ($attribute_scope, $key) = ('_members_by_source_taxon', "${source_name}_${taxon_id}");
641 return $self->_get_Member_Attribute($attribute_scope, $key);
642 }
643
644 =head2 get_Member_Attribute_by_GenomeDB
645
646 Arg [1] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
647 Example : $domain->get_Member_Attribute_by_GenomeDB($genome_db)
648 Description: Returns all [Member_Attribute] entries linked to this GenomeDB.
649 This will only return EnsEMBL based entries since UniProtKB
650 entries are not linked to a GenomeDB.
651 Returntype : array reference of Bio::EnsEMBL::Compara::Member
652 Exceptions : If input is undefined & genome db is not of expected type
653 Caller : public
654
655 =cut
656
657 sub get_Member_Attribute_by_GenomeDB { # DEPRECATED
658 my ($self, $genome_db) = @_;
659 throw("Should give defined genome_db as an argument\n") unless defined $genome_db;
660 assert_ref($genome_db, 'Bio::EnsEMBL::Compara::GenomeDB');
661 my ($attribute_scope, $key) = ('_members_by_genome_db', $genome_db->dbID());
662 return $self->_get_Member_Attribute($attribute_scope, $key);
663 }
664
665 =head2 get_Member_Attribute_by_source_GenomeDB
666
667 Arg [1] : string $source_name
668 Arg [2] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
669 Example : $domain->get_Member_by_source_taxon('ENSEMBLPEP', $genome_db)
670 Description: Returns all [Member_Attribute] entries linked to this GenomeDB
671 and the given source_name. This will only return EnsEMBL based
672 entries since UniProtKB entries are not linked to a GenomeDB.
673 Returntype : array reference of Bio::EnsEMBL::Compara::Member
674 Exceptions : If input is undefined & genome db is not of expected type
675 Caller : public
676
677 =cut
678
679 sub get_Member_Attribute_by_source_GenomeDB { # DEPRECATED
680 my ($self, $source_name, $genome_db) = @_;
681 throw("Should give defined source_name & genome_db as arguments\n") unless defined $source_name && $genome_db;
682 assert_ref($genome_db, 'Bio::EnsEMBL::Compara::GenomeDB');
683 my ($attribute_scope, $key) = ('_members_by_source_genome_db', "${source_name}_".$genome_db->dbID());
684 return $self->_get_Member_Attribute($attribute_scope, $key);
685 }
686
687 =head2 _get_Member_Attribute
688
689 Arg [1] : string $attribute_scope
690 Arg [2] : string $key
691 Example : $domain->_get_Member_Attribute('_members_by_source', 'ENSEMBLPEP')
692 Description: Used as the generic reference point for all
693 get_Memeber_Attribute_by* methods. The method searches the given
694 scope & if the values cannot be found will initalize that value
695 to an empty array reference.
696 Returntype : array reference of Bio::EnsEMBL::Compara::Member
697 Exceptions : None.
698 Caller : internal
699
700 =cut
701
702 sub _get_Member_Attribute { # DEPRECATED
703 my ($self, $attribute_scope, $key) = @_;
704 $self->get_all_Member_Attribute();
705 $self->{$attribute_scope}->{$key} = [] unless defined $self->{$attribute_scope}->{$key};
706 return $self->_tranform_array_to_Member_Attributes($self->{$attribute_scope}->{$key});
707 }
708
709
710
711
712
713 =head2 Member_count_by_source
714
715 Arg [1] : string $source_name
716 e.g. "ENSEMBLPEP"
717 Example : $domain->Member_count_by_source('ENSEMBLPEP');
718 Description:
719 Returntype : int
720 Exceptions :
721 Caller : public
722
723 =cut
724
725 sub Member_count_by_source {
726 my ($self, $source_name) = @_;
727
728 throw("Should give a defined source_name as argument\n") unless (defined $source_name);
729
730 return scalar @{$self->get_Member_by_source($source_name)};
731 }
732
733 =head2 Member_count_by_source_taxon
734
735 Arg [1] : string $source_name
736 Arg [2] : int $taxon_id
737 Example : Member_count_by_source_taxon('ENSEMBLPEP',9606);
738 Description:
739 Returntype : int
740 Exceptions :
741 Caller : public
742
743 =cut
744
745 sub Member_count_by_source_taxon {
746 my ($self, $source_name, $taxon_id) = @_;
747
748 throw("Should give defined source_name and taxon_id as arguments\n") unless (defined $source_name && defined $taxon_id);
749
750 return scalar @{$self->get_Member_by_source_taxon($source_name,$taxon_id)};
751 }
752
753 =head2 Member_count_by_GenomeDB
754
755 Arg [1] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
756 Example : Member_count_by_GenomeDB($genome_db);
757 Description: Convenience wrapper for member counts by a GenomeDB
758 Returntype : int
759 Exceptions : Thrown by subrountines this call. See get_Member
760 equivalent
761 Caller : public
762
763 =cut
764
765 sub Member_count_by_GenomeDB {
766 my ($self, $genome_db) = @_;
767 return scalar @{$self->get_Member_by_GenomeDB($genome_db)};
768 }
769
770 =head2 Member_count_by_source_GenomeDB
771
772 Arg [1] : string $source_name
773 Arg [2] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
774 Example : Member_count_by_source_GenomeDB('ENSEMBLPEP', $genome_db);
775 Description: Convenience wrapper for member counts by a GenomeDB
776 Returntype : int
777 Exceptions : Thrown by subrountines this call. See get_Member
778 equivalent
779 Caller : public
780
781 =cut
782
783
784 sub Member_count_by_source_GenomeDB {
785 my ($self, $source_name, $genome_db) = @_;
786 return scalar @{$self->get_Member_by_source_GenomeDB($source_name, $genome_db)};
787 }
788
789
790 =head2 get_all_taxa_by_member_source_name
791
792 Arg [1] : string $source_name
793 e.g. "ENSEMBLPEP"
794 Example :
795 Description: Returns the distinct taxons found in this family across
796 the specified source. If you do not specify a source then
797 the code will return all taxons in this family.
798 Returntype : array reference of distinct Bio::EnsEMBL::Compara::NCBITaxon
799 objects found in this family
800 Exceptions :
801 Caller : public
802
803 =cut
804
805 sub get_all_taxa_by_member_source_name {
806 my ($self, $source_name) = @_;
807
808 my $ncbi_ta = $self->adaptor->db->get_NCBITaxonAdaptor();
809 my @taxa;
810 $self->get_all_Members;
811 foreach my $key (keys %{$self->{_members_by_source_taxon}}) {
812 my @parts = split('_', $key);
813 if ($parts[0] eq $source_name) {
814 push @taxa, $ncbi_ta->fetch_node_by_taxon_id($parts[1]);
815 }
816 }
817 return \@taxa;
818 }
819
820 =head2 get_all_GenomeDBs_by_member_source_name
821
822 Arg [1] : string $source_name
823 e.g. "ENSEMBLPEP"
824 Example :
825 Description: Returns the distinct GenomeDBs found in this family. Please note
826 that if you specify a source other than an EnsEMBL based one
827 the chances of getting back GenomeDBs are very low.
828 Returntype : array reference of distinct Bio::EnsEMBL::Compara::GenomeDB
829 objects found in this family
830 Exceptions :
831 Caller : public
832
833 =cut
834
835 sub get_all_GenomeDBs_by_member_source_name {
836 my ($self, $source_name) = @_;
837
838 my $gdb_a = $self->adaptor->db->get_GenomeDBAdaptor();
839 my @gdbs;
840 $self->get_all_Members;
841 foreach my $key (keys %{$self->{_members_by_source_genome_db}}) {
842 my @parts = split('_', $key);
843 if ($parts[0] eq $source_name) {
844 push @gdbs, $gdb_a->fetch_by_dbID($parts[1]);
845 }
846 }
847 return \@gdbs;
848 }
849
850 =head2 has_species_by_name
851
852 Arg [1] : string $species_name
853 Example : my $ret = $homology->has_species_by_name("Homo sapiens");
854 Description: return TRUE or FALSE whether one of the members in the homology is from the given species
855 Returntype : 1 or 0
856 Exceptions :
857 Caller :
858
859 =cut
860
861
862 sub has_species_by_name {
863 my $self = shift;
864 my $species_name = shift;
865
866 foreach my $member (@{$self->get_all_Members}) {
867 return 1 if defined $member->genome_db and ($member->genome_db->name eq $species_name);
868 }
869 return 0;
870 }
871
872
873 1;