Bio::EnsEMBL::Variation::DBSQL
SampleAdaptor
Toolbar
Summary
Bio::EnsEMBL::Variation::DBSQL::SampleAdaptor
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Abstract class - should not be instantiated. Implementation of
abstract methods must be performed by subclasses.
Base adaptors provides:
#using the adaptor of the subclass, given the id of the sample, returns all synonyms in database
$synonyms = $sample_adaptor->fetch_synonyms($sample_id);
#using the adaptor of the subclass and given the name of the synonym, returns the sample
$sample = $sample_adaptor->fetch_sample_by_synonym($sample_synonym_id);
Description
This is a base class implementing common methods in population, individual and strain. This base
class is simply a way of merging similar concepts that should have the same ID
Methods
Methods description
Arg [1] : listref of ints $id_list The unique database identifiers for the samples to be obtained Example : @individuals = @{$individual_adaptor->fetch_by_dbID_list([1234, 2131, 982]))}; Description: Returns the samples created from the database defined by the the ids in contained in the id list $id_list. If none of the samples are found in the database a reference to an empty list is returned. Returntype : listref of Bio::EnsEMBL::Variation::Sample Exceptions : thrown if $id arg is not provided does not exist Caller : general Status : At Risk |
Arg [1] : int $id The unique sample identifier for the sample to be obtained Example : $population = $population_adaptor->fetch_by_dbID(1234); Description: Returns the feature sample from the database defined by the the id $id. Returntype : Bio::EnsEMBL::Variation::Sample Exceptions : thrown if $id arg is not provided does not exist Caller : general Status : At Risk |
Arg [1] : $sample_synonym Example : my $pop = $pop_adaptor->fetch_sample_by_synonym($sample_synonym,$source); Description : Retrieves sample for the synonym given in the source. If no source is provided, retrieves all the synonyms Returntype : list of Bio::EnsEMBL::Variation::Sample Exceptions : none Caller : general Status : At Risk |
Arg [1] : $sample_id Arg [2] (optional) : $source Example : my $dbSNP_synonyms = $pop_adaptor->fetch_synonyms($sample_id,$dbSNP); my $all_synonyms = $pop_adaptor->fetch_synonyms($sample_id); Description: Retrieves synonyms for the source provided. Otherwise, return all the synonyms for the sample Returntype : list of strings Exceptions : none Caller : Bio:EnsEMBL:Variation::Sample Status : At Risk |
Methods code
sub fetch_all_by_dbID_list
{ my ($self,$id_list_ref) = @_;
if(!defined($id_list_ref) || ref($id_list_ref) ne 'ARRAY') {
throw("id_list list reference argument is required");
}
return [] if(!@$id_list_ref);
my @out;
my @tabs = $self->_tables;
my ($name, $syn) = @{$tabs[0]};
my $max_size = 200;
my @id_list = @$id_list_ref;
while(@id_list) {
my @ids;
if(@id_list > $max_size) {
@ids = splice(@id_list, 0, $max_size);
} else {
@ids = splice(@id_list, 0);
}
my $id_str;
if(@ids > 1) {
$id_str = " IN (" . join(',', @ids). ")";
} else {
$id_str = " = ?";
$self->bind_param_generic_fetch($ids[0],SQL_INTEGER);
}
my $constraint = "${syn}.sample_id $id_str";
push @out, @{$self->generic_fetch($constraint)};
}
return\@ out;
}
1; } |
sub fetch_by_dbID
{ my ($self,$id) = @_;
throw("id argument is required") if(!defined $id);
my @tabs = $self->_tables;
my ($name, $syn) = @{$tabs[0]};
my $constraint = "${syn}.sample_id = ?";
$self->bind_param_generic_fetch($id,SQL_INTEGER);
my ($feat) = @{$self->generic_fetch($constraint)};
return undef if(!$feat);
return $feat; } |
sub fetch_sample_by_synonym
{ my $self = shift;
my $synonym_name = shift;
my $source = shift;
my $sql;
my $sample;
my $sample_array;
if (defined $source){
$sql = qq{SELECT sample_id FROM sample_synonym ss, source s WHERE ss.name = ? and ss.source_id = s.source_id AND s.name = "$source"};
}
else{
$sql = qq{SELECT sample_id FROM sample_synonym WHERE name = ?};
}
my $sample_id;
my $sth = $self->prepare($sql);
$sth->bind_param(1,$synonym_name,SQL_VARCHAR);
$sth->execute();
$sth->bind_columns(\$sample_id);
while ($sth->fetch()){
push @{$sample_array}, $sample_id;
}
return $sample_array; } |
sub fetch_synonyms
{ my $self = shift;
my $dbID = shift;
my $source = shift;
my $sample_synonym;
my $synonyms;
my $sql;
if (defined $source){
$sql = qq{SELECT ss.name FROM sample_synonym ss, source s WHERE ss.sample_id = ? AND ss.source_id = s.source_id AND s.name = "$source"}
}
else{
$sql = qq{SELECT name FROM sample_synonym WHERE sample_id = ?};
}
my $sth = $self->prepare($sql);
$sth->bind_param(1,$dbID,SQL_INTEGER);
$sth->execute();
$sth->bind_columns(\$sample_synonym);
while ($sth->fetch){
push @{$synonyms},$sample_synonym;
}
return $synonyms; } |
General documentation