| 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::MappedSlice - an object representing a mapped slice | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | # get a reference slice | ||
| 38 | my $slice = | ||
| 39 | $slice_adaptor->fetch_by_region( 'chromosome', 14, 900000, 950000 ); | ||
| 40 | |||
| 41 | # create MappedSliceContainer based on the reference slice | ||
| 42 | my $msc = Bio::EnsEMBL::MappedSliceContainer->new( -SLICE => $slice ); | ||
| 43 | |||
| 44 | # set the adaptor for fetching AssemblySlices | ||
| 45 | my $asa = $slice->adaptor->db->get_AssemblySliceAdaptor; | ||
| 46 | $msc->set_AssemblySliceAdaptor($asa); | ||
| 47 | |||
| 48 | # add an AssemblySlice to your MappedSliceContainer | ||
| 49 | $msc->attach_AssemblySlice('NCBIM36'); | ||
| 50 | |||
| 51 | foreach my $mapped_slice ( @{ $msc->get_all_MappedSlices } ) { | ||
| 52 | print $mapped_slice->name, "\n"; | ||
| 53 | |||
| 54 | foreach my $sf ( @{ $mapped_slice->get_all_SimpleFeatures } ) { | ||
| 55 | print " ", &to_string($sf), "\n"; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | =head1 DESCRIPTION | ||
| 60 | |||
| 61 | NOTE: this code is under development and not fully functional nor tested | ||
| 62 | yet. Use only for development. | ||
| 63 | |||
| 64 | This object represents a mapped slice, i.e. a slice that's attached | ||
| 65 | to a reference slice and a mapper to convert coordinates to/from the | ||
| 66 | reference. The attachment is done via a MappedSliceContainer which | ||
| 67 | has the reference slice and the "container slice" defining the common | ||
| 68 | coordinate system for all MappedSlices. | ||
| 69 | |||
| 70 | A MappedSlice is supposed to behave as close to a Bio::EnsEMBL::Slice | ||
| 71 | as possible. Most Slice methods are implemented in MappedSlice and will | ||
| 72 | return an equivalent value to what Slice does. There are some exceptions | ||
| 73 | of unimplemented methods, either because there is no useful equivalent | ||
| 74 | for a MappedSlice to do, or they are too complicated. | ||
| 75 | |||
| 76 | Not supported Bio::EnsEMBL::Slice methods: | ||
| 77 | |||
| 78 | All Bio::PrimarySeqI compliance methods | ||
| 79 | expand | ||
| 80 | get_generic_features | ||
| 81 | get_seq_region_id | ||
| 82 | seq_region_Slice | ||
| 83 | |||
| 84 | Not currently supported but maybe should/could: | ||
| 85 | |||
| 86 | calculate_pi | ||
| 87 | calculate_theta | ||
| 88 | get_base_count | ||
| 89 | get_by_Individual | ||
| 90 | get_by_strain | ||
| 91 | invert | ||
| 92 | |||
| 93 | Internally, a MappedSlice is a collection of Bio::EnsEMBL::Slices and | ||
| 94 | associated Bio::EnsEMBL::Mappers which map the slices to the common | ||
| 95 | container coordinate system. | ||
| 96 | |||
| 97 | MappedSlices are usually created and attached to a MappedSliceContainer | ||
| 98 | by an adaptor/factory. | ||
| 99 | |||
| 100 | =head1 METHODS | ||
| 101 | |||
| 102 | new | ||
| 103 | add_Slice_Mapper_pair | ||
| 104 | get_all_Slice_Mapper_pairs | ||
| 105 | adaptor | ||
| 106 | container | ||
| 107 | name | ||
| 108 | seq_region_name | ||
| 109 | start | ||
| 110 | end | ||
| 111 | strand | ||
| 112 | length | ||
| 113 | seq_region_length | ||
| 114 | centrepoint | ||
| 115 | coord_system | ||
| 116 | coord_system_name | ||
| 117 | is_toplevel | ||
| 118 | seq (not implemented yet) | ||
| 119 | subseq (not implemented yet) | ||
| 120 | get_repeatmasked_seq (not implemented yet) | ||
| 121 | sub_MappedSlice (not implemented yet) | ||
| 122 | project (not implemented yet) | ||
| 123 | |||
| 124 | =head1 RELATED MODULES | ||
| 125 | |||
| 126 | Bio::EnsEMBL::MappedSlice | ||
| 127 | Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor | ||
| 128 | Bio::EnsEMBL::Compara::AlignSlice | ||
| 129 | Bio::EnsEMBL::Compara::AlignSlice::Slice | ||
| 130 | Bio::EnsEMBL::StrainSlice | ||
| 131 | |||
| 132 | =cut | ||
| 133 | |||
| 134 | package Bio::EnsEMBL::MappedSlice; | ||
| 135 | $Bio::EnsEMBL::MappedSlice::VERSION = '114.0.0_50'; # TRIAL | ||
| 136 | $Bio::EnsEMBL::MappedSlice::VERSION = '114.0.050'; | ||
| 137 | use strict; | ||
| 138 | use warnings; | ||
| 139 | no warnings 'uninitialized'; | ||
| 140 | |||
| 141 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 142 | use Bio::EnsEMBL::Utils::Exception qw(throw warning); | ||
| 143 | use Bio::EnsEMBL::Mapper; | ||
| 144 | use Scalar::Util qw(weaken); | ||
| 145 | |||
| 146 | use vars qw($AUTOLOAD); | ||
| 147 | |||
| 148 | |||
| 149 | =head2 new | ||
| 150 | |||
| 151 | Arg [ADAPTOR] : Adaptor $adaptor - an adaptor of the appropriate type | ||
| 152 | Arg [CONTAINER] : Bio::EnsEMBL::MappedSliceContainer $container - the | ||
| 153 | container this MappedSlice is attached to | ||
| 154 | Arg [NAME] : String $name - name | ||
| 155 | Example : my $mapped_slice = Bio::EnsEMBL::MappedSlice->new( | ||
| 156 | -ADAPTOR => $adaptor, | ||
| 157 | -CONTAINER => $container, | ||
| 158 | -NAME => $name, | ||
| 159 | ); | ||
| 160 | Description : Constructor. Usually you won't call this method manually, but | ||
| 161 | the MappedSlice will be constructed by an adaptor/factory. | ||
| 162 | Return type : Bio::EnsEMBL::MappedSlice | ||
| 163 | Exceptions : thrown on wrong or missing arguments | ||
| 164 | Caller : general, MappedSlice adaptors | ||
| 165 | Status : At Risk | ||
| 166 | : under development | ||
| 167 | |||
| 168 | =cut | ||
| 169 | |||
| 170 | sub new { | ||
| 171 | my $caller = shift; | ||
| 172 | my $class = ref($caller) || $caller; | ||
| 173 | |||
| 174 | my ($adaptor, $container, $name) = | ||
| 175 | rearrange([qw(ADAPTOR CONTAINER NAME)], @_); | ||
| 176 | |||
| 177 | # arguement check | ||
| 178 | unless ($container and ref($container) and | ||
| 179 | $container->isa('Bio::EnsEMBL::MappedSliceContainer')) { | ||
| 180 | throw("Need a MappedSliceContainer."); | ||
| 181 | } | ||
| 182 | |||
| 183 | my $self = {}; | ||
| 184 | bless ($self, $class); | ||
| 185 | |||
| 186 | # | ||
| 187 | # initialise object | ||
| 188 | # | ||
| 189 | |||
| 190 | # need to weaken reference to prevent circular reference | ||
| 191 | weaken($self->{'container'} = $container); | ||
| 192 | |||
| 193 | $self->adaptor($adaptor) if (defined($adaptor)); | ||
| 194 | $self->{'name'} = $name if (defined($name)); | ||
| 195 | |||
| 196 | $self->{'slice_mapper_pairs'} = []; | ||
| 197 | |||
| 198 | return $self; | ||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 202 | =head2 add_Slice_Mapper_pair | ||
| 203 | |||
| 204 | Arg[1] : Bio::EnsEMBL::Slice $slice - slice to add | ||
| 205 | Arg[2] : Bio::EnsEMBL::Mapper $mapper - the mapper for this slice | ||
| 206 | Example : $mapped_slice->add_Slice_Mapper_pair($slice, $mapper); | ||
| 207 | Description : Adds a native slice and a corresponding mapper to map to/from | ||
| 208 | the artificial container coord system. | ||
| 209 | Return type : listref of Bio::EnsEMBL::MappedSlice | ||
| 210 | Exceptions : thrown on wrong or missing arguments | ||
| 211 | Caller : general, MappedSlice adaptors | ||
| 212 | Status : At Risk | ||
| 213 | : under development | ||
| 214 | |||
| 215 | =cut | ||
| 216 | |||
| 217 | sub add_Slice_Mapper_pair { | ||
| 218 | my $self = shift; | ||
| 219 | my $slice = shift; | ||
| 220 | my $mapper = shift; | ||
| 221 | |||
| 222 | # argument check | ||
| 223 | unless ($slice and ref($slice) and ($slice->isa('Bio::EnsEMBL::Slice') or $slice->isa('Bio::EnsEMBL::LRGSlice')) ) { | ||
| 224 | throw("You must provide a slice."); | ||
| 225 | } | ||
| 226 | |||
| 227 | unless ($mapper and ref($mapper) and $mapper->isa('Bio::EnsEMBL::Mapper')) { | ||
| 228 | throw("You must provide a mapper."); | ||
| 229 | } | ||
| 230 | |||
| 231 | push @{ $self->{'slice_mapper_pairs'} }, [ $slice, $mapper ]; | ||
| 232 | |||
| 233 | return $self->{'slice_mapper_pairs'}; | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | =head2 get_all_Slice_Mapper_pairs | ||
| 238 | |||
| 239 | Example : foreach my $pair (@{ $self->get_all_Slice_Mapper_pairs }) { | ||
| 240 | my ($slice, $mapper) = @$pair; | ||
| 241 | |||
| 242 | # get container coordinates | ||
| 243 | my @coords = $mapper->map_coordinates( | ||
| 244 | $slice->seq_region_name, | ||
| 245 | $slice->start, | ||
| 246 | $slice->end, | ||
| 247 | $slice->strand, | ||
| 248 | 'mapped_slice' | ||
| 249 | ); | ||
| 250 | |||
| 251 | # .... | ||
| 252 | } | ||
| 253 | Description : Gets all Slice/Mapper pairs this MappedSlice is composed of. | ||
| 254 | Each slice (and features on it) can be mapped onto the | ||
| 255 | artificial container coord system using the mapper. | ||
| 256 | Return type : listref of listref of a Bio::EnsEMBL::Slice and | ||
| 257 | Bio::EnsEMBL::Mapper pair | ||
| 258 | Exceptions : none | ||
| 259 | Caller : general | ||
| 260 | Status : At Risk | ||
| 261 | : under development | ||
| 262 | |||
| 263 | =cut | ||
| 264 | |||
| 265 | sub get_all_Slice_Mapper_pairs { | ||
| 266 | my $self = shift; | ||
| 267 | return $self->{'slice_mapper_pairs'}; | ||
| 268 | } | ||
| 269 | |||
| 270 | |||
| 271 | =head2 adaptor | ||
| 272 | |||
| 273 | Arg[1] : (optional) Adaptor $adaptor - the adaptor/factory for this | ||
| 274 | object | ||
| 275 | Example : $mapped_slice->adaptor($assembly_slice_adaptor); | ||
| 276 | Description : Getter/setter for the adaptor/factory for this object. | ||
| 277 | Return type : Adaptor of appropriate type | ||
| 278 | Exceptions : none | ||
| 279 | Caller : general | ||
| 280 | Status : At Risk | ||
| 281 | : under development | ||
| 282 | |||
| 283 | =cut | ||
| 284 | |||
| 285 | sub adaptor { | ||
| 286 | my $self = shift; | ||
| 287 | weaken($self->{'adaptor'} = shift) if (@_); | ||
| 288 | return $self->{'adaptor'}; | ||
| 289 | } | ||
| 290 | |||
| 291 | |||
| 292 | =head2 container | ||
| 293 | |||
| 294 | Arg[1] : (optional) Bio::EnsEMBL::MappedSliceContainer - the container | ||
| 295 | this object is attached to | ||
| 296 | Example : my $container = $mapped_slice->container; | ||
| 297 | print $container->ref_slice->name, "\n"; | ||
| 298 | Description : Getter/setter for the container this object is attached to. The | ||
| 299 | container will give you access to the reference slice, a common | ||
| 300 | artificial container slice, and a mapper to map to it from the | ||
| 301 | container coord system. | ||
| 302 | |||
| 303 | The implementation uses a weak reference to attach the container | ||
| 304 | since the container holds a list of MappedSlices itself. | ||
| 305 | Return type : Bio::EnsEMBL::MappedSliceContainer | ||
| 306 | Exceptions : none | ||
| 307 | Caller : general | ||
| 308 | Status : At Risk | ||
| 309 | : under development | ||
| 310 | |||
| 311 | =cut | ||
| 312 | |||
| 313 | sub container { | ||
| 314 | my $self = shift; | ||
| 315 | weaken($self->{'container'} = shift) if (@_); | ||
| 316 | return $self->{'container'}; | ||
| 317 | } | ||
| 318 | |||
| 319 | |||
| 320 | =head2 name | ||
| 321 | |||
| 322 | Arg[1] : String - the name of this object | ||
| 323 | Example : my $name = $mapped_slice->container->ref_slice->name . | ||
| 324 | ":mapped_" . $ident_string; | ||
| 325 | $mapped_slice->name($name); | ||
| 326 | Description : Getter/setter for this object's name | ||
| 327 | Return type : String | ||
| 328 | Exceptions : none | ||
| 329 | Caller : general | ||
| 330 | Status : At Risk | ||
| 331 | : under development | ||
| 332 | |||
| 333 | =cut | ||
| 334 | |||
| 335 | sub name { | ||
| 336 | my $self = shift; | ||
| 337 | $self->{'name'} = shift if (@_); | ||
| 338 | return $self->{'name'}; | ||
| 339 | } | ||
| 340 | |||
| 341 | |||
| 342 | =head2 seq_region_name | ||
| 343 | |||
| 344 | Example : my $sr_name = $mapped_slice->seq_region_name; | ||
| 345 | Description : Returns the seq_region name of the reference slice. | ||
| 346 | Return type : String | ||
| 347 | Exceptions : none | ||
| 348 | Caller : general | ||
| 349 | Status : At Risk | ||
| 350 | : under development | ||
| 351 | |||
| 352 | =cut | ||
| 353 | |||
| 354 | sub seq_region_name { | ||
| 355 | my $self = shift; | ||
| 356 | return $self->container->ref_slice->seq_region_name; | ||
| 357 | } | ||
| 358 | |||
| 359 | |||
| 360 | =head2 start | ||
| 361 | |||
| 362 | Example : my $start = $mapped_slice->start; | ||
| 363 | Description : Returns the start of the container slice. | ||
| 364 | Return type : Int | ||
| 365 | Exceptions : none | ||
| 366 | Caller : general | ||
| 367 | Status : At Risk | ||
| 368 | : under development | ||
| 369 | |||
| 370 | =cut | ||
| 371 | |||
| 372 | sub start { | ||
| 373 | my $self = shift; | ||
| 374 | return $self->container->container_slice->start; | ||
| 375 | } | ||
| 376 | |||
| 377 | |||
| 378 | =head2 end | ||
| 379 | |||
| 380 | Example : my $end = $mapped_slice->end; | ||
| 381 | Description : Returns the end of the container slice. | ||
| 382 | Return type : Int | ||
| 383 | Exceptions : none | ||
| 384 | Caller : general | ||
| 385 | Status : At Risk | ||
| 386 | : under development | ||
| 387 | |||
| 388 | =cut | ||
| 389 | |||
| 390 | sub end { | ||
| 391 | my $self = shift; | ||
| 392 | return $self->container->container_slice->end; | ||
| 393 | } | ||
| 394 | |||
| 395 | |||
| 396 | =head2 strand | ||
| 397 | |||
| 398 | Example : my $strand = $mapped_slice->strand; | ||
| 399 | Description : Returns the strand of the container slice. | ||
| 400 | Return type : Int | ||
| 401 | Exceptions : none | ||
| 402 | Caller : general | ||
| 403 | Status : At Risk | ||
| 404 | : under development | ||
| 405 | |||
| 406 | =cut | ||
| 407 | |||
| 408 | sub strand { | ||
| 409 | my $self = shift; | ||
| 410 | return $self->container->container_slice->strand; | ||
| 411 | } | ||
| 412 | |||
| 413 | |||
| 414 | =head2 length | ||
| 415 | |||
| 416 | Example : my $length = $mapped_slice->length; | ||
| 417 | Description : Returns the length of the container slice | ||
| 418 | Return type : Int | ||
| 419 | Exceptions : none | ||
| 420 | Caller : general | ||
| 421 | Status : At Risk | ||
| 422 | : under development | ||
| 423 | |||
| 424 | =cut | ||
| 425 | |||
| 426 | sub length { | ||
| 427 | my $self = shift; | ||
| 428 | return $self->container->container_slice->length; | ||
| 429 | } | ||
| 430 | |||
| 431 | |||
| 432 | =head2 seq_region_length | ||
| 433 | |||
| 434 | Example : my $sr_length = $mapped_slice->seq_region_length; | ||
| 435 | Description : Returns the seq_region length of the reference slice. | ||
| 436 | Return type : Int | ||
| 437 | Exceptions : none | ||
| 438 | Caller : general | ||
| 439 | Status : At Risk | ||
| 440 | : under development | ||
| 441 | |||
| 442 | =cut | ||
| 443 | |||
| 444 | sub seq_region_length { | ||
| 445 | my $self = shift; | ||
| 446 | return $self->container->ref_slice->seq_region_length; | ||
| 447 | } | ||
| 448 | |||
| 449 | |||
| 450 | =head2 centrepoint | ||
| 451 | |||
| 452 | Example : my $centrepoint = $mapped_slice->centrepoint; | ||
| 453 | Description : Returns the centrepoint of the container slice. | ||
| 454 | Return type : Int | ||
| 455 | Exceptions : none | ||
| 456 | Caller : general | ||
| 457 | Status : At Risk | ||
| 458 | : under development | ||
| 459 | |||
| 460 | =cut | ||
| 461 | |||
| 462 | sub centrepoint { | ||
| 463 | my $self = shift; | ||
| 464 | return $self->container->container_slice->centrepoint; | ||
| 465 | } | ||
| 466 | |||
| 467 | |||
| 468 | =head2 coord_system | ||
| 469 | |||
| 470 | Example : my $cs = $mapped_slice->coord_system; | ||
| 471 | Description : Returns the coord system of the container slice. | ||
| 472 | Return type : Bio::EnsEMBL::CoordSystem | ||
| 473 | Exceptions : none | ||
| 474 | Caller : general | ||
| 475 | Status : At Risk | ||
| 476 | : under development | ||
| 477 | |||
| 478 | =cut | ||
| 479 | |||
| 480 | sub coord_system { | ||
| 481 | my $self = shift; | ||
| 482 | return $self->container->container_slice->coord_system; | ||
| 483 | } | ||
| 484 | |||
| 485 | =head2 coord_system_name | ||
| 486 | |||
| 487 | Example : my $cs_name = $mapped_slice->coord_system_name; | ||
| 488 | Description : Returns the coord system name of the container slice. | ||
| 489 | Return type : Int | ||
| 490 | Exceptions : none | ||
| 491 | Caller : general | ||
| 492 | Status : At Risk | ||
| 493 | : under development | ||
| 494 | |||
| 495 | =cut | ||
| 496 | |||
| 497 | sub coord_system_name { | ||
| 498 | my $self = shift; | ||
| 499 | return $self->container->container_slice->coord_system_name; | ||
| 500 | } | ||
| 501 | |||
| 502 | =head2 is_toplevel | ||
| 503 | |||
| 504 | Example : my $toplevel_flag = $mapped_slice->is_toplevel; | ||
| 505 | Description : Returns weather the container slice is toplevel. | ||
| 506 | Return type : Int | ||
| 507 | Exceptions : none | ||
| 508 | Caller : general | ||
| 509 | Status : At Risk | ||
| 510 | : under development | ||
| 511 | |||
| 512 | =cut | ||
| 513 | |||
| 514 | sub is_toplevel { | ||
| 515 | my $self = shift; | ||
| 516 | return $self->container->container_slice->is_toplevel; | ||
| 517 | } | ||
| 518 | |||
| 519 | |||
| 520 | =head2 seq | ||
| 521 | |||
| 522 | Example : my $seq = $mapped_slice->seq() | ||
| 523 | Description : Retrieves the expanded sequence of this mapped slice, | ||
| 524 | including "-" characters where there are inserts in any other | ||
| 525 | mapped slices. This will align with the sequence returned by | ||
| 526 | the container's seq() method. | ||
| 527 | Return type : String | ||
| 528 | Exceptions : none | ||
| 529 | Caller : general | ||
| 530 | Status : At Risk | ||
| 531 | : under development | ||
| 532 | |||
| 533 | =cut | ||
| 534 | |||
| 535 | sub seq { | ||
| 536 | my $self = shift; | ||
| 537 | |||
| 538 | # create an empty string | ||
| 539 | my $ms_seq = ''; | ||
| 540 | |||
| 541 | # this coord represents the current position in the MS sequence | ||
| 542 | my $start = 0; | ||
| 543 | |||
| 544 | # get slice/mapper pairs from mapped slice (usually only one anyway) | ||
| 545 | foreach my $pair(@{$self->get_all_Slice_Mapper_pairs()}) { | ||
| 546 | my ($s, $m) = @$pair; | ||
| 547 | |||
| 548 | # make sure to send extra args | ||
| 549 | # eg strain slices might need read coverage filtering | ||
| 550 | my $seq = $s->seq(@_); | ||
| 551 | |||
| 552 | # project from mapped slice to reference slice using the mapper | ||
| 553 | foreach my $ref_coord($m->map_coordinates('mapped_slice', 1, CORE::length($seq), $s->strand, 'mapped_slice')) { | ||
| 554 | |||
| 555 | # normal coord | ||
| 556 | if(!$ref_coord->isa('Bio::EnsEMBL::Mapper::IndelCoordinate') && !$ref_coord->isa('Bio::EnsEMBL::Mapper::Gap')) { | ||
| 557 | |||
| 558 | # project from reference slice to container slice using the container's mapper | ||
| 559 | foreach my $ms_coord($self->container->mapper->map_coordinates($self->container->ref_slice->seq_region_name, $ref_coord->start, $ref_coord->end, $ref_coord->strand, 'ref_slice')) { | ||
| 560 | |||
| 561 | # normal coord | ||
| 562 | if(!$ms_coord->isa('Bio::EnsEMBL::Mapper::IndelCoordinate') && !$ms_coord->isa('Bio::EnsEMBL::Mapper::Gap')) { | ||
| 563 | $ms_seq .= substr($seq, $start, $ms_coord->length); | ||
| 564 | |||
| 565 | $start += $ms_coord->length(); | ||
| 566 | } | ||
| 567 | |||
| 568 | # indel coord | ||
| 569 | else { | ||
| 570 | $ms_seq .= '-' x $ms_coord->length(); | ||
| 571 | } | ||
| 572 | } | ||
| 573 | } | ||
| 574 | |||
| 575 | # indel / gap | ||
| 576 | else { | ||
| 577 | if($ref_coord->isa('Bio::EnsEMBL::Mapper::IndelCoordinate')) { | ||
| 578 | if($ref_coord->gap_length > 0) { | ||
| 579 | $ms_seq .= substr($seq, $start, $ref_coord->gap_length); | ||
| 580 | $start += $ref_coord->gap_length; | ||
| 581 | } | ||
| 582 | $ms_seq .= '-' x ($ref_coord->length() - $ref_coord->gap_length()); | ||
| 583 | } else { | ||
| 584 | $ms_seq .= '-' x $ref_coord->length(); | ||
| 585 | } | ||
| 586 | } | ||
| 587 | } | ||
| 588 | } | ||
| 589 | |||
| 590 | return $ms_seq; | ||
| 591 | } | ||
| 592 | |||
| 593 | sub subseq { | ||
| 594 | } | ||
| 595 | |||
| 596 | sub get_repeatmasked_seq { | ||
| 597 | } | ||
| 598 | |||
| 599 | sub sub_MappedSlice { | ||
| 600 | } | ||
| 601 | |||
| 602 | sub project { | ||
| 603 | } | ||
| 604 | |||
| 605 | |||
| 606 | =head2 AUTOLOAD | ||
| 607 | |||
| 608 | Arg[1..N] : Arguments passed on to the calls on the underlying slices. | ||
| 609 | Example : my @simple_features = @{ $mapped_slice->get_all_SimpleFeatures }; | ||
| 610 | Description : Aggregate data gathered from composing Slices. | ||
| 611 | This will call Slice->get_all_* and combine the results. | ||
| 612 | Coordinates will be transformed to be on the container slice | ||
| 613 | coordinate system. | ||
| 614 | |||
| 615 | Calls involving DAS features are skipped since the DAS adaptor | ||
| 616 | handles coordinate conversions natively. | ||
| 617 | Return type : listref of features (same type as corresponding Slice method) | ||
| 618 | Exceptions : none | ||
| 619 | Caller : general | ||
| 620 | Status : At Risk | ||
| 621 | : under development | ||
| 622 | |||
| 623 | =cut | ||
| 624 | |||
| 625 | sub AUTOLOAD { | ||
| 626 | my $self = shift; | ||
| 627 | |||
| 628 | my $method = $AUTOLOAD; | ||
| 629 | $method =~ s/.*:://; | ||
| 630 | |||
| 631 | # AUTOLOAD should only deal with get_all_* methods | ||
| 632 | return unless ($method =~ /^get_all_/); | ||
| 633 | |||
| 634 | # skip DAS methods | ||
| 635 | return if ($method =~ /DAS/); | ||
| 636 | |||
| 637 | my @mapped_features = (); | ||
| 638 | |||
| 639 | foreach my $pair (@{ $self->get_all_Slice_Mapper_pairs }) { | ||
| 640 | my ($slice, $mapper) = @$pair; | ||
| 641 | #warn $slice->name; | ||
| 642 | |||
| 643 | # call $method on each native slice composing the MappedSlice | ||
| 644 | my @features = @{ $slice->$method(@_) }; | ||
| 645 | |||
| 646 | # map features onto the artificial container coordinate system | ||
| 647 | foreach my $f (@features) { | ||
| 648 | |||
| 649 | my @coords = $mapper->map_coordinates( | ||
| 650 | $f->slice->seq_region_name, | ||
| 651 | $f->start, | ||
| 652 | $f->end, | ||
| 653 | $f->strand, | ||
| 654 | 'mapped_slice' | ||
| 655 | ); | ||
| 656 | |||
| 657 | # sanity check | ||
| 658 | if (scalar(@coords) > 1) { | ||
| 659 | warning("Got more than one Coordinate returned, expected only one!\n"); | ||
| 660 | } | ||
| 661 | |||
| 662 | $f->start($coords[0]->start); | ||
| 663 | $f->end($coords[0]->end); | ||
| 664 | $f->strand($coords[0]->strand); | ||
| 665 | $f->slice($self->container->container_slice); | ||
| 666 | |||
| 667 | push @mapped_features, $f; | ||
| 668 | } | ||
| 669 | |||
| 670 | } | ||
| 671 | |||
| 672 | return \@mapped_features; | ||
| 673 | } | ||
| 674 | |||
| 675 | |||
| 676 | 1; | ||
| 677 |