Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Map/OrderedPosition.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 # BioPerl module for Bio::Map::OrderedPosition | |
| 2 # | |
| 3 # Cared for by Chad Matsalla <bioinformatics1@dieselwurks.com> | |
| 4 # | |
| 5 # Copyright Chad Matsalla | |
| 6 # | |
| 7 # You may distribute this module under the same terms as perl itself | |
| 8 | |
| 9 # POD documentation - main docs before the code | |
| 10 | |
| 11 =head1 NAME | |
| 12 | |
| 13 Bio::Map::OrderedPosition - Abstracts the notion of a member | |
| 14 of an ordered list of markers. Each marker is a certain distance | |
| 15 from the one in the ordered list before it. | |
| 16 | |
| 17 =head1 SYNOPSIS | |
| 18 | |
| 19 use Bio::Map::OrderedPosition; | |
| 20 # the first marker in the sequence | |
| 21 my $position = new Bio::Map::OrderedPosition(-order => 1, | |
| 22 -positions => [ [ $map, 22.3] ] ); | |
| 23 # the second marker in the sequence, 15.6 units from the fist one | |
| 24 my $position2 = new Bio::Map::OrderedPosition(-order => 2, | |
| 25 -positions => [ [ $map, 37.9] ] ); | |
| 26 # the third marker in the sequence, coincidental with the second | |
| 27 # marker | |
| 28 my $position3 = new Bio::Map::OrderedPosition(-order => 3, | |
| 29 -posititions => [ [ $map, 37.9]] ); | |
| 30 | |
| 31 =head1 DESCRIPTION | |
| 32 | |
| 33 This object is an implementation of the PositionI interface and the | |
| 34 Position object handles the specific values of a position. | |
| 35 OrderedPosition is intended to be slightly more specific then Position | |
| 36 but only specific enough for a parser from the MarkerIO subsystem to | |
| 37 create and then pass to a client application to bless into the proper | |
| 38 type. For an example of how this is intended to work, see the | |
| 39 Mapmaker.pm. | |
| 40 | |
| 41 No units are assumed here - units are handled by context of which Map | |
| 42 a position is placed in. | |
| 43 | |
| 44 Se Bio::Map::Position for additional information. | |
| 45 | |
| 46 =head1 FEEDBACK | |
| 47 | |
| 48 =head2 Mailing Lists | |
| 49 | |
| 50 User feedback is an integral part of the evolution of this and other | |
| 51 Bioperl modules. Send your comments and suggestions preferably to | |
| 52 the Bioperl mailing list. Your participation is much appreciated. | |
| 53 | |
| 54 bioperl-l@bioperl.org - General discussion | |
| 55 http://bioperl.org/MailList.shtml - About the mailing lists | |
| 56 | |
| 57 =head2 Reporting Bugs | |
| 58 | |
| 59 Report bugs to the Bioperl bug tracking system to help us keep track | |
| 60 of the bugs and their resolution. Bug reports can be submitted via | |
| 61 email or the web: | |
| 62 | |
| 63 bioperl-bugs@bioperl.org | |
| 64 http://bugzilla.bioperl.org/ | |
| 65 | |
| 66 =head1 AUTHOR - Chad Matsalla | |
| 67 | |
| 68 Email bioinformatics1@dieselwurks.com | |
| 69 | |
| 70 =head1 CONTRIBUTORS | |
| 71 | |
| 72 Lincoln Stein, lstein@cshl.org | |
| 73 Heikki Lehvaslaiho, heikki@ebi.ac.uk | |
| 74 Jason Stajich, jason@bioperl.org | |
| 75 | |
| 76 =head1 APPENDIX | |
| 77 | |
| 78 The rest of the documentation details each of the object methods. | |
| 79 Internal methods are usually preceded with a _ | |
| 80 | |
| 81 =cut | |
| 82 | |
| 83 | |
| 84 # Let the code begin... | |
| 85 | |
| 86 | |
| 87 package Bio::Map::OrderedPosition; | |
| 88 use vars qw(@ISA); | |
| 89 use strict; | |
| 90 | |
| 91 use Bio::Map::Position; | |
| 92 | |
| 93 @ISA = qw(Bio::Map::Position); | |
| 94 | |
| 95 =head2 new | |
| 96 | |
| 97 Title : new | |
| 98 Usage : my $obj = new Bio::Map::OrderedPosition(); | |
| 99 Function: Builds a new Bio::Map::OrderedPosition object | |
| 100 Returns : Bio::Map::OrderedPosition | |
| 101 Args : -order - The order of this position | |
| 102 | |
| 103 =cut | |
| 104 | |
| 105 sub new { | |
| 106 my($class,@args) = @_; | |
| 107 my $self = $class->SUPER::new(@args); | |
| 108 # $self->{'_order'} = []; | |
| 109 | |
| 110 my ($map, $marker, $value, $order) = | |
| 111 $self->_rearrange([qw( MAP | |
| 112 MARKER | |
| 113 VALUE | |
| 114 ORDER | |
| 115 )], @args); | |
| 116 # print join ("|-|", ($map, $marker, $value, $order)), "\n"; | |
| 117 $map && $self->map($map); | |
| 118 $marker && $self->marker($marker); | |
| 119 $value && $self->value($value); | |
| 120 $order && $self->order($order); | |
| 121 | |
| 122 return $self; | |
| 123 } | |
| 124 | |
| 125 =head2 order | |
| 126 | |
| 127 Title : order | |
| 128 Usage : $o_position->order($new_position) _or_ | |
| 129 $o_position->order() | |
| 130 Function: get/set the order position of this position in a map | |
| 131 Returns : | |
| 132 Args : If $new_position is provided, the current position of this Position | |
| 133 will be set to $new_position. | |
| 134 | |
| 135 =cut | |
| 136 | |
| 137 sub order { | |
| 138 my ($self,$order) = @_; | |
| 139 if ($order) { | |
| 140 # no point in keeping the old ones | |
| 141 $self->{'_order'} = $order; | |
| 142 } | |
| 143 return $self->{'_order'}; | |
| 144 } | |
| 145 | |
| 146 =head2 Bio::Map::Position functions | |
| 147 | |
| 148 =cut | |
| 149 | |
| 150 =head2 known_maps | |
| 151 | |
| 152 Title : known_maps | |
| 153 Usage : my @maps = $position->known_maps | |
| 154 Function: Returns the list of maps that this position has values for | |
| 155 Returns : list of Bio::Map::MapI unique ids | |
| 156 Args : none | |
| 157 | |
| 158 =head2 in_map | |
| 159 | |
| 160 Title : in_map | |
| 161 Usage : if ( $position->in_map($map) ) {} | |
| 162 Function: Tests if a position has values in a specific map | |
| 163 Returns : boolean | |
| 164 Args : a map unique id OR Bio::Map::MapI | |
| 165 | |
| 166 =head2 each_position_value | |
| 167 | |
| 168 Title : positions | |
| 169 Usage : my @positions = $position->each_position_value($map); | |
| 170 Function: Retrieve a list of positions coded as strings or ints | |
| 171 Returns : Array of position values for a Map | |
| 172 Args : Bio::Map::MapI object to get positions for | |
| 173 | |
| 174 =head2 add_position_value | |
| 175 | |
| 176 Title : add_position_value | |
| 177 Usage : $position->add_position_value($map,'100'); | |
| 178 Function: Add a numeric or string position to the PositionI container | |
| 179 and assoiciate it with a Bio::Map::MapI | |
| 180 Returns : none | |
| 181 Args : $map - Bio::Map::MapI | |
| 182 String or Numeric coding for a position on a map | |
| 183 | |
| 184 =head2 purge_position_values | |
| 185 | |
| 186 Title : purge_position_values | |
| 187 Usage : $position->purge_position_values | |
| 188 Function: Remove all the position values stored for a position | |
| 189 Returns : none | |
| 190 Args : [optional] only purge values for a given map | |
| 191 | |
| 192 =head2 equals | |
| 193 | |
| 194 Title : equals | |
| 195 Usage : if( $mappable->equals($mapable2)) ... | |
| 196 Function: Test if a position is equal to another position. | |
| 197 Returns : boolean | |
| 198 Args : Bio::Map::PositionI | |
| 199 | |
| 200 =cut | |
| 201 | |
| 202 sub equals{ | |
| 203 my ($self,$compare) = @_; | |
| 204 return 0 if ( ! defined $compare || ! $compare->isa('Bio::Map::OrderedPosition')); | |
| 205 return ( $compare->order == $self->order); | |
| 206 } | |
| 207 | |
| 208 # admittedly these are really the best comparisons in the world | |
| 209 # but it is a first pass we'll need to refine the algorithm or not | |
| 210 # provide general comparisions and require these to be implemented | |
| 211 # by objects closer to the specific type of data | |
| 212 | |
| 213 =head2 less_than | |
| 214 | |
| 215 Title : less_than | |
| 216 Usage : if( $mappable->less_than($m2) ) ... | |
| 217 Function: Tests if a position is less than another position | |
| 218 It is assumed that 2 positions are in the same map. | |
| 219 Returns : boolean | |
| 220 Args : Bio::Map::PositionI | |
| 221 | |
| 222 =cut | |
| 223 | |
| 224 | |
| 225 sub less_than{ | |
| 226 my ($self,$compare) = @_; | |
| 227 return 0 if ( ! defined $compare || ! $compare->isa('Bio::Map::OrderedPosition')); | |
| 228 return ( $compare->order < $self->order); | |
| 229 } | |
| 230 | |
| 231 =head2 greater_than | |
| 232 | |
| 233 Title : greater_than | |
| 234 Usage : if( $mappable->greater_than($m2) ) ... | |
| 235 Function: Tests if position is greater than another position. | |
| 236 It is assumed that 2 positions are in the same map. | |
| 237 Returns : boolean | |
| 238 Args : Bio::Map::PositionI | |
| 239 | |
| 240 =cut | |
| 241 | |
| 242 sub greater_than{ | |
| 243 my ($self,$compare) = @_; | |
| 244 return 0 if ( ! defined $compare || ! $compare->isa('Bio::Map::OrderedPosition')); | |
| 245 return ( $compare->order > $self->order); | |
| 246 } | |
| 247 | |
| 248 1; |
