Browse Source

Fixed several memory leask

spficklin 12 years ago
parent
commit
774562ff8e

+ 19 - 20
tripal_core/api/tripal_core.api.inc

@@ -202,7 +202,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
       $insert_values[$field] = $value;
       $insert_values[$field] = $value;
     }
     }
   }
   }
-
+  
   if ($validate) {
   if ($validate) {
 
 
     // check for violation of any unique constraints
     // check for violation of any unique constraints
@@ -238,7 +238,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
         }
         }
       }
       }
     }
     }
-
+    
     // if trying to insert a field that is the primary key, make sure it also is unique
     // if trying to insert a field that is the primary key, make sure it also is unique
     if (array_key_exists('primary key', $table_desc)) {
     if (array_key_exists('primary key', $table_desc)) {
       $pkey = $table_desc['primary key'][0];
       $pkey = $table_desc['primary key'][0];
@@ -251,10 +251,12 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
       }
       }
     }
     }
 
 
-    // make sure required fields have a value
+    // make sure required fields have a value     
     if (!is_array($table_desc['fields'])) {
     if (!is_array($table_desc['fields'])) {
       $table_desc['fields'] = array();
       $table_desc['fields'] = array();
-      watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
+      watchdog('tripal_core', "tripal_core_chado_insert: %table missing fields: \n %schema", 
+        array('%table' => $table, '%schema' => print_r($table_desc, 1)), WATCHDOG_WARNING);
+      
     }
     }
     foreach ($table_desc['fields'] as $field => $def) {
     foreach ($table_desc['fields'] as $field => $def) {
       // a field is considered missing if it cannot be NULL and there is no default
       // a field is considered missing if it cannot be NULL and there is no default
@@ -305,7 +307,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
       $idatatypes[] = 'text';
       $idatatypes[] = 'text';
     }
     }
   }
   }
-
+  
   // create the SQL
   // create the SQL
   $sql = "INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $itypes) . ")";
   $sql = "INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $itypes) . ")";
 
 
@@ -336,14 +338,11 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
 
 
   // if we have a result then add primary keys to return array
   // if we have a result then add primary keys to return array
   if ($result) {
   if ($result) {
-    $primary_key = array();
-    if (!is_array($table_desc['primary key'])) {
-      $table_desc['primary key'] = array();
-      watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
-    }
-    foreach ($table_desc['primary key'] as $field) {
-      $value =  db_result(chado_query("SELECT CURRVAL('" . $table . "_" . $field . "_seq')"));
-      $values[$field] = $value;
+    if (array_key_exists('primary key', $table_desc) and is_array($table_desc['primary key'])) {
+      foreach ($table_desc['primary key'] as $field) {
+        $value =  db_result(chado_query("SELECT CURRVAL('" . $table . "_" . $field . "_seq')"));
+        $values[$field] = $value;
+      }
     }
     }
     return $values;
     return $values;
   }
   }
@@ -1976,7 +1975,7 @@ function chado_query($sql) {
 
 
   // Execute the query on the chado database/schema
   // Execute the query on the chado database/schema
   // Use the persistent chado connection if it already exists
   // Use the persistent chado connection if it already exists
-  $persistent_connection = variable_get('tripal_persistent_chado', NULL);
+  $persistent_connection = variable_get('tripal_persistent_chado', NULL);  
   if ($persistent_connection) {
   if ($persistent_connection) {
 
 
     $query = $sql;
     $query = $sql;
@@ -2000,10 +1999,6 @@ function chado_query($sql) {
       $queries[] = array($query, $diff);
       $queries[] = array($query, $diff);
     }
     }
 
 
-    if ($debug) {
-      print '<p>query: ' . $query . '<br />error:' . pg_last_error($persistent_connection) . '</p>';
-    }
-
     if ($last_result !== FALSE) {
     if ($last_result !== FALSE) {
       return $last_result;
       return $last_result;
     }
     }
@@ -2015,7 +2010,7 @@ function chado_query($sql) {
     }
     }
     // END COPY FROM _db_query in database.pgsql.inc
     // END COPY FROM _db_query in database.pgsql.inc
   }
   }
-  else {
+  else {  	
     $previous_db = tripal_db_set_active('chado');
     $previous_db = tripal_db_set_active('chado');
     $results = _db_query($sql);
     $results = _db_query($sql);
     tripal_db_set_active($previous_db);
     tripal_db_set_active($previous_db);
@@ -2727,7 +2722,11 @@ function tripal_db_release_persistent_chado() {
  */
  */
 function tripal_db_start_transaction() {
 function tripal_db_start_transaction() {
   $connection = tripal_db_persistent_chado();
   $connection = tripal_db_persistent_chado();
-  chado_query("BEGIN");
+  if ($connection) {
+    chado_query("BEGIN");  
+    return $connection;
+  } 
+  return FALSE;
 }
 }
 
 
 /**
 /**

+ 1 - 1
tripal_core/includes/custom_tables.php

@@ -175,7 +175,7 @@ function tripal_core_create_custom_table(&$ret, $table, $schema, $skip_creation
   	}
   	}
   }
   }
 
 
-  return $ret;
+  return TRUE;
 }
 }
 
 
 /**
 /**

+ 87 - 0
tripal_feature/api/tripal_feature.api.inc

@@ -844,3 +844,90 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
   }
   }
   return $residues;
   return $residues;
 }
 }
+
+/**
+ * This function simply defines all tables needed for the module to work
+ * correctly.  By putting the table definitions in a separate function we
+ * can easily provide the entire list for hook_install or individual
+ * tables for an update.
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_get_schemas($table = NULL) {
+  $schema = array();
+
+
+  if (!$table or strcmp($table, 'chado_feature')==0) {
+    $schema['chado_feature'] = array(
+      'fields' => array(
+        'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'feature_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+        'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
+      ),
+      'indexes' => array(
+        'feature_id' => array('feature_id')
+      ),
+      'unique keys' => array(
+        'nid_vid' => array('nid', 'vid'),
+        'vid' => array('vid')
+      ),
+      'primary key' => array('nid'),
+    );
+  }
+  if (!$table or strcmp($table, 'tripal_feature_relagg')==0) {
+    $schema['tripal_feature_relagg'] = array(
+      'fields' => array(
+        'type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'rel_type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      ),
+      'indexes' => array(
+        'type_id' => array('type_id')
+      ),
+    );
+  }
+  return $schema;
+};
+/**
+ * This function defines the custom tables that will be created 
+ * in the chado schema.
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_get_custom_tables($table = NULL) {
+
+ if (!$table or strcmp($table, 'tripal_gff_temp')==0) {
+    $schema['tripal_gff_temp'] = array(
+      'table' => 'tripal_gff_temp',
+      'fields' => array(
+        'feature_id' => array(
+          'type' => 'int',
+          'not null' => TRUE,
+        ),
+        'organism_id' => array(
+          'type' => 'int',
+          'not null' => TRUE,
+        ),
+        'uniquename' => array(
+          'type' => 'text',
+          'not null' => TRUE,
+        ),
+        'type_name' => array(
+          'type' => 'varchar',
+          'length' => '1024',
+          'not null' => TRUE,
+        ),
+      ),
+      'indexes' => array(
+        'tripal_gff_temp_idx0' => array('feature_id'),
+        'tripal_gff_temp_idx0' => array('orgnaism_id'),
+        'tripal_gff_temp_idx1' => array('uniquename'),
+      ),
+      'unique keys' => array(
+        'tripal_gff_temp_uq0' => array('feature_id'),
+        'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
+      ),
+    );
+  }
+  return $schema;
+}

+ 148 - 153
tripal_feature/includes/gff_loader.inc

@@ -208,19 +208,29 @@ function tripal_feature_gff3_load_form_submit($form, &$form_state) {
  */
  */
 function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, 
 function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, 
   $add_only =0, $update = 0, $refresh = 0, $remove = 0, $job = NULL) {  
   $add_only =0, $update = 0, $refresh = 0, $remove = 0, $job = NULL) {  
+
+  // make sure our temporary table exists
+  $ret = array(); 
+  if (!db_table_exists('tripal_gff_temp')) { 
+	  $schema = tripal_feature_get_custom_tables('tripal_gff_temp');  
+	  $success = tripal_core_create_custom_table($ret, 'tripal_gff_temp', $schema['tripal_gff_temp']);
+	  if(!$success) {
+	  	 watchdog('T_gff3_loader', "Cannot creat temporary loading table", array(), WATCHDOG_ERROR); 
+	  	return;
+	  } 
+  }
+  // empty the temp table
+  $sql = "DELETE FROM tripal_gff_temp";
+  chado_query($sql);
   	
   	
-  // try to get a persistent connection so our loads go faster
-  $connection = tripal_db_persistent_chado();
+  // begin the transaction
+  $connection = tripal_db_start_transaction();
     
     
-  // if we cannot get a connection the abandon the prepared statement
-  if(!$connection){
+  // if we cannot get a connection then let the user know the loading will be slow
+  if (!$connection) {
      print "A persistant connection was not obtained. Loading will be slow\n";
      print "A persistant connection was not obtained. Loading will be slow\n";
   }
   }
 
 
-  // this array is used to cache all of the features in the GFF file and
-  // used to lookup parent and target relationships
-  $gff_features = array();
-
   // check to see if the file is located local to Drupal
   // check to see if the file is located local to Drupal
   $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $gff_file;
   $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $gff_file;
   if (!file_exists($dfile)) {
   if (!file_exists($dfile)) {
@@ -229,7 +239,8 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
     $dfile = $gff_file;
     $dfile = $gff_file;
   }
   }
   if (!file_exists($dfile)) {
   if (!file_exists($dfile)) {
-    watchdog('T_gff3_loader',"Cannot find the file: %dfile", array($dfile), WATCHDOG_ERROR);
+    watchdog('T_gff3_loader',"Cannot find the file: %dfile", 
+      array('%dfile' => $dfile), WATCHDOG_ERROR);
     return 0;
     return 0;
   }
   }
 
 
@@ -240,7 +251,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
   $fh = fopen($dfile, 'r');
   $fh = fopen($dfile, 'r');
   if (!$fh) {
   if (!$fh) {
     watchdog('T_gff3_loader',"cannot open file: %dfile", 
     watchdog('T_gff3_loader',"cannot open file: %dfile", 
-      array($dfile), WATCHDOG_ERROR);
+      array('%dfile' => $dfile), WATCHDOG_ERROR);
     return 0;
     return 0;
   }
   }
   $filesize = filesize($dfile);
   $filesize = filesize($dfile);
@@ -252,7 +263,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
   $cv = db_fetch_object(db_query($sql, 'sequence'));
   $cv = db_fetch_object(db_query($sql, 'sequence'));
   if (!$cv) {   
   if (!$cv) {   
     watchdog('T_gff3_loader',"Cannot find the 'sequence' ontology", 
     watchdog('T_gff3_loader',"Cannot find the 'sequence' ontology", 
-      array($dfile), WATCHDOG_ERROR);
+      array(), WATCHDOG_ERROR);
     return '';
     return '';
   }
   }
 
 
@@ -261,7 +272,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
   $sql = "SELECT * FROM organism WHERE organism_id = %d";
   $sql = "SELECT * FROM organism WHERE organism_id = %d";
   $organism = db_fetch_object(db_query($sql, $organism_id));
   $organism = db_fetch_object(db_query($sql, $organism_id));
 
 
-  $interval = intval($filesize * 0.01);
+  $interval = intval($filesize * 0.0001);
   if ($interval == 0) {
   if ($interval == 0) {
     $interval = 1;
     $interval = 1;
   }
   }
@@ -309,7 +320,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
     $cols = explode("\t", $line);
     $cols = explode("\t", $line);
     if (sizeof($cols) != 9) {
     if (sizeof($cols) != 9) {
       watchdog('T_gff3_loader','improper number of columns on line %line_num', 
       watchdog('T_gff3_loader','improper number of columns on line %line_num', 
-        array($line_num), WATCHDOG_ERROR);
+        array('%line_num' => $line_num), WATCHDOG_ERROR);
       return '';
       return '';
     }
     }
     
     
@@ -322,8 +333,8 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
     $score    = $cols[5];
     $score    = $cols[5];
     $strand   = $cols[6];
     $strand   = $cols[6];
     $phase    = $cols[7];
     $phase    = $cols[7];
-    $attrs    = explode(";", $cols[8]);  // split by a semicolon
-
+    $attrs    = explode(";", $cols[8]);  // split by a semicolon 
+    
     // ready the start and stop for chado.  Chado expects these positions
     // ready the start and stop for chado.  Chado expects these positions
     // to be zero-based, so we substract 1 from the fmin
     // to be zero-based, so we substract 1 from the fmin
     $fmin = $start - 1;
     $fmin = $start - 1;
@@ -358,18 +369,22 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
                WHERE CV.cv_id = $1 and (CVT.name = $2 or CVTS.synonym = $3)";
                WHERE CV.cv_id = $1 and (CVT.name = $2 or CVTS.synonym = $3)";
        $status = chado_query($psql);
        $status = chado_query($psql);
        if (!$status) {
        if (!$status) {
-         watchdog('T_gff3_loader','cannot prepare statement \'sel_cvterm_cvid_cvtname_synonym\' for ontology term %line_num', array($line_num), WATCHDOG_ERROR);
+         watchdog('T_gff3_loader','cannot prepare statement \'sel_cvterm_cvid_cvtname_synonym\' for ontology term %line_num', 
+           array('%line_num' => $line_num), WATCHDOG_ERROR);
          return '';
          return '';
       }
       }
       
       
     } 
     } 
-
+  
     $result = chado_query("EXECUTE sel_cvterm_cvid_cvtname_synonym (%d, '%s', '%s')", $cv->cv_id, $type, $type);
     $result = chado_query("EXECUTE sel_cvterm_cvid_cvtname_synonym (%d, '%s', '%s')", $cv->cv_id, $type, $type);
+   
     $cvterm = db_fetch_object($result);
     $cvterm = db_fetch_object($result);
     if (!$cvterm) {
     if (!$cvterm) {
-      watchdog('T_gff3_loader','cannot find ontology term \'%type\' on line %line_num', array($type, $line_num), WATCHDOG_ERROR);
+      watchdog('T_gff3_loader','cannot find ontology term \'%type\' on line %line_num', 
+        array('%type' => $type, '%line_num' => $line_num), WATCHDOG_ERROR);
       return '';
       return '';
     }
     }
+ 
 
 
     // break apart each of the attributes
     // break apart each of the attributes
     $tags = array();
     $tags = array();
@@ -391,7 +406,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       }
       }
       if (!preg_match('/^[^\=]+\=.+$/', $attr)) {
       if (!preg_match('/^[^\=]+\=.+$/', $attr)) {
         watchdog('T_gff3_loader','Attribute is not correctly formatted on line %line_num: %attr', 
         watchdog('T_gff3_loader','Attribute is not correctly formatted on line %line_num: %attr', 
-          array($line_num, $attr), WATCHDOG_ERROR);
+          array('%line_num' => $line_num, '%attr' => $attr), WATCHDOG_ERROR);
         return '';
         return '';
       }
       }
 
 
@@ -437,7 +452,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       }
       }
       else {
       else {
         watchdog('T_gff3_loader','Cannot generate a uniquename for feature on line %line_num', 
         watchdog('T_gff3_loader','Cannot generate a uniquename for feature on line %line_num', 
-          array($line_num), WATCHDOG_ERROR);
+          array('%line_num' => $line_num), WATCHDOG_ERROR);
         exit;
         exit;
       }
       }
       $attr_name = $attr_uniquename;
       $attr_name = $attr_uniquename;
@@ -470,13 +485,13 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       if (!$count or $count[0]->num_landmarks == 0) {
       if (!$count or $count[0]->num_landmarks == 0) {
         watchdog('T_gff3_loader',"The landmark '%landmark' cannot be found for this organism. ".
         watchdog('T_gff3_loader',"The landmark '%landmark' cannot be found for this organism. ".
               "Please add the landmark and then retry the import of this GFF3 ".
               "Please add the landmark and then retry the import of this GFF3 ".
-              "file", array($landmark), WATCHDOG_ERROR);
+              "file", array('%landmark' => $landmark), WATCHDOG_ERROR);
         return '';
         return '';
 
 
       }
       }
       if ($count[0]->num_landmarks > 1) {
       if ($count[0]->num_landmarks > 1) {
         watchdog('T_gff3_loader',"The landmark '%landmark' is not unique for this organism. ".
         watchdog('T_gff3_loader',"The landmark '%landmark' is not unique for this organism. ".
-              "The features cannot be associated", array($landmark), WATCHDOG_ERROR);
+              "The features cannot be associated", array('%landmark' => $landmark), WATCHDOG_ERROR);
         return '';
         return '';
       }  
       }  
     }
     }
@@ -493,7 +508,8 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       );
       );
       $result = tripal_core_chado_delete('feature',$match);
       $result = tripal_core_chado_delete('feature',$match);
       if (!$result) {
       if (!$result) {
-        watchdog('T_gff3_loader',"cannot delete feature %attr_uniquename", array($attr_uniquename), WATCHDOG_ERROR);
+        watchdog('T_gff3_loader',"cannot delete feature %attr_uniquename", 
+          array('%attr_uniquename' => $attr_uniquename), WATCHDOG_ERROR);
       }
       }
       $feature = 0;
       $feature = 0;
       unset($result);
       unset($result);
@@ -505,38 +521,49 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       // add/update the feature
       // add/update the feature
       $feature = tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm,
       $feature = tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm,
         $attr_uniquename, $attr_name, $residues, $attr_is_analysis,
         $attr_uniquename, $attr_name, $residues, $attr_is_analysis,
-        $attr_is_obsolete, $add_only, $score, $log);
-
-      // store all of the features for use later by parent and target
-      // relationships
-      $gff_features[$feature->uniquename]['type'] = $type;
-      $gff_features[$feature->uniquename]['strand'] = $strand;
-
+        $attr_is_obsolete, $add_only, $score);  
+   
       if ($feature) {
       if ($feature) {
+      	
+      	// add a record for this feature to the tripal_gff_temp table for
+        // later lookup
+        $values = array(
+          'feature_id' => $feature->feature_id,
+          'organism_id' => $feature->organism_id,
+          'type_name' => $type,
+          'uniquename' => $feature->uniquename
+        );
+        $options = array('statement_name' => 'ins_tripalgfftemp');
+        $result = tripal_core_chado_insert('tripal_gff_temp', $values, $options);
+        if (!$result) {
+          watchdog('T_gff3_loader',"Cound not save record in temporary table, Cannot continue.", array(), WATCHDOG_ERROR);
+          return;
+        }
 
 
         // add/update the featureloc if the landmark and the ID are not the same
         // add/update the featureloc if the landmark and the ID are not the same
         // if they are the same then this entry in the GFF is probably a landmark identifier
         // if they are the same then this entry in the GFF is probably a landmark identifier
         if (strcmp($landmark, $attr_uniquename) !=0 ) {
         if (strcmp($landmark, $attr_uniquename) !=0 ) {
           tripal_feature_load_gff3_featureloc($feature, $organism,
           tripal_feature_load_gff3_featureloc($feature, $organism,
             $landmark, $fmin, $fmax, $strand, $phase, $attr_fmin_partial,
             $landmark, $fmin, $fmax, $strand, $phase, $attr_fmin_partial,
-            $attr_fmax_partial, $attr_residue_info, $attr_locgroup, $log);
+            $attr_fmax_partial, $attr_residue_info, $attr_locgroup);
         }
         }
+               
         // add any aliases for this feature
         // add any aliases for this feature
         if (array_key_exists('Alias', $tags)) {
         if (array_key_exists('Alias', $tags)) {
-          tripal_feature_load_gff3_alias($feature, $tags['Alias'], $log);
+          tripal_feature_load_gff3_alias($feature, $tags['Alias']);
         }
         }
         // add any dbxrefs for this feature
         // add any dbxrefs for this feature
         if (array_key_exists('Dbxref', $tags)) {
         if (array_key_exists('Dbxref', $tags)) {
-          tripal_feature_load_gff3_dbxref($feature, $tags['Dbxref'], $log);
+          tripal_feature_load_gff3_dbxref($feature, $tags['Dbxref']);
         }
         }
         // add any ontology terms for this feature
         // add any ontology terms for this feature
         if (array_key_exists('Ontology_term', $tags)) {
         if (array_key_exists('Ontology_term', $tags)) {
-          tripal_feature_load_gff3_ontology($feature, $tags['Ontology_term'], $log);
-        }
+          tripal_feature_load_gff3_ontology($feature, $tags['Ontology_term']);
+        }       
         // add parent relationships
         // add parent relationships
         if (array_key_exists('Parent', $tags)) {
         if (array_key_exists('Parent', $tags)) {
-          tripal_feature_load_gff3_parents($feature, $cvterm, $tags['Parent'], $gff_features, $organism_id, $fmin, $log);
-        }
+          tripal_feature_load_gff3_parents($feature, $cvterm, $tags['Parent'], $organism_id, $fmin);
+        }       
         // add target relationships
         // add target relationships
         if (array_key_exists('Target', $tags)) {
         if (array_key_exists('Target', $tags)) {
           preg_match('/^(.*)\s+\d+\s+\d+\s+(\+|\-)*$/', $tags['Target'][0], $matches);
           preg_match('/^(.*)\s+\d+\s+\d+\s+(\+|\-)*$/', $tags['Target'][0], $matches);
@@ -559,40 +586,43 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
           #print "Target: $target_feature, $target_fmin-$target_fmax $target_dir\n";
           #print "Target: $target_feature, $target_fmin-$target_fmax $target_dir\n";
           tripal_feature_load_gff3_featureloc($feature, $organism,
           tripal_feature_load_gff3_featureloc($feature, $organism,
             $target_feature, $target_fmin, $target_fmax, $target_strand, $phase, $attr_fmin_partial,
             $target_feature, $target_fmin, $target_fmax, $target_strand, $phase, $attr_fmin_partial,
-            $attr_fmax_partial, $attr_residue_info, $attr_locgroup, $log);
+            $attr_fmax_partial, $attr_residue_info, $attr_locgroup);
         }
         }
+        
+        
         // add gap information.  This goes in simply as a property
         // add gap information.  This goes in simply as a property
         if (array_key_exists('Gap', $tags)) {
         if (array_key_exists('Gap', $tags)) {
           foreach ($tags['Gap'] as $value) {
           foreach ($tags['Gap'] as $value) {
-            tripal_feature_load_gff3_property($feature, 'Gap', $value, $log);
+            tripal_feature_load_gff3_property($feature, 'Gap', $value);
           }
           }
         }
         }
         // add notes. This goes in simply as a property
         // add notes. This goes in simply as a property
         if (array_key_exists('Note', $tags)) {
         if (array_key_exists('Note', $tags)) {
           foreach ($tags['Note'] as $value) {
           foreach ($tags['Note'] as $value) {
-              tripal_feature_load_gff3_property($feature, 'Note', $value, $log);
+              tripal_feature_load_gff3_property($feature, 'Note', $value);
           }
           }
         }
         }
         // add the Derives_from relationship (e.g. polycistronic genes).
         // add the Derives_from relationship (e.g. polycistronic genes).
         if (array_key_exists('Derives_from', $tags)) {
         if (array_key_exists('Derives_from', $tags)) {
-          tripal_feature_load_gff3_derives_from($feature, $tags['Derives_from'][0], $gff_features, $organism, $log);
+          tripal_feature_load_gff3_derives_from($feature, $tags['Derives_from'][0], $organism);
         }
         }
 
 
         // add in the GFF3_source dbxref so that GBrowse can find the feature using the source column
         // add in the GFF3_source dbxref so that GBrowse can find the feature using the source column
         $source_ref = array('GFF_source:' . $source);
         $source_ref = array('GFF_source:' . $source);
-        tripal_feature_load_gff3_dbxref($feature, $source_ref, $log);
+        tripal_feature_load_gff3_dbxref($feature, $source_ref);
 
 
         // add any additional attributes
         // add any additional attributes
         if ($attr_others) {
         if ($attr_others) {
           foreach ($attr_others as $tag_name => $values) {
           foreach ($attr_others as $tag_name => $values) {
             foreach ($values as $value){
             foreach ($values as $value){
-              tripal_feature_load_gff3_property($feature, $tag_name, $value, $log);
+              tripal_feature_load_gff3_property($feature, $tag_name, $value);
             }
             }
           }
           }
         }
         }
       }
       }
     }
     }
   }
   }
+return;  
   // now set the rank of any parent/child relationships.  The order is based
   // now set the rank of any parent/child relationships.  The order is based
   // on the fmin.  The start rank is 1.  This allows features with other
   // on the fmin.  The start rank is 1.  This allows features with other
   // relationships to be '0' (the default), and doesn't interfer with the
   // relationships to be '0' (the default), and doesn't interfer with the
@@ -612,7 +642,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
         ),
         ),
       );
       );
 
 
-      $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+      $options = array('statement_name' => 'sel_feature_orunty');
       $result = tripal_core_chado_select('feature', array('*'), $values, $options);
       $result = tripal_core_chado_select('feature', array('*'), $values, $options);
       $pfeature = $result[0];
       $pfeature = $result[0];
 
 
@@ -649,8 +679,8 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
     }
     }
   }
   }
 
 
-  //tripal_db_set_active($previous_db);
-  
+  // commit the transaction
+  tripal_db_commit_transaction();
   print "Done\n";
   print "Done\n";
   
   
   return 1;
   return 1;
@@ -660,25 +690,38 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
  *
  *
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
-function tripal_feature_load_gff3_derives_from($feature, $subject, $gff_features, $organism, $log) {
+function tripal_feature_load_gff3_derives_from($feature, $subject, $organism) {
 
 
-   // first get the subject feature
+	// get the subject type
+  $values = array(
+    'organism_id' => $organism->organism_id,
+    'uniquename' => $subject,
+  );
+  $options = array('statement_name' => 'sel_tripalgfftemp_orun');
+  $result = tripal_core_chado_select('tripal_gff_temp', array('type_name'), $values, $options);   
+  if (count($result) == 0) {
+    watchdog("T_gff3_loader", "Cannot find subject type: %subject", array('%subject' => $subject), WATCHDOG_WARNING);
+     return ''; 
+  }
+  $subject_type = $result[0]->type_name;
+	
+  // get the subject feature
   $match = array(
   $match = array(
     'organism_id' => $organism->organism_id,
     'organism_id' => $organism->organism_id,
     'uniquename' => $subject,
     'uniquename' => $subject,
     'type_id' => array(
     'type_id' => array(
-      'name' => $gff_features[$subject]['type'],
+      'name' => $subject_type,
       'cv_id' => array(
       'cv_id' => array(
         'name' => 'sequence'
         'name' => 'sequence'
       ),
       ),
-    ),
+    ),      
   );
   );
-  $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+  $options = array('statement_name' => 'sel_feature_orunty');
   $sfeature = tripal_core_chado_select('feature', array('*'), $match, $options);
   $sfeature = tripal_core_chado_select('feature', array('*'), $match, $options);
   if (count($sfeature)==0) {
   if (count($sfeature)==0) {
     watchdog('T_gff3_loader',"Could not add 'Derives_from' relationship ".
     watchdog('T_gff3_loader',"Could not add 'Derives_from' relationship ".
       "for %uniquename and %subject.  Subject feature, '%subject', ".
       "for %uniquename and %subject.  Subject feature, '%subject', ".
-      "cannot be found", array($feature->uniquename, $subject, $subject), WATCHDOG_ERROR);
+      "cannot be found", array('%uniquename' => $feature->uniquename, '%subject' => $subject), WATCHDOG_ERROR);
     return;
     return;
   }
   }
 
 
@@ -697,7 +740,6 @@ function tripal_feature_load_gff3_derives_from($feature, $subject, $gff_features
   $options = array('statement_name' => 'sel_featurerelationship_objectid_subjectid_typeid_rank');
   $options = array('statement_name' => 'sel_featurerelationship_objectid_subjectid_typeid_rank');
   $rel = tripal_core_chado_select('feature_relationship', array('*'), $values, $options);
   $rel = tripal_core_chado_select('feature_relationship', array('*'), $values, $options);
   if (count($rel) > 0) {
   if (count($rel) > 0) {
-    // fwrite($log, "   Relationship already exists: $feature->uniquename derives_from $subject\n");
     return;
     return;
   }
   }
 
 
@@ -705,10 +747,8 @@ function tripal_feature_load_gff3_derives_from($feature, $subject, $gff_features
   $options = array('statement_name' => 'ins_featurerelationship_objectid_subjectid_typeid_rank');
   $options = array('statement_name' => 'ins_featurerelationship_objectid_subjectid_typeid_rank');
   $ret = tripal_core_chado_insert('feature_relationship', $values, $options);
   $ret = tripal_core_chado_insert('feature_relationship', $values, $options);
   if (!$ret) {
   if (!$ret) {
-    watchdog("T_gff3_loader", "Could not add 'Derives_from' relationship for $feature->uniquename and $subject", NULL, WATCHDOG_WARNING);
-  }
-  else {
-    //fwrite($log, "   Added relationship: $feature->uniquename derives_from $subject\n");
+    watchdog("T_gff3_loader", "Could not add 'Derives_from' relationship for $feature->uniquename and $subject", 
+      array(), WATCHDOG_WARNING);
   }
   }
 }
 }
 /**
 /**
@@ -716,7 +756,7 @@ function tripal_feature_load_gff3_derives_from($feature, $subject, $gff_features
  *
  *
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
-function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, &$gff_features, $organism_id, $fmin, $log) {
+function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, $organism_id, $fmin) {
 
 
   $uname = $feature->uniquename;
   $uname = $feature->uniquename;
   $type = $cvterm->name;
   $type = $cvterm->name;
@@ -732,15 +772,26 @@ function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, &$gff_fea
              WHERE cv.name = $1 and (CVT.name = $2 or CVTS.synonym = $3)";
              WHERE cv.name = $1 and (CVT.name = $2 or CVTS.synonym = $3)";
     $status = chado_query($psql);
     $status = chado_query($psql);
     if (!$status) {
     if (!$status) {
-       //fwrite($log, "ERROR: cannot prepare statement 'sel_cvterm_cvname_cvtname_synonym' for ontology term\n");
-       watchdog("T_gff3_loader", "Cannot prepare statement 'sel_cvterm_cvname_cvtname_synonym' for ontology term", NULL, WATCHDOG_WARNING);
+       watchdog("T_gff3_loader", "Cannot prepare statement 'sel_cvterm_cvname_cvtname_synonym' for ontology term", 
+         array(), WATCHDOG_WARNING);
        return '';
        return '';
     }
     }
   }
   }
 
 
   // iterate through the parents in the list
   // iterate through the parents in the list
   foreach ($parents as $parent) {
   foreach ($parents as $parent) {
-    $parent_type = $gff_features[$parent]['type'];
+  	// get the parent cvterm
+  	$values = array(
+  	  'organism_id' => $organism_id,
+      'uniquename' => $parent,
+  	);
+  	$options = array('statement_name' => 'sel_tripalgfftemp_orun');
+  	$result = tripal_core_chado_select('tripal_gff_temp', array('type_name'), $values, $options);  	
+  	if (count($result) == 0) {
+  	  watchdog("T_gff3_loader", "Cannot find parent type: %parent", array('%parent' => $parent), WATCHDOG_WARNING);
+       return '';	
+  	}
+    $parent_type = $result[0]->type_name;
 
 
     // try to find the parent
     // try to find the parent
     $parentcvterm = db_fetch_object(chado_query("EXECUTE sel_cvterm_cvname_cvtname_synonym ('%s', '%s', '%s')", 'sequence', $parent_type, $parent_type));
     $parentcvterm = db_fetch_object(chado_query("EXECUTE sel_cvterm_cvname_cvtname_synonym ('%s', '%s', '%s')", 'sequence', $parent_type, $parent_type));
@@ -750,15 +801,10 @@ function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, &$gff_fea
         'uniquename' => $parent,
         'uniquename' => $parent,
         'type_id' => $parentcvterm->cvterm_id,
         'type_id' => $parentcvterm->cvterm_id,
     );
     );
-    $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+    $options = array('statement_name' => 'sel_feature_orunty');
     $result = tripal_core_chado_select('feature', array('*'), $values, $options);
     $result = tripal_core_chado_select('feature', array('*'), $values, $options);
     $parent_feature = $result[0];
     $parent_feature = $result[0];
 
 
-    // we want to add this feature to the child list for the parent
-    // when the loader finishes, it will go back through the parent
-    // features and rank the children by position
-    $gff_features[$parent]['children'][$feature->feature_id] = $fmin;
-
     // if the parent exists then add the relationship otherwise print error and skip
     // if the parent exists then add the relationship otherwise print error and skip
     if ($parent_feature) {
     if ($parent_feature) {
 
 
@@ -772,7 +818,6 @@ function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, &$gff_fea
       $rel = tripal_core_chado_select('feature_relationship', array('*'), $values, $options);
       $rel = tripal_core_chado_select('feature_relationship', array('*'), $values, $options);
 
 
       if (count($rel) > 0) {
       if (count($rel) > 0) {
-        //fwrite($log, "   Relationship already exists, skipping '$uname' ($type) $rel_type '$parent' ($parent_type)\n");
       }
       }
       else {
       else {
         // the relationship doesn't already exist, so add it.
         // the relationship doesn't already exist, so add it.
@@ -784,17 +829,14 @@ function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, &$gff_fea
         $options = array('statement_name' => 'ins_featurerelationship_subjectid_objectid_typeid');
         $options = array('statement_name' => 'ins_featurerelationship_subjectid_objectid_typeid');
         $result = tripal_core_chado_insert('feature_relationship', $values, $options);
         $result = tripal_core_chado_insert('feature_relationship', $values, $options);
         if (!$result) {
         if (!$result) {
-          //fwrite($log, "WARNING: failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)\n");
-          watchdog("T_gff3_loader", "Failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)", NULL, WATCHDOG_WARNING);
-        }
-        else {
-          //fwrite($log, "   Inserted relationship relationship: '$uname' ($type) $rel_type '$parent' ($parent_type)\n");
+          watchdog("T_gff3_loader", "Failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)", 
+            array(), WATCHDOG_WARNING);
         }
         }
       }
       }
     }
     }
     else {
     else {
-//      fwrite($log, "WARNING: cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent\n");
-      watchdog("T_gff3_loader", "Cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent", NULL, WATCHDOG_WARNING);      
+      watchdog("T_gff3_loader", "Cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent", 
+        array(), WATCHDOG_WARNING);      
     }
     }
   }
   }
 }
 }
@@ -805,7 +847,7 @@ function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, &$gff_fea
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
 
 
-function tripal_feature_load_gff3_dbxref($feature, $dbxrefs, $log) {
+function tripal_feature_load_gff3_dbxref($feature, $dbxrefs) {
 
 
   // iterate through each of the dbxrefs
   // iterate through each of the dbxrefs
   foreach ($dbxrefs as $dbxref) {
   foreach ($dbxrefs as $dbxref) {
@@ -829,13 +871,11 @@ function tripal_feature_load_gff3_dbxref($feature, $dbxrefs, $log) {
       $ret = tripal_core_chado_insert('db', array('name' => $dbname,
       $ret = tripal_core_chado_insert('db', array('name' => $dbname,
         'description' => 'Added automatically by the GFF loader'), $options);
         'description' => 'Added automatically by the GFF loader'), $options);
       if ($ret) {
       if ($ret) {
-        //fwrite($log, "   Added new database: $dbname\n");
         $options = array('statement_name' => 'sel_db_name');
         $options = array('statement_name' => 'sel_db_name');
         $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
         $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
       }
       }
       else {
       else {
-        //fwrite($log, "ERROR: cannot find or add the database $dbname\n");
-        watchdog("T_gff3_loader", "Cannot find or add the database $dbname", NULL, WATCHDOG_WARNING);
+        watchdog("T_gff3_loader", "Cannot find or add the database $dbname", array(), WATCHDOG_WARNING);
         return 0;
         return 0;
       }
       }
     }
     }
@@ -870,16 +910,13 @@ function tripal_feature_load_gff3_dbxref($feature, $dbxrefs, $log) {
         'dbxref_id' => $dbxref->dbxref_id,
         'dbxref_id' => $dbxref->dbxref_id,
         'feature_id' => $feature->feature_id), $options);
         'feature_id' => $feature->feature_id), $options);
       if ($ret) {
       if ($ret) {
-        //fwrite($log, "   Adding Dbxref $dbname:$accession\n");
       }
       }
       else {
       else {
-        //fwrite($log, "ERROR: failed to insert Dbxref: $dbname:$accession\n");
-        watchdog("T_gff3_loader", "Failed to insert Dbxref: $dbname:$accession", NULL, WATCHDOG_WARNING);
+        watchdog("T_gff3_loader", "Failed to insert Dbxref: $dbname:$accession", array(), WATCHDOG_WARNING);
         return 0;
         return 0;
       }
       }
     }
     }
     else {
     else {
-      //fwrite($log, "   Dbxref already associated, skipping $dbname:$accession\n");
     }
     }
   }
   }
   return 1;
   return 1;
@@ -889,7 +926,7 @@ function tripal_feature_load_gff3_dbxref($feature, $dbxrefs, $log) {
  *
  *
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
-function tripal_feature_load_gff3_ontology($feature, $dbxrefs, $log) {
+function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
 
 
    // iterate through each of the dbxrefs
    // iterate through each of the dbxrefs
   foreach ($dbxrefs as $dbxref) {
   foreach ($dbxrefs as $dbxref) {
@@ -906,8 +943,7 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs, $log) {
       $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
       $db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
     }
     }
     if (sizeof($db) == 0) {
     if (sizeof($db) == 0) {
-      //fwrite($log, "ERROR: Database, $dbname is missing for reference: $dbname:$accession\n");
-      watchdog("T_gff3_loader", "Database, $dbname is missing for reference: $dbname:$accession", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Database, $dbname is missing for reference: $dbname:$accession", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
     $db = $db[0];
     $db = $db[0];
@@ -917,8 +953,7 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs, $log) {
     $dbxref = tripal_core_chado_select('dbxref', array('dbxref_id'), array(
     $dbxref = tripal_core_chado_select('dbxref', array('dbxref_id'), array(
        'accession' => $accession, 'db_id' => $db->db_id), $options);
        'accession' => $accession, 'db_id' => $db->db_id), $options);
     if (sizeof($dbxref) == 0) {
     if (sizeof($dbxref) == 0) {
-      //fwrite($log, "ERROR: Accession, $accession is missing for reference: $dbname:$accession\n");
-      watchdog("T_gff3_loader", "Accession, $accession is missing for reference: $dbname:$accession", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Accession, $accession is missing for reference: $dbname:$accession", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
     $dbxref = $dbxref[0];
     $dbxref = $dbxref[0];
@@ -934,8 +969,7 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs, $log) {
         'dbxref_id' => $dbxref->dbxref_id), $options);
         'dbxref_id' => $dbxref->dbxref_id), $options);
     }
     }
     if (sizeof($cvterm) == 0) {
     if (sizeof($cvterm) == 0) {
-      //fwrite($log, "ERROR: CV Term is missing for reference: $dbname:$accession\n");
-      watchdog("T_gff3_loader", "CV Term is missing for reference: $dbname:$accession", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "CV Term is missing for reference: $dbname:$accession", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
     $cvterm = $cvterm[0];
     $cvterm = $cvterm[0];
@@ -960,17 +994,12 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs, $log) {
       $ret = tripal_core_chado_insert('feature_cvterm', $values, $options);
       $ret = tripal_core_chado_insert('feature_cvterm', $values, $options);
 
 
       if ($ret) {
       if ($ret) {
-        //fwrite($log, "   Adding ontology term $dbname:$accession\n");
       }
       }
       else {
       else {
-        //fwrite($log, "ERROR: failed to insert ontology term: $dbname:$accession\n");
-        watchdog("T_gff3_loader", "Failed to insert ontology term: $dbname:$accession", NULL, WATCHDOG_WARNING);
+        watchdog("T_gff3_loader", "Failed to insert ontology term: $dbname:$accession", array(), WATCHDOG_WARNING);
         return 0;
         return 0;
       }
       }
     }
     }
-    else {
-      //fwrite($log, "   Ontology term already associated, skipping $dbname:$accession\n");
-    }
   }
   }
   return 1;
   return 1;
 }
 }
@@ -979,7 +1008,7 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs, $log) {
  *
  *
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
-function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
+function tripal_feature_load_gff3_alias($feature, $aliases) {
 
 
   // make sure we have a 'synonym_type' vocabulary
   // make sure we have a 'synonym_type' vocabulary
   $select = array('name' => 'synonym_type');
   $select = array('name' => 'synonym_type');
@@ -994,8 +1023,7 @@ function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
     $options = array('statement_name' => 'ins_cv_name_definition');
     $options = array('statement_name' => 'ins_cv_name_definition');
     $result = tripal_core_chado_insert('cv', $values, $options);
     $result = tripal_core_chado_insert('cv', $values, $options);
     if (!result) {
     if (!result) {
-      //fwrite($log, "ERROR: Failed to add the synonyms type vocabulary");
-      watchdog("T_gff3_loader", "Failed to add the synonyms type vocabulary", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Failed to add the synonyms type vocabulary", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
     // now that we've added the cv we need to get the record
     // now that we've added the cv we need to get the record
@@ -1027,15 +1055,13 @@ function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
     // TODO: fix the function so it uses prepared statements    
     // TODO: fix the function so it uses prepared statements    
     $syntype = tripal_cv_add_cvterm($term, $syncv->name, 0, 1);
     $syntype = tripal_cv_add_cvterm($term, $syncv->name, 0, 1);
     if (!$syntype) {
     if (!$syntype) {
-      //fwrite($log, "Cannot add synonym type: internal:$type");
-      watchdog("T_gff3_loader", "Cannot add synonym type: internal:$type", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Cannot add synonym type: internal:$type", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
   }
   }
 
 
   // iterate through all of the aliases and add each one
   // iterate through all of the aliases and add each one
   foreach ($aliases as $alias) {
   foreach ($aliases as $alias) {
-    //fwrite($log, "   Adding Alias $alias\n");
 
 
     // check to see if the alias already exists in the synonym table
     // check to see if the alias already exists in the synonym table
     // if not, then add it
     // if not, then add it
@@ -1055,8 +1081,7 @@ function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
       $options = array('statement_name' => 'ins_synonym_name_typeid_synonymsgml');
       $options = array('statement_name' => 'ins_synonym_name_typeid_synonymsgml');
       $result = tripal_core_chado_insert('synonym', $values, $options);
       $result = tripal_core_chado_insert('synonym', $values, $options);
       if (!$result) {
       if (!$result) {
-        //fwrite($log, "ERROR: cannot add alias $alias to synonym table\n");
-        watchdog("T_gff3_loader", "Cannot add alias $alias to synonym table", NULL, WATCHDOG_WARNING);
+        watchdog("T_gff3_loader", "Cannot add alias $alias to synonym table", array(), WATCHDOG_WARNING);
       }
       }
     }
     }
     $options = array('statement_name' => 'sel_synonym_name_typeid');
     $options = array('statement_name' => 'sel_synonym_name_typeid');
@@ -1083,16 +1108,14 @@ function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
                   WHERE CVT.name = $1 and DB.name = $2)";
                   WHERE CVT.name = $1 and DB.name = $2)";
         $status = chado_query($psql);
         $status = chado_query($psql);
         if (!$status) {
         if (!$status) {
-          //fwrite($log, "ERROR: cannot prepare statement 'ins_pub_uniquename_typeid'\n");
-          watchdog("T_gff3_loader", "Cannot prepare statement 'ins_pub_uniquename_typeid", NULL, WATCHDOG_WARNING);
+          watchdog("T_gff3_loader", "Cannot prepare statement 'ins_pub_uniquename_typeid", array(), WATCHDOG_WARNING);
           return 0;
           return 0;
         } 
         } 
       }    
       }    
       // insert the null pub 
       // insert the null pub 
       $result = db_fetch_object(chado_query("EXECUTE ins_pub_uniquename_typeid ('%s', '%s')", 'null', 'null'));
       $result = db_fetch_object(chado_query("EXECUTE ins_pub_uniquename_typeid ('%s', '%s')", 'null', 'null'));
       if (!$result) {
       if (!$result) {
-        //fwrite($log, "ERROR: cannot add null publication needed for setup of alias\n");
-        watchdog("T_gff3_loader", "Cannot add null publication needed for setup of alias", NULL, WATCHDOG_WARNING);
+        watchdog("T_gff3_loader", "Cannot add null publication needed for setup of alias", array(), WATCHDOG_WARNING);
         return 0;
         return 0;
       }
       }
     }
     }
@@ -1119,14 +1142,10 @@ function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
       $options = array('statement_name', 'ins_synonymfeature_synonymid_featureid_pubid');
       $options = array('statement_name', 'ins_synonymfeature_synonymid_featureid_pubid');
       $result = tripal_core_chado_insert('feature_synonym', $values, $options);
       $result = tripal_core_chado_insert('feature_synonym', $values, $options);
       if (!$result) {
       if (!$result) {
-        //fwrite($log, "ERROR: cannot add alias $alias to feature synonym table\n");
-        watchdog("T_gff3_loader", "Cannot add alias $alias to feature synonym table", NULL, WATCHDOG_WARNING);
+        watchdog("T_gff3_loader", "Cannot add alias $alias to feature synonym table", array(), WATCHDOG_WARNING);
         return 0;
         return 0;
       }
       }
     }
     }
-    else {
-      //fwrite($log, "   Synonym $alias already exists. Skipping\n");
-    }
   }
   }
   return 1;
   return 1;
 }
 }
@@ -1137,7 +1156,7 @@ function tripal_feature_load_gff3_alias($feature, $aliases, $log) {
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
 function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uniquename, $name,
 function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uniquename, $name,
-  $residues, $is_analysis='f', $is_obsolete='f', $add_only, $score, $log) {
+  $residues, $is_analysis = 'f', $is_obsolete = 'f', $add_only, $score) {
 
 
   // check to see if the feature already exists
   // check to see if the feature already exists
   $fselect = array(
   $fselect = array(
@@ -1145,7 +1164,7 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
      'uniquename' => $uniquename,
      'uniquename' => $uniquename,
      'type_id' => $cvterm->cvterm_id
      'type_id' => $cvterm->cvterm_id
   );
   );
-  $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+  $options = array('statement_name' => 'sel_feature_orunty');
   $result = tripal_core_chado_select('feature', array('*'), $fselect, $options); 
   $result = tripal_core_chado_select('feature', array('*'), $fselect, $options); 
   $feature = $result[0];
   $feature = $result[0];
 
 
@@ -1164,7 +1183,6 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
 
 
   // insert the feature if it does not exist otherwise perform an update
   // insert the feature if it does not exist otherwise perform an update
   if (!$feature) {
   if (!$feature) {
-    //fwrite($log, "   Adding feature '$uniquename' ($cvterm->name)\n");
     $values = array(
     $values = array(
        'organism_id' => $organism->organism_id,
        'organism_id' => $organism->organism_id,
        'name' => $name,
        'name' => $name,
@@ -1179,13 +1197,11 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
     $options = array('statement_name' => 'ins_feature_all');
     $options = array('statement_name' => 'ins_feature_all');
     $result = tripal_core_chado_insert('feature', $values, $options);
     $result = tripal_core_chado_insert('feature', $values, $options);
     if (!$result) {
     if (!$result) {
-      //fwrite($log, "ERROR: failed to insert feature '$uniquename' ($cvterm->name)\n");
-      watchdog("T_gff3_loader", "Failed to insert feature '$uniquename' ($cvterm->name)", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Failed to insert feature '$uniquename' ($cvterm->name)", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
   }
   }
   elseif (!$add_only) {
   elseif (!$add_only) {
-    //fwrite($log, "Updating feature '$uniquename' ($cvterm->name)\n");
     $values = array(
     $values = array(
       'name' => $name,
       'name' => $name,
       'residues' => $residues,
       'residues' => $residues,
@@ -1202,20 +1218,18 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
     $options = array('statement_name' => 'upd_feature');
     $options = array('statement_name' => 'upd_feature');
     $result = tripal_core_chado_update('feature', $match, $values, $options);
     $result = tripal_core_chado_update('feature', $match, $values, $options);
     if (!$result) {
     if (!$result) {
-      //fwrite($log, "ERROR: failed to update feature '$uniquename' ($cvterm->name)\n");
-      watchdog("T_gff3_loader", "Failed to update feature '$uniquename' ($cvterm->name)", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Failed to update feature '$uniquename' ($cvterm->name)", array(), WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
   }
   }
   else {
   else {
     // the feature exists and we don't want to update it so return
     // the feature exists and we don't want to update it so return
     // a value of 0.  This will stop all downstream property additions
     // a value of 0.  This will stop all downstream property additions
-    //fwrite($log, "Skipping existing feature: '$uniquename' ($cvterm->name).\n");
     return 0;
     return 0;
   }
   }
 
 
   // get the newly added feature
   // get the newly added feature
-  $options = array('statement_name' => 'sel_feature_organismid_uniquename_typeid');
+  $options = array('statement_name' => 'sel_feature_orunty');
   $result = tripal_core_chado_select('feature', array('*'), $fselect, $options);  
   $result = tripal_core_chado_select('feature', array('*'), $fselect, $options);  
   $feature = $result[0];
   $feature = $result[0];
 
 
@@ -1236,12 +1250,8 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
       $options = array('statement_name' => 'ins_analysisfeature_analysisid_featureid');
       $options = array('statement_name' => 'ins_analysisfeature_analysisid_featureid');
     }
     }
     if (!tripal_core_chado_insert('analysisfeature', $af_values, $options)) {
     if (!tripal_core_chado_insert('analysisfeature', $af_values, $options)) {
-      //fwrite($log, "ERROR: could not add analysisfeature record: $analysis_id, $feature->feature_id\n");
-      watchdog("T_gff3_loader", "Could not add analysisfeature record: $analysis_id, $feature->feature_id", NULL, WATCHDOG_WARNING);
-    }
-    else {
-      //fwrite($log, "   Added analysisfeature record\n");
-    }
+      watchdog("T_gff3_loader", "Could not add analysisfeature record: $analysis_id, $feature->feature_id", array(), WATCHDOG_WARNING);
+    }    
   }
   }
   else {
   else {
     // if a score is available then set that to be the significance field
     // if a score is available then set that to be the significance field
@@ -1256,11 +1266,7 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
       $options = array('statement_name' => 'upd_analysisfeature');
       $options = array('statement_name' => 'upd_analysisfeature');
       $ret = tripal_core_chado_update('analysisfeature', $af_values, $new_vals, $options);
       $ret = tripal_core_chado_update('analysisfeature', $af_values, $new_vals, $options);
       if (!$ret) {
       if (!$ret) {
-        //fwrite($log, "ERROR: could not update analysisfeature record: $analysis_id, $feature->feature_id\n");
-        watchdog("T_gff3_loader", "Could not update analysisfeature record: $analysis_id, $feature->feature_id", NULL, WATCHDOG_WARNING);
-      }
-      else {
-        //fwrite($log, "   Updated analysisfeature record\n");
+        watchdog("T_gff3_loader", "Could not update analysisfeature record: $analysis_id, $feature->feature_id", array(), WATCHDOG_WARNING);
       }
       }
     }
     }
   }
   }
@@ -1273,7 +1279,7 @@ function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uni
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
 function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fmin,
 function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fmin,
-  $fmax, $strand, $phase, $is_fmin_partial, $is_fmax_partial, $residue_info, $locgroup, $log) {
+  $fmax, $strand, $phase, $is_fmin_partial, $is_fmax_partial, $residue_info, $locgroup) {
 
 
   $select = array(
   $select = array(
     'organism_id' => $organism->organism_id,
     'organism_id' => $organism->organism_id,
@@ -1292,13 +1298,12 @@ function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fm
     $options = array('statement_name' => 'sel_feature_organism_id_name');
     $options = array('statement_name' => 'sel_feature_organism_id_name');
     $r = tripal_core_chado_select('feature', array('*'), $select, $options);
     $r = tripal_core_chado_select('feature', array('*'), $select, $options);
     if (count($r) == 0){
     if (count($r) == 0){
-       //fwrite($log, "ERROR: cannot find landmark feature: '$landmark'.  Cannot add the feature location record\n");
-       watchdog("T_gff3_loader", "Cannot find landmark feature: '$landmark'.  Cannot add the feature location record", NULL, WATCHDOG_WARNING);
+       watchdog("T_gff3_loader", "Cannot find landmark feature: '$landmark'.  Cannot add the feature location record", array(), WATCHDOG_WARNING);
        return 0;
        return 0;
     } 
     } 
     elseif (count($r) > 1) {
     elseif (count($r) > 1) {
-       //fwrite($log, "ERROR: multiple landmarks exist with the name: '$landmark'.  Cannot resolve which one to use. Cannot add the feature location record\n");
-       watchdog("T_gff3_loader", "multiple landmarks exist with the name: '$landmark'.  Cannot resolve which one to use. Cannot add the feature location record", NULL, WATCHDOG_WARNING);
+       watchdog("T_gff3_loader", "multiple landmarks exist with the name: '$landmark'.  Cannot resolve which one to use. Cannot add the feature location record", 
+         array(), WATCHDOG_WARNING);
        return 0;    
        return 0;    
     }
     }
     
     
@@ -1354,10 +1359,6 @@ function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fm
       if (count($values) > 0) {
       if (count($values) > 0) {
         $options = array('statement_name' => 'upd_featureloc_all');
         $options = array('statement_name' => 'upd_featureloc_all');
         tripal_core_chado_update('featureloc', $match, $values, $options);
         tripal_core_chado_update('featureloc', $match, $values, $options);
-        //fwrite($log, "   Updated featureloc\n");
-      }
-      else {
-        //fwrite($log, "   No change to featureloc\n");
       }
       }
     }
     }
     $rank = $featureloc->rank + 1;
     $rank = $featureloc->rank + 1;
@@ -1377,7 +1378,6 @@ function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fm
     elseif (strcmp($is_fmax_partial, 't')==0 or $is_fmax_partial = 1) {
     elseif (strcmp($is_fmax_partial, 't')==0 or $is_fmax_partial = 1) {
       $is_fmax_partial = 'TRUE';
       $is_fmax_partial = 'TRUE';
     }
     }
-    //fwrite($log, "   Adding featureloc $srcfeature->uniquename fmin: $fmin (is_partial: $is_fmin_partial), fmax: $fmax (is_partial: $is_fmin_partial), strand: $strand, phase: $phase, rank: $rank\n");
     $values = array(
     $values = array(
        'feature_id'      => $feature->feature_id,
        'feature_id'      => $feature->feature_id,
        'srcfeature_id'   => $srcfeature->feature_id,
        'srcfeature_id'   => $srcfeature->feature_id,
@@ -1398,8 +1398,7 @@ function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fm
     
     
     $success = tripal_core_chado_insert('featureloc', $values, $options);
     $success = tripal_core_chado_insert('featureloc', $values, $options);
     if (!$success) {
     if (!$success) {
-      //fwrite($log, "ERROR: failed to insert featureloc\n");
-      watchdog("T_gff3_loader", "Failed to insert featureloc", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "Failed to insert featureloc", array(), WATCHDOG_WARNING);
       exit;
       exit;
       return 0;
       return 0;
     }
     }
@@ -1411,7 +1410,7 @@ function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fm
  *
  *
  * @ingroup gff3_loader
  * @ingroup gff3_loader
  */
  */
-function tripal_feature_load_gff3_property($feature, $property, $value, $log) {
+function tripal_feature_load_gff3_property($feature, $property, $value) {
 
 
   // first make sure the cvterm exists.  if not, then add it
   // first make sure the cvterm exists.  if not, then add it
   $select = array(
   $select = array(
@@ -1430,13 +1429,12 @@ function tripal_feature_load_gff3_property($feature, $property, $value, $log) {
       'namespace' => 'feature_property',
       'namespace' => 'feature_property',
       'is_obsolete' => 0,
       'is_obsolete' => 0,
     );
     );
-    //fwrite($log, "   Adding cvterm, $property\n");
     
     
     $cvterm = (object) tripal_cv_add_cvterm($term, 'feature_property', 0, 0);
     $cvterm = (object) tripal_cv_add_cvterm($term, 'feature_property', 0, 0);
   }
   }
 
 
   if (!$cvterm) {
   if (!$cvterm) {
-    watchdog("T_gff3_loader", "Cannot add cvterm, $property", NULL, WATCHDOG_WARNING);
+    watchdog("T_gff3_loader", "Cannot add cvterm, $property", array(), WATCHDOG_WARNING);
     exit;
     exit;
   }
   }
 
 
@@ -1459,14 +1457,12 @@ function tripal_feature_load_gff3_property($feature, $property, $value, $log) {
   foreach ($results as $prop){
   foreach ($results as $prop){
     if (strcmp($prop->value, $value)==0) {
     if (strcmp($prop->value, $value)==0) {
       $add = NULL; // don't add it, it already exists
       $add = NULL; // don't add it, it already exists
-      //fwrite($log, "   Property already exists, skipping\n");
     }
     }
     $rank = $prop->rank + 1;
     $rank = $prop->rank + 1;
   }
   }
 
 
   // add the property if we pass the check above
   // add the property if we pass the check above
   if ($add) {
   if ($add) {
-    //fwrite($log, "   Setting feature property. $property: $value\n");
     $values = array(
     $values = array(
        'feature_id' => $feature->feature_id,
        'feature_id' => $feature->feature_id,
        'type_id' => $cvterm->cvterm_id,
        'type_id' => $cvterm->cvterm_id,
@@ -1476,8 +1472,7 @@ function tripal_feature_load_gff3_property($feature, $property, $value, $log) {
     $options = array('statement_name' => 'ins_featureprop_all');
     $options = array('statement_name' => 'ins_featureprop_all');
     $result = tripal_core_chado_insert('featureprop', $values, $options);
     $result = tripal_core_chado_insert('featureprop', $values, $options);
     if(!$result){
     if(!$result){
-      //fwrite($log, "ERROR: cannot add featureprop, $property\n");
-      watchdog("T_gff3_loader", "cannot add featureprop, $property", NULL, WATCHDOG_WARNING);
+      watchdog("T_gff3_loader", "cannot add featureprop, $property", array(), WATCHDOG_WARNING);
     }
     }
   }
   }
 }
 }

+ 0 - 45
tripal_feature/tripal_feature.install

@@ -132,51 +132,6 @@ function tripal_feature_uninstall() {
   }
   }
 }
 }
 
 
-/**
- * This function simply defines all tables needed for the module to work
- * correctly.  By putting the table definitions in a separate function we
- * can easily provide the entire list for hook_install or individual
- * tables for an update.
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_get_schemas($table = NULL) {
-  $schema = array();
-
-
-  if (!$table or strcmp($table, 'chado_feature')==0) {
-    $schema['chado_feature'] = array(
-      'fields' => array(
-        'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-        'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-        'feature_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-        'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
-      ),
-      'indexes' => array(
-        'feature_id' => array('feature_id')
-      ),
-      'unique keys' => array(
-        'nid_vid' => array('nid', 'vid'),
-        'vid' => array('vid')
-      ),
-      'primary key' => array('nid'),
-    );
-  }
-  if (!$table or strcmp($table, 'tripal_feature_relagg')==0) {
-    $schema['tripal_feature_relagg'] = array(
-      'fields' => array(
-        'type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-        'rel_type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      ),
-      'indexes' => array(
-        'type_id' => array('type_id')
-      ),
-    );
-  }
-
-  return $schema;
-}
-
 /**
 /**
  * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  * before installation
  * before installation