my ($self,@uos) = @_;
if( scalar(@uos) == 0 ) {
throw("Must call store with list of UnmappedObjects");
}
my $db = $self->db();
my $analysis_adaptor = $db->get_AnalysisAdaptor();
my $sth_reason = $self->prepare
("INSERT INTO unmapped_reason (summary_description, full_description)".
" VALUES (?,?)");
my $sth_unmapped_object = $self->prepare
("INSERT INTO unmapped_object (type, analysis_id, external_db_id,
identifier, unmapped_reason_id, query_score, target_score,
ensembl_id, ensembl_object_type)".
" VALUES (?,?,?,?,?,?,?,?,?)");
my $sth_fetch_reason =
$self->prepare(
"SELECT
unmapped_reason_id
FROM
unmapped_reason
WHERE
full_description = ?
" );
FEATURE: foreach my $uo ( @uos ) {
if( !ref $uo || !$uo->isa("Bio::EnsEMBL::UnmappedObject") ) {
throw("UnmappedObject must be an Ensembl UnmappedObject, " .
"not a [".ref($uo)."]");
}
if($uo->is_stored($db)){
next;
}
my $analysis = $uo->analysis();
throw("UnmappedObject must have an analysis object.".$uo->analysis."\n") if(!defined($analysis));
my $analysis_id;
if($analysis->is_stored($db)) {
$analysis_id = $analysis->dbID();
}
else {
$analysis_id = $db->get_AnalysisAdaptor->store($analysis);
}
# Check if unmapped reason is cached
# Check if it has been added since the cache was created
# Try to store it
if(!defined($desc_to_id{$uo->{'description'}})){
$sth_reason->bind_param(1,$uo->{'summary'},SQL_VARCHAR);
$sth_reason->bind_param(2,$uo->{'description'},SQL_VARCHAR);
if(! eval{ $sth_reason->execute(); 1 }){
# DBI Trace possible here?
warning($@); #
my $msg;
$msg .= "INSERT INTO unmapped_reason (summary_description, full_description) VALUES (";
$msg .= $uo->{'summary'} .','. $uo->{'description'}. ')';
# Temporary fix for naughty cross-dependency regulation code.
use Data::Dumper;
warning("Query: \n$msg");
print STDERR "UnmappedObject: \n";
print STDERR Dumper $uo;
$sth_fetch_reason->execute($uo->{'description'});
my $unmapped_reasons = $sth_fetch_reason->fetchrow_arrayref();
if(! defined($unmapped_reasons)){
my $msg = $uo->{'description'}. " unable to store. Check MySQL schema, maybe PK not big enough?";
throw($msg);
}
if(scalar @$unmapped_reasons != 1){
throw("Multiple results for this description");
}
$uo->{'unmapped_reason_id'} = $unmapped_reasons->[0];
}
else{
# print 'Last mohican: '.$self->last_insert_id ."\n";
$uo->{'unmapped_reason_id'} = $self->last_insert_id;
}
}
else{
$uo->{'unmapped_reason_id'} = $desc_to_id{$uo->{'description'}};
}
$sth_unmapped_object->bind_param(1,$uo->{'type'},SQL_VARCHAR);
$sth_unmapped_object->bind_param(2,$uo->analysis->dbID,SQL_INTEGER);
$sth_unmapped_object->bind_param(3,$uo->{'external_db_id'},SQL_INTEGER);
$sth_unmapped_object->bind_param(4,$uo->{'identifier'},SQL_VARCHAR);
$sth_unmapped_object->bind_param(5,$uo->{'unmapped_reason_id'},SQL_VARCHAR);
$sth_unmapped_object->bind_param(6,$uo->{'query_score'},SQL_DOUBLE);
$sth_unmapped_object->bind_param(7,$uo->{'target_score'},SQL_DOUBLE);
$sth_unmapped_object->bind_param(8,$uo->{'ensembl_id'},SQL_INTEGER);
$sth_unmapped_object->bind_param(9,$uo->{'ensembl_object_type'},SQL_VARCHAR);
$sth_unmapped_object->execute();
$uo->dbID($self->last_insert_id('unmapped_object_id', undef, 'unmapped_object'));
}
$sth_reason->finish();
return;
}