DBEntryAdaptor.pm 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# EnsEMBL External object reference reading writing adaptor for mySQL
#
# Copyright EMBL-EBI 2001
#
# Author: Arne Stabenau
# 
# Date : 06.03.2001
#

=head1 NAME

Bio::EnsEMBL::DBSQL::DBEntryAdaptor - 
MySQL Database queries to load and store external object references.

=head1 SYNOPSIS

Graham McVicker's avatar
Graham McVicker committed
17 18 19
$db_entry_adaptor = $db_adaptor->get_DBEntryAdaptor();
$dbEntry = $db_entry_adaptor->fetch_by_dbID($id);

20 21 22 23 24 25 26 27 28 29 30 31 32 33
=head1 CONTACT

  Arne Stabenau: stabenau@ebi.ac.uk
  Ewan Birney  : birney@ebi.ac.uk

=head1 APPENDIX

=cut

package Bio::EnsEMBL::DBSQL::DBEntryAdaptor;

use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::DBEntry;
34
use Bio::EnsEMBL::IdentityXref;
35 36 37 38 39 40

use vars qw(@ISA);
use strict;

@ISA = qw( Bio::EnsEMBL::DBSQL::BaseAdaptor );

Graham McVicker's avatar
Graham McVicker committed
41 42 43 44 45 46 47 48 49 50 51 52 53

=head2 fetch_by_dbID

  Arg [1]    : int $dbID
               the unique database identifier for the DBEntry to retrieve
  Example    : my $db_entry = $db_entry_adaptor->fetch_by_dbID($dbID);
  Description: retrieves a dbEntry from the database via its unique identifier 
  Returntype : Bio::EnsEMBL::DBEntry
  Exceptions : none
  Caller     : ?

=cut

54
sub fetch_by_dbID {
55 56 57 58
  ## this function may need revamping in the same way as
  ##  _fetch_by_EnsObject_type, using double outer join to get all stuff in
  ##  one go. PL)

59 60 61
  my ($self, $dbID ) = @_;
  
  my $sth = $self->prepare( "
62 63
    SELECT xref.xref_id, xref.dbprimary_acc, xref.display_label,
           xref.version, xref.description,
64
           exDB.db_name, exDB.release
65 66 67
      FROM xref, external_db exDB
     WHERE xref.xref_id = $dbID
       AND xref.external_db_id = exDB.external_db_id 
68 69 70
   " );

  $sth->execute();
71
  my ( $refID, $dbprimaryId, $displayid, $version, $desc, $dbname, $release) =
72 73 74 75 76 77 78 79 80 81
    $sth->fetchrow_array();

  if( ! defined $refID ) {
    return undef;
  }

  my $exDB = Bio::EnsEMBL::DBEntry->new
    ( -adaptor => $self,
      -dbID => $dbID,
      -primary_id => $dbprimaryId,
82
      -display_id => $displayid,
83 84 85 86 87 88 89 90
      -version => $version,
      -release => $release,
      -dbname => $dbname );
  
  if( $desc ) {
    $exDB->description( $desc );
  }

91
  my $get_synonym = $self->prepare( "
92
    SELECT synonym 
93 94
      FROM external_synonym
     WHERE xref_id = $dbID
95
  " );
96
  $get_synonym->execute();
97
  
98
  while( my ($synonym) = $get_synonym->fetchrow_array() ) {
99 100 101 102 103 104 105
    $exDB->add_synonym( $synonym );
  }

  return $exDB;
}


Graham McVicker's avatar
Graham McVicker committed
106 107 108 109 110 111 112 113 114 115 116 117 118
=head2 store

  Arg [1]    : ?? $exObj
  Arg [2]    : ?? $ensObject
  Arg [3]    : ?? $ensType
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 

=cut

119
sub store {
120
    my ( $self, $exObj, $ensObject, $ensType ) = @_;
121
    my $dbJustInserted;
122 123 124 125
    
    # check if db exists
    # urlPattern dbname release
    my $sth = $self->prepare( "
126 127
     SELECT external_db_id
       FROM external_db
Arne Stabenau's avatar
Arne Stabenau committed
128 129 130
      WHERE db_name = ?
        AND release = ?
    " );
131
    $sth->execute( $exObj->dbname(), $exObj->release() );
Arne Stabenau's avatar
Arne Stabenau committed
132
    
133 134 135
    my $dbRef;
    
    if(  ($dbRef) =  $sth->fetchrow_array() ) {
136
        $dbJustInserted = 0;
137
    } else {
Graham McVicker's avatar
Graham McVicker committed
138 139
      # store it, get dbID for that
      $sth = $self->prepare( "
140
       INSERT INTO external_db 
Arne Stabenau's avatar
Arne Stabenau committed
141
       SET db_name = ?,
142 143
           release = ?,
           status  = ?
Arne Stabenau's avatar
Arne Stabenau committed
144
     " );
145
	
Graham McVicker's avatar
Graham McVicker committed
146 147 148 149 150 151 152 153 154
      $sth->execute( $exObj->dbname(), $exObj->release(), $exObj->status);
      
      $dbJustInserted = 1;
      $sth = $self->prepare( "SELECT LAST_INSERT_ID()" );
      $sth->execute();
      ( $dbRef ) = $sth->fetchrow_array();
      if( ! defined $dbRef ) {
	$self->throw( "Database entry failed." );
      }
Arne Stabenau's avatar
Arne Stabenau committed
155
    }
156 157 158
    
    my $dbX;
    
159
    if(  $dbJustInserted ) {
Graham McVicker's avatar
Graham McVicker committed
160 161 162
      # dont have to check for existence; cannnot have been inserted at
      # this point, so $dbX is certainly undefined
      $dbX = undef;
163
    } else {
164
	$sth = $self->prepare( "
165 166 167 168
       SELECT xref_id
         FROM xref
        WHERE external_db_id = ?
          AND dbprimary_acc = ?
Arne Stabenau's avatar
Arne Stabenau committed
169 170
          AND version = ?
     " );
171 172 173 174 175 176 177 178
	$sth->execute( $dbRef, $exObj->primary_id(), 
		       $exObj->version() );
	( $dbX ) = $sth->fetchrow_array();
    }
    
    if( ! defined $dbX ) {
	
	$sth = $self->prepare( "
179 180 181
      INSERT INTO xref 
       SET dbprimary_acc = ?,
           display_label = ?,
Arne Stabenau's avatar
Arne Stabenau committed
182 183
           version = ?,
           description = ?,
184
           external_db_id = $dbRef
Arne Stabenau's avatar
Arne Stabenau committed
185
     " );
186
	$sth->execute( $exObj->primary_id(), $exObj->display_id(), $exObj->version(),
187
		       $exObj->description());
188
	
189
	$sth = $self->prepare( "
Arne Stabenau's avatar
Arne Stabenau committed
190 191
      SELECT LAST_INSERT_ID()
    " );
192 193 194 195 196 197 198 199 200
	$sth->execute();
	( $dbX ) = $sth->fetchrow_array();
	
	# synonyms
	my @synonyms = $exObj->get_synonyms();
	foreach my $syn ( @synonyms ) {
	    
#Check if this synonym is already in the database for the given primary id
	    my $sth = $self->prepare( "
201
     SELECT xref_id,
202
            synonym
203 204
       FROM external_synonym
      WHERE xref_id = '$dbX'
205 206 207 208
        AND synonym = '$syn'
    " );
	    $sth->execute;
	    
209
	    my ($dbSyn) = $sth->fetchrow_array();
210 211 212
	    
	    #print STDERR $dbSyn[0],"\n";
	    
213
	    if( ! $dbSyn ) {
214
		$sth = $self->prepare( "
215 216
        INSERT INTO external_synonym
         SET xref_id = $dbX,
Arne Stabenau's avatar
Arne Stabenau committed
217 218
            synonym = '$syn'
      " );
219 220 221
		$sth->execute();
	    }
	}
222 223 224
	
	
	$sth = $self->prepare( "
225 226
   INSERT INTO object_xref
     SET xref_id = $dbX,
Arne Stabenau's avatar
Arne Stabenau committed
227 228 229
         ensembl_object_type = ?,
         ensembl_id = ?
  " );
230 231 232 233 234 235
	
	$sth->execute( $ensType, $ensObject );
	
	$exObj->dbID( $dbX );
	$exObj->adaptor( $self );
	
236
	if ($exObj->isa('Bio::EnsEMBL::IdentityXref')) {
237 238 239 240 241 242 243
	    $sth = $self->prepare( "
      SELECT LAST_INSERT_ID()
    " );
	    $sth->execute();
	    my ( $Xidt ) = $sth->fetchrow_array();
	    
	    $sth = $self->prepare( "
244 245
             INSERT INTO identity_xref
             SET object_xref_id = $Xidt,
246 247 248 249 250 251
             query_identity = ?,
             target_identity = ?
    " );
	    $sth->execute( $exObj->query_identity, $exObj->target_identity );
	    
	}
252
    } else {
253
	$sth = $self->prepare ( "
254

255 256 257
              SELECT xref_id
              FROM object_xref
              WHERE xref_id = $dbX
258 259
              AND   ensembl_object_type = '$ensType'
              AND   ensembl_id = '$ensObject'");
260 261 262 263 264
	
	$sth->execute;
	my ($tst) = $sth->fetchrow_array;


265
	if (! defined $tst) {
266
	# line is already in xref table. Need to add to object_xref
267
	    $sth = $self->prepare( "
268 269
             INSERT INTO object_xref
               SET xref_id = $dbX,
270 271 272
               ensembl_object_type = ?,
               ensembl_id = ?");
	
273
	    $sth->execute( $ensType, $ensObject );
274
	
275 276
	    $exObj->dbID( $dbX );
	    $exObj->adaptor( $self );
277 278


279
	    if ($exObj->isa('Bio::EnsEMBL::IdentityXref')) {
280 281 282 283 284 285 286
		$sth = $self->prepare( "
      SELECT LAST_INSERT_ID()
    " );
		$sth->execute();
		my ( $Xidt ) = $sth->fetchrow_array();
		
		$sth = $self->prepare( "
287 288
             INSERT INTO identity_xref
             SET object_xref_id = $Xidt,
289 290 291 292 293 294 295 296
             query_identity = ?,
             target_identity = ?
    " );
		$sth->execute( $exObj->query_identity, $exObj->target_identity );
		
	    }


297
	}
298
    }
299
        
300
    return $dbX;
301
    
302 303
}

304

Graham McVicker's avatar
Graham McVicker committed
305

Graham McVicker's avatar
Graham McVicker committed
306
=head2 fetch_by_Gene
Graham McVicker's avatar
Graham McVicker committed
307

Graham McVicker's avatar
Graham McVicker committed
308 309 310 311 312 313 314
  Arg [1]    : Bio::EnsEMBL::Gene $gene 
               The gene to retrienve DBEntries for
  Example    : @db_entries = @{$db_entry_adaptor->fetch_by_Gene($gene)};
  Description: This should be changed, it modifies the gene passed in
  Returntype : listref of Bio::EnsEMBL::DBEntries
  Exceptions : none
  Caller     : Bio::EnsEMBL::Gene
Graham McVicker's avatar
Graham McVicker committed
315 316 317

=cut

318
sub fetch_by_Gene {
319
  my ( $self, $gene ) = @_;
320 321 322
  my $query1 = "SELECT t.translation_id 
                FROM transcript t
                WHERE t.gene_id = ?";
323 324 325 326 327

  my $sth1 = $self->prepare($query1);
  $sth1->execute( $gene->dbID );

  while (my $transid = $sth1->fetchrow) {
Graham McVicker's avatar
Graham McVicker committed
328 329 330
    my $translation_xrefs = 
      $self->_fetch_by_object_type( $transid, 'Translation' );
    foreach my $translink(@$translation_xrefs) {
331 332 333
      $gene->add_DBLink($translink);
    }
  }
Graham McVicker's avatar
Graham McVicker committed
334 335
  my $genelinks = $self->_fetch_by_object_type( $gene->stable_id, 'Gene' );
  foreach my $genelink ( @$genelinks ) {
336 337
    $gene->add_DBLink( $genelink );
  }
338 339
}

Graham McVicker's avatar
Graham McVicker committed
340 341


Graham McVicker's avatar
Graham McVicker committed
342
=head2 fetch_by_RawContig
Graham McVicker's avatar
Graham McVicker committed
343

Graham McVicker's avatar
Graham McVicker committed
344 345 346 347 348 349
  Arg [1]    : Bio::EnsEMBL::RawContig $contig
  Example    : @db_entries = @{$db_entry_adaptor->fetch_by_RawContig($contig)}
  Description: Retrieves a list of RawContigs for this object
  Returntype : listref of Bio::EnsEMBL::DBEntries
  Exceptions : none
  Caller     : general
Graham McVicker's avatar
Graham McVicker committed
350 351 352

=cut

Graham McVicker's avatar
Graham McVicker committed
353 354 355
sub fetch_by_RawContig {
  my ( $self, $contig ) = @_;
  return $self->_fetch_by_object_type( $rawContigId, 'RawContig' );
Arne Stabenau's avatar
Arne Stabenau committed
356 357
}

Graham McVicker's avatar
Graham McVicker committed
358

Graham McVicker's avatar
Graham McVicker committed
359
=head2 fetch_by_Transcript
Graham McVicker's avatar
Graham McVicker committed
360

Graham McVicker's avatar
Graham McVicker committed
361
  Arg [1]    : Bio::EnsEMBL::Transcript
Graham McVicker's avatar
Graham McVicker committed
362
  Example    : 
Graham McVicker's avatar
Graham McVicker committed
363
  Description: This should be changed, it modifies the transcipt passed in
Graham McVicker's avatar
Graham McVicker committed
364 365 366 367 368 369
  Returntype : 
  Exceptions : 
  Caller     : 

=cut

Graham McVicker's avatar
Graham McVicker committed
370
sub fetch_by_Transcript {
371 372
  my ( $self, $trans ) = @_;

373 374 375
  my $query1 = "SELECT t.translation_id 
                FROM transcript t
                WHERE t.transcript_id = ?";
376 377 378 379 380 381 382 383 384 385 386

  my $sth1 = $self->prepare($query1);
  $sth1->execute( $trans->dbID );

  # 
  # Did this to be consistent with fetch_by_Gene, but don't like
  # it (filling in the object). I think returning the array would
  # be better. Oh well. EB
  #
  
  while (my $transid = $sth1->fetchrow) {
Graham McVicker's avatar
Graham McVicker committed
387 388 389 390 391
    my $translation_xrefs = $self->_fetch_by_object_type( $transid, 
							  'Translation' );
    foreach my $translink(@$translation_xrefs) {
      $trans->add_DBLink($translink);
    }
392
  }
393 394
}

Graham McVicker's avatar
Graham McVicker committed
395

Graham McVicker's avatar
Graham McVicker committed
396
=head2 fetch_by_Translation
Graham McVicker's avatar
Graham McVicker committed
397

Graham McVicker's avatar
Graham McVicker committed
398 399 400 401 402 403 404
  Arg [1]    : Bio::EnsEMBL::Translation $trans
               The translation to fetch database entries for
  Example    : @db_entries = @{$db_entry_adptr->fetch_by_Translation($trans)};
  Description: Retrieves external database entries for an EnsEMBL translation
  Returntype : listref of dbEntries to obtain
  Exceptions : none
  Caller     : general
Graham McVicker's avatar
Graham McVicker committed
405 406 407

=cut

Graham McVicker's avatar
Graham McVicker committed
408 409 410
sub fetch_by_Translation {
  my ( $self, $trans ) = @_;
  return $self->_fetch_by_object_type( $trans->dbID(), 'Translation' );
411 412 413
}


Graham McVicker's avatar
Graham McVicker committed
414 415

=head2 fetch_by_object_type
Graham McVicker's avatar
Graham McVicker committed
416 417 418 419 420 421 422 423 424 425

  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 

=cut

Graham McVicker's avatar
Graham McVicker committed
426
sub _fetch_by_object_type {
427 428
  my ( $self, $ensObj, $ensType ) = @_;
  my @out;
429 430
  
  my $sth = $self->prepare("
Graham McVicker's avatar
Graham McVicker committed
431 432 433 434 435 436 437 438 439 440 441 442 443
    SELECT xref.xref_id, xref.dbprimary_acc, xref.display_label, xref.version,
           xref.description,
           exDB.db_name, exDB.release, 
           oxr.object_xref_id, 
           es.synonym, 
           idt.query_identity, idt.target_identity
    FROM   xref xref, external_db exDB, object_xref oxr 
    LEFT JOIN external_synonym es on es.xref_id = xref.xref_id 
    LEFT JOIN identity_xref idt on idt.object_xref_id = oxr.object_xref_id
    WHERE  xref.xref_id = oxr.xref_id
      AND  xref.external_db_id = exDB.external_db_id 
      AND  oxr.ensembl_id = '$ensObj'
      AND  oxr.ensembl_object_type = '$ensType'
444 445
  ");
  
446
  $sth->execute();
447 448 449 450
  
  
  my %seen;
  
451
  while ( my $arrRef = $sth->fetchrow_arrayref() ) {
Graham McVicker's avatar
Graham McVicker committed
452 453 454
    my ( $refID, $dbprimaryId, $displayid, $version, 
	 $desc, $dbname, $release, $objid, 
         $synonym, $queryid, $targetid ) = @$arrRef;
455 456 457
    
    my $exDB;
    
458
    # using an outer join on the synonyms as well as on identity_xref, we
459
    # now have to filter out the duplicates (see v.1.18 for
460
    # original). Since there is at most one identity_xref row per xref,
461 462 463 464
    # this is easy enough; all the 'extra' bits are synonyms
    if ( !$seen{$refID} )  {
      $seen{$refID}++;
      
465
      if ((defined $queryid)) {         # an xref with similarity scores
466
        $exDB = Bio::EnsEMBL::IdentityXref->new
467 468 469
          ( -adaptor => $self,
            -dbID => $refID,
            -primary_id => $dbprimaryId,
470
            -display_id => $displayid,
471 472 473 474 475 476 477 478 479 480 481 482
            -version => $version,
            -release => $release,
            -dbname => $dbname);
        
        $exDB->query_identity($queryid);
        $exDB->target_identity($targetid);
        
      } else {
        $exDB = Bio::EnsEMBL::DBEntry->new
          ( -adaptor => $self,
            -dbID => $refID,
            -primary_id => $dbprimaryId,
483
            -display_id => $displayid,
484 485 486 487 488 489 490 491
            -version => $version,
            -release => $release,
            -dbname => $dbname );
      }
      
      if( $desc ) {
        $exDB->description( $desc );
      }
492
      
493 494 495
      push( @out, $exDB );
    }                                   # if (!$seen{$refID})

496
    # $exDB still points to the same xref, so we can keep adding synonyms
497 498 499
    #if ($synonym) {
    #  $exDB->add_synonym( $synonym );
    #}
500 501
  }                                     # while <a row from database>
  
Graham McVicker's avatar
Graham McVicker committed
502
  return \out;
503 504
}

505 506


Graham McVicker's avatar
Graham McVicker committed
507 508 509 510 511 512 513 514
=head2 geneids_by_extids

  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 
515 516 517 518 519

=cut

sub geneids_by_extids{
   my ($self,$name) = @_;
520
   my @genes;
521

522
   my $sth = $self->prepare("SELECT DISTINCT( tr.gene_id ) 
Arne Stabenau's avatar
Arne Stabenau committed
523
                  FROM transcript tr, 
524
                       xref x, object_xref oxr
Arne Stabenau's avatar
Arne Stabenau committed
525
                  WHERE tr.translation_id = oxr.ensembl_id 
526 527
                    AND oxr.xref_id = x.xref_id 
                    AND x.display_label = '$name'");
528 529 530 531
   $sth->execute();

   while( ($a) = $sth->fetchrow_array ) {
       push(@genes,$a);
532
   }
533

534 535 536
   unless (scalar @genes){ 
       $sth = $self->prepare("SELECT DISTINCT( tr.gene_id ) 
		      FROM transcript tr, 
537
			   xref x, object_xref oxr
538
		      WHERE tr.translation_id = oxr.ensembl_id 
539 540
			AND oxr.xref_id = x.xref_id 
			AND x.dbprimary_acc='$name'");
541 542 543 544 545 546
       $sth->execute();
       while( ($a) = $sth->fetchrow_array ) {
	   push(@genes,$a);
       }
   }

547
   return @genes;
548 549 550
}


Graham McVicker's avatar
Graham McVicker committed
551
=head2 transcriptids_by_extids
552

Graham McVicker's avatar
Graham McVicker committed
553 554 555 556 557 558
  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 
559 560 561 562 563

=cut

sub transcriptids_by_extids{
   my ($self,$name) = @_;
564 565 566 567 568 569 570 571 572 573 574
   my @transcripts;
   my @translations = $self->_type_by_external_id($name,'Translation');

foreach my $t (@translations) {
       my $sth = $self->prepare( "select id from transcript where translation = '$t'");
       $sth->execute();
       my $tr = $sth->fetchrow;
       push (@transcripts,$tr);
   }
   return @transcripts;

575 576 577 578
}



Graham McVicker's avatar
Graham McVicker committed
579 580 581 582 583 584 585 586
=head2 translationids_by_extids

  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 
587 588 589 590 591 592 593 594 595

=cut

sub translationids_by_extids{
    my ($self,$name) = @_;
    return $self->_type_by_external_id($name,'Transcript');
}


Graham McVicker's avatar
Graham McVicker committed
596
=head2 rawContigids_by_extids
597

Graham McVicker's avatar
Graham McVicker committed
598 599 600 601 602 603
  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 
604 605 606 607 608 609 610 611 612

=cut

sub rawContigids_by_extids{
   my ($self,$name) = @_;
   return $self->_type_by_external_id($name,'rawContig');
}


613

614 615
=head2 _type_by_external_id

Graham McVicker's avatar
Graham McVicker committed
616 617 618 619 620 621
  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 
622 623 624 625 626 627 628 629

=cut

sub _type_by_external_id{
   my ($self,$name,$ensType) = @_;
   
my @out;

630

631 632
  my $sth = $self->prepare( "
    SELECT oxr.ensembl_id
633 634 635
    FROM xref, external_db exDB, object_xref oxr, external_synonym syn 
     WHERE (xref.dbprimary_acc = '$name'
            AND xref.xref_id = oxr.xref_id
636
            AND oxr.ensembl_object_type = '$ensType')
637 638
     OR    (xref.display_label = '$name'
            AND xref.xref_id = oxr.xref_id
639 640
            AND oxr.ensembl_object_type = '$ensType')
     OR    (syn.synonym = '$name'
641
            AND syn.xref_id = oxr.xref_id
642 643 644 645 646 647 648 649 650 651 652 653 654
            AND oxr.ensembl_object_type = '$ensType')
         " );

   $sth->execute();
   while ( my $arrRef = $sth->fetchrow_arrayref() ) {
       my ( $ensID) =
	   @$arrRef;;
       push (@out,$ensID);
     }
   
   return @out;
}

655

Graham McVicker's avatar
Graham McVicker committed
656 657 658 659 660 661 662 663 664 665 666 667

=head2 create_tables

  Arg [1]    : 
  Example    : 
  Description: 
  Returntype : 
  Exceptions : 
  Caller     : 

=cut

668 669 670 671 672
# creates all tables for this adaptor
# if they exist they are emptied and newly created
sub create_tables {
  my $self = shift;

673
  my $sth = $self->prepare( "drop table if exists object_xref, xref, externalDescription, external_synonym, external_db" );
674 675 676
  $sth->execute();

  $sth = $self->prepare( qq{
677 678 679 680 681 682 683 684 685 686 687
    
    CREATE TABLE object_xref(
			     object_xref_id INT not null auto_increment,
			     ensembl_id int unsigned not null, 
			     ensembl_object_type ENUM( 'RawContig', 'Transcript', 'Gene', 'Translation' ) not null,
			     xref_id INT unsigned not null,
			     
			     UNIQUE ( ensembl_object_type, ensembl_id, xref_id ),
			     KEY xref_index( object_xref_id, xref_id, ensembl_object_type, ensembl_id )
			    );
  } );
688 689
  $sth->execute();
  $sth = $self->prepare( qq{
690 691 692 693 694 695 696 697 698 699 700 701 702
    CREATE TABLE xref (
		       xref_id INT unsigned not null auto_increment,
		       external_db_id int not null,
		       dbprimary_acc VARCHAR(40) not null,
		       display_label VARCHAR(40) not null,
		       version VARCHAR(10) DEFAULT '' NOT NULL,
		       description VARCHAR(255),
		       
		       PRIMARY KEY( xref_id ),
		       UNIQUE KEY id_index( dbprimary_acc, external_db_id ),
		       KEY display_index ( display_label )
		      );
    
703 704 705 706 707
   } );

  $sth->execute();

  $sth = $self->prepare( qq{
708 709
     CREATE TABLE external_synonym(
         xref_id INT not null,
710
         synonym VARCHAR(40) not null,
711
         PRIMARY KEY( xref_id, synonym ),
712 713 714 715 716
	 KEY nameIdx( synonym )) 
   } );
  $sth->execute();

  $sth = $self->prepare( qq{
717 718
     CREATE TABLE external_db(
         external_db_id INT not null auto_increment,
719 720
         db_name VARCHAR(40) not null,
	 release VARCHAR(40),
721
         PRIMARY KEY( external_db_id ) ) 
722 723 724 725 726 727
   } );
  $sth->execute();
}



Graham McVicker's avatar
Graham McVicker committed
728
=head2 fetch_by_translation
729

Graham McVicker's avatar
Graham McVicker committed
730 731 732 733 734 735 736 737 738 739 740
  Arg [1]    : none
  Example    : none
  Description: DEPRECATED use fetch_by_Translation instead
  Returntype : none
  Exceptions : none
  Caller     : none

=cut

sub fetch_by_translation {
  my ($self, $trans_id) = @_;
741

Graham McVicker's avatar
Graham McVicker committed
742 743
  $self->warn("fetch_by_translation has been renamed fetch_by_Translation");
  my $trans = $self->db->get_TranslationAdaptor->fetch_by_dbID($trans_id);
744

Graham McVicker's avatar
Graham McVicker committed
745
  return $self->fetch_by_Translation($trans);
746 747
}

Graham McVicker's avatar
Graham McVicker committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768


=head2 fetch_by_rawContig

  Arg [1]    : none
  Example    : none
  Description: DEPRECATED use Bio::EnsEMBL::fetch_by_rawContig instead
  Returntype : none
  Exceptions : none
  Caller     : none

=cut

sub fetch_by_rawContig {
  my ( $self, $rawContigId ) = @_;
  
  $self->warn("fetch_by_rawContig has been renamed fetch_by_RawContig");
  my $contig = 
    $self->db->get_RawContigAdaptor->fetch_by_dbID($rawContigID);

  return $self->fetch_by_RawContig( $contig );
769 770
}

Graham McVicker's avatar
Graham McVicker committed
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798


=head2 fetch_by_transcript

  Arg [1]    : none
  Example    : none
  Description: DEPRECATED fetch_by_Transcript instead
  Returntype : none
  Exceptions : none
  Caller     : none

=cut

sub fetch_by_transcript {
  my ( $self, $trans ) = @_;

  $self->warn("fetch_by_transcript has been renamed fetch_by_Transcript");

  return $self->fetch_by_Transcript($trans);
}


1;


__END__


799
Objectxref
800 801 802
=============
ensembl_id varchar, later int
ensembl_object_type  enum 
803 804
xref_id int
primary key (ensembl_id,ensembl_object_type,xref_id) 
805 806


807
xref
808
=================
809 810 811
xref_id int (autogenerated) 
external_db_id int
dbprimary_acc  varchar
812 813
version varchar

814
primary key (xref_id)
815 816 817

ExternalDescription
=======================
818
xref_id int
819 820
description varchar (256)

821
primary key (xref_id)
822 823 824

ExternalSynonym
=================
825
xref_id int
826 827 828 829 830 831 832
synonym varchar

primary key (external_id,synonym)


ExternalDB
===================
833
external_db_id int
834 835 836
db_name varchar
release varchar