Bio::EnsEMBL::Funcgen::DBSQL
DataSetAdaptor
Toolbar
Summary
Bio::EnsEMBL::DBSQL::Funcgen::DataSetAdaptor - A database adaptor for fetching and
storing DataSet objects.
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
my $dset_adaptor = $db->get_DataSetAdaptor();
my $dset = $dset_adaptor->fetch_by_dbID(1);
my @displayable_dsets = $dset_adaptor->fetch_all_displayable();
Description
The DataSetAdaptor is a database adaptor for storing and retrieving
DataSet objects.
Methods
Methods description
Args : None Example : None Description: PROTECTED implementation of superclass abstract method. Returns a list of columns to use for queries. Returntype : List Exceptions : None Caller : Internal Status : At Risk |
Args : None Example : None Description: PROTECTED implementation of superclass abstract method. Returns an additional table joining constraint to use for queries. Returntype : List Exceptions : None Caller : Internal Status : At Risk |
Arg [1] : DBI statement handle object Example : None Description: PROTECTED implementation of superclass abstract method. Creates Array objects from an executed DBI statement handle. Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : None Caller : Internal Status : At Risk |
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 Exceptions : None Caller : Internal Status : At Risk |
Arg [1] : Bio::EnsEMBL::Funcgen::ResultSet Example : my @dsets = $fs_adaptopr->fetch_all_by_ResultSet($rset); Description: Retrieves DataSet objects from the database based on the ResultSet. Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : Throws if arg is not a valid ResultSet Caller : General Status : At Risk - to be removed |
Arg [1] : string - class of associated FeatureSet FeatureType Arg [2] : optional: string - status e.g. 'DISPLAYABLE' Example : my @dsets = @{$ds_adaptopr->fetch_all_by_feature_type_class('HISTONE')}; Description: Retrieves DataSet objects from the database based on the FeatureSet FeatureType class. Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : Throws if no class arg defined Caller : General Status : At Risk |
Arg [1] : string - product feature set type for this data_set e.g. 'annotated', 'regulatory' Arg [2] : (optional) string - status e.g. 'DISPLAYABLE' Example : my $dsets = $dset_adaptor->fetch_all_by_product_FeatureSet_type('regulatory'); Description: Fetch all DataSets of a given product feature set type Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : Throws if no product feaure set type passed Caller : General Status : At Risk - not yet implmented |
Arg [1] : Bio::EnsEMBL::Funcgen::Result|FeatureSet Example : my @dsets = $fs_adaptopr->fetch_all_by_supporting_set($rset); Description: Retrieves DataSet objects from the database based on the given supporting Result or FeatureSet. Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : Throws if arg is not a valid Result|FeatureSet Caller : General Status : At Risk |
Arg [1] : string - type of supporting_sets i.e. result or feature Arg [2] : (optional) string - status e.g. 'DISPLAYABLE' Example : my $dsets = $dset_adaptor->fetch_all_by_supporting_set('feature'); Description: Fetch all DataSets whose pre-processed data consists of a particular set type Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : Throws if no supporting_set_type passed Caller : General Status : At Risk |
Arg [1] : string - class of associated FeatureSet FeatureType Example : my @dsets = @{$ds_adaptopr->fetch_all_displayable_by_feature_type_class('HISTONE')}; Description: Wrapper method, retrieves all displayable DataSets with given FeatureSet FeatureType class Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : None Caller : General Status : At Risk |
Arg [1] : string - name of DataSet Arg [2] : (optional) string - status e.g. 'DISPLAYABLE' Example : my $dsets = $dset_adaptor->fetch_by_name('data_set-1'); Description: Fetch all FeatureSets wit a given name Returntype : Bio::EnsEMBL::Funcgen::DataSet Exceptions : Throws if no name passed Caller : General Status : At Risk |
Arg [1] : Bio::EnsEMBL::Funcgen::FeatureSet Example : my @dsets = $fs_adaptopr->fetch_by_product_FeatureSet($fset); Description: Retrieves DataSet objects from the database based on the FeatureSet. Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::DataSet objects Exceptions : Throws if arg is not a valid FeatureSet Caller : General Status : At Risk |
Args : None Example : my @feature_ids = @{$ofa->list_dbIDs()}; Description: Gets an array of internal IDs for all OligoFeature objects in the current database. Returntype : List of ints Exceptions : None Caller : ? Status : Stable |
Args : List of Bio::EnsEMBL::Funcgen::DataSet objects Example : $dsa->store(@dsets); Description: Stores given DataSet objects in the database. Sets dbID and adaptor on the objects that it stores. Returntype : ARRAYREF of stored DataSet objects Exceptions : Throws if no DataSet objects passed Throws if DataSet object has already been stored Throws if any supporting sets have not been stored Caller : General Status : At Risk |
Args : List of previously stored Bio::EnsEMBL::Funcgen::DataSet objects Example : $dsa->store_updated_sets(@dsets); Description: Updates added supporting sets for a given previously stored DataSet Returntype : ARRAYREF of updated DataSet objects Exceptions : Throws if a list of DataSet objects is not provided Throws if DataSet has not been previosuly stored Throws if supporting set has not been previously stored ? should we throw or warn if a set has been deleted? Caller : General Status : At Risk |
Methods code
sub _columns
{
return qw(
ds.data_set_id ds.feature_set_id
ds.name ss.type
ss.supporting_set_id
); } |
sub _left_join
{ my $self = shift;
return (['supporting_set', 'ds.data_set_id = ss.data_set_id']); } |
sub _objs_from_sth
{ my ($self, $sth) = @_;
my (@data_sets, @supporting_sets, $data_set, $dbID, $set_id);
my ($fset_id, $fset, $set, $name, $ss_type, $ss_id);
my %set_adaptors = (
feature => $self->db->get_FeatureSetAdaptor(),
result => $self->db->get_ResultSetAdaptor(),
experimental => $self->db->get_ExperimentalSetAdaptor(),
);
$sth->bind_columns(\$dbID,\$ fset_id,\$ name,\$ ss_type,\$ ss_id);
while ( $sth->fetch() ) {
if((! $data_set) || ($data_set->dbID() != $dbID)){
if($data_set){
$data_set->add_supporting_sets(\@supporting_sets);
push @data_sets, $data_set;
undef @supporting_sets;
}
$fset = ($fset_id) ? $set_adaptors{'feature'}->fetch_by_dbID($fset_id) : undef;
$data_set = Bio::EnsEMBL::Funcgen::DataSet->new(
-DBID => $dbID,
-NAME => $name,
-FEATURE_SET => $fset,
-ADAPTOR => $self,
);
}
push @supporting_sets, $set_adaptors{$ss_type}->fetch_by_dbID($ss_id) if $ss_id;
}
if($data_set){
$data_set->add_supporting_sets(\@supporting_sets);
push @data_sets, $data_set;
}
return\@ data_sets; } |
sub _tables
{ my $self = shift;
return (
[ 'data_set', 'ds' ],
[ 'supporting_set', 'ss'],
); } |
sub fetch_all_by_FeatureSet
{ my $self = shift;
deprecate('Use fetch_by_product_FeatureSet');
return $self->fetch_by_product_FeatureSet(@_); } |
sub fetch_all_by_ResultSet
{ my $self = shift;
my $rset = shift;
deprecate('Use fetch_all_by_supporting_set');
return $self->fetch_all_by_supporting_set($rset);
} |
sub fetch_all_by_feature_type_class
{ my ($self, $class, $status) = @_;
throw ('Must provide a FeatureType class to retrieve DataSets') if ! defined $class;
my ($constraint, @dsets);
if($status){
$constraint = $self->status_to_constraint($status) if $status;
}
foreach my $dset(@{$self->generic_fetch($constraint)}){
push @dsets, $dset if uc($dset->product_FeatureSet->feature_type->class()) eq uc($class);
}
return\@ dsets; } |
sub fetch_all_by_product_FeatureSet_type
{ my ($self, $type, $status) = @_;
throw('Not yet implemented');
throw("Must provide a supporting_set type argument") if (! defined $type);
my $sql = "ss.type='".$type."'";
if($status){
my $constraint = $self->status_to_constraint($status) if $status;
$sql = (defined $constraint) ? $sql." ".$constraint : undef;
}
return $self->generic_fetch($sql); } |
sub fetch_all_by_supporting_set
{ my $self = shift;
my $set = shift;
if(! (ref($set) &&
( $set->isa("Bio::EnsEMBL::Funcgen::ResultSet") ||
$set->isa("Bio::EnsEMBL::Funcgen::FeatureSet") ||
$set->isa("Bio::EnsEMBL::Funcgen::ExperimentalSet"))
&& $set->dbID())){
throw("Must provide a valid stored Bio::EnsEMBL::Funcgen::ResultSet, FeatureSet or ExperimentalSet object");
}
my $sql = ' ds.data_set_id IN (SELECT data_set_id from supporting_set where type="'.$set->set_type.'" and supporting_set_id='.$set->dbID().')';
return $self->generic_fetch($sql); } |
sub fetch_all_by_supporting_set_type
{ my ($self, $type, $status) = @_;
throw("Must provide a supporting_set type argument") if (! defined $type);
my $sql = "ss.type='".$type."'";
if($status){
my $constraint = $self->status_to_constraint($status) if $status;
$sql = (defined $constraint) ? $sql." ".$constraint : undef;
}
return $self->generic_fetch($sql); } |
sub fetch_all_displayable_by_feature_type_class
{ my ($self, $class) = @_;
return $self->fetch_all_by_feature_type_class($class, 'DISPLAYABLE'); } |
sub fetch_by_name
{ my ($self, $name, $status) = @_;
throw("Must provide a name argument") if (! defined $name);
my $sql = "ds.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]; } |
sub fetch_by_product_FeatureSet
{ my $self = shift;
my $fset = shift;
if(! ($fset && $fset->isa("Bio::EnsEMBL::Funcgen::FeatureSet") && $fset->dbID())){
throw("Must provide a valid stored Bio::EnsEMBL::Funcgen::FeatureSet object");
}
my $sql = "ds.feature_set_id = '".$fset->dbID()."'";
return $self->generic_fetch($sql)->[0]; } |
sub list_dbIDs
{ my $self = shift;
return $self->_list_dbIDs('data_set');
}
1; } |
sub store
{ my ($self, @dsets) = @_;
throw('Must pass a list of DataSet objects to store') if(! @dsets || $#dsets < 0);
my $sth = $self->prepare("INSERT INTO data_set (feature_set_id, name)
VALUES (?, ?)");
my $sth2 = $self->prepare("INSERT INTO supporting_set (data_set_id, supporting_set_id, type)
VALUES (?, ?, ?)");
my ($fset_id);
my $db = $self->db();
foreach my $dset (@dsets) {
throw('Must pass a DataSet object to store') if( ! ( ref $dset &&
$dset->isa('Bio::EnsEMBL::Funcgen::DataSet')));
if ( $dset->is_stored($db) ) {
throw('DataSet [' . $dset->dbID() . '] is already stored in the database,'.
'use store_updated_sets method to add new supporting sets in this DataSet');
}
$fset_id = (defined $dset->product_FeatureSet()) ? $dset->product_FeatureSet->dbID() : 0;
$sth->bind_param(1, $fset_id, SQL_INTEGER);
$sth->bind_param(2, $dset->name(), SQL_VARCHAR);
$sth->execute();
$dset->dbID( $sth->{'mysql_insertid'} );
$dset->adaptor($self);
foreach my $sset (@{$dset->get_supporting_sets()}){
throw("All supporting Feature and ResultSets must be stored previously.".
" Use store_updated_sets method if your DataSet has been stored") if(! $sset->is_stored($db));
$sth2->bind_param(1, $dset->dbID(), SQL_INTEGER);
$sth2->bind_param(2, $sset->dbID(), SQL_INTEGER);
$sth2->bind_param(3, $sset->set_type(), SQL_VARCHAR); $sth2->execute();
}
}
return\@ dsets } |
sub store_updated_sets
{ my ($self, @dsets) = @_;
throw('Must pass a list of DataSet objects to store') if(! @dsets || $#dsets < 0);
my $sth = $self->prepare("INSERT INTO supporting_set (data_set_id, supporting_set_id, type)
VALUES (?, ?, ?)");
my $db = $self->db();
foreach my $dset (@dsets) {
throw('Must pass a DataSet object to update') if( ! ( ref $dset &&
$dset->isa('Bio::EnsEMBL::Funcgen::DataSet')));
throw('DataSet [' . $dset->dbID() . '] must be previous stored in the database') if (! $dset->is_stored($db) );
my $stored_dset = $self->fetch_by_name($dset->name);
my $fset = $dset->product_FeatureSet;
my $stored_fset = $stored_dset->product_FeatureSet;
if(defined $stored_fset){
if(! defined $fset){
warn("Populating absent product FeatureSet from DB for DataSet:\t".$dset->name);
}else{
if($fset->dbID != $stored_fset->dbID){
throw('Found product FeatureSet mismatch whilst updating DataSet('.$dset->name.
"):\tStored:".$stored_fset->name."\tUpdate:".$fset->name);
}
}
}else{
my $sql = 'update data_set set feature_set_id='.$fset->dbID.' where data_set_id='.$dset->dbID;
$self->dbc->do($sql);
}
my %stored_dbids;
map {$stored_dbids{$_->dbID} = undef} @{$stored_dset->get_supporting_sets()};
foreach my $sset(@{$dset->get_supporting_sets()}){
my $dbid = $sset->dbid;
if(! grep(/^${dbid}$/, keys %stored_dbids)){
throw("All supporting sets must be stored previously.".
" Use store_updated_sets method if your DataSet has been stored") if(! $sset->is_stored($db));
throw('You are trying to update supporting sets for a data set which already has a product FeatureSet('.$stored_fset->name.'). You must rollback the FeatureSet before adding more supporting sets.') if defined $stored_fset;
$sth->bind_param(1, $dset->dbID, SQL_INTEGER);
$sth->bind_param(2, $sset->dbID, SQL_INTEGER);
$sth->bind_param(2, $sset->set_type, SQL_VARCHAR);
$sth->execute();
}
}
}
return\@ dsets } |
General documentation
This module was created by Nathan Johnson.
This module is part of the Ensembl project:
/
Args : None
Example : None
Description: PROTECTED implementation of superclass abstract method.
Returns an ORDER BY clause. Sorting by oligo_feature_id would be
enough to eliminate duplicates, but sorting by location might
make fetching features on a slice faster.
Returntype : String
Exceptions : None
Caller : generic_fetch
Status : At Risk