From 1f63d134f5c7307222ad46eea51f8dc47f491b96 Mon Sep 17 00:00:00 2001
From: Glenn Proctor <gp1@sanger.ac.uk>
Date: Thu, 23 Feb 2006 16:21:09 +0000
Subject: [PATCH] Added info_type and info_text to xref.

---
 modules/Bio/EnsEMBL/DBEntry.pm              | 64 +++++++++++++++++++--
 modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm | 44 +++++++++-----
 modules/t/dbEntries.t                       |  4 +-
 sql/table.sql                               |  5 +-
 4 files changed, 96 insertions(+), 21 deletions(-)

diff --git a/modules/Bio/EnsEMBL/DBEntry.pm b/modules/Bio/EnsEMBL/DBEntry.pm
index 9382690fd1..f999c465bb 100644
--- a/modules/Bio/EnsEMBL/DBEntry.pm
+++ b/modules/Bio/EnsEMBL/DBEntry.pm
@@ -85,7 +85,9 @@ sub new_fast {
 						       -primary_id_linkable =>$primary_id_linkable,
 						       -display_id_linkable =>$display_id_linkable,
 						       -priority => $priority,
-						       -db_display_name => $db_display_name );
+						       -db_display_name => $db_display_name,
+						       -info_type => $info_type,
+						       -info_text => $info_text);
   Description: Creates a new DBEntry object
   Returntype : Bio::EnsEMBL::DBEntry
   Exceptions : none
@@ -104,11 +106,12 @@ sub new {
 
   my ( $adaptor, $dbID, $primary_id, $version,
        $dbname, $release, $display_id, $description,
-       $primary_id_linkable, $display_id_linkable, $priority, $db_display_name) =
+       $primary_id_linkable, $display_id_linkable, $priority, 
+       $db_display_name, $info_type, $info_text) =
     rearrange ( ['ADAPTOR','DBID','PRIMARY_ID','VERSION',
                  'DBNAME','RELEASE','DISPLAY_ID','DESCRIPTION',
 		 'PRIMARY_ID_LINKABLE','DISPLAY_ID_LINKABLE','PRIORITY',
-		 'DB_DISPLAY_NAME'], @args );
+		 'DB_DISPLAY_NAME', 'INFO_TYPE', 'INFO_TEXT'], @args );
 
   $self->{'adaptor'} = $adaptor;
   $self->{'dbID'}    = $dbID;
@@ -124,6 +127,8 @@ sub new {
   if( defined $display_id_linkable) { $self->display_id_linkable($display_id_linkable) }
   if( defined $priority) { $self->priority($priority) }
   if( defined $db_display_name) { $self->db_display_name($db_display_name) }
+  if( defined $info_type) { $self->db_display_name($info_type) }
+  if( defined $info_text) { $self->db_display_name($info_text) }
   $self->{synonyms} = [];;
 
   return $self;
@@ -377,7 +382,7 @@ sub priority {
   Arg [1]    : String $db_display_name
   Example    : none
   Db_display_name: get/set for attribute db_display_name
-  Returntype : string
+  Returntype : string; has "Projected " prepended if info_type='PROJECTION'
   Exceptions : none
   Caller     : general
 
@@ -387,10 +392,59 @@ sub db_display_name {
   my ( $self, $arg ) = @_;
   if( defined $arg ) {
     $self->{db_display_name} = $arg;
+  }
+
+  my $name;
+  if ($self->{info_type} eq "PROJECTION") {
+    $name = "Projected " . $self->{db_display_name};
+  } else {
+    $name =  $self->{db_display_name};
+  }
+
+  return $name;
+}
+
+
+=head2 info_type
+
+  Arg [1]    : String $info_type
+  Example    : none
+  Info_type: get/set for attribute info_type
+  Returntype : string
+  Exceptions : none
+  Caller     : general
+
+=cut
+
+sub info_type {
+  my ( $self, $arg ) = @_;
+  if( defined $arg ) {
+    $self->{info_type} = $arg;
+  } 
+  return $self->{info_type};
+}
+
+
+=head2 info_text
+
+  Arg [1]    : String $info_text
+  Example    : none
+  Info_text: get/set for attribute info_text
+  Returntype : string
+  Exceptions : none
+  Caller     : general
+
+=cut
+
+sub info_text {
+  my ( $self, $arg ) = @_;
+  if( defined $arg ) {
+    $self->{info_text} = $arg;
   } 
-  return $self->{db_display_name};
+  return $self->{info_text};
 }
 
+
 =head2 add_synonym
 
   Arg  1     : string $synonym
diff --git a/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm
index 1b6fc54fd9..3bab0c8299 100644
--- a/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm
@@ -66,7 +66,8 @@ sub fetch_by_dbID {
    "SELECT xref.xref_id, xref.dbprimary_acc, xref.display_label,
            xref.version, xref.description,
            exDB.dbprimary_acc_linkable, exDB.display_label_linkable, exDB.priority,
-           exDB.db_name, exDB.db_display_name, exDB.release, es.synonym
+           exDB.db_name, exDB.db_display_name, exDB.release, es.synonym,
+           exDB.info_type, exDB.info_text
     FROM   xref, external_db exDB
     LEFT JOIN external_synonym es on es.xref_id = xref.xref_id
     WHERE  xref.xref_id = ?
@@ -80,7 +81,8 @@ sub fetch_by_dbID {
   while ( my $arrayref = $sth->fetchrow_arrayref()){
     my ( $refID, $dbprimaryId, $displayid, $version, $desc,
 	 $primary_id_linkable, $display_id_linkable, $priority,
-         $dbname, $db_display_name, $release, $synonym) = @$arrayref;
+         $dbname, $db_display_name, $release, $synonym, 
+	 $info_type, $info_text) = @$arrayref;
 
     if(!$exDB) {
       $exDB = Bio::EnsEMBL::DBEntry->new
@@ -94,7 +96,9 @@ sub fetch_by_dbID {
 	  -primary_id_linkable => $primary_id_linkable,
 	  -display_id_linkable => $display_id_linkable,
 	  -priority => $priority,
-	  -db_display_name => $db_display_name);
+	  -db_display_name => $db_display_name,
+	  -info_type => $info_type,
+	  -info_text => $info_text);
 
       $exDB->description( $desc ) if ( $desc );
     }
@@ -137,7 +141,8 @@ sub fetch_by_db_accession {
    "SELECT xref.xref_id, xref.dbprimary_acc, xref.display_label,
            xref.version, xref.description,
            exDB.dbprimary_acc_linkable, exDB.display_label_linkable, exDB.priority,
-           exDB.db_name, exDB.db_display_name, exDB.release, es.synonym
+           exDB.db_name, exDB.db_display_name, exDB.release, es.synonym,
+           exDB.info_type, exDB.info_text
     FROM   xref, external_db exDB
     LEFT JOIN external_synonym es on es.xref_id = xref.xref_id
     WHERE  xref.dbprimary_acc = ?
@@ -168,7 +173,7 @@ sub fetch_by_db_accession {
   while ( my $arrayref = $sth->fetchrow_arrayref()){
     my ( $dbID, $dbprimaryId, $displayid, $version, $desc, $dbname,$db_display_name,
 	 $primary_id_linkable, $display_id_linkable, $priority,
-         $release, $synonym) = @$arrayref;
+         $release, $synonym, $info_type, $info_text) = @$arrayref;
 
     if(!$exDB) {
       $exDB = Bio::EnsEMBL::DBEntry->new
@@ -182,7 +187,9 @@ sub fetch_by_db_accession {
 	  -primary_id_linkable => $primary_id_linkable,
 	  -display_id_linkable => $display_id_linkable,
 	  -priority => $priority,
-	  -db_display_name=>$db_display_name);
+	  -db_display_name=>$db_display_name,
+	  -info_type => $info_type,
+	  -info_text => $info_text);
 
       $exDB->description( $desc ) if ( $desc );
     }
@@ -269,12 +276,17 @@ sub store {
            display_label = ?,
            version = ?,
            description = ?,
-           external_db_id = ?");
-    $sth->bind_param(1,$exObj->primary_id,SQL_VARCHAR);
-    $sth->bind_param(2,$exObj->display_id,SQL_VARCHAR);
-    $sth->bind_param(3,$exObj->version,SQL_VARCHAR);
-    $sth->bind_param(4,$exObj->description,SQL_VARCHAR);
-    $sth->bind_param(5,$dbRef,SQL_INTEGER);
+           external_db_id = ?,
+           info_type = ?,
+           info_text = ?");
+    $sth->bind_param(1, $exObj->primary_id,SQL_VARCHAR);
+    $sth->bind_param(2, $exObj->display_id,SQL_VARCHAR);
+    $sth->bind_param(3, $exObj->version,SQL_VARCHAR);
+    $sth->bind_param(4, $exObj->description,SQL_VARCHAR);
+    $sth->bind_param(5, $dbRef,SQL_INTEGER);
+    $sth->bind_param(6, $exObj->info_type, SQL_VARCHAR);
+    $sth->bind_param(7, $exObj->info_text, SQL_VARCHAR);
+
     $sth->execute();
 
     $dbX = $sth->{'mysql_insertid'};
@@ -653,7 +665,8 @@ sub _fetch_by_object_type {
            idt.query_identity, idt.target_identity, idt.hit_start,
            idt.hit_end, idt.translation_start, idt.translation_end,
            idt.cigar_line, idt.score, idt.evalue, idt.analysis_id,
-           gx.linkage_type
+           gx.linkage_type,
+           xref.info_type, xref.info_text
     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
@@ -676,7 +689,8 @@ sub _fetch_by_object_type {
          $dbname, $release, $exDB_status, $exDB_db_display_name, $objid,
          $synonym, $queryid, $targetid, $query_start, $query_end,
          $translation_start, $translation_end, $cigar_line,
-         $score, $evalue, $analysis_id, $linkage_type ) = @$arrRef;
+         $score, $evalue, $analysis_id, $linkage_type,
+	 $info_type, $info_text) = @$arrRef;
 
     my %obj_hash = ( 
 		    'adaptor'    => $self,
@@ -726,6 +740,8 @@ sub _fetch_by_object_type {
       $exDB->display_id_linkable($display_id_linkable);
       $exDB->priority($priority);
       $exDB->db_display_name($exDB_db_display_name);
+      $exDB->info_type($info_type);
+      $exDB->info_text($info_text);
 
       push( @out, $exDB );
       $seen{$refID} = $exDB;
diff --git a/modules/t/dbEntries.t b/modules/t/dbEntries.t
index 16a8a0eb02..8152408221 100644
--- a/modules/t/dbEntries.t
+++ b/modules/t/dbEntries.t
@@ -89,7 +89,9 @@ my $xref = Bio::EnsEMBL::DBEntry->new
    -primary_id_linkable => "0",
    -display_id_linkable => "1",
    -priority => "5",
-   -db_display_name => "Nice friendly name"
+   -db_display_name => "Nice friendly name",
+   -info_type => "PROJECTION",
+   -info_text => "from human gene ENSG0000011111"
    );
 
 
diff --git a/sql/table.sql b/sql/table.sql
index e7564a3295..adb4dcdfc6 100755
--- a/sql/table.sql
+++ b/sql/table.sql
@@ -655,10 +655,13 @@ CREATE TABLE xref (
    display_label              VARCHAR(128) not null,
    version                    VARCHAR(10) DEFAULT '' NOT NULL,
    description                VARCHAR(255),
+   info_type                  ENUM('PROJECTION', 'MISC'),
+   info_text                  VARCHAR(255),
 
    PRIMARY KEY( xref_id ),
    UNIQUE KEY id_index( dbprimary_acc, external_db_id ),
-   KEY display_index ( display_label )
+   KEY display_index ( display_label ),
+   KEY info_type_idx ( info_type )
 
 ) COLLATE=latin1_swedish_ci;
 
-- 
GitLab