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