Bio::EnsEMBL::Pipeline::DBSQL FlagAdaptor
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::EnsEMBL::Pipeline::DBSQL::FlagAdaptor
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::Pipeline::Flag
Bio::EnsEMBL::Root
Carp
strict
Inherit
Bio::EnsEMBL::Root
Synopsis
 $Adaptor = $dbobj->getFlagAdaptor();
Description
Module to encapsulate all db access to flag table
Methods
check_flag
No description
Code
dbDescriptionCode
fetch_allDescriptionCode
fetch_by_analysisDescriptionCode
fetch_by_dbIDDescriptionCode
fetch_by_ensembl_idDescriptionCode
new
No description
Code
prepare
No description
Code
removeDescriptionCode
storeDescriptionCode
Methods description
dbcode    nextTop
  Title   : db
Usage : $self->db;
Function: gets the DBSQL::DBAdaptor for the Adaptor. Set is private.
Returns : Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor;
Args : -
fetch_allcodeprevnextTop
  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 : -
fetch_by_analysiscodeprevnextTop
  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
fetch_by_dbIDcodeprevnextTop
  Title   : fetch_by_dbID
Usage : $self->fetch_by_dbID
Function: Fetches object by its db identifier
Returns : Bio::EnsEMBL::Pipeline::Flag
Args : Scalar
fetch_by_ensembl_idcodeprevnextTop
  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
removecodeprevnextTop
  Title   : remove
Usage : $self->remove( $flag );
Function: removes given object from database.
Returns : dbID of object that was removed
Args : Bio::EnsEMBL::Pipeline::Flag
storecodeprevnextTop
  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
check_flagdescriptionprevnextTop
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;
}
dbdescriptionprevnextTop
sub db {
  my ($self,$db) = @_;
  ( defined $db ) &&
    ( $self->{'_db'} = $db );
  $self->{'_db'};
}


# Convenience prepare function
}
fetch_alldescriptionprevnextTop
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;
}
fetch_by_analysisdescriptionprevnextTop
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;
}
fetch_by_dbIDdescriptionprevnextTop
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;
}
fetch_by_ensembl_iddescriptionprevnextTop
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;
}
newdescriptionprevnextTop
sub new {
  my ($class,$dbobj) = @_;
  my $self = $class->SUPER::new();

  $self->db( $dbobj );
  return $self;
}
preparedescriptionprevnextTop
sub prepare {
  my ($self,$query)  = @_;
  $self->db->dbc->prepare( $query );
}


1;
}
removedescriptionprevnextTop
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;
}
storedescriptionprevnextTop
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
CONTACTTop
Post general queries to ensembl-dev@ebi.ac.uk
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
ConstructorTop
  Title   : new
Usage : $dbobj->get_FlagAdaptor
Function: Standard Adaptor Constructor
Returns : Bio::EnsEMBL::Pipeline::DBSQL::FlagAdaptor
Args : Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor