Bio::EnsEMBL::Funcgen::DBSQL FeatureSetAdaptor
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::EnsEMBL::Funcgen::DBSQL::FeatureSetAdaptor - A database adaptor for fetching and
storing Funcgen feature sets.
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::Funcgen::DBSQL::BaseAdaptor
Bio::EnsEMBL::Funcgen::FeatureSet
Bio::EnsEMBL::Utils::Exception qw ( warning throw )
Inherit
Bio::EnsEMBL::Funcgen::DBSQL::BaseAdaptor
Synopsis
my $fs_adaptor = $db->get_FeatureSetAdaptor();
my @fsets = $fs_adaptor->fetch_all_by_Experiment($exp);
my @displayable_fsets = @{$fs_adaptor->fetch_all_displayable()};
Description
The FeatureSetAdaptor is a database adaptor for storing and retrieving
Funcgen feature set.
Methods
_columnsDescriptionCode
_objs_from_sthDescriptionCode
_tablesDescriptionCode
fetch_all_by_CellTypeDescriptionCode
fetch_all_by_FeatureTypeDescriptionCode
fetch_all_by_FeatureType_AnalysisDescriptionCode
fetch_all_by_typeDescriptionCode
fetch_all_displayable_by_typeDescriptionCode
fetch_attributesDescriptionCode
fetch_by_nameDescriptionCode
list_dbIDsDescriptionCode
storeDescriptionCode
Methods description
_columnscode    nextTop
  Args       : None
Example : None
Description: PROTECTED implementation of superclass abstract method.
Returns a list of columns to use for queries.
Returntype : List of strings
Exceptions : None
Caller : Internal
Status : At Risk
_objs_from_sthcodeprevnextTop
  Arg [1]    : DBI statement handle object
Example : None
Description: PROTECTED implementation of superclass abstract method.
Creates OligoArray objects from an executed DBI statement
handle.
Returntype : Listref of Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : None
Caller : Internal
Status : At Risk
_tablescodeprevnextTop
  Args       : None
Example : None
Description: PROTECTED implementation of superclass abstract method.
Returns the names and aliases of the tables to use for queries.
Returntype : List of listrefs of strings
Exceptions : None
Caller : Internal
Status : Medium Risk
fetch_all_by_CellTypecodeprevnextTop
  Arg [1]    : Bio::EnsEMBL::Funcgen::CellType
Arg [2] : (optional) string - status e.g. 'DISPLAYABLE'
Example : my @fsets = $fs_adaptopr->fetch_all_by_CellType($ctype);
Description: Retrieves FeatureSet objects from the database based on the CellType.
Returntype : Listref of Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : Throws if arg is not a valid CellType
Caller : General
Status : At Risk
fetch_all_by_FeatureTypecodeprevnextTop
  Arg [1]    : Bio::EnsEMBL::Funcgen::FeatureType
Arg [2] : (optional) string - status e.g. 'DISPLAYABLE'
Example : my @fsets = $fs_adaptopr->fetch_all_by_FeatureType($type);
Description: Retrieves FeatureSet objects from the database based on feature_type id.
Returntype : Listref of Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : Throws if arg is not a valid FeatureType
Caller : General
Status : At Risk
fetch_all_by_FeatureType_AnalysiscodeprevnextTop
  Arg [1]    : Bio::EnsEMBL::Funcgen::FeatureType
Arg [2] : Bio::EnsEMBL::Analysis
Arg [3] : (optional) Bio::EnsEMBL::Funcgen::CellType
Example : my @fsets = $fs_adaptopr->fetch_all_by_FeatureType_Analysis($ftype, $anal, $ctype);
Description: Retrieves FeatureSet objects from the database based on FeatureType, Analysis and
CellType if defined.
Returntype : Listref of Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : Throws if args 1 and 2 are not valid or stored
Caller : General
Status : At Risk
fetch_all_by_typecodeprevnextTop
  Arg [1]    : String - Type of feature set i.e. 'annotated', 'regulatory' or 'supporting'
Arg [2] : (optional) string - status e.g. 'DISPLAYABLE'
Example : my @fsets = $fs_adaptopr->fetch_all_by_type('annotated');
Description: Retrieves FeatureSet objects from the database based on feature_set type.
Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : Throws if type not defined
Caller : General
Status : At Risk
fetch_all_displayable_by_typecodeprevnextTop
  Arg [1]    : String - Type of feature set i.e. 'annotated', 'regulatory' or 'supporting'
Example : my @fsets = $fs_adaptopr->fetch_all_by_type('annotated');
Description: Wrapper method for fetch_all_by_type
Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : None
Caller : General
Status : At Risk
fetch_attributescodeprevnextTop
  Arg [1]    : Bio::EnsEMBL::Funcgen::FeatureSet - array to fetch attributes for
Example : None
Description: This function is solely intended to lazy load attributes into
empty FeatureSet objects. You should not need to call this.
Returntype : None
Exceptions : None
Caller : Bio::EnsEMBL::Funcgen::FeatureSet getters
Status : At Risk - Not implemented for FeatureSets, remove?
fetch_by_namecodeprevnextTop
  Arg [1]    : string - name of FeatureSet
Arg [2] : (optional) string - status e.g. 'DISPLAYABLE'
Example : my @fsets = @{$fset_adaptor->fetch_by_name('feature_set-1')};
Description: Fetch all FeatureSets wit a given name
Returntype : Bio::EnsEMBL::Funcgen::FeatureSet objects
Exceptions : Throws if no name passed
Caller : General
Status : At Risk - change to fetch_by_name when name is made unique key
list_dbIDscodeprevnextTop
  Args       : None
Example : my @array_ids = @{$oaa->list_dbIDs()};
Description: Gets an array of internal IDs for all OligoArray objects in the
current database.
Returntype : List of ints
Exceptions : None
Caller : ?
Status : Medium Risk
storecodeprevnextTop
  Args       : List of Bio::EnsEMBL::Funcgen::FeatureSet objects
Example : $oaa->store($fset1, $fset2, $fset3);
Description: Stores FeatureSet objects in the database.
Returntype : Listref of stored FeatureSet objects
Exceptions : Throws if FeatureSet does not have a stored FeatureType
Throws if invalid FeatureSet passed
Throws if not FeatureSets passed
Warns if external_db_name not defined is type is external
Throws if external_db is not present in the db
Caller : General
Status : At Risk
Methods code
_columnsdescriptionprevnextTop
sub _columns {
	my $self = shift;
	
	return qw( fs.feature_set_id fs.feature_type_id fs.analysis_id fs.cell_type_id fs.name fs.type fs.description fs.display_label);
}
_objs_from_sthdescriptionprevnextTop
sub _objs_from_sth {
	my ($self, $sth) = @_;
	
	my (@fsets, $fset, $analysis, %analysis_hash, $feature_type, $cell_type, $name, $type, $display_label, $desc);
	my ($feature_set_id, $ftype_id, $analysis_id, $ctype_id, %ftype_hash, %ctype_hash);
	
	my $ft_adaptor = $self->db->get_FeatureTypeAdaptor();
	my $anal_adaptor = $self->db->get_AnalysisAdaptor();
	my $ct_adaptor = $self->db->get_CellTypeAdaptor();
	$ctype_hash{'NULL'} = undef;

	$sth->bind_columns(\$feature_set_id,\$ ftype_id,\$ analysis_id,\$ ctype_id,\$ name,\$ type,\$ desc,\$ display_label);
	
	while ( $sth->fetch()) {

		$ctype_id ||= 'NULL';

		# Get the analysis object
$analysis_hash{$analysis_id} = $anal_adaptor->fetch_by_dbID($analysis_id) if(! exists $analysis_hash{$analysis_id}); # Get the feature type object
$ftype_hash{$ftype_id} = $ft_adaptor->fetch_by_dbID($ftype_id) if(! exists $ftype_hash{$ftype_id}); # Get the cell_type object
$ctype_hash{$ctype_id} = $ct_adaptor->fetch_by_dbID($ctype_id) if(! exists $ctype_hash{$ctype_id}); $fset = Bio::EnsEMBL::Funcgen::FeatureSet->new ( -dbID => $feature_set_id, -adaptor => $self, -feature_type => $ftype_hash{$ftype_id}, -analysis => $analysis_hash{$analysis_id}, -cell_type => $ctype_hash{$ctype_id}, -name => $name, -type => $type, -display_label => $display_label, -description => $desc, ); push @fsets, $fset; } return\@ fsets;
}
_tablesdescriptionprevnextTop
sub _tables {
	my $self = shift;
	
	return (['feature_set',     'fs']);
}
fetch_all_by_CellTypedescriptionprevnextTop
sub fetch_all_by_CellType {
    my $self = shift;
    my $ctype = shift;
    my $status = shift;
    
    if(! ($ctype && $ctype->isa("Bio::EnsEMBL::Funcgen::CellType") && $ctype->dbID())){
      throw("Must provide a valid stored Bio::EnsEMBL::Funcgen::CellType object");
    }
	
    my $sql = "fs.cell_type_id = '".$ctype->dbID()."'";

    if($status){
      my $constraint = $self->status_to_constraint($status) if $status;
      $sql = (defined $constraint) ? $sql." ".$constraint : undef;
    }

    return $self->generic_fetch($sql);
}
fetch_all_by_FeatureTypedescriptionprevnextTop
sub fetch_all_by_FeatureType {
    my $self = shift;
    my $ftype = shift;
    my $status = shift;
    
    if(! ($ftype && $ftype->isa("Bio::EnsEMBL::Funcgen::FeatureType"))){
      throw("Must provide a valid Bio::EnsEMBL::Funcgen::FeatureType object");
    }
	
    my $sql = "fs.feature_type_id = '".$ftype->dbID()."'";

    if($status){
      my $constraint = $self->status_to_constraint($status);
      $sql = (defined $constraint) ? $sql." ".$constraint : undef;
    }

    return $self->generic_fetch($sql);
}
fetch_all_by_FeatureType_AnalysisdescriptionprevnextTop
sub fetch_all_by_FeatureType_Analysis {
    my ($self, $ftype, $anal, $ctype) = @_;
    

	my $sql = '';

    if(! ($ftype && $ftype->isa("Bio::EnsEMBL::Funcgen::FeatureType") && $ftype->dbID())){
      throw("Must provide a valid stored Bio::EnsEMBL::Funcgen::FeatureType object");
    }
	
	if(! ($anal && $anal->isa("Bio::EnsEMBL::Analysis") && $anal->dbID())){
      throw("Must provide a valid stored Bio::EnsEMBL::Analysis object");
    }

	if($ctype){

	  if(! ($ctype->isa("Bio::EnsEMBL::Funcgen::CellType") && $ctype->dbID())){
		throw("Argument must be a valid stored Bio::EnsEMBL::Funcgen::CellType object");
	  }
	  
	  $sql = ' AND fs.cell_type_id='.$ctype->dbID();
	}


    $sql = 'fs.feature_type_id ='.$ftype->dbID().' AND fs.analysis_id='.$anal->dbID().$sql;

  
    return $self->generic_fetch($sql);
}
fetch_all_by_typedescriptionprevnextTop
sub fetch_all_by_type {
    my $self = shift;
    my $type = shift;
    my $status = shift;
    
    throw('Must provide a feature_set type') if(! defined $type);
	
    my $sql = "fs.type = '".$type."'";

    if($status){
      my $constraint = $self->status_to_constraint($status);
      $sql = (defined $constraint) ? $sql." AND ".$constraint : undef;
    }

    return $self->generic_fetch($sql);
}
fetch_all_displayable_by_typedescriptionprevnextTop
sub fetch_all_displayable_by_type {
    my $self = shift;
    my $type = shift;
  
	$self->fetch_all_by_type($type, 'DISPLAYABLE');
}
fetch_attributesdescriptionprevnextTop
sub fetch_attributes {
    my $self = shift;
    my $array = shift;

    my $tmp_array = $self->fetch_by_dbID( $array->dbID() );
    %$array = %$tmp_array;
}
fetch_by_namedescriptionprevnextTop
sub fetch_by_name {
  my ($self, $name, $status) = @_;
  
  throw("Must provide a name argument") if (! defined $name);
  
  my $sql = "fs.name='".$name."'";
  
  if($status){
    my $constraint = $self->status_to_constraint($status) if $status;
    $sql = (defined $constraint) ? $sql." ".$constraint : undef;
  }

  return $self->generic_fetch($sql)->[0];
}
list_dbIDsdescriptionprevnextTop
sub list_dbIDs {
    my ($self) = @_;
	
    return $self->_list_dbIDs('feature_set');
}



1;
}
storedescriptionprevnextTop
sub store {
    my $self = shift;
    my @fsets = @_;

	throw('Must supply a list of FeatureSets to store') if(scalar(@fsets) == 0);

	my $sth = $self->prepare("INSERT INTO feature_set
                                 (feature_type_id, analysis_id, cell_type_id, name, type, description, display_label)
                                 VALUES (?, ?, ?, ?, ?, ?, ?)");


	my ($sql, $edb_id, %edb_hash);
	
    foreach my $fset (@fsets) {
		throw('Can only store FeatureSet objects, skipping $fset')	if ( ! $fset->isa('Bio::EnsEMBL::Funcgen::FeatureSet'));
		
		if (!( $fset->dbID() && $fset->adaptor() == $self )){#use is_stored?
throw("FeatureSet must have a stored FeatureType") if (! $fset->feature_type->is_stored($self->db)); my $ctype_id = (defined $fset->cell_type) ? $fset->cell_type->dbID : undef; $sth->bind_param(1, $fset->feature_type->dbID, SQL_INTEGER); $sth->bind_param(2, $fset->analysis->dbID, SQL_INTEGER); $sth->bind_param(3, $ctype_id, SQL_INTEGER); $sth->bind_param(4, $fset->name, SQL_VARCHAR); $sth->bind_param(5, $fset->type, SQL_VARCHAR); $sth->bind_param(6, $fset->description, SQL_VARCHAR); $sth->bind_param(7, $fset->display_label, SQL_VARCHAR); $sth->execute(); $fset->dbID($sth->{'mysql_insertid'}); $fset->adaptor($self); } else{ #assume we want to update the states
warn('You may want to use $fset->adaptor->store_states($fset)'); $self->store_states($fset); } } return\@ fsets;
}
General documentation
AUTHORTop
This module was created by Nathan Johnson.
This module is part of the Ensembl project: /
CONTACTTop
Post comments or questions to the Ensembl development list: ensembl-dev@ebi.ac.uk