| 1 | =head1 LICENSE | ||
| 2 | |||
| 3 | See the NOTICE file distributed with this work for additional information | ||
| 4 | regarding copyright ownership. | ||
| 5 | |||
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | you may not use this file except in compliance with the License. | ||
| 8 | You may obtain a copy of the License at | ||
| 9 | |||
| 10 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | |||
| 12 | Unless required by applicable law or agreed to in writing, software | ||
| 13 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | See the License for the specific language governing permissions and | ||
| 16 | limitations under the License. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::StableIdEvent- object representing a stable ID mapping event | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | my $old_id = Bio::EnsEMBL::ArchiveStableId->new( | ||
| 38 | -stable_id => 'ENSG001', | ||
| 39 | -version => 1, | ||
| 40 | -type => 'Gene', | ||
| 41 | ); | ||
| 42 | |||
| 43 | my $new_id = Bio::EnsEMBL::ArchiveStableId->new( | ||
| 44 | -stable_id => 'ENSG001', | ||
| 45 | -version => 2, | ||
| 46 | -type => 'Gene', | ||
| 47 | ); | ||
| 48 | |||
| 49 | my $event = Bio::EnsEMBL::StableIdEvent->new( | ||
| 50 | -old_id => $old_id, | ||
| 51 | -new_id => $new_id, | ||
| 52 | -score => 0.997 | ||
| 53 | ); | ||
| 54 | |||
| 55 | # directly access attributes in old and new ArchiveStableId | ||
| 56 | my $old_stable_id = $event->get_attribute( 'old', 'stable_id' ); | ||
| 57 | |||
| 58 | =head1 DESCRIPTION | ||
| 59 | |||
| 60 | This object represents a stable ID mapping event. Such an event links two | ||
| 61 | ArchiveStableIds with a mapping score. | ||
| 62 | |||
| 63 | =head1 METHODS | ||
| 64 | |||
| 65 | new | ||
| 66 | old_ArchiveStableId | ||
| 67 | new_ArchiveStableId | ||
| 68 | score | ||
| 69 | get_attribute | ||
| 70 | ident_string | ||
| 71 | |||
| 72 | =head1 RELATED MODULES | ||
| 73 | |||
| 74 | Bio::EnsEMBL::ArchiveStableId | ||
| 75 | Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | ||
| 76 | Bio::EnsEMBL::StableIdHistoryTree | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | package Bio::EnsEMBL::StableIdEvent; | ||
| 81 | $Bio::EnsEMBL::StableIdEvent::VERSION = '114.0.0_50'; # TRIAL | ||
| 82 | $Bio::EnsEMBL::StableIdEvent::VERSION = '114.0.050'; | ||
| 83 | use strict; | ||
| 84 | use warnings; | ||
| 85 | no warnings 'uninitialized'; | ||
| 86 | |||
| 87 | use Bio::EnsEMBL::Utils::Exception qw(throw warning); | ||
| 88 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 89 | |||
| 90 | |||
| 91 | =head2 new | ||
| 92 | |||
| 93 | Arg[1] : Bio::EnsEMBL::ArchiveStableId $old_id | ||
| 94 | The old ArchiveStableId in the mapping event | ||
| 95 | Arg[2] : Bio::EnsEMBL::ArchiveStableId $new_id | ||
| 96 | The new ArchiveStableId in the mapping event | ||
| 97 | Arg[3] : (optional) float $score - score of this mapping event | ||
| 98 | Example : my $event = Bio::EnsEMBL::StableIdEvent->new( | ||
| 99 | $arch_id1, $arch_id2, 0.977); | ||
| 100 | Description : object constructor | ||
| 101 | Return type : Bio::EnsEMBL::StableIdEvent | ||
| 102 | Exceptions : thrown on wrong argument types | ||
| 103 | Caller : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor::fetch_history_tree_by_stable_id, general | ||
| 104 | Status : At Risk | ||
| 105 | : under development | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | sub new { | ||
| 110 | my $caller = shift; | ||
| 111 | my $class = ref($caller) || $caller; | ||
| 112 | |||
| 113 | my ($old_id, $new_id, $score) = rearrange([qw(OLD_ID NEW_ID SCORE)], @_); | ||
| 114 | |||
| 115 | throw("Need old or new Bio::EnsEMBL::ArchiveStableId to create StableIdEvent") | ||
| 116 | unless ($old_id || $new_id); | ||
| 117 | |||
| 118 | my $self = {}; | ||
| 119 | bless $self, $class; | ||
| 120 | |||
| 121 | # initialise object | ||
| 122 | $self->old_ArchiveStableId($old_id); | ||
| 123 | $self->new_ArchiveStableId($new_id); | ||
| 124 | $self->score($score); | ||
| 125 | |||
| 126 | return $self; | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | =head2 old_ArchiveStableId | ||
| 131 | |||
| 132 | Arg[1] : (optional) Bio::EnsEMBL::ArchiveStableId $archive_id, or undef | ||
| 133 | The old ArchiveStableId to set for this mapping event | ||
| 134 | Example : # getter | ||
| 135 | my $archive_id = $event->old_ArchiveStableId; | ||
| 136 | |||
| 137 | # setter | ||
| 138 | $event->old_ArchiveStableId($archive_id); | ||
| 139 | Description : Getter/setter for old ArchiveStableId in this mapping event. | ||
| 140 | Return type : Bio::EnsEMBL::ArchiveStableId | ||
| 141 | Exceptions : thrown on wrong argument type | ||
| 142 | Caller : general | ||
| 143 | Status : At Risk | ||
| 144 | : under development | ||
| 145 | |||
| 146 | =cut | ||
| 147 | |||
| 148 | sub old_ArchiveStableId { | ||
| 149 | my $self = shift; | ||
| 150 | |||
| 151 | # setter | ||
| 152 | if (@_) { | ||
| 153 | my $archive_id = shift; | ||
| 154 | |||
| 155 | # if argument is defined, check type. undef is also legal as an argument. | ||
| 156 | if (defined($archive_id)) { | ||
| 157 | throw("Need a Bio::EnsEMBL::ArchiveStableId.") unless | ||
| 158 | (ref($archive_id) && $archive_id->isa('Bio::EnsEMBL::ArchiveStableId')); | ||
| 159 | } | ||
| 160 | |||
| 161 | $self->{'old_id'} = $archive_id; | ||
| 162 | } | ||
| 163 | |||
| 164 | # getter | ||
| 165 | return $self->{'old_id'}; | ||
| 166 | } | ||
| 167 | |||
| 168 | |||
| 169 | =head2 new_ArchiveStableId | ||
| 170 | |||
| 171 | Arg[1] : (optional) Bio::EnsEMBL::ArchiveStableId $archive_id, or undef | ||
| 172 | The new ArchiveStableId to set for this mapping event | ||
| 173 | Example : # getter | ||
| 174 | my $archive_id = $event->new_ArchiveStableId; | ||
| 175 | |||
| 176 | # setter | ||
| 177 | $event->new_ArchiveStableId($archive_id); | ||
| 178 | Description : Getter/setter for new ArchiveStableId in this mapping event. | ||
| 179 | Return type : Bio::EnsEMBL::ArchiveStableId | ||
| 180 | Exceptions : thrown on wrong argument type | ||
| 181 | Caller : general | ||
| 182 | Status : At Risk | ||
| 183 | : under development | ||
| 184 | |||
| 185 | =cut | ||
| 186 | |||
| 187 | sub new_ArchiveStableId { | ||
| 188 | my $self = shift; | ||
| 189 | |||
| 190 | # setter | ||
| 191 | if (@_) { | ||
| 192 | my $archive_id = shift; | ||
| 193 | |||
| 194 | # if argument is defined, check type. undef is also legal as an argument. | ||
| 195 | if (defined($archive_id)) { | ||
| 196 | throw("Need a Bio::EnsEMBL::ArchiveStableId.") unless | ||
| 197 | (ref($archive_id) && $archive_id->isa('Bio::EnsEMBL::ArchiveStableId')); | ||
| 198 | } | ||
| 199 | |||
| 200 | $self->{'new_id'} = $archive_id; | ||
| 201 | } | ||
| 202 | |||
| 203 | # getter | ||
| 204 | return $self->{'new_id'}; | ||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | =head2 score | ||
| 209 | |||
| 210 | Arg[1] : (optional) float $score - the score to set | ||
| 211 | Example : my $score = $event->score; | ||
| 212 | Description : Getter/setter for mapping event score. | ||
| 213 | Return type : float or undef | ||
| 214 | Exceptions : none | ||
| 215 | Caller : general | ||
| 216 | Status : At Risk | ||
| 217 | : under development | ||
| 218 | |||
| 219 | =cut | ||
| 220 | |||
| 221 | sub score { | ||
| 222 | my $self = shift; | ||
| 223 | $self->{'score'} = shift if (@_); | ||
| 224 | return $self->{'score'}; | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | =head2 get_attribute | ||
| 229 | |||
| 230 | Arg[1] : String $type - determines whether to get attribute from 'old' | ||
| 231 | or 'new' ArchiveStableId | ||
| 232 | Arg[2] : String $attr - ArchiveStableId attribute to fetch | ||
| 233 | Example : my $old_stable_id = $event->get_attribute('old', 'stable_id'); | ||
| 234 | Description : Accessor to attributes of the ArchiveStableIds attached to this | ||
| 235 | event. Convenience method that does the check for undef old | ||
| 236 | and/or new ArchiveStableId for you. | ||
| 237 | Return type : same as respective method in Bio::EnsEMBL::ArchiveStableId, or | ||
| 238 | undef | ||
| 239 | Exceptions : thrown on wrong arguments | ||
| 240 | Caller : general | ||
| 241 | Status : At Risk | ||
| 242 | : under development | ||
| 243 | |||
| 244 | =cut | ||
| 245 | |||
| 246 | sub get_attribute { | ||
| 247 | my ($self, $type, $attr) = @_; | ||
| 248 | |||
| 249 | throw("First argument passed to this function has to be 'old' or 'new'.") | ||
| 250 | unless ($type eq 'old' or $type eq 'new'); | ||
| 251 | |||
| 252 | my %allowed_attribs = map { $_ => 1 } | ||
| 253 | qw(stable_id version db_name release assembly); | ||
| 254 | |||
| 255 | throw("Attribute $attr not allowed.") unless $allowed_attribs{$attr}; | ||
| 256 | |||
| 257 | my $call = $type.'_ArchiveStableId'; | ||
| 258 | |||
| 259 | if (my $id = $self->$call) { | ||
| 260 | return $id->$attr; | ||
| 261 | } else { | ||
| 262 | return undef; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | |||
| 267 | =head2 ident_string | ||
| 268 | |||
| 269 | Example : print $event->ident_string, "\n"; | ||
| 270 | Description : Returns a string that can be used to identify your StableIdEvent. | ||
| 271 | Useful in debug warnings. | ||
| 272 | Return type : String | ||
| 273 | Exceptions : none | ||
| 274 | Caller : general | ||
| 275 | Status : At Risk | ||
| 276 | : under development | ||
| 277 | |||
| 278 | =cut | ||
| 279 | |||
| 280 | sub ident_string { | ||
| 281 | my $self = shift; | ||
| 282 | |||
| 283 | my $old_id = $self->old_ArchiveStableId; | ||
| 284 | my $new_id = $self->new_ArchiveStableId; | ||
| 285 | |||
| 286 | my $str; | ||
| 287 | |||
| 288 | if ($old_id) { | ||
| 289 | $str = $old_id->stable_id.'.'.$old_id->version.' ('. | ||
| 290 | $old_id->release.')'; | ||
| 291 | } else { | ||
| 292 | $str = 'null'; | ||
| 293 | } | ||
| 294 | |||
| 295 | $str .= ' -> '; | ||
| 296 | |||
| 297 | if ($new_id) { | ||
| 298 | $str .= $new_id->stable_id.'.'.$new_id->version.' ('. | ||
| 299 | $new_id->release.')'; | ||
| 300 | } else { | ||
| 301 | $str .= 'null'; | ||
| 302 | } | ||
| 303 | |||
| 304 | $str .= ' ['.$self->score.']'; | ||
| 305 | |||
| 306 | return $str; | ||
| 307 | } | ||
| 308 | |||
| 309 | |||
| 310 | 1; | ||
| 311 |