Skip to content
Snippets Groups Projects
Commit 49bf7bab authored by Dan Staines's avatar Dan Staines
Browse files

updated adaptors to handle analysis types for operons and their transcripts

parent 3bae0460
No related branches found
No related tags found
No related merge requests found
......@@ -63,8 +63,7 @@ use vars '@ISA';
# Status : Stable
sub _tables {
return ( [ 'operon', 'o' ],
[ 'operon_stable_id', 'osi' ]);
return ( [ 'operon', 'o' ], [ 'operon_stable_id', 'osi' ] );
}
# _columns
......@@ -87,8 +86,8 @@ sub _columns {
return ( 'o.operon_id', 'o.seq_region_id', 'o.seq_region_start',
'o.seq_region_end', 'o.seq_region_strand', 'o.display_label',
'osi.stable_id', 'osi.version', $created_date,
$modified_date );
'o.analysis_id', 'osi.stable_id', 'osi.version',
$created_date, $modified_date );
}
sub _left_join {
......@@ -199,11 +198,12 @@ sub fetch_by_stable_id {
Status : At Risk
=cut
sub fetch_all {
my ($self) = @_;
my $constraint = '';
my @operons = @{ $self->generic_fetch($constraint) };
my @operons = @{ $self->generic_fetch($constraint) };
return \@operons;
}
......@@ -342,8 +342,9 @@ sub fetch_all_by_Slice {
if ( $slice != $ext_slice ) {
$new_tr = $tr->transfer($slice);
if ( !defined($new_tr) ) {
throw( "Unexpected. "
. "Transcript could not be transfered onto operon slice." );
throw( "Unexpected. "
. "Transcript could not be transfered onto operon slice."
);
}
} else {
$new_tr = $tr;
......@@ -438,9 +439,9 @@ sub fetch_by_operon_transcript_stable_id {
}
sub fetch_by_operon_transcript {
my ( $self, $trans ) = @_;
assert_ref($trans,'Bio::EnsEMBL::OperonTranscript');
$self->fetch_by_operon_transcript_id($trans->dbID());
my ( $self, $trans ) = @_;
assert_ref( $trans, 'Bio::EnsEMBL::OperonTranscript' );
$self->fetch_by_operon_transcript_id( $trans->dbID() );
}
=head2 store
......@@ -471,7 +472,14 @@ sub store {
if ( $operon->is_stored($db) ) {
return $operon->dbID();
}
my $analysis = $operon->analysis();
throw("Operons must have an analysis object.") if(!defined($analysis));
my $analysis_id;
if ( $analysis->is_stored($db) ) {
$analysis_id = $analysis->dbID();
} else {
$analysis_id = $db->get_AnalysisAdaptor->store( $analysis );
}
# ensure coords are correct before storing
#$operon->recalculate_coordinates();
......@@ -485,17 +493,19 @@ sub store {
seq_region_start = ?,
seq_region_end = ?,
seq_region_strand = ?,
display_label = ?
display_label = ?,
analysis_id = ?
);
# column status is used from schema version 34 onwards (before it was
# confidence)
my $sth = $self->prepare($store_operon_sql);
$sth->bind_param(1,$seq_region_id,SQL_INTEGER);
$sth->bind_param( 2, $operon->start(), SQL_INTEGER );
$sth->bind_param( 3, $operon->end(), SQL_INTEGER );
$sth->bind_param( 4, $operon->strand(), SQL_TINYINT );
$sth->bind_param( 5, $operon->display_label(), SQL_VARCHAR );
$sth->bind_param( 1, $seq_region_id, SQL_INTEGER );
$sth->bind_param( 2, $operon->start(), SQL_INTEGER );
$sth->bind_param( 3, $operon->end(), SQL_INTEGER );
$sth->bind_param( 4, $operon->strand(), SQL_TINYINT );
$sth->bind_param( 5, $operon->display_label(), SQL_VARCHAR );
$sth->bind_param( 6, $analysis_id, SQL_INTEGER );
$sth->execute();
$sth->finish();
......@@ -595,9 +605,9 @@ sub remove {
$dbe_adaptor->remove_from_object( $dbe, $operon, 'Operon' );
}
# # remove the attributes associated with this transcript
# my $attrib_adaptor = $self->db->get_AttributeAdaptor;
# $attrib_adaptor->remove_from_Operon($operon);
# # remove the attributes associated with this transcript
# my $attrib_adaptor = $self->db->get_AttributeAdaptor;
# $attrib_adaptor->remove_from_Operon($operon);
# remove all of the transcripts associated with this operon
my $transcriptAdaptor = $self->db->get_OperonTranscriptAdaptor();
......@@ -650,23 +660,24 @@ sub _objs_from_sth {
#
my $sa = $self->db()->get_SliceAdaptor();
#my $aa = $self->db->get_AnalysisAdaptor();
my $aa = $self->db->get_AnalysisAdaptor();
my @operons;
my %analysis_hash;
my %slice_hash;
my %sr_name_hash;
my %sr_cs_hash;
my ( $stable_id, $version, $created_date, $modified_date );
my ( $stable_id, $version, $created_date, $modified_date, $analysis_id );
my ( $operon_id, $seq_region_id, $seq_region_start, $seq_region_end,
$seq_region_strand, $display_label );
my ( $operon_id, $seq_region_id, $seq_region_start,
$seq_region_end, $seq_region_strand, $display_label );
$sth->bind_columns( \$operon_id, \$seq_region_id,
\$seq_region_start, \$seq_region_end,
\$seq_region_strand, \$display_label,
\$stable_id, \$version,
\$created_date, \$modified_date );
\$analysis_id, \$stable_id,
\$version, \$created_date,
\$modified_date );
my $asm_cs;
my $cmp_cs;
......@@ -701,9 +712,10 @@ sub _objs_from_sth {
my $count = 0;
OPERON: while ( $sth->fetch() ) {
$count++;
# #get the analysis object
# my $analysis = $analysis_hash{$analysis_id} ||=
# $aa->fetch_by_dbID($analysis_id);
#get the analysis object
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
$analysis_hash{$analysis_id} = $analysis;
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
#get the slice object
......@@ -774,21 +786,20 @@ sub _objs_from_sth {
$slice = $dest_slice;
} ## end if ($dest_slice)
push(
@operons,
Bio::EnsEMBL::Operon->new(
-START => $seq_region_start,
-END => $seq_region_end,
-STRAND => $seq_region_strand,
-SLICE => $slice,
-DISPLAY_LABEL => $display_label,
-ADAPTOR => $self,
-DBID => $operon_id,
-STABLE_ID => $stable_id,
-VERSION => $version,
-CREATED_DATE => $created_date || undef,
-MODIFIED_DATE => $modified_date || undef
));
push( @operons,
Bio::EnsEMBL::Operon->new(
-START => $seq_region_start,
-END => $seq_region_end,
-STRAND => $seq_region_strand,
-SLICE => $slice,
-DISPLAY_LABEL => $display_label,
-ADAPTOR => $self,
-DBID => $operon_id,
-STABLE_ID => $stable_id,
-VERSION => $version,
-CREATED_DATE => $created_date || undef,
-MODIFIED_DATE => $modified_date || undef,
-ANALYSIS => $analysis ) );
} ## end while ( $sth->fetch() )
......
......@@ -92,8 +92,9 @@ sub _columns {
return ( 'o.operon_transcript_id', 'o.seq_region_id',
'o.seq_region_start', 'o.seq_region_end',
'o.seq_region_strand', 'o.display_label',
'osi.stable_id', 'osi.version',
$created_date, $modified_date );
'o.analysis_id', 'osi.stable_id',
'osi.version', $created_date,
$modified_date );
}
sub _left_join {
......@@ -194,6 +195,7 @@ sub fetch_by_name {
return $operon;
}
=head2 fetch_all
Example : $operon_transcripts = $operon_adaptor->fetch_all();
......@@ -203,6 +205,7 @@ sub fetch_by_name {
Status : At Risk
=cut
sub fetch_all {
my ($self) = @_;
......@@ -529,7 +532,15 @@ sub store {
( $operon_transcript, $seq_region_id ) =
$self->_pre_store($operon_transcript);
my $analysis = $operon_transcript->analysis();
throw("OperonTranscripts must have an analysis object.")
if ( !defined($analysis) );
my $analysis_id;
if ( $analysis->is_stored($db) ) {
$analysis_id = $analysis->dbID();
} else {
$analysis_id = $db->get_AnalysisAdaptor->store($analysis);
}
my $store_operon_transcript_sql = qq(
INSERT INTO operon_transcript
SET seq_region_id = ?,
......@@ -537,7 +548,8 @@ sub store {
seq_region_end = ?,
seq_region_strand = ?,
display_label = ?,
operon_id = ?
operon_id = ?,
analysis_id =?
);
# column status is used from schema version 34 onwards (before it was
# confidence)
......@@ -549,6 +561,7 @@ sub store {
$sth->bind_param( 4, $operon_transcript->strand(), SQL_TINYINT );
$sth->bind_param( 5, $operon_transcript->display_label(), SQL_VARCHAR );
$sth->bind_param( 6, $operon_id, SQL_INTEGER );
$sth->bind_param( 7, $analysis_id, SQL_INTEGER );
$sth->execute();
$sth->finish();
......@@ -557,18 +570,18 @@ sub store {
# store stable ids if they are available
if ( defined( $operon_transcript->stable_id() ) ) {
my $statement = sprintf(
"INSERT INTO operon_transcript_stable_id SET "
. "operon_transcript_id = ?, "
. "stable_id = ?, "
. "version = ?, "
. "created_date = %s, "
. "modified_date = %s",
$self->db()->dbc()->from_seconds_to_date(
my $statement = sprintf( "INSERT INTO operon_transcript_stable_id SET "
. "operon_transcript_id = ?, "
. "stable_id = ?, "
. "version = ?, "
. "created_date = %s, "
. "modified_date = %s",
$self->db()->dbc()->from_seconds_to_date(
$operon_transcript->created_date()
),
$self->db()->dbc()
->from_seconds_to_date( $operon_transcript->modified_date() ) );
),
$self->db()->dbc()->from_seconds_to_date(
$operon_transcript->modified_date()
) );
$sth = $self->prepare($statement);
$sth->bind_param( 1, $operon_transcript_dbID, SQL_INTEGER );
......@@ -674,9 +687,9 @@ sub remove {
'OperonTranscript' );
}
# # remove the attributes associated with this transcript
# my $attrib_adaptor = $self->db->get_AttributeAdaptor;
# $attrib_adaptor->remove_from_OperonTranscript($operon_transcript);
# # remove the attributes associated with this transcript
# my $attrib_adaptor = $self->db->get_AttributeAdaptor;
# $attrib_adaptor->remove_from_OperonTranscript($operon_transcript);
# remove the stable identifier
my $sth = $self->prepare(
......@@ -722,7 +735,7 @@ sub _objs_from_sth {
#
my $sa = $self->db()->get_SliceAdaptor();
#my $aa = $self->db->get_AnalysisAdaptor();
my $aa = $self->db->get_AnalysisAdaptor();
my @operons;
my %analysis_hash;
......@@ -732,13 +745,15 @@ sub _objs_from_sth {
my ( $stable_id, $version, $created_date, $modified_date );
my ( $operon_transcript_id, $seq_region_id, $seq_region_start,
$seq_region_end, $seq_region_strand, $display_label );
$seq_region_end, $seq_region_strand, $display_label,
$analysis_id );
$sth->bind_columns( \$operon_transcript_id, \$seq_region_id,
\$seq_region_start, \$seq_region_end,
\$seq_region_strand, \$display_label,
\$stable_id, \$version,
\$created_date, \$modified_date );
\$analysis_id, \$stable_id,
\$version, \$created_date,
\$modified_date );
my $asm_cs;
my $cmp_cs;
......@@ -774,8 +789,9 @@ sub _objs_from_sth {
OPERON: while ( $sth->fetch() ) {
$count++;
# #get the analysis object
# my $analysis = $analysis_hash{$analysis_id} ||=
# $aa->fetch_by_dbID($analysis_id);
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
$analysis_hash{$analysis_id} = $analysis;
#need to get the internal_seq_region, if present
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
#get the slice object
......@@ -848,18 +864,18 @@ sub _objs_from_sth {
push( @operons,
Bio::EnsEMBL::OperonTranscript->new(
-START => $seq_region_start,
-END => $seq_region_end,
-STRAND => $seq_region_strand,
-SLICE => $slice,
-DISPLAY_LABEL => $display_label,
-ADAPTOR => $self,
-DBID => $operon_transcript_id,
-STABLE_ID => $stable_id,
-VERSION => $version,
-CREATED_DATE => $created_date || undef,
-MODIFIED_DATE => $modified_date || undef
) );
-START => $seq_region_start,
-END => $seq_region_end,
-STRAND => $seq_region_strand,
-SLICE => $slice,
-DISPLAY_LABEL => $display_label,
-ADAPTOR => $self,
-DBID => $operon_transcript_id,
-STABLE_ID => $stable_id,
-VERSION => $version,
-CREATED_DATE => $created_date || undef,
-MODIFIED_DATE => $modified_date || undef,
-ANALYSIS => $analysis ) );
} ## end while ( $sth->fetch() )
......
......@@ -4,7 +4,7 @@ use warnings;
BEGIN {
$| = 1;
use Test;
plan tests => 12;
plan tests => 15;
}
use Bio::EnsEMBL::DBEntry;
use Bio::EnsEMBL::Operon;
......@@ -31,6 +31,7 @@ my $end = 31225946;
my $strand = 1;
my $display_label = "accBC";
my $analysis = $dba->get_AnalysisAdaptor->fetch_by_logic_name("Genscan");
ok(defined $analysis);
my $operon = Bio::EnsEMBL::Operon->new(
-START => $start,
-END => $end,
......@@ -49,6 +50,7 @@ ok( $display_label, $operon->display_label(), "Operon name" );
ok( $start, $operon->seq_region_start(), "Operon start" );
ok( $end, $operon->seq_region_end(), "Operon end" );
ok( $strand, $operon->seq_region_strand(), "Operon strand" );
ok( $analysis, $operon->analysis(), "Analysis" );
my $operon_adaptor = Bio::EnsEMBL::DBSQL::OperonAdaptor->new($dba);
......@@ -64,4 +66,7 @@ ok( $operon2->seq_region_end(), $operon->seq_region_end(), "Operon end" );
ok( $operon2->seq_region_strand(),
$operon->seq_region_strand(),
"Operon strand" );
ok( $operon2->analysis(),
$operon->analysis(),
"Analysis" );
......@@ -2,7 +2,7 @@ use strict;
use warnings;
BEGIN { $| = 1;
use Test;
plan tests => 12;
plan tests => 17;
}
use Bio::EnsEMBL::Test::MultiTestDB;
......@@ -25,11 +25,13 @@ my $operon_adaptor = Bio::EnsEMBL::DBSQL::OperonAdaptor->new($dba);
my $operon = $operon_adaptor->fetch_by_name("16152-16153-4840");
ok(defined $operon);
debug("O ".$operon->dbID());
ok(defined $operon->analysis());
# iterate over its transcripts
my $transcripts = $operon->get_all_OperonTranscripts();
ok(defined $transcripts);
ok(scalar(@$transcripts)>0);
for my $ot (@$transcripts) {
ok(defined $ot->analysis());
debug("OT ".$ot->dbID());
for my $gene (@{$ot->get_all_Genes()}) {
debug("G ".$gene->dbID());
......@@ -43,6 +45,7 @@ my $operons = $operon_adaptor->fetch_all_by_Slice($slice);
ok(defined $operons);
ok(scalar(@$operons)>0);
for my $o (@$operons) {
ok(defined $o->analysis());
debug("O ".$o->dbID());
for my $ot (@{$o->get_all_OperonTranscripts()}) {
debug("OT ".$ot->dbID());
......
......@@ -4,7 +4,7 @@ use warnings;
BEGIN {
$| = 1;
use Test;
plan tests => 40;
plan tests => 46;
}
use Bio::EnsEMBL::Test::MultiTestDB;
use Bio::EnsEMBL::Test::TestUtils;
......@@ -34,11 +34,13 @@ my $start = 3403162;
my $end = 3405288;
my $strand = 1;
my $display_label = "accBC";
my $analysis = $dba->get_AnalysisAdaptor->fetch_by_logic_name("Genscan");
my $operon = Bio::EnsEMBL::Operon->new( -START => $start,
-END => $end,
-STRAND => $strand,
-SLICE => $slice,
-DISPLAY_LABEL => $display_label, -STABLE_ID=>"op1" );
-DISPLAY_LABEL => $display_label, -STABLE_ID=>"op1", -ANALYSIS=>$analysis );
ok( $analysis, $operon->analysis(), "Analysis" );
my $gene_name = "accB";
my $gene_start = 31225346;
......@@ -54,7 +56,6 @@ my $gene = Bio::EnsEMBL::Gene->new();
my $transcript = Bio::EnsEMBL::Transcript->new();
my $exon = Bio::EnsEMBL::Exon->new();
my $translation = Bio::EnsEMBL::Translation->new();
my $analysis = $dba->get_AnalysisAdaptor->fetch_by_logic_name("Genscan");
ok( defined $analysis );
for my $feature ( $gene, $transcript, $exon ) {
$feature->start($gene_start);
......@@ -117,18 +118,20 @@ my $operon_transcript =
Bio::EnsEMBL::OperonTranscript->new( -START => $start,
-END => $end,
-STRAND => $strand,
-SLICE => $slice, -STABLE_ID=>"opt1" );
-SLICE => $slice, -STABLE_ID=>"opt1", -ANALYSIS=>$analysis );
$operon_transcript->add_gene($gene);
$operon_transcript->add_gene($gene2);
$operon->add_OperonTranscript($operon_transcript);
ok( $analysis, $operon_transcript->analysis(), "Analysis" );
my $operon_transcript2 =
Bio::EnsEMBL::OperonTranscript->new( -START => $start,
-END => $gene_start2,
-STRAND => $strand,
-SLICE => $slice, -STABLE_ID=>"opt2" );
-SLICE => $slice, -STABLE_ID=>"opt2", -ANALYSIS=>$analysis );
$operon_transcript2->add_gene($gene);
$operon->add_OperonTranscript($operon_transcript2);
ok( $analysis, $operon_transcript->analysis(), "Analysis" );
# store the lot
# store operon
......@@ -144,6 +147,7 @@ ok( $operon2->seq_region_end(), $operon->seq_region_end(), "Operon end" );
ok( $operon2->seq_region_strand(),
$operon->seq_region_strand(),
"Operon strand" );
ok( $operon2->analysis(), $operon->analysis(), "Analysis" );
my @operon_transcripts = @{ $operon2->get_all_OperonTranscripts() };
# check operon transcript
ok( scalar @operon_transcripts, 2, "Expected number of transcripts" );
......@@ -160,6 +164,7 @@ ok( $operon_transcript_r->seq_region_end(),
ok( $operon_transcript_r->seq_region_strand(),
$operon_transcript->seq_region_strand(),
"Operon transcript strand" );
ok( $operon_transcript->analysis(), $operon_transcript_r->analysis(), "Analysis" );
# check genes
my @ogenes = @{ $operon_transcript_r->get_all_Genes() };
......@@ -188,6 +193,7 @@ ok( $operon_transcript_r2->seq_region_end(),
ok( $operon_transcript_r2->seq_region_strand(),
$operon_transcript2->seq_region_strand(),
"Operon transcript strand" );
ok( $operon_transcript2->analysis(), $operon_transcript_r2->analysis(), "Analysis" );
# check genes
@ogenes = @{ $operon_transcript_r2->get_all_Genes() };
......
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