my $msa = $registry->get_adaptor( 'Human', 'Core', 'MiscSet' );
my $misc_set = $msa->fetch_by_dbID(1234);
$misc_set = $msa->fetch_by_code('clone');
This class provides database interactivity for MiscSet objects.
MiscSets are used to classify MiscFeatures into groups.
sub fetch_all
{ my $self = shift;
my $sth = $self->prepare
('SELECT misc_set_id, code, name, description, max_length FROM misc_set');
$sth->execute();
my ($dbID, $code, $name, $desc, $max_len);
$sth->bind_columns(\$dbID,\$ code,\$ name,\$ desc,\$ max_len);
my @all;
while($sth->fetch()) {
my $ms = Bio::EnsEMBL::MiscSet->new
(-DBID => $dbID,
-ADAPTOR => $self,
-CODE => $code,
-NAME => $name,
-DESCRIPTION => $desc,
-LONGEST_FEATURE => $max_len);
$self->{'_id_cache'}->{$dbID} = $ms;
$self->{'_code_cache'}->{lc($code)} = $ms;
push @all, $ms;
}
$sth->finish();
return\@ all; } |
sub fetch_by_code
{ my $self = shift;
my $code = shift;
if(!$self->{'_code_cache'}->{lc($code)}) {
$self->fetch_all();
}
return $self->{'_code_cache'}->{lc($code)}; } |
sub fetch_by_dbID
{ my $self = shift;
my $dbID = shift;
if(!$self->{'_id_cache'}->{$dbID}) {
$self->fetch_all();
}
return $self->{'_id_cache'}->{$dbID}; } |
sub new
{ my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{'_id_cache'} = {};
$self->{'_code_cache'} = {};
$self->fetch_all();
return $self; } |
sub store
{ my $self = shift;
my @misc_sets = @_;
my $sth = $self->prepare
("INSERT IGNORE INTO misc_set " .
"SET code = ?, " .
" name = ?, " .
" description = ?, " .
" max_length = ?");
my $db = $self->db();
SET:
foreach my $ms (@misc_sets) {
if(!ref($ms) || !$ms->isa('Bio::EnsEMBL::MiscSet')) {
throw("List of MiscSet arguments expected.");
}
if($ms->is_stored($db)) {
warning("MiscSet [".$ms->dbID."] is already stored in this database.");
next SET;
}
$sth->bind_param(1,$ms->code,SQL_VARCHAR);
$sth->bind_param(2,$ms->name,SQL_VARCHAR);
$sth->bind_param(3,$ms->description,SQL_LONGVARCHAR);
$sth->bind_param(4,$ms->longest_feature,SQL_INTEGER);
my $num_inserted = $sth->execute();
my $dbID;
if($num_inserted == 0) {
my $sth2 = $self->prepare("SELECT misc_set_id from misc_set " .
"WHERE code = ?");
$sth2->bind_param(1,$ms->code,SQL_VARCHAR);
$sth2->execute();
if($sth2->rows() != 1) {
throw("Could not retrieve or store MiscSet, code=[".$ms->code."]\n".
"Wrong database user/permissions?");
}
($dbID) = $sth2->fetchrow_array();
} else {
$dbID = $sth->{'mysql_insertid'};
}
$ms->dbID($dbID);
$ms->adaptor($self);
$self->{'_id_cache'}->{$dbID} = $ms;
$self->{'_code_cache'}->{lc($ms->code())} = $ms;
}
return;
}
1; } |