Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Tree/AlleleNode.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: AlleleNode.pm,v 1.4 2002/10/22 07:45:24 lapp Exp $ | |
| 2 # | |
| 3 # BioPerl module for Bio::Tree::AlleleNode | |
| 4 # | |
| 5 # Cared for by Jason Stajich <jason@bioperl.org> | |
| 6 # | |
| 7 # Copyright Jason Stajich | |
| 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::Tree::AlleleNode - DESCRIPTION of Object | |
| 16 | |
| 17 =head1 SYNOPSIS | |
| 18 | |
| 19 Give standard usage here | |
| 20 | |
| 21 =head1 DESCRIPTION | |
| 22 | |
| 23 Describe the object here | |
| 24 | |
| 25 =head1 FEEDBACK | |
| 26 | |
| 27 =head2 Mailing Lists | |
| 28 | |
| 29 User feedback is an integral part of the evolution of this and other | |
| 30 Bioperl modules. Send your comments and suggestions preferably to | |
| 31 the Bioperl mailing list. Your participation is much appreciated. | |
| 32 | |
| 33 bioperl-l@bioperl.org - General discussion | |
| 34 http://bioperl.org/MailList.shtml - About the mailing lists | |
| 35 | |
| 36 =head2 Reporting Bugs | |
| 37 | |
| 38 Report bugs to the Bioperl bug tracking system to help us keep track | |
| 39 of the bugs and their resolution. Bug reports can be submitted via | |
| 40 email or the web: | |
| 41 | |
| 42 bioperl-bugs@bioperl.org | |
| 43 http://bugzilla.bioperl.org/ | |
| 44 | |
| 45 =head1 AUTHOR - Jason Stajich | |
| 46 | |
| 47 Email jason@bioperl.org | |
| 48 | |
| 49 Describe contact details here | |
| 50 | |
| 51 =head1 CONTRIBUTORS | |
| 52 | |
| 53 Additional contributors names and emails here | |
| 54 | |
| 55 =head1 APPENDIX | |
| 56 | |
| 57 The rest of the documentation details each of the object methods. | |
| 58 Internal methods are usually preceded with a _ | |
| 59 | |
| 60 =cut | |
| 61 | |
| 62 | |
| 63 # Let the code begin... | |
| 64 | |
| 65 | |
| 66 package Bio::Tree::AlleleNode; | |
| 67 use vars qw(@ISA); | |
| 68 use strict; | |
| 69 | |
| 70 use Bio::Tree::Node; | |
| 71 | |
| 72 @ISA = qw(Bio::Tree::Node ); | |
| 73 | |
| 74 =head2 new | |
| 75 | |
| 76 Title : new | |
| 77 Usage : my $obj = new Bio::Tree::AlleleNode(); | |
| 78 Function: Builds a new Bio::Tree::AlleleNode object | |
| 79 Returns : Bio::Tree::AlleleNode | |
| 80 Args : | |
| 81 | |
| 82 | |
| 83 =cut | |
| 84 | |
| 85 sub new { | |
| 86 my($class,@args) = @_; | |
| 87 | |
| 88 my $self = $class->SUPER::new(@args); | |
| 89 | |
| 90 my ($alleles) = $self->_rearrange([qw(ALLELES)], @args); | |
| 91 $self->{'_data'} = {}; | |
| 92 if( defined $alleles ) { | |
| 93 if( ref($alleles) !~ /HASH/i ) { | |
| 94 $self->warn("Must specify a valid HASH reference for the -alleles value...Ignoring initializing input"); | |
| 95 | |
| 96 } else { | |
| 97 foreach my $mkr ( keys %{$alleles} ) { | |
| 98 $self->add_alleles($mkr,@{$alleles->{$mkr}}); | |
| 99 } | |
| 100 } | |
| 101 } | |
| 102 return $self; | |
| 103 } | |
| 104 | |
| 105 =head2 add_alleles | |
| 106 | |
| 107 Title : add_alleles | |
| 108 Usage : $node->add_alleles($mkr,@alleles); | |
| 109 Function: Adds allele(s) for $mkr, @alleles can be a single or | |
| 110 multiple alleles. If the same marker is added more than one, the | |
| 111 previous value will be overwritten with a warning. | |
| 112 Returns : none | |
| 113 Args : $marker => marker name | |
| 114 @alleles => alleles for the marker | |
| 115 | |
| 116 | |
| 117 =cut | |
| 118 | |
| 119 sub add_alleles{ | |
| 120 my ($self,$marker,@alleles) = @_; | |
| 121 if( ! defined $marker || $marker eq '' ) { | |
| 122 $self->warn("must specify a valid marker name for add_alleles"); | |
| 123 return; | |
| 124 } | |
| 125 if( $self->{'_data'}->{$marker} ) { | |
| 126 $self->warn("Overwriting value of $marker"); | |
| 127 } | |
| 128 $self->{'_data'}->{$marker} = []; # reset the array ref | |
| 129 foreach my $a ( sort @alleles ) { | |
| 130 next if ! defined $a; # skip undef alleles | |
| 131 push @{$self->{'_data'}->{$marker}},$a; | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 =head2 get_alleles | |
| 136 | |
| 137 Title : get_alleles | |
| 138 Usage : my @alleles = $node->get_alleles($marker); | |
| 139 Function: Return the alleles for a marker $marker | |
| 140 Returns : Array of Alleles for a marker or empty array | |
| 141 Args : $marker name | |
| 142 | |
| 143 =cut | |
| 144 | |
| 145 sub get_alleles{ | |
| 146 my ($self,$marker) = @_; | |
| 147 if( defined $self->{'_data'}->{$marker} ) { | |
| 148 return @{$self->{'_data'}->{$marker}}; | |
| 149 } | |
| 150 return (); | |
| 151 } | |
| 152 | |
| 153 =head2 get_marker_names | |
| 154 | |
| 155 Title : get_marker_names | |
| 156 Usage : my @names =$node->get_marker_names(); | |
| 157 Function: Return the names of the markers that have been added to this node | |
| 158 Returns : List of Marker Names | |
| 159 Args : none | |
| 160 | |
| 161 =cut | |
| 162 | |
| 163 sub get_marker_names{ | |
| 164 my ($self) = @_; | |
| 165 return keys %{$self->{'_data'}}; | |
| 166 } | |
| 167 | |
| 168 =head2 purge_markers | |
| 169 | |
| 170 Title : purge_markers | |
| 171 Usage : $node->purge_markers; | |
| 172 Function: Reset the markers and alleles | |
| 173 Returns : none | |
| 174 Args : none | |
| 175 | |
| 176 | |
| 177 =cut | |
| 178 | |
| 179 sub purge_markers{ | |
| 180 my ($self) = @_; | |
| 181 $self->{'_data'} = {}; | |
| 182 return; | |
| 183 } | |
| 184 | |
| 185 | |
| 186 1; |
