Bio::EnsEMBL::Funcgen::DBSQL
SetFeatureAdaptor
Toolbar
Summary
Bio::EnsEMBL::DBSQL::Funcgen::SetFeatureAdaptor - A base database adaptor for SetFeature adaptors.
storing SetFeature objects.
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
my $afa = $db->get_SetFeatureAdaptor();
my $features = $afa->fetch_all_by_Slice($slice);
Description
The SetFeatureAdaptor is a base adaptor for all SetFeature adaptors.
e.g. SetFeature, AnnotatedFeature etc. It provides common methods
across all feature types.
Methods
Methods description
Args : None Example : None Description: PROTECTED implementation of superclass abstract method. Returns an additional table joining constraint to use for queries. Returntype : List of strings Exceptions : None Caller : Internal Status : At Risk |
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 |
Example : my $syn = $adaptor->_main_table->[1]; Description: Convenience method to retrieve the main table or main table synonym for this adaptor Entirely dependent on ensembl convention of always having main table as first element of tables array. Returntype : Arrayref Exceptions : None Caller : General Status : At Risk |
Arg [1] : Arrayref of Bio::EnsEMBL::FeatureSet objects Arg [2] : optional - analysis.logic_name Example : my $features = $set_feature_adaptor->fetch_all_by_FeatureSets(@fsets); Description: Retrieves a list of features specific for a given list of FeatureSets. Returntype : Listref of Bio::EnsEMBL::SetFeature objects Exceptions : Throws if list provided does not contain FeatureSets or if none provided Caller : General Status : At Risk |
Arg [1] : Bio::EnsEMBL::Slice Arg [2] : Bio::EnsEMBL::FeatureType Arg [3] : (optional) hashref - params hash associated => 1, #Also return feature which have the associated FeatureType logic_name => 'analysis.logic_name' Example : my $slice = $sa->fetch_by_region('chromosome', '1'); my $features = $ofa->fetch_all_by_Slice_FeatureType($slice, $ft); Description: Retrieves a list of features on a given slice, specific for a given FeatureType. Returntype : Listref of Bio::EnsEMBL::SetFeature objects Exceptions : Throws if no FeatureType object provided Caller : General Status : At Risk |
Arg [1] : Bio::EnsEMBL::SetFeature Arg [] : (optional) string - analysis logic name Arg [4] : (optional) hashref - params hash, all entries optional -logic_name => 'analysis.logic_name' -include_direct_links => 1, #Also return feature which are linked by Feature->feature_type Example : my $slice = $sa->fetch_by_region('chromosome', '1'); my $features = $ofa->fetch_all_by_Slice_FeatureType($slice, $ft); Description: Retrieves a list of all features linked via the associated FeatureTypes of the given Feature in the same FeatureSet Returntype : Listref of Bio::EnsEMBL::SetFeature objects Exceptions : Throws if SetFeature not stored and valid Caller : General Status : At Risk |
Arg [1] : Bio::EnsEMBL::Slice Arg [2] : Arrayref of Bio::EnsEMBL::FeatureSet objects Arg [3] : optional - analysis.logic_name Example : my $slice = $sa->fetch_by_region('chromosome', '1'); my $features = $ofa->fetch_by_Slice_FeatureSets($slice, @fsets); Description: Retrieves a list of features on a given slice, specific for a given list of FeatureSets. Returntype : Listref of Bio::EnsEMBL::SetFeature objects Exceptions : Throws if list provided does not contain FeatureSets or if none provided Caller : General Status : At Risk |
Arg [1] : Bio::EnsEMBL::Slice Arg [2] : Bio::EnsEMBL::FeatureType Arg [3] : (optional) string - analysis logic name Example : my $slice = $sa->fetch_by_region('chromosome', '1'); my $features = $ofa->fetch_all_by_Slice_FeatureType($slice, $ft); Description: Retrieves a list of features on a given slice, specific for a given FeatureType. Returntype : Listref of Bio::EnsEMBL::SetFeature objects Exceptions : Throws if no FeatureType object provided Caller : General Status : At Risk |
Arg [1] : string $logic_name the logic name of the analysis of features to obtain Example : $fs = $a->fetch_all_by_logic_name('foobar'); Description : Returns an arrayref of features created from the database. only features with an analysis of type $logic_name will be returned. Returntype : arrayref of Bio::EnsEMBL::SetFeatures Exceptions : thrown if $logic_name not defined 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 : Medium Risk |
Arg [1] : string $logic_name the logic name of the analysis of features to obtain Example : $fs = $a->fetch_all_by_logic_name('foobar'); Description : Returns an arrayref of features created from the database. only features with an analysis of type $logic_name will be returned. Returntype : arrayref of Bio::EnsEMBL::SetFeatures Exceptions : thrown if $logic_name not defined Caller : General Status : At risk |
Methods code
sub _default_where_clause
{ my $self = shift;
return $self->_main_table->[1].'.feature_set_id = fs.feature_set_id'; } |
sub _final_clause
{ my $self = shift;
return ' ORDER BY '.$self->_main_table->[1].'.seq_region_id, '.$self->_main_table->[1].'.seq_region_start';
}
} |
sub _logic_name_to_constraint
{ my $self = shift;
my $constraint = shift;
my $logic_name = shift;
return $constraint if (!$logic_name);
my $aa = $self->db->get_AnalysisAdaptor();
my $an = $aa->fetch_by_logic_name($logic_name);
if(! $an) {
warn("No analysis associated with logic_name $logic_name");
return undef;
}
my $an_id = $an->dbID();
$constraint .= ' AND' if($constraint);
$constraint .= " fs.analysis_id = $an_id";
return $constraint; } |
sub _main_table
{ my $self = shift;
my @tables = $self->_tables();
return $tables[0];
}
1; } |
sub fetch_all_by_FeatureSets
{ my ($self, $fsets, $logic_name) = @_;
my @fs_ids;
throw('Must provide a list of Bio::EnsEMBL::FeatureSet objects') if scalar(@{$fsets}) == 0;
foreach my $fset (@{$fsets}) {
throw('Not a FeatureSet object')
if ! (ref($fset) && $fset->isa("Bio::EnsEMBL::Funcgen::FeatureSet"));
push (@fs_ids, $fset->dbID());
}
my $fs_ids = join(',', @fs_ids) if scalar(@fs_ids >1);
my $constraint = $self->_main_table->[1].'.feature_set_id ';
$constraint .= (scalar(@fs_ids) >1) ? "IN ($fs_ids)" : '='.$fs_ids[0];
$constraint = $self->_logic_name_to_constraint($constraint, $logic_name);
return $self->generic_fetch($constraint); } |
sub fetch_all_by_FeatureType_FeatureSets
{ my ($self, $ftype, $fsets, $params) = @_;
$params->{'logic_name'} ||= undef;
$params->{'associated'} ||= undef;
$self->db->is_stored_and_valid('Bio::EnsEMBL::Funcgen::FeatureType', $ftype);
my @fs_ids;
throw('Must provide a list of Bio::EnsEMBL::FeatureSet objects') if scalar(@{$fsets}) == 0;
foreach my $fset (@{$fsets}) {
$self->db->is_stored_and_valid('Bio::EnsEMBL::Funcgen::FeatureSet', $fset);
push (@fs_ids, $fset->dbID());
}
my $fs_ids = join(',', @fs_ids) if scalar(@fs_ids >1);
my ($table_name, $table_syn) = @{$self->_main_table};
my $constraint = $table_syn.'.feature_set_id = fs.feature_set_id AND '.
$table_syn.'.feature_type_id='.$ftype->dbID.' AND '.$table_syn.'.feature_set_id ';
$constraint .= (scalar(@fs_ids) >1) ? "IN ($fs_ids)" : '='.$fs_ids[0];
$constraint = $self->_logic_name_to_constraint($constraint, $params->{logic_name});
my @features = @{$self->generic_fetch($constraint)};
if ($params->{'associated'}){
for my $fset(@{$fsets}){
next if $table_name ne lc($fset->type).'_feature';
my $sql = 'SELECT feature_id from associated_feature_type where feature_table="'.$fset->type.'" and feature_type_id='.$ftype->dbID;
my @dbids = map $_ = "@$_", @{$self->dbc->db_handle->selectall_arrayref($sql)};
if(@dbids){
$constraint = " $table_syn.${table_name}_id in (".join(',',@dbids).') ' if @dbids;
push @features, @{$self->generic_fetch($constraint, $params->{logic_name})};
}
}
}
return\@ features;
} |
sub fetch_all_by_Feature_associated_feature_types
{ my ($self, $feature, $params) = @_;
$self->db->is_stored_and_valid('Bio::EnsEMBL::Funcgen::SetFeature', $feature);
$params->{'include_direct_links'} ||= undef;
$params->{'logic_name'} ||= undef;
my %dbIDs; my ($table_name, $table_syn) = @{$self->_main_table};
my $fset = $feature->feature_set;
my ($sql, $constraint, @features);
if($params->{'include_direct_links'}){
$sql = "SELECT ${table_name}_id from $table_name where feature_type_id=".$feature->feature_type->dbID.' and feature_set_id='.$fset->dbID;
map {$dbIDs{"@$_"} = undef} @{$self->dbc->db_handle->selectall_arrayref($sql)};
}
my @assoc_ftypes = @{$feature->associated_feature_types};
if(@assoc_ftypes){
my $ftype_ids = join(', ', (map $_->dbID, @assoc_ftypes));
$sql = "SELECT feature_id from associated_feature_type aft, $table_name $table_syn where aft.feature_table='".$fset->type."' and aft.feature_type_id in ($ftype_ids) and aft.feature_id=${table_syn}.${table_name}_id and ${table_syn}.feature_set_id=".$fset->dbID;
map {$dbIDs{"@$_"} = undef} @{$self->dbc->db_handle->selectall_arrayref($sql)};
}
if(keys %dbIDs){
$constraint = " $table_syn.${table_name}_id in (".join(',', keys %dbIDs).')';
push @features, @{$self->generic_fetch($constraint, $params->{logic_name})};
}
return\@ features; } |
sub fetch_all_by_Slice_FeatureSets
{ my ($self, $slice, $fsets, $logic_name) = @_;
my @fs_ids;
throw('Must provide a list of Bio::EnsEMBL::FeatureSet objects') if scalar(@{$fsets}) == 0;
foreach my $fset (@{$fsets}) {
throw('Not a FeatureSet object')
if ! ($fset && ref($fset) && $fset->isa("Bio::EnsEMBL::Funcgen::FeatureSet"));
push (@fs_ids, $fset->dbID());
}
my $fs_ids = join(',', @fs_ids) if scalar(@fs_ids >1);
my $constraint = $self->_main_table->[1].'.feature_set_id ';
$constraint .= (scalar(@fs_ids) >1) ? "IN ($fs_ids)" : '='.$fs_ids[0];
$constraint = $self->_logic_name_to_constraint($constraint, $logic_name);
return $self->SUPER::fetch_all_by_Slice_constraint($slice, $constraint);
}
} |
sub fetch_all_by_Slice_FeatureType
{ my ($self, $slice, $type, $logic_name) = @_;
$self->db->is_stored_and_valid('Bio::EnsEMBL::Funcgen::FeatureType', $type);
my $ft_id = $type->dbID();
my $constraint = $self->_main_table->[1].".feature_set_id = fs.feature_set_id AND ".
"fs.feature_type_id = '$ft_id'";
$constraint = $self->_logic_name_to_constraint($constraint, $logic_name);
return $self->SUPER::fetch_all_by_Slice_constraint($slice, $constraint); } |
sub fetch_all_by_logic_name
{ my $self = shift;
my $logic_name = shift || throw( "Need a logic_name" );
my $constraint;
my $an = $self->db->get_AnalysisAdaptor->fetch_by_logic_name($logic_name);
$constraint = ' '.$self->_main_table->[1].'.feature_set_id=fs.feature_set_id and fs.analysis_id = '.$an->dbID() if($an);
return (defined $constraint) ? $self->generic_fetch($constraint) : undef; } |
sub list_dbIDs
{ my $self = shift;
return $self->_list_dbIDs($self->_main_table->[0]); } |
sub store_associated_feature_types
{ my ($self, $set_feature) = @_;
my $assoc_ftypes = $set_feature->{'associated_feature_types'};
return if ! defined $assoc_ftypes || scalar(@$assoc_ftypes) == 0;
my $type = $set_feature->feature_set->type;
my $feature_id = $set_feature->dbID;
my $sql = 'INSERT into associated_feature_type(feature_id, feature_table, feature_type_id) values (?,?,?)';
foreach my $ftype(@$assoc_ftypes){
$self->db->is_stored_and_valid('Bio::EnsEMBL::Funcgen::FeatureType', $ftype);
my $sth = $self->prepare($sql);
$sth->bind_param(1, $feature_id, SQL_INTEGER);
$sth->bind_param(2, $type, SQL_VARCHAR);
$sth->bind_param(3, $ftype->dbID, SQL_INTEGER);
$sth->execute();
}
return; } |
General documentation
This module was created by Nathan Johnson.
This module is part of the Ensembl project:
/