ChainedAssemblyMapper.pm 21.6 KB
Newer Older
1
=head1 LICENSE
2

3
Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4

5
6
7
8
9
10
11
12
13
14
15
16
17
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut
18
19
20
21
22


=head1 CONTACT

  Please email comments or questions to the public Ensembl
23
  developers list at <dev@ensembl.org>.
24
25
26
27
28

  Questions may also be sent to the Ensembl help desk at
  <helpdesk@ensembl.org>.

=cut
29
30
31

=head1 NAME

32
Bio::EnsEMBL::ChainedAssemblyMapper -
33
34
Handles mapping between two coordinate systems using the information
stored in the assembly table
35
36

=head1 SYNOPSIS
37

38
    $db   = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
39
40
41
    $asma = $db->get_AssemblyMapperAdaptor();
    $csa  = $db->get_CoordSystemAdaptor();

42
43
    my $chr_cs = $cs_adaptor->fetch_by_name( 'chromosome', 'NCBI33' );
    my $cln_cs = $cs_adaptor->fetch_by_name('clone');
44

45
    $asm_mapper = $map_adaptor->fetch_by_CoordSystems( $cs1, $cs2 );
46

47
48
49
    # Map to contig coordinate system from chromosomal
    @cln_coords =
      $asm_mapper->map( 'X', 1_000_000, 2_000_000, 1, $chr_cs );
50

51
52
53
    # Map to chromosome coordinate system from contig
    @chr_coords =
      $asm_mapper->map( 'AL30421.1', 100, 10000, -1, $cln_cs );
54

55
56
    # List contig names for a region of chromsome
    @cln_ids = $asm_mapper->list_ids( '13', 1_000_000, 1, $chr_cs );
57

58
59
60
    # List chromosome names for a contig region
    @chr_ids =
      $asm_mapper->list_ids( 'AL30421.1', 1, 1000, -1, $cln_cs );
61
62
63

=head1 DESCRIPTION

64
65
66
67
68
The ChainedAssemblyMapper is an extension of the regular AssemblyMapper
that allows for mappings between coordinate systems that require
multi-step mapping.  For example if explicit mappings are defined
between the following coordinate systems,

69
70
71
  chromosome <-> contig
  contig     <-> clone

72
73
74
75
76
the ChainedAssemblyMapper would be able to perform implicit mapping
between the chromosome and clone coordinate systems.  This should be
transparent to the user of this module, and users should not even
realise that they are using a chained assembly mapper as opposed to a
normal assembly mapper.
77
78
79
80
81
82
83
84
85
86
87
88
89
90

=head1 METHODS

=cut

package Bio::EnsEMBL::ChainedAssemblyMapper;

use strict;
use warnings;
use integer; #use proper arithmetic bitshifts

use Bio::EnsEMBL::Mapper;
use Bio::EnsEMBL::Mapper::RangeRegistry;
use Bio::EnsEMBL::Utils::Exception qw(throw deprecate);
Monika Komorowska's avatar
Monika Komorowska committed
91
use Scalar::Util qw(weaken);
92

93
94
95
96
my $FIRST = 'first';
my $MIDDLE = 'middle';
my $LAST  = 'last';

97
#2^20 = approx 10^6
98
my $CHUNKFACTOR = 20;
99
100

# max size of the pair cache in the mappers
101
my $DEFAULT_MAX_PAIR_COUNT = 6000;
102
103
104
105
106
107
108
109
110
111
112
113

=head2 new

  Arg [1]    : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
  Arg [2]    : Bio::EnsEMBL::CoordSystem $src_cs
  Arg [3]    : Bio::EnsEMBL::CoordSystem $int_cs
  Arg [4]    : Bio::EnsEMBL::CoordSystem $dst_cs
  Example    : Should use AssemblyMapperAdaptor->fetch_by_CoordSystems
  Description: Creates a new AssemblyMapper
  Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
  Exceptions : thrown if wrong number of coord_systems are provided
  Caller     : AssemblyMapperAdaptor
114
  Status     : Stable
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

=cut

sub new {
  my ($caller,$adaptor,@coord_systems) = @_;

  my $class = ref($caller) || $caller;

  my $self = {};
  bless $self, $class;

  $self->adaptor($adaptor);

  if(@coord_systems != 3) {
    throw('ChainedMapper can only map between 3 coordinate systems. ' .
          scalar(@coord_systems) . ' were provided');
  }

133
  $adaptor->cache_seq_ids_with_mult_assemblys();
134

135
136
137
138
139
140
141
142
143
144
145
146
147
  # Set the component, intermediate and assembled coordinate systems
  $self->{'first_cs'}   = $coord_systems[0];
  $self->{'mid_cs'}   = $coord_systems[1];
  $self->{'last_cs'}   = $coord_systems[2];

  #maps between first and intermediate coord systems
  $self->{'first_mid_mapper'} = Bio::EnsEMBL::Mapper->new($FIRST, $MIDDLE);

  #maps between last and intermediate
  $self->{'last_mid_mapper'} = Bio::EnsEMBL::Mapper->new($LAST, $MIDDLE);

  #mapper that is actually used and is loaded by the mappings generated
  #by the other two mappers
148
149
150
  $self->{'first_last_mapper'} = Bio::EnsEMBL::Mapper->new($FIRST, $LAST,
                                                           $coord_systems[0],
                                                           $coord_systems[2]);
151
152
153
154
155
156

  #need registries to keep track of what regions are registered in source
  #and destination coordinate systems
  $self->{'first_registry'} = Bio::EnsEMBL::Mapper::RangeRegistry->new();
  $self->{'last_registry'} = Bio::EnsEMBL::Mapper::RangeRegistry->new();

157
158
  $self->{'max_pair_count'} = $DEFAULT_MAX_PAIR_COUNT;

159
160
161
162
  return $self;
}


163
164
165
166
167
168
169
170
171
172
173
=head2 max_pair_count

  Arg [1]    : (optional) int $max_pair_count
  Example    : $mapper->max_pair_count(100000)
  Description: Getter/Setter for the number of mapping pairs allowed in the
               internal cache. This can be used to override the default value
               (6000) to tune the performance and memory usage for certain
               scenarios. Higher value = bigger cache, more memory used
  Returntype : int
  Exceptions : none
  Caller     : general
174
  Status     : Stable
175
176
177
178
179
180
181
182
183
184
185

=cut

sub max_pair_count {
  my $self = shift;
  $self->{'max_pair_count'} = shift if(@_);
  return $self->{'max_pair_count'};
}



Graham McVicker's avatar
Graham McVicker committed
186
187
188
189
190
191
192
193
194
195
196

=head2 register_all

  Arg [1]    : none
  Example    : $mapper->max_pair_count(10e6);
               $mapper->register_all();
  Description: Pre-registers all assembly information in this mapper.  The
               cache size should be set to a sufficiently large value
               so that all of the information can be stored.  This method
               is useful when *a lot* of mapping will be done in regions
               which are distributed around the genome.   After registration
197
               the mapper will consume a lot of memory but will not have to
Graham McVicker's avatar
Graham McVicker committed
198
199
200
201
               perform any SQL and will be faster.
  Returntype : none
  Exceptions : none
  Caller     : specialised programs doing a lot of mapping
202
  Status     : Stable
Graham McVicker's avatar
Graham McVicker committed
203
204
205
206
207
208
209
210
211
212
213
214

=cut

sub register_all {
  my $self = shift;
  $self->adaptor->register_all_chained($self);
  return;
}




215
216
217
218
219
220
221
222
223
224
sub flush {
  my $self = shift;
  $self->{'first_registry'}->flush();
  $self->{'last_registry'}->flush();

  $self->{'first_mid_mapper'}->flush();
  $self->{'last_mid_mapper'}->flush();
  $self->{'first_last_mapper'}->flush();
}

225
226
227
228
229
230
231
232
233
234
=head2 size

  Args       : none
  Example    : $num_of_pairs = $mapper->size();
  Description: return the number of pairs currently stored.
  Returntype : int
  Exceptions : none
  Caller     : general
  Status     : Stable

235
=cut
236

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
sub size {
  my $self = shift;
  return ( $self->{'first_last_mapper'}->{'pair_count'} +
           $self->{'last_mid_mapper'}->{'pair_count'} +
           $self->{'first_mid_mapper'}->{'pair_count'} );
}



=head2 map

  Arg [1]    : string $frm_seq_region
               The name of the sequence region to transform FROM
  Arg [2]    : int $frm_start
               The start of the region to transform FROM
  Arg [3]    : int $frm_end
               The end of the region to transform FROM
  Arg [4]    : int $strand
               The strand of the region to transform FROM
  Arg [5]    : Bio::EnsEMBL::CoordSystem
               The coordinate system to transform FROM
258
259
260
  Arg [6]    : (optional) fastmap
  Arg [7]    : (optional) Bio::Ensembl::Slice
               The slice to transform TO
261
262
263
264
265
266
267
268
269
  Example    : @coords = $asm_mapper->map('X', 1_000_000, 2_000_000,
                                            1, $chr_cs);
  Description: Transforms coordinates from one coordinate system
               to another.
  Returntype : List of Bio::EnsEMBL::Mapper::Coordinate and/or
               Bio::EnsEMBL::Mapper:Gap objects
  Exceptions : thrown if the specified TO coordinat system is not one
               of the coordinate systems associated with this assembly mapper
  Caller     : general
270
  Status     : Stable
271
272
273
274
275
276

=cut

sub map {
  throw('Incorrect number of arguments.') if(@_ < 6);

277
  my ($self, $frm_seq_region_name, $frm_start,
278
      $frm_end, $frm_strand, $frm_cs, $fastmap, $to_slice) = @_;
279
280
281
282
283

  my $mapper  = $self->{'first_last_mapper'};
  my $first_cs  = $self->{'first_cs'};
  my $last_cs  = $self->{'last_cs'};

284
285
  my $is_insert = ($frm_end + 1 == $frm_start);

286
287
288
  my $frm;
  my $registry;

289
290
291



292
293
294
295
  my @tmp;
  push @tmp, $frm_seq_region_name;
  my $seq_region_id = @{$self->adaptor()->seq_regions_to_ids($frm_cs, \@tmp)}[0];

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  #speed critical section:
  #try to do simple pointer equality comparisons of the coord system objects
  #first since this is likely to work most of the time and is much faster
  #than a function call

  if($frm_cs == $first_cs ||
     ($frm_cs != $last_cs && $frm_cs->equals($first_cs))) {
    $frm = $FIRST;
    $registry = $self->{'first_registry'};
  } elsif($frm_cs == $last_cs || $frm_cs->equals($last_cs)) {
    $frm = $LAST;
    $registry = $self->{'last_registry'};
  } else {
    throw("Coordinate system " . $frm_cs->name . " " . $frm_cs->version .
          " is neither the first nor the last coordinate system " .
          " of this ChainedAssemblyMapper");
  }

  #the minimum area we want to register if registration is necessary is
  #about 1MB. Break requested ranges into chunks of 1MB and then register
  #this larger region if we have a registry miss.

  #use bitwise shift for fast and easy integer multiplication and division
  my ($min_start, $min_end);

321
322
323
324
325
326
327
  if($is_insert) {
    $min_start = (($frm_end >> $CHUNKFACTOR) << $CHUNKFACTOR);
    $min_end   = ((($frm_start >> $CHUNKFACTOR) + 1) << $CHUNKFACTOR) - 1 ;
  } else {
    $min_start = (($frm_start >> $CHUNKFACTOR) << $CHUNKFACTOR);
    $min_end   = ((($frm_end >> $CHUNKFACTOR) + 1) << $CHUNKFACTOR) - 1 ;
  }
328
329
330
331

  #get a list of ranges in the requested region that have not been registered,
  #and register them at the same

332
333
334
  my $ranges;

  if($is_insert) {
335
    $ranges = $registry->check_and_register($seq_region_id, $frm_end,
336
337
                                            $frm_start, $min_start, $min_end);
  } else {
338
    $ranges = $registry->check_and_register($seq_region_id, $frm_start,
339
340
                                            $frm_end, $min_start, $min_end);
  }
341
342

  if(defined($ranges)) {
343
    if( $self->size() > $self->{'max_pair_count'} ) {
344
      $self->flush();
345
346
347

      if($is_insert) {
        $ranges = $registry->check_and_register
348
          ($seq_region_id, $frm_end, $frm_start, $min_start, $min_end);
349
350
      } else {
        $ranges = $registry->check_and_register
351
          ($seq_region_id, $frm_start, $frm_end, $min_start, $min_end);
352
      }
353
    }
354
    $self->adaptor->register_chained($self,$frm,$seq_region_id,$ranges,$to_slice);
355
356
357
  }

  if($fastmap) {
358
    return $mapper->fastmap($seq_region_id, $frm_start, $frm_end,
359
                            $frm_strand, $frm);
360
361
  }

362
  return $mapper->map_coordinates($seq_region_id, $frm_start, $frm_end,
363
364
365
366
367
368
                                  $frm_strand, $frm);
}


sub fastmap {
  my $self = shift;
369
  return $self->map(@_,1);
370
371
372
}


373
=head2 list_ids
374
375
376
377
378
379
380
381
382

  Arg [1]    : string $frm_seq_region
               The name of the sequence region of interest
  Arg [2]    : int $frm_start
               The start of the region of interest
  Arg [3]    : int $frm_end
               The end of the region to transform of interest
  Arg [5]    : Bio::EnsEMBL::CoordSystem $frm_cs
               The coordinate system to obtain overlapping ids of
383
  Example    : foreach $id ($asm_mapper->list_ids('X',1,1000,$chr_cs)) {...}
384
  Description: Retrieves a list of overlapping seq_region internal identifiers
385
               of another coordinate system.  This is the same as the
386
               list_seq_regions method but uses internal identfiers rather
387
388
               than seq_region strings
  Returntype : List of ints
389
390
  Exceptions : none
  Caller     : general
391
  Status     : Stable
392
393
394
395

=cut


396
sub list_ids {
397
  throw('Incorrect number of arguments.') if(@_ != 5);
398
  my($self, $frm_seq_region_name, $frm_start, $frm_end, $frm_cs) = @_;
399

400
401
  my $is_insert = ($frm_start == $frm_end + 1);

402
403
404
405
406
  #the minimum area we want to register if registration is necessary is
  #about 1MB. Break requested ranges into chunks of 1MB and then register
  #this larger region if we have a registry miss.

  #use bitwise shift for fast and easy integer multiplication and division
407
  my ($min_start, $min_end);
408

409
410
411
412
413
414
415
  if($is_insert) {
    $min_start = (($frm_end >> $CHUNKFACTOR) << $CHUNKFACTOR);
    $min_end   = ((($frm_start >> $CHUNKFACTOR) + 1) << $CHUNKFACTOR) - 1;
  } else {
    $min_start = (($frm_start >> $CHUNKFACTOR) << $CHUNKFACTOR);
    $min_end   = ((($frm_end >> $CHUNKFACTOR) + 1) << $CHUNKFACTOR) - 1;
  }
416

417
418
419
420
  my @tmp;
  push @tmp, $frm_seq_region_name;
  my $seq_region_id = @{$self->adaptor()->seq_regions_to_ids($frm_cs, \@tmp)}[0];

421
422
  if($frm_cs->equals($self->{'first_cs'})) {
    my $registry = $self->{'first_registry'};
423
424
425

    my $ranges;

426

427
428
    if($is_insert) {
      $ranges = $registry->check_and_register
429
        ($seq_region_id, $frm_end, $frm_start, $min_start, $min_end);
430
431
    } else {
      $ranges = $registry->check_and_register
432
        ($seq_region_id, $frm_start, $frm_end, $min_start, $min_end);
433
    }
434
435

    if(defined($ranges)) {
436
      $self->adaptor->register_chained($self,$FIRST,$seq_region_id,$ranges);
437
438
439
    }

    return map {$_->to()->id()}
440
      $self->first_last_mapper()->list_pairs($seq_region_id, $frm_start,
441
442
443
444
				  $frm_end, $FIRST);

  } elsif($frm_cs->equals($self->{'last_cs'})) {
    my $registry = $self->{'last_registry'};
445
446
447
448

    my $ranges;
    if($is_insert) {
      $ranges = $registry->check_and_register
449
        ($seq_region_id, $frm_end, $frm_start, $min_start, $min_end);
450
451
    } else {
      $ranges = $registry->check_and_register
452
        ($seq_region_id, $frm_start, $frm_end, $min_start, $min_end);
453
    }
454
455

    if(defined($ranges)) {
456
      $self->adaptor->register_chained($self,$LAST,$seq_region_id,$ranges);
457
458
459
    }

    return map {$_->from()->id()}
460
      $self->first_last_mapper()->list_pairs($seq_region_id, $frm_start,
461
462
463
464
465
466
467
468
469
				  $frm_end, $LAST);
  } else {
    throw("Coordinate system " . $frm_cs->name . " " . $frm_cs->version .
          " is neither the first nor the last coordinate system " .
          " of this ChainedAssemblyMapper");
  }
}


470
=head2 list_seq_regions
471
472
473
474
475
476
477
478
479

  Arg [1]    : string $frm_seq_region
               The name of the sequence region of interest
  Arg [2]    : int $frm_start
               The start of the region of interest
  Arg [3]    : int $frm_end
               The end of the region to transform of interest
  Arg [5]    : Bio::EnsEMBL::CoordSystem $frm_cs
               The coordinate system to obtain overlapping ids of
480
  Example    : foreach $id ($asm_mapper->list_ids('X',1,1000,$ctg_cs)) {...}
481
  Description: Retrieves a list of overlapping seq_region internal identifiers
482
               of another coordinate system.  This is the same as the
483
484
               list_ids method but uses seq_region names rather internal ids
  Returntype : List of strings
485
486
  Exceptions : none
  Caller     : general
487
  Status     : Stable
488
489
490

=cut

491
sub list_seq_regions {
492
493
494
495
496
  throw('Incorrect number of arguments.') if(@_ != 5);
  my($self, $frm_seq_region, $frm_start, $frm_end, $frm_cs) = @_;

  #retrieve the seq_region names
  my @seq_regs =
497
    $self->list_ids($frm_seq_region,$frm_start,$frm_end,$frm_cs);
498
499
500
501
502
503
504
505
506
507

  #The seq_regions are from the 'to' coordinate system not the
  #from coordinate system we used to obtain them
  my $to_cs;
  if($frm_cs->equals($self->first_CoordSystem())) {
    $to_cs = $self->last_CoordSystem();
  } else {
    $to_cs = $self->first_CoordSystem();
  }

508
509
  #convert them to names
  return @{$self->adaptor()->seq_ids_to_regions(\@seq_regs)};
510
511
512
513
514
515
516
}






517
518
519
520
521
522
523
524
525
526
=head2 first_last_mapper

  Args       : none
  Example    : $mapper = $cam->first_last_mapper();
  Description: return the mapper.
  Returntype : Bio::EnsEMBL::Mapper
  Exceptions : none
  Caller     : internal
  Status     : Stable

527
=cut
528

529
530
531
532
533
sub first_last_mapper {
  my $self = shift;
  return $self->{'first_last_mapper'};
}

534
535
536
537
538
539
540
541
542
543
=head2 first_middle_mapper

  Args       : none
  Example    : $mapper = $cam->first_middle_mapper();
  Description: return the mapper.
  Returntype : Bio::EnsEMBL::Mapper
  Exceptions : none
  Caller     : internal
  Status     : Stable

544
545
=cut

546

547
548
549
550
551
sub first_middle_mapper {
  my $self = shift;
  return $self->{'first_mid_mapper'};
}

552
553
554
555
556
557
558
559
560
561
=head2 last_middle_mapper

  Args       : none
  Example    : $mapper = $cam->last_middle_mapper();
  Description: return the mapper.
  Returntype : Bio::EnsEMBL::Mapper
  Exceptions : none
  Caller     : internal
  Status     : Stable

562
=cut
563

564
565
566
567
568
569
sub last_middle_mapper {
  my $self = shift;
  return $self->{'last_mid_mapper'};
}


570
571
572
573
574
575
576
577
578
579
=head2 first_CoordSystem

  Args       : none
  Example    : $coordsys = $cam->first_CoordSystem();
  Description: return the CoordSystem.
  Returntype : Bio::EnsEMBL::CoordSystem
  Exceptions : none
  Caller     : internal
  Status     : Stable

580
=cut
581

582
583
584
585
586
587
sub first_CoordSystem {
  my $self = shift;
  return $self->{'first_cs'};
}


588
589
590
591
592
593
594
595
596
597
=head2 middle_CoordSystem

  Args       : none
  Example    : $coordsys = $cam->middle_CoordSystem();
  Description: return the CoordSystem.
  Returntype : Bio::EnsEMBL::CoordSystem
  Exceptions : none
  Caller     : internal
  Status     : Stable

598
=cut
599

600
601
602
603
604
sub middle_CoordSystem {
  my $self = shift;
  return $self->{'mid_cs'};
}

605
606
607
608
609
610
611
612
613
614
=head2 last_CoordSystem

  Args       : none
  Example    : $coordsys = $cam->last_CoordSystem();
  Description: return the CoordSystem.
  Returntype : Bio::EnsEMBL::CoordSystem
  Exceptions : none
  Caller     : internal
  Status     : Stable

615
=cut
616

617
618
619
620
621
sub last_CoordSystem {
  my $self = shift;
  return $self->{'last_cs'};
}

622
623
624
=head2 first_registry

  Args       : none
625
  Example    : $rr = $cam->first_registry();
626
627
628
629
630
631
  Description: return the Registry.
  Returntype : Bio::EnsEMBL::Mapper::RangeRegistry
  Exceptions : none
  Caller     : internal
  Status     : Stable

632
633
=cut

634
635
636
637
638
sub first_registry {
  my $self = shift;
  return $self->{'first_registry'};
}

639
=head2 last_registry
640
641

  Args       : none
642
  Example    : $rr = $cam->last_registry();
643
644
645
646
647
648
  Description: return the Registry.
  Returntype : Bio::EnsEMBL::Mapper::RangeRegistry
  Exceptions : none
  Caller     : internal
  Status     : Stable

649
=cut
650

651
652
653
654
655
656
657
sub last_registry {
  my $self = shift;
  return $self->{'last_registry'};
}


#
658
659
660
661
# Methods supplied to maintain polymorphism with AssemblyMapper there
# is no real assembled or component in the chained mapper, since the
# ordering is arbitrary and both ends might actually be assembled, but
# these methods provide convenient synonyms
662
#
663
664
665
666
667
668
669
670
671
672
673

=head2 mapper

  Args       : none
  Example    : $mapper = $cam->mapper();
  Description: return the first_last_mapper.
  Returntype : Bio::EnsEMBL::Mapper
  Exceptions : none
  Caller     : internal
  Status     : Stable

674
=cut
675

676
677
678
679
sub mapper {
  my $self = shift;
  return $self->first_last_mapper();
}
680
681
682
683
684
685
686
687
688
689
690

=head2 assembled_CoordSystem

  Args       : none
  Example    : $coordsys = $cam->assembled_CoordSystem();
  Description: return the first CoordSystem.
  Returntype : Bio::EnsEMBL::CoordSystem
  Exceptions : none
  Caller     : internal
  Status     : Stable

691
=cut
692
693


694
695
696
697
sub assembled_CoordSystem {
  my $self = shift;
  return $self->{'first_cs'};
}
698
699
700
701
702
703
704
705
706
707
708

=head2 component_CoordSystem

  Args       : none
  Example    : $coordsys = $cam->component_CoordSystem();
  Description: return the last CoordSystem.
  Returntype : Bio::EnsEMBL::CoordSystem
  Exceptions : none
  Caller     : internal
  Status     : Stable

709
=cut
710

711
712
713
714
715
716
717
718
719
720
721
722
723
sub component_CoordSystem {
  my $self = shift;
  return $self->{'last_cs'};
}


=head2 adaptor

  Arg [1]    : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor $adaptor
  Description: get/set for this objects database adaptor
  Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
  Exceptions : none
  Caller     : general
724
  Status     : Stable
725
726
727
728
729

=cut

sub adaptor {
  my $self = shift;
Monika Komorowska's avatar
Monika Komorowska committed
730
  weaken($self->{'adaptor'} = shift) if(@_);
731
732
733
734
735
736
  return $self->{'adaptor'};
}


=head2 in_assembly

Kieron Taylor's avatar
Kieron Taylor committed
737
  Deprecated. Use map() or list_ids() instead
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

=cut

sub in_assembly {
  my ($self, $object) = @_;

  deprecate('Use map() or list_ids() instead.');

  my $csa = $self->db->get_CoordSystemAdaptor();

  my $top_level = $csa->fetch_top_level();

  my $asma = $self->adaptor->fetch_by_CoordSystems($object->coord_system(),
                                                   $top_level);

  my @list = $asma->list_ids($object->seq_region(), $object->start(),
                             $object->end(), $object->coord_system());

  return (@list > 0);
}


=head2 map_coordinates_to_assembly

Kieron Taylor's avatar
Kieron Taylor committed
762
  DEPRECATED use map() instead
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

=cut

sub map_coordinates_to_assembly {
  my ($self, $contig_id, $start, $end, $strand) = @_;

  deprecate('Use map() instead.');

  #not sure if contig_id is seq_region_id or name...
  return $self->map($contig_id, $start, $end, $strand,
                   $self->contig_CoordSystem());

}


=head2 fast_to_assembly

Kieron Taylor's avatar
Kieron Taylor committed
780
  DEPRECATED use map() instead
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796

=cut

sub fast_to_assembly {
  my ($self, $contig_id, $start, $end, $strand) = @_;

  deprecate('Use map() instead.');

  #not sure if contig_id is seq_region_id or name...
  return $self->map($contig_id, $start, $end, $strand,
                    $self->contig_CoordSystem());
}


=head2 map_coordinates_to_rawcontig

Kieron Taylor's avatar
Kieron Taylor committed
797
  DEPRECATED use map() instead
798
799
800
801
802
803
804
805
806
807
808
809
810
811

=cut

sub map_coordinates_to_rawcontig {
  my ($self, $chr_name, $start, $end, $strand) = @_;

  deprecate('Use map() instead.');

  return $self->map($chr_name, $start, $end, $strand,
                    $self->assembled_CoordSystem());

}

=head2 list_contig_ids
Kieron Taylor's avatar
Kieron Taylor committed
812
  DEPRECATED Use list_ids instead
813
814
815
816
817
818
819
820

=cut

sub list_contig_ids {
  my ($self, $chr_name, $start, $end) = @_;

  deprecate('Use list_ids() instead.');

821
  return $self->list_ids($chr_name, $start, $end,
822
823
824
825
826
827
                         $self->assembled_CoordSystem());
}



1;