Commit 56f2d59f authored by James Allen's avatar James Allen
Browse files

Set an object's default version to 1 when it is created, rather than when it...

Set an object's default version to 1 when it is created, rather than when it is stored, to allow undef versions (which can then be stored as NULLs in the database).
parent 985f2e36
......@@ -383,9 +383,8 @@ sub store {
if ( defined($exon->stable_id) ) {
$exonst->bind_param( 9, $exon->stable_id, SQL_VARCHAR );
my $version = ($exon->version()) ? $exon->version() : 1;
$exonst->bind_param( 10, $version, SQL_INTEGER );
$exonst->bind_param( 9, $exon->stable_id, SQL_VARCHAR );
$exonst->bind_param( 10, $exon->version, SQL_INTEGER );
}
$exonst->execute();
......
......@@ -1340,8 +1340,7 @@ sub store {
if (defined($gene->stable_id)) {
$sth->bind_param(12, $gene->stable_id, SQL_VARCHAR);
my $version = ($gene->version()) ? $gene->version() : 1;
$sth->bind_param(13, $version, SQL_INTEGER);
$sth->bind_param(13, $gene->version, SQL_INTEGER);
}
$sth->execute();
......
......@@ -1174,8 +1174,7 @@ sub store {
if ( defined( $transcript->stable_id() ) ) {
$tst->bind_param( ++$i, $transcript->stable_id(), SQL_VARCHAR );
my $version = ($transcript->version()) ? $transcript->version() : 1;
$tst->bind_param( ++$i, $version, SQL_INTEGER );
$tst->bind_param( ++$i, $transcript->version(), SQL_INTEGER );
}
$tst->execute();
......
......@@ -522,8 +522,7 @@ sub store {
if (defined($translation->stable_id)) {
$sth->bind_param(6, $translation->stable_id,SQL_VARCHAR);
my $version = ($translation->version()) ? $translation->version() : 1;
$sth->bind_param(7, $version,SQL_VARCHAR);
$sth->bind_param(7, $translation->version,SQL_VARCHAR);
}
$sth->execute();
......
......@@ -138,10 +138,13 @@ sub new {
$self->{'end_phase'} = $end_phase;
$self->{'stable_id'} = $stable_id;
$self->{'version'} = $version;
$self->{'created_date'} = $created_date;
$self->{'modified_date'} = $modified_date;
# Default version
if ( !defined($version) ) { $version = 1 }
$self->{'version'} = $version;
# Default is_current
if ( !defined($is_current) ) { $is_current = 1 }
$self->{'is_current'} = $is_current;
......
......@@ -165,7 +165,6 @@ sub new {
}
$self->stable_id($stable_id);
$self->version($version);
$self->{'created_date'} = $created_date;
$self->{'modified_date'} = $modified_date;
......@@ -182,6 +181,10 @@ sub new {
$self->status($status); # add new naming
$self->source($source);
# Default version
if ( !defined($version) ) { $version = 1 }
$self->{'version'} = $version;
# default to is_current
$is_current = 1 unless (defined($is_current));
$self->{'is_current'} = $is_current;
......
......@@ -172,7 +172,6 @@ sub new {
}
$self->stable_id($stable_id);
$self->version($version);
$self->{'created_date'} = $created_date;
$self->{'modified_date'} = $modified_date;
$self->external_name($external_name) if ( defined $external_name );
......@@ -188,6 +187,10 @@ sub new {
$self->biotype($biotype);
$self->source($source);
# Default version
if ( !defined($version) ) { $version = 1 }
$self->{'version'} = $version;
# default is_current
$is_current = 1 unless ( defined($is_current) );
$self->{'is_current'} = $is_current;
......
......@@ -113,6 +113,9 @@ sub new {
rearrange( [ "START_EXON", "END_EXON", "SEQ_START", "SEQ_END",
"STABLE_ID", "VERSION", "DBID", "ADAPTOR",
"SEQ", "CREATED_DATE", "MODIFIED_DATE" ], @_ );
# Default version
if ( !defined($version) ) { $version = 1 }
my $self = bless {
'start_exon' => $start_exon,
......
......@@ -281,8 +281,7 @@ my $e1 = Bio::EnsEMBL::Exon->new(
-slice => $slice,
-phase => 0,
-end_phase => 0,
-stable_id => 'ENSE0001',
-version => 1
-stable_id => 'ENSE0001'
);
my $e2 = Bio::EnsEMBL::Exon->new(
......@@ -297,17 +296,40 @@ my $e2 = Bio::EnsEMBL::Exon->new(
-is_current => 0
);
my $e3 = Bio::EnsEMBL::Exon->new(
-start => 10,
-end => 1000,
-strand => 1,
-slice => $slice,
-phase => 0,
-end_phase => 0,
-stable_id => 'ENSE0001',
-is_current => 0
);
$e3->version(undef);
$exonad->store($e1);
$exonad->store($e2);
$exonad->store($e3);
$exon = $exonad->fetch_by_stable_id('ENSE0001');
ok( $exon->is_current == 1);
ok( $exon->version == 1);
@exons = @{ $exonad->fetch_all_versions_by_stable_id('ENSE0001') };
foreach my $e (@exons) {
next unless ($e->version == 2);
ok($e->is_current == 0);
if (defined $e->version && $e->version == 2) {
ok($e->is_current == 0);
}
}
my $null_versions = 0;
foreach my $e (@exons) {
if (! defined $e->version) {
$null_versions++;
}
}
is ( $null_versions, 1, "Null/undef version stored and retrieved");
$multi->restore();
......
......@@ -140,6 +140,11 @@ my $translation2 = Bio::EnsEMBL::Translation->new();
ok($gene);
is($gene->version, 1, 'Default gene version = 1');
is($transcript1->version, 1, 'Default transcript version = 1');
is($ex1->version, 1, 'Default exon version = 1');
is($translation1->version, 1, 'Default translation version = 1');
$ex1->start(13586);
$ex1->end(13735);
$ex1->phase(0);
......@@ -324,6 +329,9 @@ my $gene_out = $genes->[0];
#make sure the stable_id was stored
ok($gene_out->stable_id eq $stable_id);
#make sure the version was stored
ok($gene_out->version == 1);
#make sure the description was stored
ok($gene_out->description eq $desc);
......@@ -923,13 +931,20 @@ $gene->dbID(undef);
$gene->adaptor(undef);
$ga->store($gene);
$gene->version(undef);
$gene->is_current(0);
$gene->dbID(undef);
$gene->adaptor(undef);
$ga->store($gene);
$gene = $ga->fetch_by_stable_id('ENSG00000355555');
ok($gene->is_current == 1);
@genes = @{$ga->fetch_all_versions_by_stable_id('ENSG00000355555')};
foreach my $g (@genes) {
next unless ($g->version == 4);
ok($g->is_current == 0);
if (defined $g->version && $g->version == 4) {
ok($g->is_current == 0);
}
}
$gene->is_current(0);
......@@ -942,6 +957,13 @@ $ga->update($gene);
$gene = $ga->fetch_by_stable_id('ENSG00000355555');
ok($gene->is_current == 1);
my $null_versions = 0;
foreach my $g (@genes) {
if (! defined $g->version) {
$null_versions++;
}
}
is ( $null_versions, 1, "Null/undef version stored and retrieved");
$ga->remove_by_Slice($slice);
$geneCount = $ga->count_all_by_Slice($slice);
......
......@@ -71,15 +71,15 @@ my $db = $mtdb->get_DBAdaptor("core");
my $gtf_serializer = Bio::EnsEMBL::Utils::IO::GTFSerializer->new($fh);
$gtf_serializer->print_Gene($gene);
my $gtf = <<GTF;
20\tensembl\tgene\t30274331\t30274404\t.\t+\t.\tgene_id \"GENE\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\";
20\tensembl\ttranscript\t30274331\t30274404\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tSelenocysteine\t30274337\t30274339\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\texon\t30274331\t30274348\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; exon_number \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; exon_id \"e1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tCDS\t30274334\t30274345\t.\t+\t0\tgene_id \"GENE\"; transcript_id \"TRANS\"; exon_number \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; protein_id \"PEP\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\texon\t30274401\t30274404\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; exon_number \"2\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; exon_id \"e2\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tfive_prime_utr\t30274331\t30274333\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tthree_prime_utr\t30274346\t30274348\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tthree_prime_utr\t30274401\t30274404\t.\t+\t.\tgene_id \"GENE\"; transcript_id \"TRANS\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tgene\t30274331\t30274404\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\";
20\tensembl\ttranscript\t30274331\t30274404\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tSelenocysteine\t30274337\t30274339\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\texon\t30274331\t30274348\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; exon_number \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; exon_id \"e1\"; exon_version \"1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tCDS\t30274334\t30274345\t.\t+\t0\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; exon_number \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; protein_id \"PEP\"; protein_version \"1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\texon\t30274401\t30274404\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; exon_number \"2\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; exon_id \"e2\"; exon_version \"1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tfive_prime_utr\t30274331\t30274333\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tthree_prime_utr\t30274346\t30274348\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
20\tensembl\tthree_prime_utr\t30274401\t30274404\t.\t+\t.\tgene_id \"GENE\"; gene_version \"1\"; transcript_id \"TRANS\"; transcript_version \"1\"; gene_source \"ensembl\"; gene_biotype \"protein_coding\"; projection_parent_gene \"ENSG_PARENT_GENE\"; transcript_source \"ensembl\"; transcript_biotype \"protein_coding\"; tag \"CCDS\"; ccds_id \"CCDS.1\"; tag \"seleno\"; projection_parent_transcript "ENST_PARENT_TRANSCRIPT";
GTF
eq_or_diff(${$fh->string_ref}, $gtf, 'Checking custom Gene object dumps UTRs, Selenocysteine, seleno tag and CCDS');
}
......
......@@ -729,8 +729,9 @@ $tr = $ta->fetch_by_stable_id('ENST00000355555');
$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", 'meta_coord' );
my $tl = $tr->translation;
$multi->hide( "core", "gene", "transcript", "translation", "meta_coord" );
$tr->version(3);
$tr->dbID(undef);
......@@ -742,13 +743,23 @@ $tr->is_current(0);
$tr->dbID(undef);
$tr->adaptor(undef);
$ta->store($tr, $g->dbID);
$tr->version(undef);
$tr->is_current(0);
$tr->dbID(undef);
$tr->adaptor(undef);
$tl->version(undef);
$tr->translation($tl);
$ta->store($tr, $g->dbID);
$tr = $ta->fetch_by_stable_id('ENST00000355555');
is($tr->is_current, 1, 'Transcript is current'); # 148
@transcripts = @{ $ta->fetch_all_versions_by_stable_id('ENST00000355555') };
foreach my $t (@transcripts) {
next unless ($t->version == 4);
is($t->is_current, 0, 'Transcript is not current'); # 149
if (defined $t->version && $t->version == 4) {
is($t->is_current, 0, 'Transcript is not current'); # 149
}
}
$tr->is_current(0);
......@@ -761,6 +772,15 @@ $ta->update($tr);
$tr = $ta->fetch_by_stable_id('ENST00000355555');
is($tr->is_current, 1, 'Transcript is now current'); # 151
my $null_versions = 0;
foreach my $t (@transcripts) {
if (! defined $t->version) {
ok(! defined $t->translation->version);
$null_versions++;
}
}
is ( $null_versions, 1, "Null/undef version stored and retrieved");
$multi->restore;
# UTR Tests
......
......@@ -52,6 +52,8 @@ ok(test_getter_setter($t, 'dbID', 3));
ok(test_getter_setter($t, 'start', 42));
ok(test_getter_setter($t, 'end', 50));
is($t->version, 1, 'Default translation version = 1');
my $exon = Bio::EnsEMBL::Exon->new();
$exon->start(10);
$exon->end(20);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment