sub fetch_by_dbID
{ my ($self,$taxon_id) = @_;
$self->throw("Should give a defined taxon_id as argument\n") unless (defined $taxon_id);
my $q = "SELECT taxon_id,genus,species,sub_species,common_name,classification
FROM taxon
WHERE taxon_id= ?";
$q = $self->prepare($q);
$q->execute($taxon_id);
if (defined (my $rowhash = $q->fetchrow_hashref)) {
my $taxon = new Bio::EnsEMBL::ExternalData::Family::Taxon;
$taxon->ncbi_taxid($taxon_id); $taxon->sub_species($rowhash->{sub_species});
my @classification = split /\s+/,$rowhash->{classification};
$taxon->classification(@classification);
$taxon->common_name($rowhash->{common_name});
return $taxon;
}
return undef; } |
sub fetch_by_taxon_id
{ my ($self,$taxon_id) = @_;
$self->throw("Should give a defined taxon_id as argument\n") unless (defined $taxon_id);
return $self->fetch_by_dbID($taxon_id); } |
sub store
{ my ($self,$taxon) = @_;
$taxon->isa('Bio::EnsEMBL::ExternalData::Family::Taxon') ||
$self->throw("You have to store a Bio::EnsEMBL::ExternalData::Family::Taxon object, not a $taxon");
my $q = "INSERT INTO taxon (taxon_id,genus,species,sub_species,common_name,classification)
VALUES (?,?,?,?,?,?)";
my $sth = $self->prepare($q);
$sth->execute($taxon->ncbi_taxid,$taxon->genus,$taxon->species,$taxon->sub_species,$taxon->common_name,join " ",$taxon->classification);
$taxon->adaptor($self);
return $taxon->dbID; } |
sub store_if_needed
{ my ($self,$taxon) = @_;
my $q = "select taxon_id from taxon where taxon_id=?";
$q = $self->prepare($q);
$q->execute($taxon->ncbi_taxid);
my $rowhash = $q->fetchrow_hashref;
if ($rowhash->{taxon_id}) {
return $rowhash->{external_db_id};
} else {
return $self->store($taxon);
}
}
1; } |