| 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::IdentityXref | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | my $xref = Bio::EnsEMBL::IdentityXref->new( | ||
| 38 | -XREF_IDENTITY => 80.4, | ||
| 39 | -ENSEMBL_IDENTITY => 90.1, | ||
| 40 | -SCORE => 90, | ||
| 41 | -EVALUE => 12, | ||
| 42 | -CIGAR_LINE => '23MD3M2I40M', | ||
| 43 | -XREF_START => 1, | ||
| 44 | -XREF_END => 68, | ||
| 45 | -ENSEMBL_START => 10, | ||
| 46 | -ENSEMBL_END => 77, | ||
| 47 | -ADAPTOR => $adaptor, | ||
| 48 | -PRIMARY_ID => $primary_id, | ||
| 49 | -DBNAME => 'SwissProt' | ||
| 50 | ); | ||
| 51 | |||
| 52 | =head1 METHODS | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | package Bio::EnsEMBL::IdentityXref; | ||
| 57 | $Bio::EnsEMBL::IdentityXref::VERSION = '114.0.0'; | ||
| 58 | use vars qw(@ISA $AUTOLOAD); | ||
| 59 | use strict; | ||
| 60 | use Bio::EnsEMBL::Utils::Argument qw( rearrange ); | ||
| 61 | |||
| 62 | @ISA = qw( Bio::EnsEMBL::DBEntry ); | ||
| 63 | |||
| 64 | |||
| 65 | =head2 new | ||
| 66 | |||
| 67 | Arg [...] : XREF_IDENTITY ENSEMBL_IDENTITY SCORE EVALUE CIGAR_LINE | ||
| 68 | : XREF_START XREF_END ENSEMBL_START ENSEMBL_END | ||
| 69 | : ANALYSIS pairs | ||
| 70 | Example : see synopsis | ||
| 71 | Description: Create a new Bio::EnsEMBL::IdentityXref object | ||
| 72 | Returntype : Bio::EnsEMBL::IdentityXref | ||
| 73 | Exceptions : none | ||
| 74 | Caller : general | ||
| 75 | Status : Stable | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | my $error_shown = 0; | ||
| 80 | |||
| 81 | sub new { | ||
| 82 | my ($class, @args) = @_; | ||
| 83 | my $self = $class->SUPER::new(@args); | ||
| 84 | my ($query_identity, $target_identity, $score, $evalue, | ||
| 85 | $cigar_line, $query_start, $query_end, $translation_start, | ||
| 86 | $translation_end, $analysis, $xref_identity, $ensembl_identity, | ||
| 87 | $xref_start, $xref_end, $ensembl_start, $ensembl_end) = rearrange( | ||
| 88 | [qw(QUERY_IDENTITY TARGET_IDENTITY SCORE EVALUE CIGAR_LINE | ||
| 89 | QUERY_START QUERY_END TRANSLATION_START TRANSLATION_END | ||
| 90 | ANALYSIS XREF_IDENTITY ENSEMBL_IDENTITY XREF_START XREF_END ENSEMBL_START ENSEMBL_END)], @args); | ||
| 91 | |||
| 92 | if((defined($query_identity) or defined($target_identity) or defined($query_start) or defined ($query_end) or | ||
| 93 | defined($translation_start) or defined($translation_end)) and !$error_shown){ | ||
| 94 | print STDERR "Arguments have now been changed to stop confusion so please replace the following\n"; | ||
| 95 | print STDERR "\tQUERY_IDENTITY\t->\tXREF_IDENTITY\n"; | ||
| 96 | print STDERR "\tTARGET_IDENTITY\t->\tENSEMBL_IDENTITY\n"; | ||
| 97 | print STDERR "\tQUERY_START\t->\tXREF_START\n"; | ||
| 98 | print STDERR "\tQUERY_END\t->\tXREF_END\n"; | ||
| 99 | print STDERR "\tTRANSLATION_START\t->\tENSEMBL_START\n"; | ||
| 100 | print STDERR "\tTRANSLATION_END\t->\tENSEMBL_END\n"; | ||
| 101 | print STDERR "The old arguments will be removed in a futute release so please change your code to the new names\n"; | ||
| 102 | $error_shown = 1; | ||
| 103 | } | ||
| 104 | $self->{'xref_identity'} = $query_identity || $xref_identity; | ||
| 105 | $self->{'ensembl_identity'} = $target_identity || $ensembl_identity; | ||
| 106 | $self->{'score'} = $score; | ||
| 107 | $self->{'evalue'} = $evalue; | ||
| 108 | $self->{'cigar_line'} = $cigar_line; | ||
| 109 | $self->{'xref_start'} = $query_start || $xref_start; | ||
| 110 | $self->{'xref_end'} = $query_end || $xref_end; | ||
| 111 | $self->{'ensembl_start'} = $translation_start || $ensembl_start; | ||
| 112 | $self->{'ensembl_end'} = $translation_end || $ensembl_end; | ||
| 113 | $self->{'analysis'} = $analysis; | ||
| 114 | |||
| 115 | return $self; | ||
| 116 | } | ||
| 117 | |||
| 118 | =head2 xref_identity | ||
| 119 | |||
| 120 | Arg [1] : (optional) string $value | ||
| 121 | Example : $xref_identity = $id_xref->xref_identity; | ||
| 122 | Description: Getter/Setter for xref identity | ||
| 123 | Returntype : string | ||
| 124 | Exceptions : none | ||
| 125 | Caller : general | ||
| 126 | Status : Stable | ||
| 127 | |||
| 128 | =cut | ||
| 129 | |||
| 130 | sub xref_identity{ | ||
| 131 | my $obj = shift; | ||
| 132 | if( @_ ) { | ||
| 133 | my $value = shift; | ||
| 134 | $obj->{'xref_identity'} = $value; | ||
| 135 | } | ||
| 136 | return $obj->{'xref_identity'}; | ||
| 137 | |||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | =head2 ensembl_identity | ||
| 142 | |||
| 143 | Arg [1] : (optional) string $value | ||
| 144 | Example : $ensembl_identity = $id_xref->ensembl_identity; | ||
| 145 | Description: Getter/Setter for ensembl identity | ||
| 146 | Returntype : string | ||
| 147 | Exceptions : none | ||
| 148 | Caller : general | ||
| 149 | Status : Stable | ||
| 150 | |||
| 151 | =cut | ||
| 152 | |||
| 153 | sub ensembl_identity{ | ||
| 154 | my $obj = shift; | ||
| 155 | if( @_ ) { | ||
| 156 | my $value = shift; | ||
| 157 | $obj->{'ensembl_identity'} = $value; | ||
| 158 | } | ||
| 159 | return $obj->{'ensembl_identity'}; | ||
| 160 | |||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | |||
| 165 | =head2 cigar_line | ||
| 166 | |||
| 167 | Arg [1] : string $cigar_line | ||
| 168 | Example : none | ||
| 169 | Description: get/set for attribute cigar_line | ||
| 170 | Returntype : string | ||
| 171 | Exceptions : none | ||
| 172 | Caller : general | ||
| 173 | Status : Stable | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | sub cigar_line { | ||
| 178 | my $self = shift; | ||
| 179 | $self->{'cigar_line'} = shift if( @_ ); | ||
| 180 | return $self->{'cigar_line'}; | ||
| 181 | } | ||
| 182 | |||
| 183 | |||
| 184 | =head2 ensembl_start | ||
| 185 | |||
| 186 | Arg [1] : string $ensembl_start | ||
| 187 | Example : none | ||
| 188 | Description: get/set for attribute ensembl_start | ||
| 189 | Returntype : string | ||
| 190 | Exceptions : none | ||
| 191 | Caller : general | ||
| 192 | Status : Stable | ||
| 193 | |||
| 194 | =cut | ||
| 195 | |||
| 196 | sub ensembl_start { | ||
| 197 | my $self = shift; | ||
| 198 | $self->{'ensembl_start'} = shift if( @_ ); | ||
| 199 | return $self->{'ensembl_start'}; | ||
| 200 | } | ||
| 201 | |||
| 202 | |||
| 203 | =head2 ensembl_end | ||
| 204 | |||
| 205 | Arg [1] : string $ensembl_end | ||
| 206 | Example : none | ||
| 207 | Description: get/set for attribute ensembl_end | ||
| 208 | Returntype : string | ||
| 209 | Exceptions : none | ||
| 210 | Caller : general | ||
| 211 | Status : Stable | ||
| 212 | |||
| 213 | =cut | ||
| 214 | |||
| 215 | sub ensembl_end { | ||
| 216 | my $self = shift; | ||
| 217 | $self->{'ensembl_end'} = shift if( @_ ); | ||
| 218 | return $self->{'ensembl_end'}; | ||
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | =head2 xref_start | ||
| 223 | |||
| 224 | Arg [1] : string $xref_start | ||
| 225 | Example : none | ||
| 226 | Description: get/set for attribute xref_start | ||
| 227 | Returntype : string | ||
| 228 | Exceptions : none | ||
| 229 | Caller : general | ||
| 230 | Status : Stable | ||
| 231 | |||
| 232 | =cut | ||
| 233 | |||
| 234 | sub xref_start { | ||
| 235 | my $self = shift; | ||
| 236 | $self->{'xref_start'} = shift if( @_ ); | ||
| 237 | return $self->{'xref_start'}; | ||
| 238 | } | ||
| 239 | |||
| 240 | |||
| 241 | =head2 xref_end | ||
| 242 | |||
| 243 | Arg [1] : string $xref_end | ||
| 244 | Example : none | ||
| 245 | Description: get/set for attribute xref_end | ||
| 246 | Returntype : string | ||
| 247 | Exceptions : none | ||
| 248 | Caller : general | ||
| 249 | Status : Stable | ||
| 250 | |||
| 251 | =cut | ||
| 252 | |||
| 253 | sub xref_end { | ||
| 254 | my $self = shift; | ||
| 255 | $self->{'xref_end'} = shift if( @_ ); | ||
| 256 | return $self->{'xref_end'}; | ||
| 257 | } | ||
| 258 | |||
| 259 | |||
| 260 | =head2 score | ||
| 261 | |||
| 262 | Arg [1] : string $score | ||
| 263 | Example : none | ||
| 264 | Description: get/set for attribute score | ||
| 265 | Returntype : string | ||
| 266 | Exceptions : none | ||
| 267 | Caller : general | ||
| 268 | Status : Stable | ||
| 269 | |||
| 270 | =cut | ||
| 271 | |||
| 272 | sub score { | ||
| 273 | my $self = shift; | ||
| 274 | $self->{'score'} = shift if( @_ ); | ||
| 275 | return $self->{'score'}; | ||
| 276 | } | ||
| 277 | |||
| 278 | |||
| 279 | =head2 evalue | ||
| 280 | |||
| 281 | Arg [1] : string $evalue | ||
| 282 | Example : none | ||
| 283 | Description: get/set for attribute evalue | ||
| 284 | Returntype : string | ||
| 285 | Exceptions : none | ||
| 286 | Caller : general | ||
| 287 | Status : Stable | ||
| 288 | |||
| 289 | =cut | ||
| 290 | |||
| 291 | sub evalue { | ||
| 292 | my $self = shift; | ||
| 293 | $self->{'evalue'} = shift if( @_ ); | ||
| 294 | return $self->{'evalue'}; | ||
| 295 | } | ||
| 296 | |||
| 297 | |||
| 298 | |||
| 299 | |||
| 300 | =head2 get_mapper | ||
| 301 | |||
| 302 | Args : none | ||
| 303 | Example : none | ||
| 304 | Description: produces a mapper object that takes coordinates from one side | ||
| 305 | of the alignment to the other side. "ensembl" and "external" | ||
| 306 | are the two coordinate systems contained. | ||
| 307 | Returntype : Bio::EnsEMBL::Mapper | ||
| 308 | Exceptions : none | ||
| 309 | Caller : general, ProteinDAS subsystem | ||
| 310 | Status : Stable | ||
| 311 | |||
| 312 | =cut | ||
| 313 | |||
| 314 | |||
| 315 | sub get_mapper { | ||
| 316 | my ( $self ) = @_; | ||
| 317 | # parse the cigar_line and create a mapper ... | ||
| 318 | if( exists $self->{'_cached_mapper'} ) { | ||
| 319 | return $self->{'_cached_mapper'}; | ||
| 320 | } | ||
| 321 | |||
| 322 | my ( @lens, @chars ); | ||
| 323 | |||
| 324 | # if there is no cigar line, nothing is going to be loaded | ||
| 325 | if( $self->cigar_line() ) { | ||
| 326 | my @pre_lens = split( '[DMI]', $self->cigar_line() ); | ||
| 327 | @lens = map { if( ! $_ ) { 1 } else { $_ }} @pre_lens; | ||
| 328 | @chars = grep { /[DMI]/ } split( //, $self->cigar_line() ); | ||
| 329 | } | ||
| 330 | my $translation_start = $self->ensembl_start(); | ||
| 331 | my $translation_end = $self->ensembl_end(); | ||
| 332 | my $query_start = $self->xref_start(); | ||
| 333 | my $query_end = $self->xref_end(); | ||
| 334 | |||
| 335 | # my $hit_id = $self->display_id(); | ||
| 336 | my $ensembl_id = "ensembl_id"; | ||
| 337 | my $external_id = "external_id"; | ||
| 338 | # now build the mapper | ||
| 339 | my $mapper = Bio::EnsEMBL::Mapper->new( "external", "ensembl" ); | ||
| 340 | |||
| 341 | |||
| 342 | for( my $i=0; $i<=$#lens; $i++ ) { | ||
| 343 | my $length = $lens[$i]; | ||
| 344 | my $char = $chars[$i]; | ||
| 345 | if( $char eq "M" ) { | ||
| 346 | $mapper->add_map_coordinates( $external_id, $query_start, | ||
| 347 | $query_start + $length - 1, 1, | ||
| 348 | $ensembl_id, $translation_start, | ||
| 349 | $translation_start + $length - 1); | ||
| 350 | $query_start += $length; | ||
| 351 | $translation_start += $length; | ||
| 352 | |||
| 353 | } elsif( $char eq "D" ) { | ||
| 354 | $translation_start += $length; | ||
| 355 | } elsif( $char eq "I" ) { | ||
| 356 | $query_start += $length; | ||
| 357 | } | ||
| 358 | } | ||
| 359 | |||
| 360 | $self->{'_cached_mapper'} = $mapper; | ||
| 361 | |||
| 362 | return $mapper; | ||
| 363 | } | ||
| 364 | |||
| 365 | |||
| 366 | |||
| 367 | =head2 transform_feature | ||
| 368 | |||
| 369 | Arg [1] : a feature type with start and end $feature | ||
| 370 | This doesnt need to be a Bio::EnsEMBL::Feature as it doesnt | ||
| 371 | need an attached slice. We may have to introduce an appropriate | ||
| 372 | object type. | ||
| 373 | Example : my $ens_prot_feature_list = | ||
| 374 | $ident_xref->transform_feature( $swiss_prot_feature ); | ||
| 375 | Description: a list of potential partial features which represent all | ||
| 376 | mappable places | ||
| 377 | of the original feature in ensembl translation coordinates. | ||
| 378 | Returntype : listref of whatever was put in | ||
| 379 | Exceptions : none | ||
| 380 | Caller : general, ProteinDAS subsystem | ||
| 381 | Status : Stable | ||
| 382 | |||
| 383 | =cut | ||
| 384 | |||
| 385 | |||
| 386 | sub transform_feature { | ||
| 387 | my $self= shift; | ||
| 388 | my $feature = shift; | ||
| 389 | |||
| 390 | my $fstart = $feature->start(); | ||
| 391 | my $fend = $feature->end(); | ||
| 392 | |||
| 393 | my $mapper = $self->get_mapper(); | ||
| 394 | my @result; | ||
| 395 | |||
| 396 | my @coords = $mapper->map_coordinates( "external_id", $fstart, $fend, | ||
| 397 | 1, "external" ); | ||
| 398 | |||
| 399 | for my $coord ( @coords ) { | ||
| 400 | if( $coord->isa( "Bio::EnsEMBL::Mapper::Coordinate" )) { | ||
| 401 | my $new_feature; | ||
| 402 | %{$new_feature} = %$feature; | ||
| 403 | bless $new_feature, ref( $feature ); | ||
| 404 | $new_feature->start( $coord->start() ); | ||
| 405 | $new_feature->end( $coord->end() ); | ||
| 406 | |||
| 407 | push( @result, $new_feature ); | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | return \@result; | ||
| 412 | } | ||
| 413 | |||
| 414 | |||
| 415 | |||
| 416 | =head2 map_feature | ||
| 417 | |||
| 418 | Arg [1] : a start,end capable feature object | ||
| 419 | Example : none | ||
| 420 | Description: | ||
| 421 | Returntype : list of Coordinates/Gaps which represents the mapping | ||
| 422 | Exceptions : none | ||
| 423 | Caller : another way of doing ProteinDAS | ||
| 424 | Status : Stable | ||
| 425 | |||
| 426 | =cut | ||
| 427 | |||
| 428 | sub map_feature { | ||
| 429 | my $self = shift; | ||
| 430 | my $feature = shift; | ||
| 431 | |||
| 432 | |||
| 433 | my $fstart = $feature->start(); | ||
| 434 | my $fend = $feature->end(); | ||
| 435 | |||
| 436 | my $mapper = $self->get_mapper(); | ||
| 437 | my @coords = $mapper->map_coordinates( "external_id", $fstart, $fend, 1, | ||
| 438 | "external" ); | ||
| 439 | |||
| 440 | return @coords; | ||
| 441 | } | ||
| 442 | |||
| 443 | |||
| 444 | 1; |