From 6c8aeef4dfd2d98abf53d9a118a045675f8f22f1 Mon Sep 17 00:00:00 2001
From: Monika Komorowska <mk8@sanger.ac.uk>
Date: Mon, 3 Oct 2011 15:23:37 +0000
Subject: [PATCH] stable_id merge changes

---
 modules/t/archiveStableId.t                   |  1 -
 modules/t/exon.t                              | 11 ++--
 modules/t/gene.t                              | 24 +++++---
 modules/t/info_testdb.pl                      | 13 ++--
 modules/t/operon.t                            | 59 ++++++++++++++++++-
 modules/t/operon_transcript.t                 | 24 +++++++-
 .../homo_sapiens/core/meta.txt                |  1 +
 modules/t/transcript.t                        | 17 +++---
 modules/t/translation.t                       | 24 ++++++--
 9 files changed, 136 insertions(+), 38 deletions(-)

diff --git a/modules/t/archiveStableId.t b/modules/t/archiveStableId.t
index d4c08f038b..f03dcc28dd 100644
--- a/modules/t/archiveStableId.t
+++ b/modules/t/archiveStableId.t
@@ -154,7 +154,6 @@ ok( ! $asi->is_latest );
 $asi = $asi->get_latest_incarnation;
 ok( $asi->is_latest and $asi->version == 3 );
 
-
 #
 # 19 associated IDs in archive
 #
diff --git a/modules/t/exon.t b/modules/t/exon.t
index 722f3cf5f9..478d2c82f0 100644
--- a/modules/t/exon.t
+++ b/modules/t/exon.t
@@ -181,18 +181,18 @@ ok($first_seq->seq() && $first_seq->seq() eq $second_seq->seq());
 ok($first_seq->display_id()  && $first_seq->display_id() eq $second_seq->display_id());
 
 
-
 #
 # test the remove method works
 #
-$multi->save("core", "exon", "exon_stable_id", "supporting_feature",
+
+$multi->save("core", "exon", "supporting_feature",
   "dna_align_feature", "protein_align_feature");
 
 my $ex_count = count_rows($db, 'exon');
-my $exstable_count = count_rows($db, 'exon_stable_id');
 my $supfeat_count = count_rows($db, 'supporting_feature');
 
 $exon = $exonad->fetch_by_stable_id('ENSE00000859937');
+
 # check the created and modified times
 my @date_time = localtime( $exon->created_date());
 ok( $date_time[3] == 6 && $date_time[4] == 11 && $date_time[5] == 104 );
@@ -206,7 +206,6 @@ my $supfeat_minus = @{$exon->get_all_supporting_features()};
 $exonad->remove($exon);
 
 ok(count_rows($db, 'exon') == $ex_count - 1);
-ok(count_rows($db, 'exon_stable_id') == $exstable_count - 1);
 ok(count_rows($db, 'supporting_feature') == $supfeat_count - $supfeat_minus);
 
 $multi->restore();
@@ -291,3 +290,7 @@ ok( $exon->cdna_coding_end($transcript) == 462 );
 ok( $exon->coding_region_start($transcript) == 30577779 );
 ok( $exon->coding_region_end($transcript) == 30578038 );
 
+#test the get_species_and_object_type method from the Registry
+my $registry = 'Bio::EnsEMBL::Registry';
+my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENSE00000859937');
+ok( $species eq 'homo_sapiens' && $object_type eq 'Exon');
diff --git a/modules/t/gene.t b/modules/t/gene.t
index 5fe756baec..96c5fa0093 100644
--- a/modules/t/gene.t
+++ b/modules/t/gene.t
@@ -3,7 +3,7 @@ use warnings;
 
 BEGIN { $| = 1;
 	use Test;
-	plan tests => 93;
+	plan tests => 94;
 }
 
 use Bio::EnsEMBL::Test::MultiTestDB;
@@ -284,7 +284,7 @@ my $stable_id = 'ENSG00000171456';
 $gene->description($desc);
 $gene->stable_id($stable_id);
 
-$multi->hide( "core", "meta_coord", "gene", "transcript", "exon", "exon_transcript", "translation", "gene_stable_id", "transcript_stable_id", "exon_stable_id", "translation_stable_id", "supporting_feature", "dna_align_feature" );
+$multi->hide( "core", "meta_coord", "gene", "transcript", "exon", "exon_transcript", "translation", "supporting_feature", "dna_align_feature" );
 
 my $gene_ad = $db->get_GeneAdaptor();
 debug( "Storing the gene" );
@@ -527,10 +527,9 @@ ok( $ok );
 # Gene remove test
 #
 
-$multi->save( "core", "gene", "gene_stable_id",
-	      "transcript", "transcript_stable_id",
-	      "translation", "translation_stable_id", "protein_feature",
-	      "exon", "exon_stable_id", "exon_transcript", "supporting_feature",
+$multi->save( "core", "gene", "transcript", 
+	      "translation", "protein_feature",
+	      "exon", "exon_transcript", "supporting_feature",
 	      "object_xref", "ontology_xref", "identity_xref",
         "dna_align_feature", "protein_align_feature");
 
@@ -540,7 +539,6 @@ my $gene_count = count_rows( $db, "gene" );
 my $exon_count = count_rows( $db, "exon" );
 my $trans_count = count_rows( $db, "transcript" );
 my $tl_count = count_rows( $db, "translation" );
-my $gstable_count = count_rows($db, "gene_stable_id");
 
 my $tminus = scalar( @{$gene->get_all_Transcripts() } );
 my $eminus = scalar( @{$gene->get_all_Exons() } );
@@ -557,7 +555,6 @@ $ga->remove( $gene );
 ok( count_rows( $db, "gene" ) == ( $gene_count - 1 ));
 ok( count_rows( $db, "transcript" ) == ($trans_count-$tminus));
 ok( count_rows( $db, "exon" ) == ( $exon_count - $eminus ));
-ok( count_rows( $db, "gene_stable_id" ) == ($gstable_count -1));
 
 ok(!defined($gene->dbID()));
 ok(!defined($gene->adaptor()));
@@ -688,6 +685,10 @@ $gene = $ga->fetch_by_translation_stable_id('ENSP00000355555');
 debug("fetch_by_translation_stable_id");
 ok( $gene->dbID == 18275 );
 
+$gene = $ga->fetch_by_exon_stable_id('ENSE00001109603');
+debug("fetch_by_exon_stable_id");
+ok( $gene->dbID == 18275 );
+
 @genes = @{ $ga->fetch_all_by_external_name('PAL2_HUMAN') };
 debug( "fetch_all_by_external_name" );
 ok( scalar(@genes) == 1 && $genes[0]->dbID == 18264 );
@@ -712,7 +713,7 @@ foreach my $t (@{ $gene->get_all_Transcripts }) {
 }
 
 $multi->hide( "core", "gene", "transcript", "exon", 'xref', 'object_xref',
-              "exon_transcript", "translation", "gene_stable_id" );
+              "exon_transcript", "translation" );
 
 $gene->version(3);
 $gene->dbID(undef);
@@ -786,3 +787,8 @@ ok(@{$utaa->fetch_all_by_gene($new_gene)} == 0);
 $new_gene = $ga->fetch_by_dbID(18256);
 ok($new_gene->canonical_transcript->dbID == 21716);  #test 85
 ok($new_gene->canonical_annotation eq 'longest transcript in gene'); #test 86
+
+#test the get_species_and_object_type method from the Registry
+my $registry = 'Bio::EnsEMBL::Registry';
+my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENSG00000355555');
+ok( $species eq 'homo_sapiens' && $object_type eq 'Gene');
diff --git a/modules/t/info_testdb.pl b/modules/t/info_testdb.pl
index fd7f48d0d0..66fc867f86 100644
--- a/modules/t/info_testdb.pl
+++ b/modules/t/info_testdb.pl
@@ -93,7 +93,7 @@ if( $print_contig ) {
 if( $print_gene ) {
 
   print "Gene ids and names\n";
-  $sth = $db->prepare( "select gene_id, stable_id from gene_stable_id" );
+  $sth = $db->prepare( "select gene_id, stable_id from gene" );
   $sth->execute();
   $sth->bind_columns( \$id, \$name );
   while( $sth->fetch() ) {
@@ -104,7 +104,7 @@ if( $print_gene ) {
 
 if( $print_transcript ) {
   print "Transcript ids and names.\n";
-  $sth = $db->prepare( "select transcript_id, stable_id from transcript_stable_id" );
+  $sth = $db->prepare( "select transcript_id, stable_id from transcript" );
   $sth->execute();
   $sth->bind_columns( \$id, \$name );
   while( $sth->fetch() ) {
@@ -114,7 +114,7 @@ if( $print_transcript ) {
 
 if( $print_translation ) {
   print "Translations ids and names\n";
-  $sth = $db->prepare( "select translation_id, stable_id from translation_stable_id" );
+  $sth = $db->prepare( "select translation_id, stable_id from translation" );
   $sth->execute();
   $sth->bind_columns( \$id, \$name );
   while( $sth->fetch() ) {
@@ -125,11 +125,10 @@ if( $print_translation ) {
 if( $print_exon ) {
   print "Exon information\n";
   $sth = $db->prepare( "
-     select et.transcript_id, e.exon_id, esi.stable_id, 
+     select et.transcript_id, e.exon_id, 
             e.contig_id, e.contig_start, e.contig_end, e.contig_strand 
-       from exon e, exon_stable_id esi, exon_transcript et
-      where e.exon_id = esi.exon_id
-        and e.exon_id = et.exon_id    
+       from exon e, exon_transcript et
+      where e.exon_id = et.exon_id    
       order by et.transcript_id, et.rank, e.sticky_rank
 " );
   $sth->execute();
diff --git a/modules/t/operon.t b/modules/t/operon.t
index b5c8bfc7c9..003f875a9c 100644
--- a/modules/t/operon.t
+++ b/modules/t/operon.t
@@ -4,7 +4,7 @@ use warnings;
 BEGIN {
 	$| = 1;
 	use Test;
-	plan tests => 15;
+	plan tests => 24;
 }
 use Bio::EnsEMBL::DBEntry;
 use Bio::EnsEMBL::Operon;
@@ -70,3 +70,60 @@ ok( $operon2->analysis(),
 	$operon->analysis(),
 	"Analysis" );
 
+#test the get_species_and_object_type method from the Registry
+my $registry = 'Bio::EnsEMBL::Registry';
+my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('16152-16153-4840');
+ok( $species eq 'homo_sapiens' && $object_type eq 'Operon');
+
+
+debug ("Operon->list_stable_ids");
+my $stable_ids = $operon_adaptor->list_stable_ids();
+ok (@{$stable_ids});
+
+
+$operon = $operon_adaptor->fetch_by_stable_id('16152-16153-4840');
+debug( "Operon->fetch_by_stable_id()" );
+ok( $operon );
+
+#19
+my @operons = @{ $operon_adaptor->fetch_all_versions_by_stable_id('16152-16153-4840') };
+debug("fetch_all_versions_by_stable_id");
+ok( scalar(@operons) == 1 );
+
+
+#20
+
+$operon = $operon_adaptor->fetch_by_operon_transcript_stable_id('T16152-16153-4840');
+debug( "Operon->fetch_by_operon_transcript_stable_id()" );
+ok( $operon );
+
+
+#21-24
+
+#
+# Operon remove test
+#
+
+$multi->save( "core", "operon", "operon_transcript",
+	      "object_xref", "ontology_xref", "identity_xref");
+
+$operon = $operon_adaptor->fetch_by_stable_id( "16152-16153-4840" );
+
+my $operon_count = count_rows( $dba, "operon" );
+my $operon_trans_count = count_rows( $dba, "operon_transcript" );
+
+my $ots = scalar( @{$operon->get_all_OperonTranscripts() } );
+
+debug( "Operons before ".$operon_count );
+debug( "OperonTranscripts before ".$operon_trans_count );
+debug( "Operon has ".$ots." transcripts" );
+
+$operon_adaptor->remove( $operon );
+
+ok( count_rows( $dba, "operon" ) == ( $operon_count - 1 ));
+ok( count_rows( $dba, "operon_transcript" ) == ($operon_trans_count-$ots));
+
+ok(!defined($operon->dbID()));
+ok(!defined($operon->adaptor()));
+
+$multi->restore('core');
diff --git a/modules/t/operon_transcript.t b/modules/t/operon_transcript.t
index 25d96f5af0..78834abe52 100644
--- a/modules/t/operon_transcript.t
+++ b/modules/t/operon_transcript.t
@@ -4,7 +4,7 @@ use warnings;
 BEGIN {
 	$| = 1;
 	use Test;
-	plan tests => 46;
+	plan tests => 50;
 }
 use Bio::EnsEMBL::Test::MultiTestDB;
 use Bio::EnsEMBL::Test::TestUtils;
@@ -175,7 +175,7 @@ ok( $gene_r->seq_region_start(),  $gene->seq_region_start(),  "Gene start" );
 ok( $gene_r->seq_region_end(),    $gene->seq_region_end(),    "Gene end" );
 ok( $gene_r->seq_region_strand(), $gene->seq_region_strand(), "Gene strand" );
 $gene_r = $ogenes[1];
-ok( $gene_r->dbID(),$gene2->dbID(), "Gene ID" );
+ok( $gene_r->dbID(),		  $gene2->dbID(),	       "Gene ID" );
 ok( $gene_r->seq_region_start(),  $gene2->seq_region_start(),  "Gene start" );
 ok( $gene_r->seq_region_end(),    $gene2->seq_region_end(),    "Gene end" );
 ok( $gene_r->seq_region_strand(), $gene2->seq_region_strand(), "Gene strand" );
@@ -208,3 +208,23 @@ $dba->get_OperonAdaptor()->remove($operon);
 $dba->get_GeneAdaptor()->remove($gene);
 $dba->get_GeneAdaptor()->remove($gene2);
 
+#test the get_species_and_object_type method from the Registry
+my $registry = 'Bio::EnsEMBL::Registry';
+my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('T16152-16153-4840');
+ok( $species eq 'homo_sapiens' && $object_type eq 'OperonTranscript');
+
+#48
+my $ota = $dba->get_OperonTranscriptAdaptor();
+$operon_transcript = $ota->fetch_by_stable_id('T16152-16153-4840');
+debug( "OperonTranscript->fetch_by_stable_id()" );
+ok( $operon_transcript );
+
+#49
+@operon_transcripts = @{ $ota->fetch_all_versions_by_stable_id('T16152-16153-4840') };
+debug("fetch_all_versions_by_stable_id");
+ok( scalar(@operon_transcripts) == 1 );
+
+#50
+debug ("OperonTranscript->list_stable_ids");
+my $stable_ids = $ota->list_stable_ids();
+ok (@{$stable_ids});
diff --git a/modules/t/test-genome-DBs/homo_sapiens/core/meta.txt b/modules/t/test-genome-DBs/homo_sapiens/core/meta.txt
index 53e1585571..306d7039f4 100644
--- a/modules/t/test-genome-DBs/homo_sapiens/core/meta.txt
+++ b/modules/t/test-genome-DBs/homo_sapiens/core/meta.txt
@@ -22,3 +22,4 @@
 64	1	assembly.mapping	chromosome:NCBI33#chunk
 65	1	assembly.mapping	alt_chrom#chromosome:NCBI33
 66	1	assembly.mapping	alt_chrom|chromosome:NCBI33|contig
+67	1	species.production_name	homo_sapiens
diff --git a/modules/t/transcript.t b/modules/t/transcript.t
index 43de3cdfbc..7d1a15cce9 100644
--- a/modules/t/transcript.t
+++ b/modules/t/transcript.t
@@ -315,15 +315,14 @@ ok(!defined($five_prime));
 my $tl_count = count_rows($db, "translation");
 my $ex_tr_count = count_rows($db, "exon_transcript");
 my $tr_count = count_rows($db, "transcript");
-my $trstable_count = count_rows($db, "transcript_stable_id");
 
 my $ex_tr_minus = @{$tr->get_all_Exons()};
 
 
 
-$multi->save("core", "transcript", "transcript_stable_id", "translation",
-             "translation_stable_id", "protein_feature", "exon",
-             "exon_stable_id", "exon_transcript", "object_xref",
+$multi->save("core", "transcript", "translation",
+             "protein_feature", "exon",
+             "exon_transcript", "object_xref",
              "supporting_feature", "dna_align_feature","protein_align_feature",
              "ontology_xref", "identity_xref");
 
@@ -335,7 +334,6 @@ ok(!defined($tr->adaptor()));
 ok( count_rows( $db, "transcript") == ($tr_count - 1));
 ok( count_rows( $db, "translation") == ($tl_count - 1));
 ok( count_rows( $db, "exon_transcript") == ($ex_tr_count - $ex_tr_minus));
-ok( count_rows( $db, "transcript_stable_id") == ($trstable_count - 1));
 
 #
 # test _rna_edit for transcripts
@@ -477,8 +475,7 @@ $tr->adaptor(undef);
 }
 
 $multi->hide('core', 'transcript', 'transcript_attrib', 'translation',
-             'exon_transcript', 'exon', 'exon_stable_id', 
-             'transcript_stable_id', 'translation_stable_id');
+             'exon_transcript', 'exon');
 
 
 my $attrib1 = Bio::EnsEMBL::Attribute->new
@@ -545,7 +542,7 @@ $g = $db->get_GeneAdaptor->fetch_by_transcript_id($tr->dbID);
 $tr->get_all_Exons;
 
 $multi->hide( "core", "gene", "transcript", "exon", 'xref', 'object_xref',
-              "exon_transcript", "translation", "transcript_stable_id" );
+              "exon_transcript", "translation" );
 
 $tr->version(3);
 $tr->dbID(undef);
@@ -716,3 +713,7 @@ sub print_coords {
   }
 }
 
+#test the get_species_and_object_type method from the Registry
+my $registry = 'Bio::EnsEMBL::Registry';
+my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENST00000355555');
+ok( $species eq 'homo_sapiens' && $object_type eq 'Transcript');
diff --git a/modules/t/translation.t b/modules/t/translation.t
index 9525aa43d2..06b66581ad 100644
--- a/modules/t/translation.t
+++ b/modules/t/translation.t
@@ -8,7 +8,7 @@ use Bio::EnsEMBL::Exon;
 BEGIN {
     $| = 1;
     use Test;
-    plan tests => 40;
+    plan tests => 41;
 }
 
 my $loaded = 0;
@@ -154,12 +154,11 @@ ok(length($seq) == $translation->length());
 # test remove method
 #
 
-$multi->save('core', 'translation', 'translation_stable_id',
+$multi->save('core', 'translation',
              'protein_feature', 'object_xref', 'identity_xref',
              'ontology_xref');
 
 my $tl_count = count_rows($db, 'translation');
-my $tlstable_count = count_rows($db, 'translation_stable_id');
 my $pfeat_count = count_rows($db, 'protein_feature');
 
 
@@ -171,7 +170,6 @@ ok(!defined($translation->dbID));
 ok(!defined($translation->adaptor()));
 
 ok(count_rows($db, 'translation') == $tl_count - 1);
-ok(count_rows($db, 'translation_stable_id') == $tlstable_count - 1);
 ok(count_rows($db, 'protein_feature') == $pfeat_count - $pfeat_minus);
 
 #
@@ -259,8 +257,7 @@ $tl->adaptor(undef);
 $tl->dbID(undef);
 
 
-$multi->hide('core', 'transcript', 'translation_attrib', 'translation',
-             'translation_stable_id');
+$multi->hide('core', 'transcript', 'translation_attrib', 'translation');
 
 
 # add a couple of attributes to the translation
@@ -295,3 +292,18 @@ ok( $tl->cdna_end() == 1690 );
 
 ok( $tl->genomic_start() == 30572315 );
 ok( $tl->genomic_end() == 30578038 );
+
+#test the get_species_and_object_type method from the Registry
+my $registry = 'Bio::EnsEMBL::Registry';
+my ( $species, $object_type, $db_type ) = $registry->get_species_and_object_type('ENSP00000201961');
+ok( $species eq 'homo_sapiens' && $object_type eq 'Translation');
+
+
+#41
+
+my @alt_tls = @{
+      $ta->fetch_all_alternative_by_Transcript(
+                                                            $tr)
+      };
+
+ok(!scalar(@alt_tls))
-- 
GitLab