Bio::EnsEMBL::Variation::DBSQL
IndividualAdaptor
Toolbar
Summary
Bio::EnsEMBL::DBSQL::IndividualAdaptor
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
my $db = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);
my $ia = $db->get_IndividualAdaptor();
# Get an individual by its internal identifier
my $ind = $ia->fetch_by_dbID(52);
# Get all individuals with a particular name
foreach my $ind (@{$ia->fetch_all_by_name('PKH053(M)')}) {
print "Individual ", $ind->name(), "\n";
}
# get all individuals from a population
my $pop = $pop_adaptor->fetch_by_name('PACIFIC');
foreach my $ind (@{$ia->fetch_all_by_Population($pop)}) {
print $ind->name(), "\n";
}
# get all children of an individual
foreach my $child (@{$ia->fetch_all_by_parent($ind)}) {
print $child->name(), " is a child of ", $ind->name(), "\n";
}
Description
This adaptor provides database connectivity for Individual objects.
Individuals may be retrieved from the ensembl variation database by
several means using this module.
Methods
Methods description
Arg [1] : Bio::EnsEMBL::Variation::Population $pop Example : my $pop = $pop_adaptor->fetch_by_name('PACIFIC'); foreach my $ind (@{$ia->fetch_all_by_Population($pop)}) { print $ind->name(), "\n"; } Description: Retrieves all individuals from a specified population Returntype : reference to list of Bio::EnsEMBL::Variation::Individual objects Exceptions : throw if incorrect argument is passed warning if provided Population does not have an dbID Caller : general Status : At Risk |
Arg [1] : string $name the name of the individuals to retrieve Example : my @inds = @{$ind_adaptor->fetch_all_by_name('CEPH1332.05')}; Description: Retrieves all individuals with a specified name. Individual names may be non-unique which is why this method returns a reference to a list. Returntype : reference to a list of Individual ids Exceptions : throw if no argument passed Caller : general Status : At Risk |
Arg [1] : Bio::EnsEMBL::Variation::Individual Example : my @children = @{$ia->fetch_all_by_parent_Individual($ind)}; Description: Retrieves all individuals which are children of a provided parent individual. This function operates under the assumptions that Male individuals can only be fathers, Female individuals can only be mothers and Unknown individuals can only be one or the other - not both. Returntype : reference to list of Bio::EnsEMBL::Variation::Individuals Exceptions : throw if incorrect argument passed warning if provided individual has no dbID Caller : general, Individual::get_all_child_Individuals Status : At Risk |
Args : none Example : my $strains = $ind_adaptor->fetch_all_strains(); Description: Retrieves Individuals that should be considered as strain (fully inbred) in the specie. Returntype : list of Bio::EnsEMBL::Variation::Individual Exceptions : none Caller : Bio:EnsEMBL:Variation::Individual Status : At Risk |
Args : none Example : my $strains = $ind_adaptor->fetch_all_strains_with_coverage(); Description: Retrieves strain that have coverage information Returntype : list of Bio::EnsEMBL::Variation::Individual Exceptions : none Caller : web Status : At Risk |
Arg [1] : $individual_synonym Example : my $ind = $ind_adaptor->fetch_individual_by_synonym($individual_synonym,$source); Description : Retrieves individual for the synonym given in the source. If no source is provided, retrieves all the synonyms Returntype : list of Bio::EnsEMBL::Variation::Individual Exceptions : none Caller : general Status : At Risk |
Args : none Example : my $strains = $ind_adaptor->get_default_strains(); Description: Retrieves strain_names that are defined as default in the database(mainly, for web purposes) Returntype : list of strings Exceptions : none Caller : web Status : At Risk |
Args : none Example : my $strains = $ind_adaptor->get_display_strains(); Description: Retrieves strain_names that are going to be displayed in the web (reference + default + others) Returntype : list of strings Exceptions : none Caller : web Status : At Risk |
Args : none Example : my $reference_strain = $ind_adaptor->get_reference_strain_name(); Description: Retrieves the reference strain_name that is defined as default in the database(mainly, for web purposes) Returntype : string Exceptions : none Caller : web Status : At Risk |
Methods code
sub _columns
{ return qw(s.sample_id s.name s.description s.display i.gender i.father_individual_sample_id i.mother_individual_sample_id it.name it.description); } |
sub _default_where_clause
{ return 's.sample_id = i.sample_id AND i.individual_type_id = it.individual_type_id';
}
1; } |
sub _objs_from_sth
{ my $self = shift;
my $sth = shift;
my ($dbID, $name, $desc, $gender, $display_flag, $father_id, $mother_id,$it_name,$it_desc);
$sth->bind_columns(\$dbID,\$ name,\$ desc,\$ display_flag,\$ gender,\$
father_id,\$ mother_id,\$ it_name,\$ it_desc);
my %seen;
my %wanted_fathers;
my %wanted_mothers;
my @inds;
while($sth->fetch()) {
my $father;
if(defined($father_id)) {
$father = $seen{$father_id};
if(!$father) {
$wanted_fathers{$dbID} ||= [];
push @{$wanted_fathers{$father_id}}, $dbID;
}
}
my $mother;
if(defined($mother_id)) {
$mother = $seen{$mother_id};
if(!$mother) {
$wanted_mothers{$mother_id} ||= [];
push @{$wanted_mothers{$mother_id}}, $dbID;
}
}
my $ind = $seen{$dbID} ||= Bio::EnsEMBL::Variation::Individual->new
(-dbID => $dbID,
-adaptor => $self,
-description => $desc,
-display => $display_flag,
-gender => $gender,
-name => $name,
-father_individual => $father,
-mother_individual => $mother,
-father_individual_sample_id => $father_id,
-mother_individual_sample_id => $mother_id,
-type_individual => $it_name,
-type_description => $it_desc);
$seen{$dbID} = $ind;
push @inds, $ind;
}
foreach my $wanted_id (keys %wanted_fathers) {
if($seen{$wanted_id}) {
foreach my $ind_id (@{$wanted_fathers{$wanted_id}}) {
$seen{$ind_id}->father_Individual($seen{$wanted_id});
}
}
}
foreach my $wanted_id (keys %wanted_mothers) {
if($seen{$wanted_id}) {
foreach my $ind_id (@{$wanted_mothers{$wanted_id}}) {
$seen{$ind_id}->mother_Individual($seen{$wanted_id});
}
}
}
return\@ inds; } |
sub _tables{return
{(['individual','i'], ['sample','s'],
['individual_type','it']) } |
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 arg expected");
}
if(!$pop->dbID()) {
warning("Population does not have dbID, cannot retrieve Individuals");
return [];
}
my $sth = $self->prepare
(q{SELECT i.sample_id, s.name, s.description, s.display, i.gender, i.father_individual_sample_id, i.mother_individual_sample_id, it.name, it.description FROM individual i, individual_population ip, sample s, individual_type it WHERE i.sample_id = ip.individual_sample_id AND i.sample_id = s.sample_id AND i.individual_type_id = it.individual_type_id AND ip.population_sample_id = ?});
$sth->bind_param(1,$pop->dbID,SQL_INTEGER);
$sth->execute();
my $results = $self->_objs_from_sth($sth);
$sth->finish();
return $results; } |
sub fetch_all_by_name
{ my $self = shift;
my $name = shift;
defined($name) || throw("name argument expected");
my $sth = $self->prepare
(q{SELECT i.sample_id, s.name, s.description, s.display, i.gender, i.father_individual_sample_id, i.mother_individual_sample_id, it.name, it.description FROM individual i, sample s, individual_type it WHERE s.name = ? AND it.individual_type_id = i.individual_type_id AND s.sample_id = i.sample_id});
$sth->bind_param(1,$name,SQL_VARCHAR);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return $result; } |
sub fetch_all_by_parent_Individual
{ my $self = shift;
my $parent = shift;
if(!ref($parent) || !$parent->isa('Bio::EnsEMBL::Variation::Individual')) {
throw("Bio::EnsEMBL::Variation::Individual argument expected");
}
if(!defined($parent->dbID())) {
warning("Cannot fetch child Individuals for parent without dbID");
return [];
}
my $gender = $parent->gender() || '';
my $father_sql =
q{SELECT i.sample_id, s.name, s.description, s.display, i.gender, i.father_individual_sample_id, i.mother_individual_sample_id, it.name, it.description FROM individual i, sample s, individual_type it WHERE i.father_individual_sample_id = ? AND i.individual_type_id = it.individual_type_id AND s.sample_id = i.sample_id};
my $mother_sql =
q{SELECT i.sample_id, s.name, s.description, s.display, i.gender, i.father_individual_sample_id, i.mother_individual_sample_id, it.name, it.description FROM individual i, sample s, individual_type it WHERE i.mother_individual_sample_id = ? AND i.individual_type_id = it.individual_type_id AND i.sample_id = s.sample_id};
if($gender eq 'Male') {
my $sth = $self->prepare($father_sql);
$sth->bind_param(1,$parent->dbID,SQL_INTEGER);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return $result;
}
elsif($gender eq 'Female') {
my $sth = $self->prepare($mother_sql);
$sth->bind_param(1,$parent->dbID,SQL_INTEGER);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return $result;
}
my $sth = $self->prepare($mother_sql);
$sth->bind_param(1,$parent->dbID,SQL_INTEGER);
$sth->execute();
my $result = $self->_objs_from_sth($sth);
$sth->finish();
return if(@$result);
$sth = $self->prepare($father_sql);
$sth->bind_param(1,$parent->dbID,SQL_INTEGER);
$sth->execute();
$result = $self->_objs_from_sth($sth);
$sth->finish();
return $result; } |
sub fetch_all_strains
{ my $self = shift;
return $self->generic_fetch("it.name = 'fully_inbred'"); } |
sub fetch_all_strains_with_coverage
{
my $self = shift;
my $sample_id;
my @strains;
my $sth = $self->prepare(qq{SELECT DISTINCT sample_id from read_coverage
});
$sth->execute();
$sth->bind_columns(\$sample_id);
while ($sth->fetch()){
push @strains, $self->fetch_by_dbID($sample_id)
}
$sth->finish;
return\@ strains;
}
} |
sub fetch_individual_by_synonym
{ my $self = shift;
my $synonym_name = shift;
my $source = shift;
my $individuals;
my $ind;
my $samples = $self->SUPER::fetch_sample_by_synonym($synonym_name, $source);
foreach my $sample_id (@{$samples}){
$ind = $self->fetch_by_dbID($sample_id);
push @{$individuals}, $ind if (defined $ind);
}
return $individuals; } |
sub get_default_strains
{ my $self = shift;
my @strain_names;
my $name;
my $sth = $self->prepare(qq{SELECT name FROM sample WHERE display = ?});
$sth->bind_param(1, 'DEFAULT');
$sth->execute;
$sth->bind_columns(\$name);
while ($sth->fetch()){
push @strain_names, $name;
}
$sth->finish;
return\@ strain_names; } |
sub get_display_strains
{ my $self = shift;
my @strain_names;
my $name;
$name = $self->get_reference_strain_name();
push @strain_names, $name;
my $default_strains = $self->get_default_strains();
push @strain_names, @{$default_strains};
my $sth = $self->prepare(qq{SELECT name FROM sample WHERE display = ?});
$sth->bind_param(1, 'DISPLAYABLE');
$sth->execute;
$sth->bind_columns(\$name);
while ($sth->fetch()){
push @strain_names, $name;
}
$sth->finish;
return\@ strain_names; } |
sub get_reference_strain_name
{ my $self = shift;
my $name;
my $sth = $self->prepare(qq{SELECT name FROM sample WHERE display = ?});
$sth->bind_param(1, 'REFERENCE');
$sth->execute;
$sth->bind_columns(\$name);
$sth->fetch();
$sth->finish;
return $name;
} |
General documentation
AUTHOR - Graham McVicker | Top |