DBAdaptor.pm 33.2 KB
Newer Older
1

Colin Kingswood's avatar
Colin Kingswood committed
2
=head1 NAME - Bio::EnsEMBL::DBSQL::DBAdaptor
3
4
5
6
7
8
9

=head1 SYNOPSIS

    $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
        -user   => 'root',
        -dbname => 'pog',
        -host   => 'caldy',
Graham McVicker's avatar
Graham McVicker committed
10
        -driver => 'mysql'
11
12
        );

13
    $gene_adaptor = $db->get_GeneAdaptor();
14

15
    $gene = $gene_adaptor()->fetch_by_stable_id($stable_id);
16

Graham McVicker's avatar
Graham McVicker committed
17
    $slice = $db->get_SliceAdaptor()->fetch_by_chr_start_end('X', 1, 10000);
18
19
20

=head1 DESCRIPTION

21
22
23
24
25
26
27
This is the primary interface to an EnsEMBL database. It maintains an active
connection to the database and allows for the retrieval of ObjectAdaptors,
via a set of get_XxxxAdaptor methods (where Xxxx is the type of adaptor).

ObjectAdaptors can then be used to obtain objects and actual information
from the database.

28
29
30

=head1 CONTACT

Graham McVicker's avatar
Graham McVicker committed
31
Post questions to the EnsEMBL development list <ensembl-dev@ebi.ac.uk>
32

33
=head1 METHODS
34

35
36
The rest of the documentation details each of the object methods. Internal
methods are usually preceded with a _
37
38
39
40
41
42
43
44
45

=cut


package Bio::EnsEMBL::DBSQL::DBAdaptor;

use vars qw(@ISA);
use strict;

46
use Bio::EnsEMBL::DBSQL::DBConnection;
47
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
48

49
50
51
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
use Bio::EnsEMBL::Utils::Argument qw(rearrange);

52
@ISA = qw(Bio::EnsEMBL::DBSQL::DBConnection);
53

54
55


56
#Override constructor inherited by Bio::EnsEMBL::DBSQL::DBConnection
Graham McVicker's avatar
Graham McVicker committed
57
58
59
60


=head2 new

61
62
  Arg [-DNADB]: (optional) Bio::EnsEMBL::DBSQL::DBAdaptor DNADB 
               All sequence, assembly, contig information etc, will be
63
64
               retrieved from this database instead.
  Arg [..]   : Other args are passed to superclass
Graham McVicker's avatar
Graham McVicker committed
65
66
67
68
69
70
71
72
73
74
75
76
77
               Bio::EnsEMBL::DBSQL::DBConnection
  Example    : $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
						    -user   => 'root',
						    -dbname => 'pog',
						    -host   => 'caldy',
						    -driver => 'mysql' );
  Description: Constructor for DBAdaptor.
  Returntype : Bio::EnsEMBL::DBSQL::DBAdaptor
  Exceptions : none
  Caller     : general

=cut

78
sub new {
79
  my($class, @args) = @_;
80

81
82
  #call superclass constructor
  my $self = $class->SUPER::new(@args);
83
84

  my ( $dnadb ) = rearrange([qw(DNADB)],@args);
Graham McVicker's avatar
Graham McVicker committed
85
86
87
88

  if(defined $dnadb) {
    $self->dnadb($dnadb);
  }
89

90
91
	# $self here is actually a Container object
	# so need to call _obj to get the DBAdaptor
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
	$self->_obj->{'default_module'} =
    { 'Analysis'             => 'Bio::EnsEMBL::DBSQL::AnalysisAdaptor',
      'ArchiveStableId'      => 'Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor',
      'AssemblyExceptionFeature' => 'Bio::EnsEMBL::DBSQL::AssemblyExceptionFeatureAdaptor',
      'AssemblyMapper'       => 'Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor',
      'Blast'                => 'Bio::EnsEMBL::External::BlastAdaptor',
      'Chromosome'           => 'Bio::EnsEMBL::DBSQL::ChromosomeAdaptor',
      'Clone'                => 'Bio::EnsEMBL::DBSQL::CloneAdaptor',
      'CoordSystem'   => 'Bio::EnsEMBL::DBSQL::CoordSystemAdaptor',
      'CompressedSequence' => 'Bio::EnsEMBL::DBSQL::CompressedSequenceAdaptor',
      'DBEntry'              => 'Bio::EnsEMBL::DBSQL::DBEntryAdaptor',
      'DnaAlignFeature'      => 'Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor',
      'DensityFeature'       => 'Bio::EnsEMBL::DBSQL::DensityFeatureAdaptor',
      'Exon'                 => 'Bio::EnsEMBL::DBSQL::ExonAdaptor',
      'Gene'                 => 'Bio::EnsEMBL::DBSQL::GeneAdaptor',
      'KaryotypeBand'        => 'Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor',
      'MapFrag'              => 'Bio::EnsEMBL::DBSQL::MapFragAdaptor',
      'Marker'               => 'Bio::EnsEMBL::Map::DBSQL::MarkerAdaptor',
      'MarkerFeature'        =>
          'Bio::EnsEMBL::Map::DBSQL::MarkerFeatureAdaptor',
      'MetaContainer'        => 'Bio::EnsEMBL::DBSQL::MetaContainer',
      'MiscSet'              => 'Bio::EnsEMBL::DBSQL::MiscSetAdaptor',
      'MiscFeature'          => 'Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor',
      'PredictionTranscript' =>
           'Bio::EnsEMBL::DBSQL::PredictionTranscriptAdaptor',
      'PredictionExon'       => 'Bio::EnsEMBL::DBSQL::PredictionExonAdaptor',
      'ProteinFeature'       => 'Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor',
      'Protein'              => 'Bio::EnsEMBL::DBSQL::ProteinAdaptor',
      'ProteinAlignFeature'  =>
           'Bio::EnsEMBL::DBSQL::ProteinAlignFeatureAdaptor',
      'ProxySNP'             => 'Bio::EnsEMBL::DBSQL::ProxySNPAdaptor',
      'ProxyGene'            => 'Bio::EnsEMBL::DBSQL::ProxyGeneAdaptor',
      'ProxyRepeatFeature'   =>
          'Bio::EnsEMBL::DBSQL::ProxyRepeatFeatureAdaptor',
      'QtlFeature'           => 'Bio::EnsEMBL::Map::DBSQL::QtlFeatureAdaptor',
      'Qtl'                  => 'Bio::EnsEMBL::Map::DBSQL::QtlAdaptor',
      'RawContig'            => 'Bio::EnsEMBL::DBSQL::RawContigAdaptor',
      'RepeatConsensus'      => 'Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor',
      'RepeatFeature'        => 'Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor',
      'Sequence'             => 'Bio::EnsEMBL::DBSQL::SequenceAdaptor',
      'SimpleFeature'        => 'Bio::EnsEMBL::DBSQL::SimpleFeatureAdaptor',
      'Slice'                => 'Bio::EnsEMBL::DBSQL::SliceAdaptor',
      'SupportingFeature'    =>
          'Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor',
      'Transcript'           => 'Bio::EnsEMBL::DBSQL::TranscriptAdaptor',
      'Translation'          => 'Bio::EnsEMBL::DBSQL::TranslationAdaptor',

    };

141
142

	# initialise storage for hash of names of current modules
143
	%{$self->_obj->{'current_module'}} = %{$self->_obj->{'default_module'}};
144
145
146
147
148
149
150
151

	# keep a hash of objects representing objects of each adaptor type
	# instantiated as required in get adaptor
	$self->_obj->{'current_objects'} = {};

	# initialise generic feature adaptor storage
	$self->_obj->{'generic_feature_adaptors'} = {};

152
153


154
  return $self;
155
156
}

157

158

159
160
161
162
163
=head2 get_ArchiveStableIdAdaptor

  Args       : none 
  Example    : none
  Description: ...
164
  Returntype : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor
165
166
167
168
169
170
171
  Exceptions : none
  Caller     : general

=cut

sub get_ArchiveStableIdAdaptor {
    my( $self ) = @_;
172

173
    return 
174
      $self->get_adaptor("ArchiveStableId");
175
176
177
}


178
179
180
181
182
=head2 get_QtlFeatureAdaptor

  Args       : none 
  Example    : none
  Description: ...
183
  Returntype : Bio::EnsEMBL::Map::DBSQL::QtlFeatureAdaptor
184
185
186
187
188
189
  Exceptions : none
  Caller     : general

=cut

sub get_QtlFeatureAdaptor {
190
191
  my $self = shift;
  return $self->get_adaptor("QtlFeature");
192
193
194
195
196
197
198
}

=head2 get_QtlAdaptor

  Args       : none 
  Example    : none
  Description: ...
199
  Returntype : Bio::EnsEMBL::Map::DBSQL::QtlAdaptor
200
201
202
203
204
205
  Exceptions : none
  Caller     : general

=cut

sub get_QtlAdaptor {
206
207
    my $self  = shift;
    return $self->get_adaptor("Qtl");
208
209
}

210
211
=head2 get_MetaContainer

Graham McVicker's avatar
Graham McVicker committed
212
213
214
215
216
  Args       : none
  Example    : $meta_container = $db_adaptor->get_MetaContainer(); 
  Description: Gets a MetaContainer object for this database
  Returntype : Bio::EnsEMBL::DBSQL::MetaContainer
  Exceptions : none
217
  Caller     : general
218
219
220
221

=cut

sub get_MetaContainer {
222
223
    my $self = shift;
    return $self->get_adaptor('MetaContainer');
224
225
}

226

227
=head2 get_ProteinFeatureAdaptor
228

Graham McVicker's avatar
Graham McVicker committed
229
230
231
232
233
234
235
  Args       : none 
  Example    : $pfa = $database_adaptor->get_ProteinFeatureAdaptor();  
  Description: Gets a ProteinFeatureAdaptor for this database.  
               Formerly named get_Protfeat_Adaptor()
  Returntype : Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor 
  Exceptions : none
  Caller     : general
236
237
238

=cut

239
sub get_ProteinFeatureAdaptor {
240
241
    my $self = shift;
    return $self->get_adaptor("ProteinFeature");
242
}
243

244

Graham McVicker's avatar
Graham McVicker committed
245
246
247
248
249
250
251
252
253
254
255
=head2 get_SNPAdaptor

  Args       : none 
  Example    : $snp_adaptor = $db_adaptor->get_SNPAdaptor();
  Description: Gets a SNPAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::SNPAdaptor
  Exceptions : none
  Caller     : general

=cut

256
257
258
sub get_SNPAdaptor {
  my ($self)  = @_;

259
260
261
262
263
264
  my $lite = $self->get_db_adaptor('lite');
  my $primary_adaptor;

  if($lite) {
    $primary_adaptor = $lite->get_SNPAdaptor();
  } else {
Arne Stabenau's avatar
Arne Stabenau committed
265
    my $snp = $self->get_db_adaptor('SNP');
266

267
    unless($snp) {
268
      warning("No lite or SNP database, cannot get snp adaptor\n");
269
270
271
272
      return undef;
    }

    $primary_adaptor = $snp->get_SNPAdaptor();
Arne Stabenau's avatar
Arne Stabenau committed
273
    $primary_adaptor->ensembl_db( $self );
274
  }
275

276
  #return a proxy adaptor which can use the lite or the core database
277
  return $self->get_adaptor("ProxySNP",
278
                            $primary_adaptor);
279
280
281
}


282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
=head2 get_BlastAdaptor

  Args       : none 
  Example    : $blast_adaptor = $db_adaptor->get_BlastAdaptor();
  Description: Gets a BlastAdaptor for retrieving stored blast hits
  Returntype : Bio::EnsEMBL::External::BlastAdaptor
  Exceptions : none
  Caller     : general

=cut

sub get_BlastAdaptor {
  my ($self)  = @_;

  my $db_apt = $self->get_db_adaptor('blast');

298
299
  return $self->get_adaptor("Blast",
			     $db_apt);
300
301
302
}


303
=head2 get_PredictionTranscriptAdaptor
304
305

  Args       : none 
306
307
308
  Example    : $pta = $db_adaptor->get_PredictionTranscriptAdaptor();
  Description: Gets a PredictionTranscriptAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::PredictionTranscriptAdaptor
309
310
311
312
313
  Exceptions : none
  Caller     : general

=cut

314
315
sub get_PredictionTranscriptAdaptor {
  my ($self) = @_;
316

317
  return $self->get_adaptor("PredictionTranscript");
318
319
320
}


321
=head2 get_PredictionExonAdaptor
Graham McVicker's avatar
Graham McVicker committed
322

323
324
325
326
  Args       : none
  Example    : $pea = $db_adaptor->get_PredictionExonAdaptor();
  Description: Gets a PredictionExonAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::PredictionExonAdaptor
Graham McVicker's avatar
Graham McVicker committed
327
328
329
330
331
  Exceptions : none
  Caller     : general

=cut

332
333
sub get_PredictionExonAdaptor {
  my ($self) = @_;
334

335
  return $self->get_adaptor("PredictionExon");
336
337
338
}


339
=head2 get_SequenceAdaptor
340

Graham McVicker's avatar
Graham McVicker committed
341
  Args       : none 
342
343
344
  Example    : $sequence_adaptor = $db_adaptor->get_SequenceAdaptor();
  Description: Gets a SequenceAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::SequenceAdaptor
Graham McVicker's avatar
Graham McVicker committed
345
346
  Exceptions : none
  Caller     : general
347

Graham McVicker's avatar
Graham McVicker committed
348
=cut
349

350
351
sub get_SequenceAdaptor {
   my $self = shift;
352

353
   my $mc = $self->dnadb->get_MetaContainer();
354

355
   my ($use_compressed) = @{$mc->list_value_by_key('sequence.compression')};
356

357
358
359
360
361
362
363
   if($use_compressed) {
     return $self->dnadb->get_adaptor("CompressedSequence");
   } else {
     #return the sequence adaptor for the dnadb (which may be this db)
     return $self->dnadb->get_adaptor("Sequence");
   }
}
364

Graham McVicker's avatar
Graham McVicker committed
365

366
=head2 get_CompressedSequenceAdaptor
367

Graham McVicker's avatar
Graham McVicker committed
368
  Args       : none 
369
370
371
372
373
374
375
376
377
378
  Example    : $seq_adaptor = $db_adaptor->get_CompressedSequenceAdaptor();
  Description: Gets a CompressedSequenceAdaptor for this database.  
               A compressed sequence adaptor behaves like a normal
               SequenceAdaptor except that it stores and retrieves compressed
               sequence from the dnac table (rather than the dna table).
               Normally if you want to use compressed sequence you should
               convert your database to a compressed database with a script
               and then set the 'sequence.compression' meta_key to a value
               of '1' in the meta table.  This way the compressed sequence
               adaptor will be used instead of the normal sequence adaptor.
Graham McVicker's avatar
Graham McVicker committed
379
380
381
  Returntype : Bio::EnsEMBL::DBSQL::SequenceAdaptor
  Exceptions : none
  Caller     : general
382

383
=cut
384

385
sub get_CompressedSequenceAdaptor {
386
   my $self = shift;
387

388
   #return the sequence adaptor for the dnadb (which may be this db)
389
   return $self->dnadb->get_adaptor("CompressedSequence");
390
}
391

392

393

Graham McVicker's avatar
Graham McVicker committed
394
=head2 get_GeneAdaptor
395

Graham McVicker's avatar
Graham McVicker committed
396
397
398
399
400
401
  Args       : none 
  Example    : $gene_adaptor = $db_adaptor->get_GeneAdaptor();
  Description: Gets a GeneAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::GeneAdaptor
  Exceptions : none
  Caller     : general
402

Graham McVicker's avatar
Graham McVicker committed
403
=cut
404

Graham McVicker's avatar
Graham McVicker committed
405
406
407
sub get_GeneAdaptor {
  my( $self ) = @_;
  #get a core db adaptor
408
  return $self->get_adaptor("Gene");
409
  
410
  #Disable proxy for now, lite should no longer be necessary.
Graham McVicker's avatar
Graham McVicker committed
411
412
  #use a proxy gene adaptor, capable of making decisions with regards to the
  #database that it uses, passing in the core adaptor as a constructor arg
413
414
  #return $self->get_adaptor("ProxyGene",
	#		     $core_adaptor);
415
416
}

417

Graham McVicker's avatar
Graham McVicker committed
418
=head2 get_ExonAdaptor
419

Graham McVicker's avatar
Graham McVicker committed
420
421
422
423
424
425
  Args       : none 
  Example    : $exon_adaptor = $db_adaptor->get_ExonAdaptor();
  Description: Gets an ExonAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::ExonAdaptor
  Exceptions : none
  Caller     : general
426

Graham McVicker's avatar
Graham McVicker committed
427
=cut
428

429
430
431
sub get_ExonAdaptor {
  my( $self ) = @_;
  
432
  return $self->get_adaptor("Exon");
433
}
434

Graham McVicker's avatar
Graham McVicker committed
435
436
437
438
439
440
441
442
443
444
445
446

=head2 get_TranscriptAdaptor

  Args       : none 
  Example    : $transcript_adaptor = $db_adaptor->get_TranscriptAdaptor();
  Description: Gets a TranscriptAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::TranscriptAdaptor
  Exceptions : none
  Caller     : general

=cut

447
448
sub get_TranscriptAdaptor {
  my( $self ) = @_;
449
450

  return $self->get_adaptor("Transcript");
451
}
452

Graham McVicker's avatar
Graham McVicker committed
453
454
455
456
457
458
459
460
461
462
463
464

=head2 get_TranslationAdaptor

  Args       : none 
  Example    : $translation_adaptor = $db_adaptor->get_TranslationAdaptor();
  Description: Gets a TranslationAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::TranslationAdaptor
  Exceptions : none
  Caller     : general

=cut

465
466
sub get_TranslationAdaptor {
    my( $self ) = @_;
467

468
    return $self->get_adaptor("Translation");
469
}
470

Graham McVicker's avatar
Graham McVicker committed
471
472
473
474
475
476
477
478
479
480
481
482
483


=head2 get_SliceAdaptor

  Args       : none 
  Example    : $slice_adaptor = $db_adaptor->get_SliceAdaptor();
  Description: Gets a SliceAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::SliceAdaptor
  Exceptions : none
  Caller     : general

=cut

484
485
486
sub get_SliceAdaptor {
  my( $self ) = @_;
  
487
  return $self->dnadb()->get_adaptor("Slice");
488
489
}

Graham McVicker's avatar
Graham McVicker committed
490

491
492
=head2 get_AnalysisAdaptor

Graham McVicker's avatar
Graham McVicker committed
493
494
495
496
497
498
  Args       : none 
  Example    : $analysis_adaptor = $db_adaptor->get_AnalysisAdaptor();
  Description: Gets an AnalysisAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::AnalysisAdaptor
  Exceptions : none
  Caller     : general
499
500
501

=cut

502
503
sub get_AnalysisAdaptor {
    my( $self ) = @_;
504

505
    return $self->get_adaptor("Analysis");
506
}
507

Graham McVicker's avatar
Graham McVicker committed
508

509
=head2 get_SimpleFeatureAdaptor
510

Graham McVicker's avatar
Graham McVicker committed
511
512
513
514
515
516
  Args       : none 
  Example    : $sfa = $db_adaptor->get_SimpleFeatureAdaptor();
  Description: Gets a SimpleFeatureAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::SimpleFeatureAdaptor
  Exceptions : none
  Caller     : general
517
518
519

=cut

520
521
522
sub get_SimpleFeatureAdaptor {
  my( $self ) = @_;
  
523
  return $self->get_adaptor("SimpleFeature");
524
525
526
}


527
=head2 get_RepeatConsensusAdaptor
528

Graham McVicker's avatar
Graham McVicker committed
529
530
531
532
533
534
  Args       : none 
  Example    : $rca = $db_adaptor->get_RepeatConsensusAdaptor();
  Description: Gets a RepeatConsensusAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor
  Exceptions : none
  Caller     : general
535
536
537

=cut

538
539
540
sub get_RepeatConsensusAdaptor {
  my( $self ) = @_;
  
541
  return $self->get_adaptor("RepeatConsensus");
542
543
}

Graham McVicker's avatar
Graham McVicker committed
544
545
546
547
548
549
550
551
552
553
554
555

=head2 get_RepeatFeatureAdaptor

  Args       : none 
  Example    : $rfa = $db_adaptor->get_RepeatFeatureAdaptor();
  Description: Gets a RepeatFeatureAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor
  Exceptions : none
  Caller     : general

=cut

556
557
558
sub get_RepeatFeatureAdaptor {
  my( $self ) = @_;
  
559
  my $core_adaptor = 
560
    $self->dnadb->get_adaptor("RepeatFeature");
561
562
  
  #create a proxy adaptor, using a core RepeatFeatureAdaptor as constructor arg
563
  return $self->get_adaptor("ProxyRepeatFeature",
564
			    $core_adaptor);
565
}
566

567

Graham McVicker's avatar
Graham McVicker committed
568
=head2 get_ProteinAlignFeatureAdaptor
569

Graham McVicker's avatar
Graham McVicker committed
570
571
572
573
574
575
  Args       : none 
  Example    : $pafa = $db_adaptor->get_ProteinAlignFeatureAdaptor();
  Description: Gets a ProteinAlignFeatureAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::ProteinAlignFeatureAdaptor
  Exceptions : none
  Caller     : general
576
577
578

=cut

579
580
581
sub get_ProteinAlignFeatureAdaptor {
  my( $self ) = @_;
    
Graham McVicker's avatar
Graham McVicker committed
582
  return 
583
    $self->get_adaptor("ProteinAlignFeature");
584
585
}

Graham McVicker's avatar
Graham McVicker committed
586
  
587
=head2 get_DnaAlignFeatureAdaptor
588

Graham McVicker's avatar
Graham McVicker committed
589
590
591
592
593
594
  Args       : none 
  Example    : $dafa = $db_adaptor->get_DnaAlignFeatureAdaptor();
  Description: Gets a DnaAlignFeatureAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor
  Exceptions : none
  Caller     : general
595

596
=cut
Graham McVicker's avatar
Graham McVicker committed
597

598
599
sub get_DnaAlignFeatureAdaptor {
  my $self = shift;
600

Web Admin's avatar
Web Admin committed
601
  return $self->get_adaptor("DnaAlignFeature");
602
603
}

Graham McVicker's avatar
Graham McVicker committed
604

605
=head2 get_AssemblyMapperAdaptor
606

Graham McVicker's avatar
Graham McVicker committed
607
608
609
610
611
612
  Args       : none 
  Example    : $asma = $db_adaptor->get_AssemblyMapperAdaptor();
  Description: Gets an AsemblyMapperAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor
  Exceptions : none
  Caller     : general
613
614
615

=cut

616
617
sub get_AssemblyMapperAdaptor {
  my( $self ) = @_;
618

619
  return 
620
    $self->dnadb->get_adaptor("AssemblyMapper");
621
}
622
623


Graham McVicker's avatar
Graham McVicker committed
624
625
=head2 get_DBEntryAdaptor

626
  Args       : none
Graham McVicker's avatar
Graham McVicker committed
627
628
629
630
631
632
633
634
  Example    : $dbentry_adaptor = $db_adaptor->get_DBEntryAdaptor();
  Description: Gets a DBEntryAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::DBEntryAdaptor
  Exceptions : none
  Caller     : general

=cut

635
636
sub get_DBEntryAdaptor {
    my( $self ) = @_;
637

638
    return $self->get_adaptor("DBEntry");
639
}
640
641
642
643




644
645
646
647
648
649
=head2 get_DensityFeatureAdaptor

  Arg [1]    : none
  Example    : $density_feature_adaptor = $db_adaptor->get_DBEntryAdaptor();
  Description: Gets a DensityFeatureAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::DensityFeatureAdaptor
Graham McVicker's avatar
Graham McVicker committed
650
651
  Exceptions : none
  Caller     : general
652
653
654

=cut

655
656
657
sub get_DensityFeatureAdaptor {
  my $self = shift;
  return $self->get_adaptor('DensityFeature');
658
659
660
}


661
662

=head2 get_KaryotypeBandAdaptor
663

Graham McVicker's avatar
Graham McVicker committed
664
  Args       : none 
665
666
667
  Example    : $kba = $db_adaptor->get_KaryotypeBandAdaptor();
  Description: Gets a KaryotypeBandAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
Graham McVicker's avatar
Graham McVicker committed
668
669
  Exceptions : none
  Caller     : general
670
671
672

=cut

673
sub get_KaryotypeBandAdaptor {
674
    my( $self ) = @_;
675

676
    return 
677
      $self->dnadb->get_adaptor("KaryotypeBand");
678
679
}

Graham McVicker's avatar
Graham McVicker committed
680
681


682
683
684
685
686
687
688
689
690
691
692
693
694
695
=head2 get_SupportingFeatureAdaptor

  Arg [1]    : none
  Example    : $sfa = $db_adaptor->get_SupportingFeatureAdaptor();
  Description: Gets a SupportingFeatreAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor
  Exceptions : none
  Caller     : Bio::EnsEMBL::Exon

=cut

sub get_SupportingFeatureAdaptor {
  my $self = shift;

696
  return $self->get_adaptor("SupportingFeature");
697
698
699
700
}



701
702
703
704
705
706
707
708
709
710
711
712
713
714
=head2 get_MarkerFeatureAdaptor

  Arg [1]    : none
  Example    : $mfa = $db_adaptor->get_MarkerFeatureAdaptor;
  Description: Gets a MarkerFeatureAdaptor for this database
  Returntype : Bio::EnsEMBL::Map::DBSQL::MarkerFeatureAdaptor
  Exceptions : none
  Caller     : general

=cut

sub get_MarkerFeatureAdaptor {
  my $self = shift;

715
  return $self->get_adaptor('MarkerFeature');
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
}


=head2 get_MarkerAdaptor

  Arg [1]    : none
  Example    : $ma = $db_adaptor->get_MarkerAdaptor;
  Description: Gets a MarkerAdaptor for this database
  Returntype : Bio::EnsEMBL::Map::DBSQL::MarkerAdaptor
  Exceptions : none
  Caller     : general

=cut

sub get_MarkerAdaptor {
  my $self = shift;

733
  return $self->get_adaptor('Marker');
734
735
736
}


Graham McVicker's avatar
Graham McVicker committed
737

738
739
740
741
742
743
744
745
=head2 get_CoordSystemAdaptor

  Arg [1]    : none
  Example    : $csa = $db_adaptor->get_CoordSystemAdaptor();
  Description: Gets a CoordSystemAdaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::CoordSystemAdaptor
  Exceptions : none
  Caller     : general
Graham McVicker's avatar
Graham McVicker committed
746
747
748

=cut

749
750
sub get_CoordSystemAdaptor {
  my $self = shift;
751

752
753
  return $self->dnadb()->get_adaptor('CoordSystem');
}
754
755
756
757




758
=head2 get_MiscSetAdaptor
759

760
761
762
763
764
765
  Arg [1]    : none
  Example    : $msa = $db_adaptor->get_MiscSetAdaptor();
  Description: Gets a MiscSet adaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::MiscSetAdaptor
  Exceptions : none
  Caller     : general
766

767
768
=cut

769
770
sub get_MiscSetAdaptor {
  my $self = shift;
771

772
  return $self->get_adaptor('MiscSet');
773
774
775
776
}



777
778
779
780
781
782
783
784
=head2 get_MiscFeatureAdaptor

  Arg [1]    : none
  Example    : $mfa = $db_adaptor->get_MiscFeatureAdaptor();
  Description: Gets a MiscFeature adaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor
  Exceptions : none
  Caller     : general
785
786
787

=cut

788
789
sub get_MiscFeatureAdaptor {
  my $self = shift;
790

791
  return $self->get_adaptor('MiscFeature');
792
793
}

Ensembl Pipeline's avatar
Ensembl Pipeline committed
794

795
=head2 get_AssemblyExceptionFeatureAdaptor
796

797
798
799
800
801
802
  Arg [1]    : none
  Example    : $aefa = $db_adaptor->get_AssebmyExceptionFeatureAdaptor();
  Description: Gets a AssemblyExceptionFeature adaptor for this database
  Returntype : Bio::EnsEMBL::DBSQL::AssemblyExceptionFeatureAdaptor
  Exceptions : none
  Caller     : general
803
804
805

=cut

806
807
sub get_AssemblyExceptionFeatureAdaptor {
  my $self = shift;
808

809
  return $self->get_adaptor('AssemblyExceptionFeature');
810
811
}

812

Graham McVicker's avatar
Graham McVicker committed
813
814
815
816
817
818
819
820
821
822
823
824
825
=head2 dnadb

 Title   : dnadb
 Usage   : my $dnadb = $db->dnadb;
 Function: returns the database adaptor where the dna lives
           Useful if you only want to keep one copy of the dna
           on disk but have other databases with genes and features in
 Returns : dna database adaptor
  Args    : Bio::EnsEMBL::DBSQL::DBAdaptor

=cut

sub dnadb {
826
  my $self = shift;
Graham McVicker's avatar
Graham McVicker committed
827

828
829
830
  if(@_) {
    my $arg = shift;
    if(ref($arg) && (($arg->isa('Bio::EnsEMBL::Container') &&
831
832
833
834
835
836
		     $arg->_obj == $self) || $arg == $self)) {
      #we don't want to store a circular reference to our self
      return;
    }

    $self->{'dnadb'} = $arg;
Graham McVicker's avatar
Graham McVicker committed
837
  }
838

839
  return $self->{'dnadb'} || $self;
Graham McVicker's avatar
Graham McVicker committed
840
841
}

Ensembl Pipeline's avatar
Ensembl Pipeline committed
842

843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

=head2 deleteObj

  Arg [1]    : none
  Example    : none
  Description: Cleans up circular reference loops so proper garbage collection
               can occur.
  Returntype : none
  Exceptions : none
  Caller     : DBAdaptorContainer::DESTROY

=cut

sub deleteObj {
  my $self = shift;
  #print "called deleteObj on DBAdaptor\n";

  #clean up external feature adaptor references
  if(exists $self->{'_xf_adaptors'}) {
    foreach my $key (keys %{$self->{'_xf_adaptors'}}) {
863
      delete $self->{'_xf_adaptors'}->{$key};
864
865
866
    }
  }

867
868
869
870
  if(exists $self->{'current_objects'}) {
    foreach my $adaptor_name (keys %{$self->{'current_objects'}}) {
      my $adaptor = $self->{'current_objects'}->{$adaptor_name};

871
      if(ref($adaptor) && $adaptor->can('deleteObj')) {
872
873
        $adaptor->deleteObj();
      }
874

875
876
877
878
      delete $self->{'current_objects'}->{$adaptor_name};
    }
  }

879
880
881
882
883
884
885
886
887
888
889
890
891
892
  if(exists $self->{'generic_feature_adaptors'}) {
    foreach my $name (keys %{$self->{'generic_feature_adaptors'}}) {
      my $adaptor = $self->{'generic_feature_adaptors'}->{$name};
      if(ref($adaptor) && $adaptor->can('deleteObj')) {
	$adaptor->deleteObj();
      }

      delete $self->{'generic_feature_adaptors'}->{$name};
    }

    delete $self->{'generic_feature_adaptors'};
  }


893
894
  delete $self->{'_meta_container'};
  delete $self->{'dnadb'};
895

896
897
898
899
900
  #call the superclass deleteObj method
  $self->SUPER::deleteObj;
}


901
902
903
904
905
906
###########################################################
#
# Support for DAS
#
###########################################################

Graham McVicker's avatar
Graham McVicker committed
907
908
=head2 add_DASFeatureFactory

909
  Arg [1]    : Bio::EnsEMBL::ExternalFeatureFactory $value 
Graham McVicker's avatar
Graham McVicker committed
910
911
912
913
914
915
916
917
918
919
920
921
  Example    : none
  Description: Attaches a DAS Feature Factory to this method.  
               ExternalFeatureFactory objects are not really used right now.
               They may be reintroduced or taken out completely.  The fate
               of this function is unknown (although it is presently needed).
  Returntype : none
  Exceptions : none
  Caller     : EnsWeb

=cut

sub add_DASFeatureFactory{
Tanya Gray's avatar
Tanya Gray committed
922
923
 
 my ($self,$value) = @_;
Graham McVicker's avatar
Graham McVicker committed
924
925
926
927
928
929
930
931
932
933
934
  
  push(@{$self->{'_das_ff'}},$value);
}


=head2 _each_DASFeatureFactory

  Args       : none
  Example    : none
  Description: Not sure if this is used, or if it should be removed.  It 
               does not seem to be used at the moment
935
  Returntype : Bio::EnsEMBL::ExternalFeatureFactory
Graham McVicker's avatar
Graham McVicker committed
936
937
938
939
940
941
942
943
  Exceptions : none
  Caller     : ??

=cut

sub _each_DASFeatureFactory{
   my ($self) = @_;

Web Admin's avatar
Web Admin committed
944
   return @{$self->{'_das_ff'}||[]}
Graham McVicker's avatar
Graham McVicker committed
945
946
947
}


948
949
################################################################## 
# 
950
# SUPPORT FOR EXTERNAL FEATURE FACTORIES 
951
952
# 
##################################################################
953

954

955

956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
=head2 add_ExternalFeatureAdaptor

  Arg [1]    : Bio::EnsEMBL::External::ExternalFeatureAdaptor
  Example    : $db_adaptor->add_ExternalFeatureAdaptor($xfa);
  Description: Adds an external feature adaptor to this database adaptor.
               Adding the external adaptor in this way allows external
               features to be obtained from Slices and from RawContigs.

               The external feature adaptor which is passed to this method
               will have its db attribuite set to this DBAdaptor object via 
               the db accessor method. 

               ExternalFeatureAdaptors passed to this method are stored 
               internally in a hash keyed on the string returned by the 
               ExternalFeatureAdaptors track_name method.
               
               If the track name method is not implemented then the 
               a default key named 'External features' is assigned.  In the
               event of duplicate key names, a number is appended to the
               key name, and incremented for each subsequent adaptor with the
               same track name.  For example, if no track_names are specified 
               then the the external feature adaptors will be stored under the
               keys 'External features', 'External features2' 
               'External features3' etc.
980
981
  Returntype : none
  Exceptions : none
982
  Caller     : general
983
984

=cut
985

986
987
988
989
990
sub add_ExternalFeatureAdaptor {
  my ($self, $adaptor) = @_;

  unless($adaptor && ref $adaptor && 
	 $adaptor->isa('Bio::EnsEMBL::External::ExternalFeatureAdaptor')) {
991
992
     throw("[$adaptor] is not a " .
           "Bio::EnsEMBL::External::ExternalFeatureAdaptor");
993
  }
994

995
996
997
998
  unless(exists $self->{'_xf_adaptors'}) {
    $self->{'_xf_adaptors'} = {};
  }

999
  my $track_name = $adaptor->{'_track_name'};
1000
1001
1002
1003
1004
1005
1006

  #use a generic track name if one hasn't been defined
  unless(defined $track_name) {
    $track_name = "External features";
  }

  #if the track name exists add numbers to the end until a free name is found
1007
  if(exists $self->{'_xf_adaptors'}->{"$track_name"}) {
1008
    my $num = 2;
1009
    $num++ while(exists $self->{'_xf_adaptors'}->{"$track_name$num"});
1010
1011
1012
1013
1014
    $self->{'_xf_adaptors'}->{"$track_name$num"} = $adaptor;
  } else {
    $self->{'_xf_adaptors'}->{"$track_name"} = $adaptor;
  }

1015
  $adaptor->db($self);
1016
}
1017

1018

1019
1020

=head2 get_ExternalFeatureAdaptors
1021

Graham McVicker's avatar
Graham McVicker committed
1022
  Arg [1]    : none
1023
1024
1025
1026
1027
1028
1029
  Example    : @xfas = values %{$db_adaptor->get_ExternalFeatureAdaptors}; 
  Description: Retrieves all of the ExternalFeatureAdaptors which have been
               added to this DBAdaptor.  The ExternalFeatureAdaptors are 
               returned in a reference to a hash keyed on the track names
               of the external adaptors
  Returntype : Reference to a hash of ExternalFeatureAdaptors keyed on 
               their track names.
1030
  Exceptions : none
1031
  Caller     : general
1032
1033
1034

=cut

1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
sub get_ExternalFeatureAdaptors {
  my $self = shift;

  return $self->{'_xf_adaptors'};
}


=head2 add_ExternalFeatureFactory

  Arg [1]    : Bio::EnsEMBL::DB::ExternalFeatureFactoryI $value
  Example    : $db_adaptor->add_ExternalFeatureFactory
  Description: It is recommended that add_ExternalFeatureAdaptor be used 
               instead.  See documentation for 
               Bio::EnsEMBL::External::ExternalFeatureAdaptor

               Adds an external feature factory to the core database
               so that features from external sources can be displayed in 
               ensembl. This method is still available mainly for legacy
               support for external EnsEMBL installations.
  Returntype : none
  Exceptions : none
  Caller     : external

=cut

sub add_ExternalFeatureFactory{
   my ($self,$value) = @_;
1062

1063
   $self->add_ExternalFeatureAdaptor($value);
1064
1065
}

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
#
# OVERWRITABLE STANDARD ADAPTORS
#

=head2 get_adaptor

  Arg [1]    : Canonical data type for which an adaptor is required.
  Example    : $db_adaptor->get_adaptor("Protein")
  Description: Gets an adaptor object for a standard data type.
  Returntype : Adaptor Object of arbitrary type
  Exceptions : thrown if there is no associated module
  Caller     : external

=cut

sub get_adaptor() {
	my ($self, $canonical_name, @other_args) = @_;

1084
1085
1086
  if ($self->isa('Bio::EnsEMBL::Container')) {
    $self = $self->_obj;
  }
1087

1088
	# throw if module for $canonical_name does not exist
1089
1090
	throw("No such data type $canonical_name") 
    if (!exists($self->{'current_module'}->{$canonical_name}));
1091
1092
1093
1094
1095
1096

	# get module name for $canonical_name
	my $module_name = $self->{'default_module'}->{$canonical_name};

	# create and store a new one if necessary
	if (!exists($self->{'current_objects'}->{$canonical_name})) {
1097
1098
	  $self->{'current_objects'}->{$canonical_name} =
      $self->_get_adaptor($module_name, @other_args);
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
	}

	return $self->{'current_objects'}->{$canonical_name};

}


=head2 set_adaptor

  Arg [1]    : Canonical data type for new adaptor.
	Arg [2]    : Object defining the adaptor for arg1.
  Example    : $pa = Bio::EnsEMBL::DBSQL::ProteinAdaptor->new($db_adaptor);
             : $db_adaptor->set_adaptor("Protein", $pa)
1112
1113
  Description: Stores the object which represents the adaptor for the
               arg1 data type.
1114
  Returntype : none
1115
1116
  Exceptions : If arg2 is not a subclass of the default module for this
               data type.
1117
1118
1119
1120
1121
  Caller     : external

=cut

sub set_adaptor() {
1122
  my ($self, $canonical_name, $new_object) = @_;
1123

1124
1125
1126
  if ($self->isa('Bio::EnsEMBL::Container')) {
    $self = $self->_obj;
  }
1127