Bio::EnsEMBL::Pipeline::DBSQL
FlagAdaptor
Toolbar
Summary
Bio::EnsEMBL::Pipeline::DBSQL::FlagAdaptor
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
$Adaptor = $dbobj->getFlagAdaptor();
Description
Module to encapsulate all db access to flag table
Methods
Methods description
Title : db Usage : $self->db; Function: gets the DBSQL::DBAdaptor for the Adaptor. Set is private. Returns : Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor; Args : - |
Title : fetch_all Usage : @flags = $self->fetch_all; Function: retrieves list ref of all flags from db; Returns : List ref of Bio::EnsEMBL::Pipeline::Flag Args : - |
Title : fetch_by_analysis Usage : $self->fetch_by_analysis( $analysis ); Function: fetches flag objects based on analysis object Returns : Array ref of Flag objects Args : Bio::EnsEMBL::Analysis |
Title : fetch_by_dbID Usage : $self->fetch_by_dbID Function: Fetches object by its db identifier Returns : Bio::EnsEMBL::Pipeline::Flag Args : Scalar |
Title : fetch_by_ensembl_id Usage : $self->fetch_by_ensembl_id( $id ); Function: fetches all flag objects with the specified ensembl identifier ie: a transcript dbid or gene dbid, not stable identifiers Returns : Array ref of Flag objects Args : Scalar |
Title : remove Usage : $self->remove( $flag ); Function: removes given object from database. Returns : dbID of object that was removed Args : Bio::EnsEMBL::Pipeline::Flag |
Title : store Usage : $self->store( $flag ); Function: Stores a flag in db Sets adaptor and dbID in Flag Returns : - Args : Bio::EnsEMBL::Pipeline::Flag |
Methods code
sub check_flag
{ my ($self,$flag)=@_;
unless ($flag->goalAnalysis->isa("Bio::EnsEMBL::Analysis")){
$self->throw("analysis ".$flag->goalAnalysis." must be a ".
"Bio:EnsEMBL::Analysis object");
}
my $sql = "show tables;";
my $sth = $self->prepare($sql);
$sth->execute;
while ( my($result) = $sth->fetchrow_array){
if ($result eq $flag->type){
$sth->finish;
return 1;
}
}
$self->throw("Cannot find table that corresponds to flag type ".$flag->type."\n");
$sth->finish;
return 1; } |
sub db
{ my ($self,$db) = @_;
( defined $db ) &&
( $self->{'_db'} = $db );
$self->{'_db'};
}
} |
sub fetch_all
{ my $self = shift;
my $anaAdaptor = $self->db->get_AnalysisAdaptor;
my %flags;
my ( $analysis,$id,$type, $dbID );
my $sth = $self->prepare("
SELECT flag_id, ensembl_id, table_name, analysis_id
FROM flag " );
$sth->execute;
FLAG: while( my($flag_id, $ensembl_id, $table_name, $analysis_id ) = $sth->fetchrow_array ) {
$analysis = $anaAdaptor->fetch_by_dbID($analysis_id) or do {
$self->warn("Couldn't find analysis to match dbID $analysis_id");
next FLAG;
};
$dbID = $flag_id;
$id = $ensembl_id;
$type = $table_name;
my $flag = Bio::EnsEMBL::Pipeline::Flag->new
( '-dbid' => $dbID,
'-type' => $type,
'-ensembl_id' => $id,
'-goalAnalysis' => $analysis,
'-adaptor' => $self );
$flags{$dbID} = $flag;
}
my @array = values %flags;
$sth->finish;
return\@ array; } |
sub fetch_by_analysis
{ my ($self, $goal_analysis) = @_;
my @flags;
if(!$goal_analysis ||
!$goal_analysis->isa("Bio::EnsEMBL::Analysis")){
$self->throw("analysis ".$goal_analysis." must be a ".
"Bio:EnsEMBL::Analysis object");
}
my $sql = "SELECT flag_id
FROM flag
WHERE analysis_id = ".$goal_analysis->dbID;
my $sth = $self->prepare($sql);
$sth->execute;
FLAG: while( my($flag_id) = $sth->fetchrow_array ) {
push @flags, $self->fetch_by_dbID($flag_id);
}
$sth->finish;
return\@ flags; } |
sub fetch_by_dbID
{ my ($self, $dbID) = @_;
my $anaAdaptor = $self->db->get_AnalysisAdaptor;
my ( $analysis,$id,$type,$flag );
my $queryResult;
my $sth = $self->prepare("
SELECT flag_id, ensembl_id, table_name, analysis_id
FROM flag
WHERE flag_id = $dbID");
$sth->execute;
my ($flag_id, $ensembl_id, $table_name, $analysis_id ) = $sth->fetchrow;
if( !defined $flag_id ) {
return undef;
}
$analysis = $anaAdaptor->fetch_by_dbID($analysis_id)
or $self->throw("Can't find analysis with dbID $analysis_id\n");
$flag = Bio::EnsEMBL::Pipeline::Flag->new
( '-dbid' => $dbID,
'-type' => $table_name,
'-ensembl_id' => $ensembl_id,
'-goalAnalysis' => $analysis,
'-adaptor' => $self );
$sth->finish;
return $flag; } |
sub fetch_by_ensembl_id
{ my ($self, $id) = @_;
my @flags;
my $sql = "SELECT flag_id FROM flag WHERE ensembl_id = $id";
my $sth = $self->prepare($sql);
$sth->execute;
while ( my($result) = $sth->fetchrow_array){
push @flags, $self->fetch_by_dbID($result);
}
$sth->finish;
return\@ flags; } |
sub new
{ my ($class,$dbobj) = @_;
my $self = $class->SUPER::new();
$self->db( $dbobj );
return $self; } |
sub prepare
{ my ($self,$query) = @_;
$self->db->dbc->prepare( $query );
}
1; } |
sub remove
{ my ( $self, $flag ) = @_;
my $dbID = $flag->dbID;
if( !defined $dbID ) {
$self->throw( "FlagAdaptor->remove called with non persistent Flag" );
}
my $sth = $self->prepare("
DELETE FROM flag
WHERE flag_id = $dbID" );
$sth->execute;
$sth->finish;
return $dbID; } |
sub store
{ my ( $self, $flag ) = @_;
$self->check_flag($flag);
my $sql = "INSERT INTO flag SET ensembl_id = '".
$flag->ensembl_id."' , analysis_id = '".
$flag->goalAnalysis->dbID."' , table_name = '".
$flag->type."';";
my $sth = $self->prepare($sql);
$sth->execute;
$sth = $self->prepare("SELECT last_insert_id()");
$sth->execute;
my $dbID = ($sth->fetchrow_array)[0];
$flag->dbID( $dbID );
$flag->adaptor( $self );
$sth->finish;
return 1; } |
General documentation
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Title : new
Usage : $dbobj->get_FlagAdaptor
Function: Standard Adaptor Constructor
Returns : Bio::EnsEMBL::Pipeline::DBSQL::FlagAdaptor
Args : Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor