Просмотр исходного кода

Made transactions optional in GFF loader. Changed all appropriate db_queryt to chado_query in feature module. Added a drush command to sync a single feature (useful for debugging/testing).

spficklin 12 лет назад
Родитель
Сommit
2a743acf56

+ 2 - 6
tripal_core/api/tripal_core.api.inc

@@ -339,9 +339,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
   }
   }
   // if it's not a prepared statement then insert normally
   // if it's not a prepared statement then insert normally
   else {
   else {
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    $result = db_query($sql, $ivalues);
-    tripal_db_set_active($previous_db);  // now use drupal database
+    $result = chado_query($sql, $ivalues);
   }
   }
 
 
   // if we have a result then add primary keys to return array
   // if we have a result then add primary keys to return array
@@ -693,9 +691,7 @@ function tripal_core_chado_update($table, $match, $values, $options = NULL) {
   }
   }
   // if it's not a prepared statement then insert normally
   // if it's not a prepared statement then insert normally
   else {
   else {
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    $resource = db_query($sql, $uargs);
-    tripal_db_set_active($previous_db);  // now use drupal database
+    $resource = chado_query($sql, $uargs);
   }
   }
 
 
   if ($resource) {
   if ($resource) {

+ 9 - 2
tripal_feature/includes/gff_loader.inc

@@ -58,7 +58,7 @@ function tripal_feature_gff3_load_form() {
       the entire datset loaded prior to the failure will be rolled back and will not be available
       the entire datset loaded prior to the failure will be rolled back and will not be available
       in the database.  If this option is unchecked and failure occurs all records up to the point
       in the database.  If this option is unchecked and failure occurs all records up to the point
       of failure will be present in the database.'),
       of failure will be present in the database.'),
-    '#weight' => 2
+    '#weight' => 1
   );
   );
   $form['import_options']['add_only']= array(
   $form['import_options']['add_only']= array(
     '#type' => 'checkbox',
     '#type' => 'checkbox',
@@ -187,7 +187,8 @@ function tripal_feature_gff3_load_form_submit($form, &$form_state) {
   $analysis_id = $form_state['values']['analysis_id'];
   $analysis_id = $form_state['values']['analysis_id'];
   $use_transaction   = $form_state['values']['use_transaction'];
   $use_transaction   = $form_state['values']['use_transaction'];
 
 
-  $args = array($gff_file, $organism_id, $analysis_id, $add_only, $update, $refresh, $remove, $use_transaction);
+  $args = array($gff_file, $organism_id, $analysis_id, $add_only, 
+    $update, $refresh, $remove, $use_transaction);
   $type = '';
   $type = '';
   if ($add_only) {
   if ($add_only) {
     $type = 'import only new features';
     $type = 'import only new features';
@@ -245,6 +246,12 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
 	  	       "insertions/updates is rolled back and will not be found in the database\n\n";
 	  	       "insertions/updates is rolled back and will not be found in the database\n\n";
 	  }
 	  }
   }
   }
+  else {
+  	$connection = tripal_db_persistent_chado();
+    if (!$connection) {
+       print "A persistant connection was not obtained. Loading will be slow\n";
+    }
+  }
 
 
   // 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;

+ 11 - 18
tripal_feature/includes/syncFeatures.inc

@@ -226,10 +226,7 @@ function tripal_feature_sync_features($max_sync = 0, $organism_id = NULL,
         "ORDER BY feature_id";
         "ORDER BY feature_id";
 
 
   // get the list of features
   // get the list of features
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $results = db_query($sql);
-
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $results = chado_query($sql);
 
 
   // load into ids array
   // load into ids array
   $count = 0;
   $count = 0;
@@ -312,18 +309,14 @@ function tripal_feature_sync_feature($feature_id) {
          "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
          "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
          "  INNER JOIN Organism O ON F.organism_id = O.organism_ID ".
          "  INNER JOIN Organism O ON F.organism_id = O.organism_ID ".
          "WHERE F.feature_id = %d";
          "WHERE F.feature_id = %d";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $feature = db_fetch_object(db_query($fsql, $feature_id));
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $feature = db_fetch_object(chado_query($fsql, $feature_id));
 
 
   // get the synonyms for this feature
   // get the synonyms for this feature
   $synsql = "SELECT S.name ".
   $synsql = "SELECT S.name ".
-           "FROM {feature_synonym} FS ".
-           "  INNER JOIN {synonym} S on FS.synonym_id = S.synonym_id ".
-           "WHERE FS.feature_id = %d";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $synonyms = db_query($synsql, $feature_id);
-  tripal_db_set_active($previous_db);  // now use drupal database
+            "FROM {feature_synonym} FS ".
+            "  INNER JOIN {synonym} S on FS.synonym_id = S.synonym_id ".
+            "WHERE FS.feature_id = %d";
+  $synonyms = chado_query($synsql, $feature_id);
 
 
   // now add these synonyms to the feature object as a single string
   // now add these synonyms to the feature object as a single string
   $synstring = '';
   $synstring = '';
@@ -337,9 +330,9 @@ function tripal_feature_sync_feature($feature_id) {
   // clean up that node.  (If a node is found we don't know if it belongs to our feature or
   // clean up that node.  (If a node is found we don't know if it belongs to our feature or
   // not since features can have the same name/title.)
   // not since features can have the same name/title.)
   $tsql =  "SELECT * FROM {node} N ".
   $tsql =  "SELECT * FROM {node} N ".
-          "WHERE title = '%s'";
+           "WHERE title = '%s'";
   $cnsql = "SELECT * FROM {chado_feature} ".
   $cnsql = "SELECT * FROM {chado_feature} ".
-          "WHERE nid = %d";
+           "WHERE nid = %d";
   $nodes = db_query($tsql, $feature->name);
   $nodes = db_query($tsql, $feature->name);
   // cycle through all nodes that may have this title
   // cycle through all nodes that may have this title
   while ($node = db_fetch_object($nodes)) {
   while ($node = db_fetch_object($nodes)) {
@@ -353,10 +346,10 @@ function tripal_feature_sync_feature($feature_id) {
   // check if this feature already exists in the chado_feature table.
   // check if this feature already exists in the chado_feature table.
   // if we have a chado feature, we want to check to see if we have a node
   // if we have a chado feature, we want to check to see if we have a node
   $cfsql = "SELECT * FROM {chado_feature} ".
   $cfsql = "SELECT * FROM {chado_feature} ".
-          "WHERE feature_id = %d";
+           "WHERE feature_id = %d";
   // @coder-ignore: don't need to use db_rewrite_sql() since need all nodes regardless of access control
   // @coder-ignore: don't need to use db_rewrite_sql() since need all nodes regardless of access control
   $nsql =  "SELECT * FROM {node} ".
   $nsql =  "SELECT * FROM {node} ".
-          "WHERE nid = %d";
+           "WHERE nid = %d";
   $chado_feature = db_fetch_object(db_query($cfsql, $feature->feature_id));
   $chado_feature = db_fetch_object(db_query($cfsql, $feature->feature_id));
   if ($chado_feature) {
   if ($chado_feature) {
     drupal_set_message(t("%feature_id: A chado_feature entry exists", array('%feature_id' => $feature_id)));
     drupal_set_message(t("%feature_id: A chado_feature entry exists", array('%feature_id' => $feature_id)));
@@ -386,7 +379,7 @@ function tripal_feature_sync_feature($feature_id) {
   if ($create_node) {
   if ($create_node) {
     // get the organism for this feature
     // get the organism for this feature
     $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
     $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-    $organism = db_fetch_object(db_query($sql, $feature->organism_id));
+    $organism = db_fetch_object(chado_query($sql, $feature->organism_id));
 
 
     drupal_set_message(t("%feature_id: Creating node $feature->name", array('%feature_id' => $feature_id)));
     drupal_set_message(t("%feature_id: Creating node $feature->name", array('%feature_id' => $feature_id)));
     $new_node = new stdClass();
     $new_node = new stdClass();

+ 17 - 0
tripal_feature/tripal_feature.drush.inc

@@ -45,6 +45,16 @@ function tripal_feature_drush_command() {
     ),
     ),
     'aliases' => array('trp-get-seq'),
     'aliases' => array('trp-get-seq'),
   );
   );
+  $items['tripal-feature-sync'] = array(
+    'description' => dt('Syncs an individual feature.'),
+    'options'   => array(
+      'id'    => dt('The feature ID of the feature to sync'),
+    ),
+    'examples' => array(
+      'Standard example' => 'drush tripal-feature-sync --id=48273',
+    ),
+    'aliases' => array('trp-fsync'),
+  );
   return $items;
   return $items;
 }
 }
 
 
@@ -116,3 +126,10 @@ function drush_tripal_feature_tripal_get_sequence() {
     print $sequence;
     print $sequence;
   }
   }
 }
 }
+/*
+ * 
+ */
+function drush_tripal_feature_sync() {
+  $feature_id = drush_get_option('id');  
+	tripal_feature_sync_feature($feature_id);
+}

+ 27 - 64
tripal_feature/tripal_feature.module

@@ -572,9 +572,7 @@ function chado_feature_delete($node) {
   // Remove data from feature tables of chado database.  This will
   // Remove data from feature tables of chado database.  This will
   // cause a cascade delete and remove all data in referencing tables
   // cause a cascade delete and remove all data in referencing tables
   // for this feature
   // for this feature
-  $previous_db = tripal_db_set_active('chado');
-  db_query("DELETE FROM {feature} WHERE feature_id = %d", $feature_id);
-  tripal_db_set_active($previous_db);
+  chado_query("DELETE FROM {feature} WHERE feature_id = %d", $feature_id);
 
 
   drupal_set_message(t("The feature and all associated data were removed from") .
   drupal_set_message(t("The feature and all associated data were removed from") .
   "chado");
   "chado");
@@ -593,18 +591,15 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
   $syn_array = array();
   $syn_array = array();
   $syn_array = explode(" ", $synonyms);
   $syn_array = explode(" ", $synonyms);
 
 
-  // use the chado database
-  $previous_db = tripal_db_set_active('chado');
 
 
   // remove any old synonyms
   // remove any old synonyms
   $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
   $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
-  if (!db_query($feature_syn_dsql, $feature_id)) {
+  if (!chado_query($feature_syn_dsql, $feature_id)) {
     $error .= "Could not remove synonyms from feature. ";
     $error .= "Could not remove synonyms from feature. ";
   }
   }
 
 
   // return if we don't have any synonmys to add
   // return if we don't have any synonmys to add
   if (!$synonyms) {
   if (!$synonyms) {
-    tripal_db_set_active($previous_db);
     return;
     return;
   }
   }
   // iterate through each synonym and add it to the database
   // iterate through each synonym and add it to the database
@@ -618,7 +613,7 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
     // It is possible for the accession number to be present and not the feature
     // It is possible for the accession number to be present and not the feature
     $synonym_sql = "SELECT synonym_id FROM {synonym} ".
     $synonym_sql = "SELECT synonym_id FROM {synonym} ".
                    "WHERE name = '%s'";
                    "WHERE name = '%s'";
-    $synonym = db_fetch_object(db_query($synonym_sql, $syn));
+    $synonym = db_fetch_object(chado_query($synonym_sql, $syn));
     if (!$synonym) {
     if (!$synonym) {
       $synonym_isql = "INSERT INTO {synonym} (name,synonym_sgml,type_id) ".
       $synonym_isql = "INSERT INTO {synonym} (name,synonym_sgml,type_id) ".
                       "VALUES ('%s','%s', ".
                       "VALUES ('%s','%s', ".
@@ -626,25 +621,24 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
                       "    FROM {CVTerm} CVT ".
                       "    FROM {CVTerm} CVT ".
                       "    INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
                       "    INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
                       "    WHERE CV.name = 'feature_property' and CVT.name = 'synonym'))";
                       "    WHERE CV.name = 'feature_property' and CVT.name = 'synonym'))";
-      if (!db_query($synonym_isql, $syn, $syn)) {
+      if (!chado_query($synonym_isql, $syn, $syn)) {
         $error .= "Could not add synonym. ";
         $error .= "Could not add synonym. ";
       }
       }
       // now get the synonym we just added
       // now get the synonym we just added
       $synonym_sql = "SELECT synonym_id FROM {synonym} ".
       $synonym_sql = "SELECT synonym_id FROM {synonym} ".
                      "WHERE name = '%s'";
                      "WHERE name = '%s'";
-      $synonym = db_fetch_object(db_query($synonym_sql, $syn));
+      $synonym = db_fetch_object(chado_query($synonym_sql, $syn));
     }
     }
 
 
     // now add in our new sysnonym
     // now add in our new sysnonym
     $feature_syn_isql = "INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id) ".
     $feature_syn_isql = "INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id) ".
                         "VALUES (%d,%d,1)";
                         "VALUES (%d,%d,1)";
-    if (!db_query($feature_syn_isql, $synonym->synonym_id, $feature_id)) {
+    if (!chado_query($feature_syn_isql, $synonym->synonym_id, $feature_id)) {
       $error .= "Could not add synonyms to feature. ";
       $error .= "Could not add synonyms to feature. ";
     }
     }
   }
   }
 
 
   // return to the drupal database
   // return to the drupal database
-  tripal_db_set_active($previous_db);
   return $error;
   return $error;
 
 
 }
 }
@@ -656,7 +650,6 @@ function chado_feature_add_synonyms($synonyms, $feature_id) {
 function chado_feature_add_gbaccession($accession, $feature_id) {
 function chado_feature_add_gbaccession($accession, $feature_id) {
 
 
   // use chado database
   // use chado database
-  $previous_db = tripal_db_set_active('chado');
 
 
   // remove any old accession from genbank dbEST
   // remove any old accession from genbank dbEST
   $fdbxref_dsql = "DELETE FROM {feature_dbxref} ".
   $fdbxref_dsql = "DELETE FROM {feature_dbxref} ".
@@ -665,48 +658,46 @@ function chado_feature_add_gbaccession($accession, $feature_id) {
                  "    INNER JOIN DB  ON DB.db_id = DBX.db_id ".
                  "    INNER JOIN DB  ON DB.db_id = DBX.db_id ".
                  "    INNER JOIN feature_dbxref FDBX ON DBX.dbxref_id = FDBX.dbxref_id ".
                  "    INNER JOIN feature_dbxref FDBX ON DBX.dbxref_id = FDBX.dbxref_id ".
                  "    WHERE DB.name = 'DB:Genbank' and FDBX.feature_id = %d)";
                  "    WHERE DB.name = 'DB:Genbank' and FDBX.feature_id = %d)";
-  if (!db_query($fdbxref_dsql, $feature_id, $feature_id)) {
+  if (!chado_query($fdbxref_dsql, $feature_id, $feature_id)) {
     $error .= "Could not remove accession from feature. ";
     $error .= "Could not remove accession from feature. ";
   }
   }
 
 
   // if we don't have an accession number to add then just return
   // if we don't have an accession number to add then just return
   if (!$accession) {
   if (!$accession) {
-    tripal_db_set_active($previous_db);
     return;
     return;
   }
   }
   // get the db_id
   // get the db_id
   $db_sql = "SELECT db_id FROM {DB} ".
   $db_sql = "SELECT db_id FROM {DB} ".
             "WHERE name = 'DB:Genbank_est'";
             "WHERE name = 'DB:Genbank_est'";
-  $db = db_fetch_object(db_query($db_sql));
+  $db = db_fetch_object(chado_query($db_sql));
 
 
   // check to see if we have this accession number already in the database
   // check to see if we have this accession number already in the database
   // if so then don't add it again. it messes up drupal if the insert fails.
   // if so then don't add it again. it messes up drupal if the insert fails.
   // It is possible for the accession number to be present and not the feature
   // It is possible for the accession number to be present and not the feature
   $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
   $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
                 "WHERE db_id = %d and accession = '%s'";
                 "WHERE db_id = %d and accession = '%s'";
-  $dbxref = db_fetch_object(db_query($dbxref_sql, $db->db_id, $accession));
+  $dbxref = db_fetch_object(chado_query($dbxref_sql, $db->db_id, $accession));
   if (!$dbxref) {
   if (!$dbxref) {
     // add the accession number
     // add the accession number
     $dbxref_isql = "INSERT INTO {dbxref} (db_id,accession) ".
     $dbxref_isql = "INSERT INTO {dbxref} (db_id,accession) ".
                    "  VALUES (%d, '%s') ";
                    "  VALUES (%d, '%s') ";
-    if (!db_query($dbxref_isql, $db->db_id, $accession)) {
+    if (!chado_query($dbxref_isql, $db->db_id, $accession)) {
       $error .= 'Could not add accession as a database reference ';
       $error .= 'Could not add accession as a database reference ';
     }
     }
     // get the dbxref_id for the just added accession number
     // get the dbxref_id for the just added accession number
     $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
     $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
                   "WHERE db_id = %d and accession = '%s'";
                   "WHERE db_id = %d and accession = '%s'";
-    $dbxref = db_fetch_object(db_query($dbxref_sql, $db->db_id, $accession));
+    $dbxref = db_fetch_object(chado_query($dbxref_sql, $db->db_id, $accession));
   }
   }
 
 
 
 
   // associate the accession number with the feature
   // associate the accession number with the feature
   $feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) ".
   $feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) ".
                          "  VALUES (%d, %d) ";
                          "  VALUES (%d, %d) ";
-  if (!db_query($feature_dbxref_isql, $feature_id, $dbxref->dbxref_id)) {
+  if (!chado_query($feature_dbxref_isql, $feature_id, $dbxref->dbxref_id)) {
     $error .= 'Could not add feature database reference. ';
     $error .= 'Could not add feature database reference. ';
   }
   }
 
 
-  tripal_db_set_active($previous_db);
   return $error;
   return $error;
 }
 }
 
 
@@ -821,9 +812,7 @@ function chado_feature_form($node, $param) {
   );
   );
   // get the list of organisms
   // get the list of organisms
   $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
   $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $org_rset = db_query($sql);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $org_rset = chado_query($sql);
 
 
   //
   //
   $organisms = array();
   $organisms = array();
@@ -902,9 +891,7 @@ function chado_feature_validate($node) {
               INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
               INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
             WHERE uniquename = '%s'
             WHERE uniquename = '%s'
              AND organism_id = %d AND CVT.name = '%s' AND NOT feature_id = %d";
              AND organism_id = %d AND CVT.name = '%s' AND NOT feature_id = %d";
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_fetch_object(db_query($sql, $node->uniquename, $node->organism_id, $node->feature_type, $node->feature_id));
-    tripal_db_set_active($previous_db);
+    $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->feature_type, $node->feature_id));
     if ($result) {
     if ($result) {
       form_set_error('uniquename', t("Feature update cannot proceed. The feature name '$node->uniquename' is not unique for this organism. Please provide a unique name for this feature."));
       form_set_error('uniquename', t("Feature update cannot proceed. The feature name '$node->uniquename' is not unique for this organism. Please provide a unique name for this feature."));
     }
     }
@@ -918,9 +905,7 @@ function chado_feature_validate($node) {
               INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
               INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
             WHERE uniquename = '%s'
             WHERE uniquename = '%s'
              AND organism_id = %d AND CVT.name = '%s'";
              AND organism_id = %d AND CVT.name = '%s'";
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_fetch_object(db_query($sql, $node->uniquename, $node->organism_id, $node->feature_type));
-    tripal_db_set_active($previous_db);
+    $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->feature_type));
     if ($result) {
     if ($result) {
       form_set_error('uniquename', t("Feature insert cannot proceed. The feature name '$node->uniquename' already exists for this organism. Please provide a unique name for this feature."));
       form_set_error('uniquename', t("Feature insert cannot proceed. The feature name '$node->uniquename' already exists for this organism. Please provide a unique name for this feature."));
     }
     }
@@ -972,9 +957,7 @@ function chado_feature_load($node) {
 function tripal_feature_load_organism($organism_id) {
 function tripal_feature_load_organism($organism_id) {
   // add organism details
   // add organism details
   $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
   $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $organism = db_fetch_object(db_query($sql, $organism_id));
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $organism = db_fetch_object(chado_query($sql, $organism_id));
   return $organism;
   return $organism;
 }
 }
 /**
 /**
@@ -990,9 +973,7 @@ function tripal_feature_load_synonyms($feature_id) {
         "    ON FS.synonym_id = S.Synonym_id ".
         "    ON FS.synonym_id = S.Synonym_id ".
         "WHERE FS.feature_id = %d ".
         "WHERE FS.feature_id = %d ".
         "ORDER BY S.name ";
         "ORDER BY S.name ";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $results = db_query($sql, $feature_id);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $results = chado_query($sql, $feature_id);
   $synonyms = array();
   $synonyms = array();
   $i=0;
   $i=0;
   while ($synonym = db_fetch_object($results)) {
   while ($synonym = db_fetch_object($results)) {
@@ -1017,9 +998,7 @@ function tripal_feature_load_properties($feature_id) {
            INNER JOIN {db} DB      ON DB.db_id = DBX.db_id
            INNER JOIN {db} DB      ON DB.db_id = DBX.db_id
          WHERE FS.feature_id = %d
          WHERE FS.feature_id = %d
          ORDER BY FS.rank ASC";
          ORDER BY FS.rank ASC";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $results = db_query($sql, $feature_id);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $results = chado_query($sql, $feature_id);
   $i=0;
   $i=0;
   $properties = array();
   $properties = array();
   while ($property = db_fetch_object($results)) {
   while ($property = db_fetch_object($results)) {
@@ -1042,9 +1021,7 @@ function tripal_feature_load_references($feature_id) {
         "  INNER JOIN {db} on DB.db_id = DBX.db_id ".
         "  INNER JOIN {db} on DB.db_id = DBX.db_id ".
         "WHERE F.feature_id = %d ".
         "WHERE F.feature_id = %d ".
         "ORDER BY DB.name ";
         "ORDER BY DB.name ";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $results = db_query($sql, $feature_id);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $results = chado_query($sql, $feature_id);
   $references = array();
   $references = array();
   $i=0;
   $i=0;
   while ($accession = db_fetch_object($results)) {
   while ($accession = db_fetch_object($results)) {
@@ -1081,9 +1058,7 @@ function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggr
     $sql .= "WHERE FL.feature_id = %d ";
     $sql .= "WHERE FL.feature_id = %d ";
   }
   }
 
 
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $flresults = db_query($sql, $feature_id);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $flresults = chado_query($sql, $feature_id);
 
 
   // copy the results into an array
   // copy the results into an array
   $i=0;
   $i=0;
@@ -1164,9 +1139,7 @@ function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
   $sql .= " ORDER BY FR.rank";
   $sql .= " ORDER BY FR.rank";
 
 
   // get the relationships
   // get the relationships
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $results = db_query($sql, $feature_id);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $results = chado_query($sql, $feature_id);
 
 
 
 
   // iterate through the relationships, put these in an array and add
   // iterate through the relationships, put these in an array and add
@@ -1195,9 +1168,7 @@ function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
 function tripal_feature_get_aggregate_types($feature_id) {
 function tripal_feature_get_aggregate_types($feature_id) {
   // get the feature details
   // get the feature details
   $sql = 'SELECT type_id FROM {feature} WHERE feature_id = %d';
   $sql = 'SELECT type_id FROM {feature} WHERE feature_id = %d';
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $feature = db_fetch_object(db_query($sql, $feature_id));
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $feature = db_fetch_object(chado_query($sql, $feature_id));
 
 
   // check to see if this feature is of a type with an aggregate
   // check to see if this feature is of a type with an aggregate
   $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d";
   $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d";
@@ -1445,7 +1416,7 @@ function tripal_feature_get_matched_alignments($feature) {
           "  AND (CVT2.name = 'match' or CVT2.name like '%_match') ".
           "  AND (CVT2.name = 'match' or CVT2.name like '%_match') ".
           "ORDER BY FL1.fmin";
           "ORDER BY FL1.fmin";
 
 
-   $results = db_query($sql, $feature->feature_id, $feature->feature_id);
+   $results = chado_query($sql, $feature->feature_id, $feature->feature_id);
    
    
    // iterate through the results and add them to our featurelocs array
    // iterate through the results and add them to our featurelocs array
    $featurelocs = array();
    $featurelocs = array();
@@ -1514,9 +1485,7 @@ function tripal_feature_load_organism_feature_counts($organism) {
     ORDER BY num_features desc
     ORDER BY num_features desc
   ";
   ";
   $args[] = $organism->organism_id;
   $args[] = $organism->organism_id;
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $org_features = db_query($sql, $args);
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $org_features = chado_query($sql, $args);
 
 
   // iterate through the types
   // iterate through the types
   $types = array();
   $types = array();
@@ -2617,9 +2586,7 @@ function tripal_feature_set_taxonomy($node, $feature_id) {
         "  INNER JOIN Feature F on F.type_id = CVT.cvterm_id ".
         "  INNER JOIN Feature F on F.type_id = CVT.cvterm_id ".
         "  INNER JOIN Organism O ON F.organism_id = O.organism_id ".
         "  INNER JOIN Organism O ON F.organism_id = O.organism_id ".
         "WHERE F.feature_id = $feature_id";
         "WHERE F.feature_id = $feature_id";
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $feature = db_fetch_object(db_query($sql));
-  tripal_db_set_active($previous_db);  // now use drupal database
+  $feature = db_fetch_object(chado_query($sql));
 
 
   // Set the feature type for this feature
   // Set the feature type for this feature
   if ($do_ft && $ft_vid) {
   if ($do_ft && $ft_vid) {
@@ -2636,9 +2603,7 @@ function tripal_feature_set_taxonomy($node, $feature_id) {
            "FROM {Library} L ".
            "FROM {Library} L ".
            "  INNER JOIN Library_feature LF ON LF.library_id = L.library_id ".
            "  INNER JOIN Library_feature LF ON LF.library_id = L.library_id ".
            "WHERE LF.feature_id = %d ";
            "WHERE LF.feature_id = %d ";
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    $library = db_fetch_object(db_query($sql, $feature_id));
-    tripal_db_set_active($previous_db);  // now use drupal database
+    $library = db_fetch_object(chado_query($sql, $feature_id));
     $tags["$lb_vid"] = "$library->name";
     $tags["$lb_vid"] = "$library->name";
   }
   }
 
 
@@ -2654,15 +2619,13 @@ function tripal_feature_set_taxonomy($node, $feature_id) {
            "FROM {Analysis} A ".
            "FROM {Analysis} A ".
            "  INNER JOIN Analysisfeature AF ON AF.analysis_id = A.analysis_id ".
            "  INNER JOIN Analysisfeature AF ON AF.analysis_id = A.analysis_id ".
            "WHERE AF.feature_id = $feature_id ";
            "WHERE AF.feature_id = $feature_id ";
-    $results = db_query($sql);
-    $previous_db = tripal_db_set_active('chado');  // use chado database
+    $results = chado_query($sql);
     $analysis_terms = array();
     $analysis_terms = array();
     while ($analysis=db_fetch_object($results)) {
     while ($analysis=db_fetch_object($results)) {
       $tags2["$an_vid"] = "$analysis->name";
       $tags2["$an_vid"] = "$analysis->name";
       $terms['tags'] = $tags2;
       $terms['tags'] = $tags2;
       taxonomy_node_save($node, $terms);
       taxonomy_node_save($node, $terms);
     }
     }
-    tripal_db_set_active($previous_db);  // now use drupal database
   }
   }
 
 
 }
 }