SF.net SVN: gmod:[22220] schema/trunk/chado

View: New views
1 Messages — Rating Filter:   Alert me  

SF.net SVN: gmod:[22220] schema/trunk/chado

by scottcain :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Revision: 22220
          http://gmod.svn.sourceforge.net/gmod/?rev=22220&view=rev
Author:   scottcain
Date:     2009-11-03 22:11:02 +0000 (Tue, 03 Nov 2009)

Log Message:
-----------
Added a __DIE__ signal handler to clean up the database before the bulk loader croaks so that calling --remove_lock and --recreate_cache may become a thing of the past.

Modified Paths:
--------------
    schema/trunk/chado/Changes
    schema/trunk/chado/lib/Bio/GMOD/DB/Adapter.pm
    schema/trunk/chado/load/bin/bulk_load_gff3.PLS

Modified: schema/trunk/chado/Changes
===================================================================
--- schema/trunk/chado/Changes 2009-11-03 21:33:29 UTC (rev 22219)
+++ schema/trunk/chado/Changes 2009-11-03 22:11:02 UTC (rev 22220)
@@ -26,11 +26,19 @@
 * Updated all_feature_names view to search featureprop.value and
 dbxref.accession and added organism_id so GBrowse can limit
 by organism.
+* Fixed gmod_bulk_load_gff3.pl to deal correctly with the case that
+mulitple organisms have the same common name.  If the user tries to
+use a common name that corresponds to more than one organism, it will
+die gracefully.
+* Fixed gmod_bulk_load_gff3.pl so that featureloc.srcfeature_id will
+not be sometimes set incorrectly when there are multiple organisms
+with chromosomes (or other srcfeatures) with the same name.  If you have
+a database that has been affected by this bug, see http://....  for a fix.
+* Added a __DIE__ signal handler to gmod_bulk_load_gff3.pl so that the
+databsae will be cleaned up in most cases before the loader croaks.
 
 
 
-
-
 Below this line are changes up until a few years ago and are included
 for historical purposes.
 ---------------------------------------------------------------------------

Modified: schema/trunk/chado/lib/Bio/GMOD/DB/Adapter.pm
===================================================================
--- schema/trunk/chado/lib/Bio/GMOD/DB/Adapter.pm 2009-11-03 21:33:29 UTC (rev 22219)
+++ schema/trunk/chado/lib/Bio/GMOD/DB/Adapter.pm 2009-11-03 22:11:02 UTC (rev 22220)
@@ -199,6 +199,8 @@
                "INSERT INTO gff_meta (name,hostname) VALUES (?,?)";
 use constant DELETE_FROM_META =>
                "DELETE FROM gff_meta WHERE name = ? AND hostname = ?";
+use constant TMP_TABLE_CLEANUP =>
+               "DELETE FROM tmp_gff_load_cache WHERE feature_id >= ?";
 
 my $ALLOWED_UNIQUENAME_CACHE_KEYS =
                "feature_id|type_id|organism_id|uniquename|validate";
@@ -553,7 +555,13 @@
 ## dgg; keep - this is public;
 sub nextfeature {
     my $self = shift;
-    return $self->nextoid('feature',@_);
+
+    my $fid = $self->nextoid('feature',@_);
+    if (!$self->first_feature_id() ) {
+        $self->first_feature_id( $fid );
+    }
+
+    return $fid;
 #     my $arg = shift if defined(@_);
 #     if (defined($arg) && $arg eq '++') {
 #         return $self->{'nextfeature'}++;
@@ -1328,23 +1336,97 @@
     my ($self, %argv) = @_;
 
     my $dbh = $self->dbh;
-    my $select_query = $dbh->prepare(SELECT_FROM_META);
-    $select_query->execute();
+    my $select_query = $dbh->prepare(SELECT_FROM_META) or warn "select prepare failed";
+    $select_query->execute() or warn "select from meta failed";
 
-    my $delete_query = $dbh->prepare(DELETE_FROM_META);
+    my $delete_query = $dbh->prepare(DELETE_FROM_META) or warn "delete prepare failed";
 
     while (my @result = $select_query->fetchrow_array) {
         my ($name,$host,$time) = @result;
 
         if ($name =~ /gmod_bulk_load_gff3/) {
-            $delete_query->execute($name,$host);
+            $delete_query->execute($name,$host) or warn "removing the lock failed!";
+            $dbh->commit or warn "commit failed";
         }
     }
 
     return;
 }
 
+=head2 cleanup_tmp_table
 
+=over
+
+=item Usage
+
+  $obj->cleanup_tmp_table()
+
+=item Function
+
+Called when there is an abnormal exit from a loading program.  It deletes
+entries in the tmp_gff_load_cache table that have feature_ids that were used
+during the current session.
+
+=item Returns
+
+Nothing
+
+=item Arguments
+
+None (it needs the first feature_id, but that is stored in the object).
+
+=back
+
+=cut
+
+sub cleanup_tmp_table {
+    my $self = shift;
+
+    my $dbh = $self->dbh;
+    my $first_feature = $self->first_feature_id();
+    return unless $first_feature;
+
+    my $delete_query = $dbh->prepare(TMP_TABLE_CLEANUP);
+
+
+    warn "Attempting to clean up the loader temp table (so that --recreate_cache\nwon't be needed)...\n";
+    $delete_query->execute($first_feature);
+
+    return;
+}
+
+=head2 first_feature_id
+
+=over
+
+=item Usage
+
+  $obj->first_feature_id()        #get existing value
+  $obj->first_feature_id($newval) #set new value
+
+=item Function
+
+=item Returns
+
+value of first_feature_id (a scalar), that is, the feature_id of the first
+feature parsed in the current session.
+
+=item Arguments
+
+new value of first_feature_id (to set)
+
+=back
+
+=cut
+
+sub first_feature_id {
+    my $self = shift;
+    my $first_feature_id = shift if defined(@_);
+    return $self->{'first_feature_id'} = $first_feature_id if defined($first_feature_id);
+    return $self->{'first_feature_id'};
+}
+
+
 =head2 initialize_ontology
 
 =over

Modified: schema/trunk/chado/load/bin/bulk_load_gff3.PLS
===================================================================
--- schema/trunk/chado/load/bin/bulk_load_gff3.PLS 2009-11-03 21:33:29 UTC (rev 22219)
+++ schema/trunk/chado/load/bin/bulk_load_gff3.PLS 2009-11-03 22:11:02 UTC (rev 22220)
@@ -590,6 +590,8 @@
 or pod2usage(-verbose => 1, -exitval => 1);
 pod2usage(-verbose => 2, -exitval => 1) if $MANPAGE;
 
+$SIG{__DIE__} = $SIG{INT} = 'cleanup_handler';
+
 my $ORGANISM_FROM_CMDLINE = $ORGANISM;
 
 unless ($DBNAME) {
@@ -705,6 +707,7 @@
 
 $chado->remove_lock(force => 1) if $REMOVE_LOCK;
 $chado->place_lock();
+my $lock = 1;
 
 #if we need custom ontology mapping, cache them here
 if ($ONTOLOGY) {
@@ -1059,6 +1062,22 @@
 $chado->remove_lock();
 exit(0);
 
+
+sub cleanup_handler {
+    warn "@_\nAbnormal termination, trying to clean up...\n\n" if @_;  #gets the message that the die signal sent if there is one
+    if ($chado && $chado->dbh->ping) {
+        #$chado->dbh->{AutoCommit} = 1;
+        $chado->cleanup_tmp_table;
+        if ($lock) {
+            warn "Trying to remove the run lock (so that --remove_lock won't be needed)...\n";
+            $chado->remove_lock; #remove the lock only if we've set it
+        }
+        $chado->dbh->rollback;
+        print STDERR "Exiting...\n";
+    }
+    exit(1);
+}
+
 !NO!SUBS!
 close OUT or die "Can't close $file: $!";
 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Gmod-schema-cmts mailing list
Gmod-schema-cmts@...
https://lists.sourceforge.net/lists/listinfo/gmod-schema-cmts