Bio-EnsEMBL
view release on metacpan or search on metacpan
lib/Bio/EnsEMBL/DBSQL/GenomeContainer.pm view on Meta::CPAN
my $stats_id = $self->fetch_by_statistic($statistic, $attribute)->dbID;
if (defined $stats_id) {
$self->update($statistic, $value, $attribute);
} else {
my $db = $self->db();
my $species_id = $db->species_id();
my $store_genome_sql = q{
INSERT INTO genome_statistics
SET statistic = ?,
value = ?,
species_id = ?,
timestamp = now()
};
if (defined $attribute) {
$store_genome_sql .= ", attrib_type_id = ?";
}
my $sth = $self->prepare($store_genome_sql);
$sth->bind_param(1, $statistic, SQL_VARCHAR);
$sth->bind_param(2, $value, SQL_INTEGER);
$sth->bind_param(3, $species_id, SQL_INTEGER);
if (defined $attribute) {
my $attribute_adaptor = $db->get_AttributeAdaptor();
my $attribute_object = Bio::EnsEMBL::Attribute->new(-code => $attribute);
my $attribute_type_id = $attribute_adaptor->_store_type($attribute_object);
$sth->bind_param(4, $attribute_type_id, SQL_VARCHAR);
}
$sth->execute();
$sth->finish();
$stats_id = $sth->{'mysql_insertid'};
}
return $stats_id;
}
=head2 update
Arg [1] : Statistic
The type of statistic to update
Arg [2] : Value
The corresponding value for the statistic
Arg [3] : (optional) Attribute
If more than one value exists for the statistics, it will be distinguished by its attribute
Example : $genome_adaptor->update('coding_cnt', 20769);
Description: Updates an existing genome statistic in the database
Returntype : none
Exceptions :
Caller : general
Status : Stable
=cut
sub update {
my ($self, $statistic, $value, $attribute) = @_;
my $db = $self->db();
my $update_genome_sql = q{
UPDATE genome_statistics
SET value = ?,
timestamp = now()
};
if (defined $attribute) {
$update_genome_sql .= ', attrib_type_id = ?';
}
$update_genome_sql .= ' WHERE statistic = ? and species_id = ?';
my $sth = $self->prepare($update_genome_sql);
$sth->bind_param(1, $value, SQL_INTEGER);
my $increment = 2;
if (defined $attribute) {
my $attribute_adaptor = $db->get_AttributeAdaptor();
my $attribute_object = Bio::EnsEMBL::Attribute->new(-code => $attribute);
my $attribute_type_id = $attribute_adaptor->_store_type($attribute_object);
$sth->bind_param($increment, $attribute_type_id, SQL_VARCHAR);
$increment++;
}
$sth->bind_param($increment++, $statistic, SQL_VARCHAR);
$sth->bind_param($increment, $db->species_id(), SQL_INTEGER);
$sth->execute();
$sth->finish();
}
=head2 _meta_container
Arg [1] : none
Example : $meta_container = $genome->_meta_container();
Description: Internal method to return a MetaContainer object for the genome
Returntype : Bio::EnsEMBL::DBSQL::MetaContainer
Exceptions : none
Caller : general
Status : Stable
=cut
sub _meta_container {
my $self = shift;
return $self->db->get_adaptor('MetaContainer');
}
=head2 get_version
Arg [1] : (optional) assembly version
Example : $version = $genome->get_version();
Description: Getter/Setter for the assembly version
( run in 1.194 second using v1.01-cache-2.11-cpan-f56aa216473 )