sync w/ main trunk
[bioperl-live.git] / Bio / Phenotype / Phenotype.pm
blobf2c40b52bf4886a52a578b234c678332b6c76edd
1 # $Id$
3 # BioPerl module for Bio::Phenotype::Phenotype
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Christian M. Zmasek <czmasek@gnf.org> or <cmzmasek@yahoo.com>
9 # (c) Christian M. Zmasek, czmasek@gnf.org, 2002.
10 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
12 # You may distribute this module under the same terms as perl itself.
13 # Refer to the Perl Artistic License (see the license accompanying this
14 # software package, or see http://www.perl.com/language/misc/Artistic.html)
15 # for the terms under which you may use, modify, and redistribute this module.
17 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
18 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 # You may distribute this module under the same terms as perl itself
23 # POD documentation - main docs before the code
25 =head1 NAME
27 Bio::Phenotype::Phenotype - A class for modeling phenotypes
29 =head1 SYNOPSIS
31 #get Bio::Phenotype::PhenotypeI somehow
33 print $phenotype->name(), "\n";
34 print $phenotype->description(), "\n";
36 my @keywords = ( "achondroplasia", "dwarfism" );
37 $phenotype->add_keywords( @keywords );
38 foreach my $keyword ( $phenotype->each_keyword() ) {
39 print $keyword, "\n";
41 $phenotype->remove_keywords();
44 foreach my $gene_symbol ( $phenotype->each_gene_symbol() ) {
45 print $gene_symbol, "\n";
48 foreach my $corr ( $phenotype->each_Correlate() ) {
49 # Do something with $corr
52 foreach my $var ( $phenotype->each_Variant() ) {
53 # Do something with $var (mutation)
56 foreach my $measure ( $phenotype->each_Measure() ) {
57 # Do something with $measure
61 =head1 DESCRIPTION
63 This superclass implements common methods for classes modelling phenotypes.
64 Bio::Phenotype::OMIM::OMIMentry is an example of an instantiable phenotype
65 class (the design of this interface was partially guided by the need
66 to model OMIM entries).
67 Please note. This class provides methods to associate mutations
68 (methods "each_Variant", ...) and genotypes (methods "each_Genotype", ...)
69 with phenotypes. Yet, these aspects might need some future enhancements,
70 especially since there is no "genotype" class yet.
72 =head1 FEEDBACK
74 =head2 Mailing Lists
76 User feedback is an integral part of the evolution of this and other
77 Bioperl modules. Send your comments and suggestions preferably to the
78 Bioperl mailing lists Your participation is much appreciated.
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
83 =head2 Support
85 Please direct usage questions or support issues to the mailing list:
87 L<bioperl-l@bioperl.org>
89 rather than to the module maintainer directly. Many experienced and
90 reponsive experts will be able look at the problem and quickly
91 address it. Please include a thorough description of the problem
92 with code and data examples if at all possible.
94 =head2 Reporting Bugs
96 report bugs to the Bioperl bug tracking system to help us keep track
97 the bugs and their resolution. Bug reports can be submitted via the
98 web:
100 http://bugzilla.open-bio.org/
102 =head1 AUTHOR
104 Christian M. Zmasek
106 Email: czmasek@gnf.org or cmzmasek@yahoo.com
108 WWW: http://www.genetics.wustl.edu/eddy/people/zmasek/
110 Address:
112 Genomics Institute of the Novartis Research Foundation
113 10675 John Jay Hopkins Drive
114 San Diego, CA 92121
116 =head1 APPENDIX
118 The rest of the documentation details each of the object
119 methods. Internal methods are usually preceded with a _
121 =cut
124 # Let the code begin...
127 package Bio::Phenotype::Phenotype;
128 use strict;
130 use Bio::Species;
131 use Bio::Variation::VariantI;
132 use Bio::Annotation::DBLink;
133 use Bio::Annotation::Reference;
134 use Bio::Phenotype::Measure;
135 use Bio::Phenotype::Correlate;
136 use Bio::Map::CytoPosition;
137 use Bio::Range;
140 use base qw(Bio::Root::Root Bio::Phenotype::PhenotypeI);
145 =head2 new
147 Title : new
148 Usage : $obj = Bio::Phenotype::Phenotype->new( -name => "XY",
149 -description => "This is ..." );
150 Function: Creates a new Phenotype object.
151 Returns : A new Phenotype object.
152 Args : -name => the name
153 -description => the description of this phenotype
154 -species => ref to the the species
155 -comment => a comment
157 =cut
159 sub new {
161 my( $class,@args ) = @_;
163 my $self = $class->SUPER::new( @args );
165 my ( $name,
166 $description,
167 $species,
168 $comment )
169 = $self->_rearrange( [ qw( NAME
170 DESCRIPTION
171 SPECIES
172 COMMENT ) ], @args );
174 $self->init();
176 $name && $self->name( $name );
177 $description && $self->description( $description );
178 $species && $self->species( $species );
179 $comment && $self->comment( $comment );
181 return $self;
183 } # new
186 =head2 init
188 Title : init()
189 Usage : $obj->init();
190 Function: Initializes this OMIMentry to all "" and empty lists.
191 Returns :
192 Args :
194 =cut
196 sub init {
198 my( $self ) = @_;
201 $self->name( "" );
202 $self->description( "" );
203 my $species = Bio::Species->new();
204 $species->classification( qw( sapiens Homo ) );
205 $self->species( $species );
206 $self->comment( "" );
207 $self->remove_Correlates();
208 $self->remove_References();
209 $self->remove_CytoPositions();
210 $self->remove_gene_symbols();
211 $self->remove_Genotypes();
212 $self->remove_DBLinks();
213 $self->remove_keywords();
214 $self->remove_Variants();
215 $self->remove_Measures();
217 } # init
220 =head2 name
222 Title : name
223 Usage : $obj->name( "r1" );
225 print $obj->name();
226 Function: Set/get for the name or id of this phenotype.
227 Returns : A name or id [scalar].
228 Args : A name or id [scalar] (optional).
230 =cut
232 sub name {
233 my ( $self, $value ) = @_;
235 if ( defined $value ) {
236 $self->{ "_name" } = $value;
239 return $self->{ "_name" };
241 } # name
244 =head2 description
246 Title : description
247 Usage : $obj->description( "This is ..." );
249 print $obj->description();
250 Function: Set/get for the description of this phenotype.
251 Returns : A description [scalar].
252 Args : A description [scalar] (optional).
254 =cut
256 sub description {
257 my $self = shift;
258 return $self->{ "_description" } = shift if(@_);
259 return $self->{ "_description" };
262 =head2 species
264 Title : species
265 Usage : $obj->species( $species );
267 $species = $obj->species();
268 Function: Set/get for the species of this phenotype.
269 Returns : A species [Bio::Species].
270 Args : A species [Bio::Species] (optional).
272 =cut
274 sub species {
275 my ( $self, $value ) = @_;
277 if ( defined $value ) {
278 $self->_check_ref_type( $value, "Bio::Species" );
279 $self->{ "_species" } = $value;
282 return $self->{ "_species" };
284 } # species
286 =head2 comment
288 Title : comment
289 Usage : $obj->comment( "putative" );
291 print $obj->comment();
292 Function: Set/get for a comment about this phenotype.
293 Returns : A comment [scalar].
294 Args : A comment [scalar] (optional).
296 =cut
298 sub comment {
299 my $self = shift;
300 return $self->{ "_comment" } = shift if(@_);
301 return $self->{ "_comment" };
302 } # comment
305 =head2 each_gene_symbol
307 Title : each_gene_symbol()
308 Usage : @gs = $obj->each_gene_symbol();
309 Function: Returns a list of gene symbols [scalars, most likely Strings]
310 associated with this phenotype.
311 Returns : A list of scalars.
312 Args :
314 =cut
316 sub each_gene_symbol {
317 my ( $self ) = @_;
319 return @{$self->{"_gene_symbols"}} if exists($self->{"_gene_symbols"});
320 return ();
321 } # each_gene_symbol
324 =head2 add_gene_symbols
326 Title : add_gene_symbols
327 Usage : $obj->add_gene_symbols( @gs );
329 $obj->add_gene_symbols( $gs );
330 Function: Pushes one or more gene symbols [scalars, most likely Strings]
331 into the list of gene symbols.
332 Returns :
333 Args : scalar(s).
335 =cut
337 sub add_gene_symbols {
338 my ( $self, @values ) = @_;
340 return unless( @values );
342 push( @{ $self->{ "_gene_symbols" } }, @values );
344 } # add_gene_symbols
347 =head2 remove_gene_symbols
349 Usage : $obj->remove_gene_symbols();
350 Function: Deletes (and returns) the list of gene symbols [scalars,
351 most likely Strings] associated with this phenotype.
352 Returns : A list of scalars.
353 Args :
355 =cut
357 sub remove_gene_symbols {
358 my ( $self ) = @_;
360 my @a = $self->each_gene_symbol();
361 $self->{ "_gene_symbols" } = [];
362 return @a;
364 } # remove_gene_symbols
369 =head2 each_Variant
371 Title : each_Variant()
372 Usage : @vs = $obj->each_Variant();
373 Function: Returns a list of Bio::Variation::VariantI implementing objects
374 associated with this phenotype.
375 This is for representing the actual mutation(s) causing this
376 phenotype.
377 {* The "variants" data member and its methods will/might need to be
378 changed/improved in one way or another, CZ 09/06/02 *}
379 Returns : A list of Bio::Variation::VariantI implementing objects.
380 Args :
382 =cut
384 sub each_Variant {
385 my ( $self ) = @_;
387 return @{ $self->{ "_variants" } } if exists($self->{ "_variants" });
388 return ();
389 } # each_Variant
392 =head2 add_Variants
394 Usage : $obj->add_Variants( @vs );
396 $obj->add_Variants( $v );
397 Function: Pushes one or more Bio::Variation::VariantI implementing objects
398 into the list of Variants.
399 Returns :
400 Args : Bio::Variation::VariantI implementing object(s).
402 =cut
404 sub add_Variants {
405 my ( $self, @values ) = @_;
407 return unless( @values );
409 foreach my $value ( @values ) {
410 $self->_check_ref_type( $value, "Bio::Variation::VariantI" );
413 push( @{ $self->{ "_variants" } }, @values );
415 } # add_Variants
418 =head2 remove_Variants
420 Title : remove_Variants
421 Usage : $obj->remove_Variants();
422 Function: Deletes (and returns) the list of Bio::Variation::VariantI implementing
423 objects associated with this phenotype.
424 Returns : A list of Bio::Variation::VariantI implementing objects.
425 Args :
427 =cut
429 sub remove_Variants {
430 my ( $self ) = @_;
432 my @a = $self->each_Variant();
433 $self->{ "_variants" } = [];
434 return @a;
436 } # remove_Variants
441 =head2 each_Reference
443 Title : each_Reference()
444 Usage : @refs = $obj->each_Reference();
445 Function: Returns a list of Bio::Annotation::Reference objects
446 associated with this phenotype.
447 Returns : A list of Bio::Annotation::Reference objects.
448 Args :
450 =cut
452 sub each_Reference {
453 my ( $self ) = @_;
455 return @{ $self->{ "_references" } } if exists($self->{ "_references" });
456 return ();
457 } # each_Reference
460 =head2 add_References
462 Title : add_References
463 Usage : $obj->add_References( @refs );
465 $obj->add_References( $ref );
466 Function: Pushes one or more Bio::Annotation::Reference objects
467 into the list of References.
468 Returns :
469 Args : Bio::Annotation::Reference object(s).
471 =cut
473 sub add_References {
474 my ( $self, @values ) = @_;
476 return unless( @values );
478 foreach my $value ( @values ) {
479 $self->_check_ref_type( $value, "Bio::Annotation::Reference" );
482 push( @{ $self->{ "_references" } }, @values );
484 } # add_References
487 =head2 remove_References
489 Title : remove_References()
490 Usage : $obj->remove_References();
491 Function: Deletes (and returns) the list of Bio::Annotation::Reference objects
492 associated with this phenotype.
493 Returns : A list of Bio::Annotation::Reference objects.
494 Args :
496 =cut
498 sub remove_References {
499 my ( $self ) = @_;
501 my @a = $self->each_Reference();
502 $self->{ "_references" } = [];
503 return @a;
505 } # remove_References
510 =head2 each_CytoPosition
512 Title : each_CytoPosition()
513 Usage : @cps = $obj->each_CytoPosition();
514 Function: Returns a list of Bio::Map::CytoPosition objects
515 associated with this phenotype.
516 Returns : A list of Bio::Map::CytoPosition objects.
517 Args :
519 =cut
521 sub each_CytoPosition {
522 my ( $self ) = @_;
524 return @{$self->{"_cyto_positions"}} if exists($self->{"_cyto_positions"});
525 return ();
526 } # each_CytoPosition
529 =head2 add_CytoPositions
531 Title : add_CytoPositions
532 Usage : $obj->add_CytoPositions( @cps );
534 $obj->add_CytoPositions( $cp );
535 Function: Pushes one or more Bio::Map::CytoPosition objects
536 into the list of CytoPositions.
537 Returns :
538 Args : Bio::Map::CytoPosition object(s).
540 =cut
542 sub add_CytoPositions {
543 my ( $self, @values ) = @_;
545 return unless( @values );
547 foreach my $value ( @values ) {
548 $self->_check_ref_type( $value, "Bio::Map::CytoPosition" );
551 push( @{ $self->{ "_cyto_positions" } }, @values );
553 } # add_CytoPositions
556 =head2 remove_CytoPositions
558 Title : remove_CytoPositions
559 Usage : $obj->remove_CytoPositions();
560 Function: Deletes (and returns) the list o fBio::Map::CytoPosition objects
561 associated with this phenotype.
562 Returns : A list of Bio::Map::CytoPosition objects.
563 Args :
565 =cut
567 sub remove_CytoPositions {
568 my ( $self ) = @_;
570 my @a = $self->each_CytoPosition();
571 $self->{ "_cyto_positions" } = [];
572 return @a;
574 } # remove_CytoPositions
579 =head2 each_Correlate
581 Title : each_Correlate()
582 Usage : @corrs = $obj->each_Correlate();
583 Function: Returns a list of Bio::Phenotype::Correlate objects
584 associated with this phenotype.
585 (Correlates are correlating phenotypes in different species;
586 inspired by mouse correlates of human phenotypes in the OMIM
587 database.)
588 Returns : A list of Bio::Phenotype::Correlate objects.
589 Args :
591 =cut
593 sub each_Correlate {
594 my ( $self ) = @_;
596 return @{ $self->{ "_correlates" } } if exists($self->{ "_correlates" });
597 return ();
598 } # each_Correlate
603 =head2 add_Correlates
605 Title : add_Correlates
606 Usage : $obj->add_Correlates( @corrs );
608 $obj->add_Correlates( $corr );
609 Function: Pushes one or more Bio::Phenotype::Correlate objects
610 into the list of Correlates.
611 Returns :
612 Args : Bio::Phenotype::Correlate object(s).
614 =cut
616 sub add_Correlates {
617 my ( $self, @values ) = @_;
619 return unless( @values );
621 foreach my $value ( @values ) {
622 $self->_check_ref_type( $value, "Bio::Phenotype::Correlate" );
625 push( @{ $self->{ "_correlates" } }, @values );
627 } # add_Correlates
630 =head2 remove_Correlates
632 Title : remove_Correlates
633 Usage : $obj->remove_Correlates();
634 Function: Deletes (and returns) the list of Bio::Phenotype::Correlate objects
635 associated with this phenotype.
636 Returns : A list of Bio::Phenotype::Correlate objects.
637 Args :
639 =cut
641 sub remove_Correlates {
642 my ( $self ) = @_;
644 my @a = $self->each_Correlate();
645 $self->{ "_correlates" } = [];
646 return @a;
648 } # remove_Correlates
653 =head2 each_Measure
655 Title : each_Measure()
656 Usage : @ms = $obj->each_Measure();
657 Function: Returns a list of Bio::Phenotype::Measure objects
658 associated with this phenotype.
659 (Measure is for biochemically defined phenotypes
660 or any other types of measures.)
661 Returns : A list of Bio::Phenotype::Measure objects.
662 Args :
664 =cut
666 sub each_Measure {
667 my ( $self ) = @_;
669 return @{ $self->{ "_measures" } } if exists($self->{ "_measures" });
670 return ();
671 } # each_Measure
674 =head2 add_Measures
676 Title : add_Measures
677 Usage : $obj->add_Measures( @ms );
679 $obj->add_Measures( $m );
680 Function: Pushes one or more Bio::Phenotype::Measure objects
681 into the list of Measures.
682 Returns :
683 Args : Bio::Phenotype::Measure object(s).
685 =cut
687 sub add_Measures {
688 my ( $self, @values ) = @_;
690 return unless( @values );
692 foreach my $value ( @values ) {
693 $self->_check_ref_type( $value, "Bio::Phenotype::Measure" );
696 push( @{ $self->{ "_measures" } }, @values );
698 } # add_Measures
701 =head2 remove_Measures
703 Title : remove_Measures
704 Usage : $obj->remove_Measures();
705 Function: Deletes (and returns) the list of Bio::Phenotype::Measure objects
706 associated with this phenotype.
707 Returns : A list of Bio::Phenotype::Measure objects.
708 Args :
710 =cut
712 sub remove_Measures {
713 my ( $self ) = @_;
715 my @a = $self->each_Measure();
716 $self->{ "_measures" } = [];
717 return @a;
719 } # remove_Measures
724 =head2 each_keyword
726 Title : each_keyword()
727 Usage : @kws = $obj->each_keyword();
728 Function: Returns a list of key words [scalars, most likely Strings]
729 associated with this phenotype.
730 Returns : A list of scalars.
731 Args :
733 =cut
735 sub each_keyword {
736 my ( $self ) = @_;
738 return @{ $self->{ "_keywords" } } if exists($self->{ "_keywords" });
739 return ();
740 } # each_keyword
743 =head2 add_keywords
745 Title : add_keywords
746 Usage : $obj->add_keywords( @kws );
748 $obj->add_keywords( $kw );
749 Function: Pushes one or more keywords [scalars, most likely Strings]
750 into the list of key words.
751 Returns :
752 Args : scalar(s).
754 =cut
756 sub add_keywords {
757 my ( $self, @values ) = @_;
759 return unless( @values );
761 push( @{ $self->{ "_keywords" } }, @values );
763 } # add_keywords
766 =head2 remove_keywords
768 Title : remove_keywords
769 Usage : $obj->remove_keywords();
770 Function: Deletes (and returns) the list of key words [scalars,
771 most likely Strings] associated with this phenotype.
772 Returns : A list of scalars.
773 Args :
775 =cut
777 sub remove_keywords {
778 my ( $self ) = @_;
780 my @a = $self->each_keyword();
781 $self->{ "_keywords" } = [];
782 return @a;
784 } # remove_keywords
789 =head2 each_DBLink
791 Title : each_DBLink()
792 Usage : @dbls = $obj->each_DBLink();
793 Function: Returns a list of Bio::Annotation::DBLink objects
794 associated with this phenotype.
795 Returns : A list of Bio::Annotation::DBLink objects.
796 Args :
798 =cut
800 sub each_DBLink {
801 my ( $self ) = @_;
803 return @{ $self->{ "_db_links" } } if exists($self->{ "_db_links" });
804 return ();
808 =head2 add_DBLinks
810 Title : add_DBLinks
811 Usage : $obj->add_DBLinks( @dbls );
813 $obj->add_DBLinks( $dbl );
814 Function: Pushes one or more Bio::Annotation::DBLink objects
815 into the list of DBLinks.
816 Returns :
817 Args : Bio::Annotation::DBLink object(s).
819 =cut
821 sub add_DBLinks {
822 my ( $self, @values ) = @_;
824 return unless( @values );
826 foreach my $value ( @values ) {
827 $self->_check_ref_type( $value, "Bio::Annotation::DBLink" );
830 push( @{ $self->{ "_db_links" } }, @values );
832 } # add_DBLinks
835 =head2 remove_DBLinks
837 Title : remove_DBLinks
838 Usage : $obj->remove_DBLinks();
839 Function: Deletes (and returns) the list of Bio::Annotation::DBLink objects
840 associated with this phenotype.
841 Returns : A list of Bio::Annotation::DBLink objects.
842 Args :
844 =cut
846 sub remove_DBLinks {
847 my ( $self ) = @_;
849 my @a = $self->each_DBLink();
850 $self->{ "_db_links" } = [];
851 return @a;
853 } # remove_DBLinks
858 =head2 each_Genotype
860 Title : each_Reference()
861 Usage : @gts = $obj->each_Reference();
862 Function: Returns a list of "Genotype" objects
863 associated with this phenotype.
864 {* the "genotypes" data member and its methods certainly will/needs to be
865 changed/improved in one way or another since there is
866 no "Genotype" class yet, CZ 09/06/02 *}
867 Returns : A list of "Genotype" objects.
868 Args :
870 =cut
872 sub each_Genotype {
873 my ( $self ) = @_;
875 return @{ $self->{ "_genotypes" } } if exists($self->{ "_genotypes" });
876 return ();
877 } # each_Genotype
880 =head2 add_Genotypes
882 Title : add_Genotypes
883 Usage : $obj->add_Genotypes( @gts );
885 $obj->add_Genotypes( $gt );
886 Function: Pushes one or more "Genotypes"
887 into the list of "Genotypes".
888 Returns :
889 Args : "Genotypes(s)".
891 =cut
893 sub add_Genotypes {
894 my ( $self, @values ) = @_;
896 return unless( @values );
898 #foreach my $value ( @values ) {
899 # $self->_check_ref_type( $value, "Bio::GenotypeI" );
902 push( @{ $self->{ "_genotypes" } }, @values );
904 } # add_Genotypes
907 =head2 remove_Genotypes
909 Title : remove_Genotypes
910 Usage : $obj->remove_Genotypes();
911 Function: Deletes (and returns) the list of "Genotype" objects
912 associated with this phenotype.
913 Returns : A list of "Genotype" objects.
914 Args :
916 =cut
918 sub remove_Genotypes {
919 my ( $self ) = @_;
921 my @a = $self->each_Genotype();
922 $self->{ "_genotypes" } = [];
923 return @a;
925 } # remove_Genotypes
928 =head2 _check_ref_type
930 Title : _check_ref_type
931 Usage : $self->_check_ref_type( $value, "Bio::Annotation::DBLink" );
932 Function: Checks for the correct type.
933 Returns :
934 Args : The value to be checked, the expected class.
936 =cut
938 sub _check_ref_type {
939 my ( $self, $value, $expected_class ) = @_;
941 if ( ! defined( $value ) ) {
942 $self->throw( ( caller( 1 ) )[ 3 ] .": Found [undef"
943 ."] where [$expected_class] expected" );
945 elsif ( ! ref( $value ) ) {
946 $self->throw( ( caller( 1 ) )[ 3 ] .": Found scalar"
947 ." where [$expected_class] expected" );
949 elsif ( ! $value->isa( $expected_class ) ) {
950 $self->throw( ( caller( 1 ) )[ 3 ] .": Found [". ref( $value )
951 ."] where [$expected_class] expected" );
953 } # _check_ref_type