$db = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);
$aga = $db->get_AlleleGroupAdaptor();
# retrieve an allele group by its name
$ag = $aga->fetch_by_name('ABDR-10');
# retrieve a variation group by its internal identifier
$ag = $aga->fetch_by_dbID(123);
# retrieve all allele groups which are part of the same variation group
@ags = @{$aga->fetch_all_by_VariationGroup($vg)};
This adaptor provides database connectivity for AlleleGroup objects.
AlleleGroups may be retrieved from the Ensembl variation database by
several means using this module.
sub _objs_from_sth
{ my $self = shift;
my $sth = shift;
my ($ag_id, $vg_id, $sample_id, $name, $source, $freq, $allele, $var_id);
$sth->bind_columns(\$ag_id,\$ vg_id,\$ sample_id,\$ name,\$ source,\$
freq,\$ allele,\$ var_id);
my %pop_cache;
my %var_cache;
my %vg_cache;
my $pop_adaptor = $self->db->get_PopulationAdaptor();
my $vg_adaptor = $self->db->get_VariationGroupAdaptor();
my @results;
my ($cur_ag, $cur_ag_id);
while($sth->fetch()) {
if(!defined($cur_ag) || $cur_ag_id != $ag_id) {
my $pop;
if(defined($sample_id)) {
$pop = $pop_cache{$sample_id} ||= $pop_adaptor->fetch_by_dbID($sample_id);
}
my $vg;
if(defined($vg_id)) {
$vg = $vg_cache{$vg_id};
if(!$vg) {
$vg = $vg_adaptor->fetch_by_dbID($vg_id);
foreach my $v (@{$vg->get_all_Variations()}) {
$var_cache{$v->dbID()} = $v;
}
}
}
$cur_ag = Bio::EnsEMBL::Variation::AlleleGroup->new
(-dbID => $ag_id,
-adaptor => $self,
-population => $pop,
-name => $name,
-source => $source,
-variation_group => $vg,
-frequency => $freq);
$cur_ag_id = $ag_id;
push @results, $cur_ag;
}
if($var_id) {
my $var = $var_cache{$var_id};
if($var) {
$cur_ag->add_Variation($var, $allele);
} else {
warning("AlleleGroup's VariationGroup does not contain variation " .
"$var_id referenced by AlleleGroup.");
}
}
}
return\@ results;
}
1; } |
sub fetch_all_by_VariationGroup
{ my $self = shift;
my $vg = shift;
if(!ref($vg) || !$vg->isa('Bio::EnsEMBL::Variation::VariationGroup')) {
throw('Variation group argument expected');
}
my $sth = $self->prepare
(q{SELECT ag.allele_group_id, ag.variation_group_id, ag.sample_id, ag.name, s.name, ag.frequency, aga.allele, aga.variation_id FROM (allele_group ag, source s) LEFT JOIN allele_group_allele aga ON aga.allele_group_id = ag.allele_group_id WHERE ag.source_id = s.source_id AND ag.variation_group_id = ? ORDER BY ag.allele_group_id});
$sth->bind_param(1,$vg->dbID,SQL_INTEGER);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return $result; } |
sub fetch_by_dbID
{ my $self = shift;
my $dbID = shift;
throw('dbID argument expected') if(!defined($dbID));
my $sth = $self->prepare
(q{SELECT ag.allele_group_id, ag.variation_group_id, ag.sample_id, ag.name, s.name, ag.frequency, aga.allele, aga.variation_id FROM (allele_group ag, source s) LEFT JOIN allele_group_allele aga ON aga.allele_group_id = ag.allele_group_id WHERE ag.source_id = s.source_id AND ag.allele_group_id = ?});
$sth->bind_param(1,$dbID,SQL_INTEGER);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return undef if(!@$result);
return $result->[0]; } |
sub fetch_by_name
{ my $self = shift;
my $name = shift;
throw('name argument expected') if(!defined($name));
my $sth = $self->prepare
(q{SELECT ag.allele_group_id, ag.variation_group_id, ag.sample_id, ag.name, s.name, ag.frequency, aga.allele, aga.variation_id FROM (allele_group ag, source s) LEFT JOIN allele_group_allele aga ON aga.allele_group_id = ag.allele_group_id WHERE ag.source_id = s.source_id AND ag.name = ?});
$sth->bind_param(1,$name,SQL_VARCHAR);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return undef if(!@$result);
return $result->[0]; } |