Browse Source

commit for pull

Stephen Ficklin 11 years ago
parent
commit
ab3efa20a1
2 changed files with 46 additions and 53 deletions
  1. 4 9
      tripal_core/api/tripal_core_chado.api.inc
  2. 42 44
      tripal_feature/includes/gff_loader.inc

+ 4 - 9
tripal_core/api/tripal_core_chado.api.inc

@@ -221,12 +221,9 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
   // get the table description
   $table_desc = tripal_core_get_chado_table_schema($table);
   if (empty($table_desc)) {
-    tripal_core_report_error(
-      'tripal_core',
-      TRIPAL_WARNING,
+    tripal_core_report_error('tripal_core', TRIPAL_WARNING,
       'tripal_core_chado_insert; There is no table description for !table_name',
-      array('!table_name' => $table),
-      array('print' => $print_errors)
+      array('!table_name' => $table), array('print' => $print_errors)
     );
   }
 
@@ -1127,9 +1124,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     // make sure the field is in the table description. If not then return an error
     // message
     if (!array_key_exists($field, $table_desc['fields'])) {
-      tripal_core_report_error(
-        'tripal_core',
-        TRIPAL_ERROR,
+      tripal_core_report_error('tripal_core', TRIPAL_ERROR,
         'tripal_core_chado_select: The field "%field" does not exist for the table "%table".  Cannot perform query. Values: %array',
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)),
         array('print' => $print_errors)
@@ -2161,7 +2156,7 @@ function chado_query($sql, $args = array()) {
     // must automaticaly have the chado schema set as active to find 
     if(preg_match('/chado.featureloc/i', $sql)) {
       $previous_db = tripal_db_set_active('chado') ;
-      $results = db_query($sql);
+      $results = db_query($sql, $args);
       tripal_db_set_active($previous_db);
     }
     // for all other tables we should have everything in scope so just run the query

+ 42 - 44
tripal_feature/includes/gff_loader.inc

@@ -836,23 +836,20 @@ continue;
     $parents = chado_query($sql);
     
     // build and prepare the SQL for selecting the children relationship
-    $sql = "SELECT DISTINCT FR.feature_relationship_id, FL.fmin, FR.rank
-            FROM {feature_relationship} FR
-              INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id";
-    if (!$connection) {
-      $sql .= "WHERE FR.object_id = :feature_id " .
-              "ORDER BY FL.fmin ASC ";
-    }
-    else {
-      $sql = "PREPARE sel_gffchildren (int) AS " . $sql . " WHERE FR.object_id = \$1 ORDER BY FL.fmin ASC";            
-    }
-    if (!tripal_core_is_sql_prepared('sel_gffchildren')) {
-      $success = tripal_core_chado_prepare('sel_gffchildren', $sql, array('int'));
-      if (!$success) {
-        watchdog("T_gff3_loader", "Cannot prepare statement 'sel_gffchildren' and cannot set children ranks.", 
-           array(), WATCHDOG_WARNING);
-        return 0;  
-      }
+    $sql = "";
+
+    $sql = "
+      PREPARE sel_gffchildren (int) AS 
+      SELECT DISTINCT FR.feature_relationship_id, FL.fmin, FR.rank
+      FROM {feature_relationship} FR
+        INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
+      WHERE FR.object_id = \$1 ORDER BY FL.fmin ASC
+    ";            
+    $success = chado_query('sel_gffchildren', $sql);
+    if (!$success) {
+      watchdog("T_gff3_loader", "Cannot prepare statement 'sel_gffchildren' and cannot set children ranks.", 
+         array(), WATCHDOG_WARNING);
+      return 0;  
     }
     
     // now set the rank of any parent/child relationships.  The order is based
@@ -991,19 +988,19 @@ function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, $organism
   $rel_type = 'part_of';
 
   // prepare these SQL statements that will be used repeatedly.
-  if (!tripal_core_is_sql_prepared('sel_cvterm_cvname_cvtname_synonym')) {
-    $psql = "PREPARE sel_cvterm_cvname_cvtname_synonym (text, text, text) AS
-             SELECT CVT.cvterm_id
-             FROM {cvterm} CVT
-               INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
-               LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
-             WHERE cv.name = $1 and (CVT.name = $2 or CVTS.synonym = $3)";
-    $status = tripal_core_chado_prepare('sel_cvterm_cvname_cvtname_synonym', $psql, array('text', 'text', 'text'));
-    if (!$status) {
-       watchdog("T_gff3_loader", "Cannot prepare statement 'sel_cvterm_cvname_cvtname_synonym' for ontology term", 
-         array(), WATCHDOG_WARNING);
-       return '';
-    }
+  $psql = "
+    PREPARE sel_cvterm_cvname_cvtname_synonym (text, text, text) AS
+    SELECT CVT.cvterm_id
+    FROM {cvterm} CVT
+      INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+      LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
+    WHERE cv.name = $1 and (CVT.name = $2 or CVTS.synonym = $3)
+  ";
+  $status = chado_query($psql);
+  if (!$status) {
+     watchdog("T_gff3_loader", "Cannot prepare statement 'sel_cvterm_cvname_cvtname_synonym' for ontology term", 
+       array(), WATCHDOG_WARNING);
+     return '';
   }
 
   // iterate through the parents in the list
@@ -1350,20 +1347,21 @@ function tripal_feature_load_gff3_alias($feature, $aliases) {
     $result = tripal_core_chado_select('pub', array('*'), $select, $options);    
     if (count($result) == 0) {
       // prepare the statement
-      if (!tripal_core_is_sql_prepared('ins_pub_uniquename_typeid')) {
-        $psql = "PREPARE ins_pub_uniquename_typeid (text, text) AS
-                 INSERT INTO {pub} (uniquename,type_id) VALUES ('%s',
-                 (SELECT cvterm_id
-                  FROM {cvterm} CVT
-                    INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
-                    INNER JOIN {db} DB on DB.db_id = DBX.db_id
-                  WHERE CVT.name = $1 and DB.name = $2)";
-        $status = tripal_core_chado_prepare('ins_pub_uniquename_typeid', $psql, args('text', 'text'));
-        if (!$status) {
-          watchdog("T_gff3_loader", "Cannot prepare statement 'ins_pub_uniquename_typeid", array(), WATCHDOG_WARNING);
-          return 0;
-        } 
-      }    
+      $psql = "
+        PREPARE ins_pub_uniquename_typeid (text, text) AS
+        INSERT INTO {pub} (uniquename,type_id) VALUES ('%s',
+        (SELECT cvterm_id
+        FROM {cvterm} CVT
+          INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
+          INNER JOIN {db} DB on DB.db_id = DBX.db_id
+        WHERE CVT.name = $1 and DB.name = $2)
+      ";
+      $status = chado_query($psql);
+      if (!$status) {
+        watchdog("T_gff3_loader", "Cannot prepare statement 'ins_pub_uniquename_typeid", array(), WATCHDOG_WARNING);
+        return 0;
+      } 
+
       // insert the null pub 
       $result = chado_query("EXECUTE ins_pub_uniquename_typeid (:uname, :type_id)", 
         array(':uname' => 'null', ':type_id' => 'null'))->fetchObject();