$db = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);
$pga = $db->get_PopulationGenotypeAdaptor();
$pa = $db->get_PopulationAdaptor();
# Get a PopulationGenotype by its internal identifier
$pgtype = $ia->fetch_by_dbID(145);
print $pgtype->population->name(), " ",
$pgtype->allele1(), ' ', $pgtype->allele2(), ' ', $pgtype->frequency();
# Get all population genotypes for an population
$pop = $pa->fetch_by_dbID(1219);
foreach $pgtype (@{$pga->fetch_all_by_Population($pop)}) {
print $pgtype->variation()->name(), ' ',
$pgtype->frequency();
$pgtype->allele1(), '/', $pgtype->allele2(), "\n";
}
This adaptor provides database connectivity for PopulationGenotype objects.
PopulationGenotypes 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 @results;
my ($dbID, $variation_id, $sample_id, $allele_1, $allele_2, $frequency);
$sth->bind_columns(\$dbID,\$ variation_id,\$ sample_id,\$ allele_1,\$ allele_2,\$ frequency);
my %population_hash;
my %variation_hash;
while($sth->fetch()){
my $pgtype = Bio::EnsEMBL::Variation::PopulationGenotype->new
(-dbID => $dbID,
-adaptor => $self,
-allele1 => $allele_1,
-allele2 => $allele_2,
-frequency => $frequency);
$population_hash{$sample_id} ||= [];
$variation_hash{$variation_id} ||= [];
push @{$variation_hash{$variation_id}}, $pgtype; push @{$population_hash{$sample_id}}, $pgtype; push @results, $pgtype;
}
my @var_ids = keys %variation_hash;
my $va = $self->db()->get_VariationAdaptor();
my $vars = $va->fetch_all_by_dbID_list(\@var_ids);
foreach my $v (@$vars) {
foreach my $igty (@{$variation_hash{$v->dbID()}}) {
$igty->variation($v);
}
}
my @pop_ids = keys %population_hash;
my $pa = $self->db()->get_PopulationAdaptor();
my $pops = $pa->fetch_all_by_dbID_list(\@pop_ids);
foreach my $p (@$pops) {
foreach my $pgty (@{$population_hash{$p->dbID()}}) {
$pgty->population($p);
}
}
return\@ results;
}
1; } |
sub fetch_all_by_Population
{ my $self = shift;
my $pop = shift;
if(!ref($pop) || !$pop->isa('Bio::EnsEMBL::Variation::Population')) {
throw('Bio::EnsEMBL::Variation::Population argument expected');
}
if(!defined($pop->dbID())) {
warning("Cannot retrieve genotypes for population without set dbID");
return [];
}
return $self->generic_fetch("sample_id = " . $pop->dbID()); } |
sub fetch_all_by_Variation
{ my $self = shift;
my $variation = shift;
if(!ref($variation) || !$variation->isa('Bio::EnsEMBL::Variation::Variation')) {
throw('Bio::EnsEMBL::Variation::Variation argument expected');
}
if(!defined($variation->dbID())) {
warning("Cannot retrieve genotypes for variation without set dbID");
return [];
}
return $self->generic_fetch("variation_id = " . $variation->dbID()); } |
sub fetch_by_dbID
{ my $self = shift;
my $dbID = shift;
if (! $dbID){
throw('no dbID argument provided');
}
return shift @{$self->generic_fetch("population_genotype_id = " . $dbID)}; } |