Bladeren bron

various bug fixes.. can't remember all

Stephen Ficklin 13 jaren geleden
bovenliggende
commit
308000ead1

+ 4 - 1
tripal_core/cvterms.php

@@ -16,7 +16,10 @@
  */
 
 /**
- * Add a materialized view to the chado database to help speed data access.
+ * DEPRECATED: This function should no longer be used. But rather the
+ * tripal_cv_add_cvterm function should be used. 
+ * 
+ * This function adds a term to the cvterm table of Chado.
  *
  * @param $name 
  *   The name of the term

+ 18 - 16
tripal_core/tripal_core.api.inc

@@ -595,7 +595,7 @@ function tripal_core_chado_select($table,$columns,$values,$options = null){
               'case_insensitive_columns' => $options['case_insensitive_columns']
             );
             $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value, $foreign_options);
-            if (sizeof($results) < 1) {
+            if (count($results) ==0) {
               // foreign key records are required
               // thus if none matched then return false and alert the admin through watchdog
               //watchdog('tripal_core', 
@@ -759,10 +759,12 @@ function tripal_core_chado_get_foreign_key($table_desc,$field,$values, $options
                $select_cols = array($right);
                $result = tripal_core_chado_select($table,$select_cols,$values, $options);
                $fields = array();
-               foreach ($result as $obj) {
-                 $fields[] = $obj->$right;
+               if(count($result) > 0){
+                  foreach ($result as $obj) {
+                    $fields[] = $obj->$right;
+                  }
+                  return $fields;
                }
-               return $fields;
             }
          }
       } 
@@ -1366,7 +1368,10 @@ function chado_get_node_id ($table, $id) {
  *   The name of the cv that the above cvterm is part of
  *
  * @return
- *   A chado variable with the specified properties expanded
+ *   An array in the same format as that generated by the function
+ *   tripal_core_generate_chado_var().  If only one record is returned it
+ *   is a single object.  If more than one record is returned then it is an array
+ *   of objects
  *
  * @ingroup tripal_chado_api
  */
@@ -1425,22 +1430,24 @@ function tripal_core_insert_property($basetable, $record_id, $property,
    // first see if the property already exists, if the user want's to update
    // then we can do that, but otherwise we want to increment the rank and
    // insert
-   $prop = tripal_core_get_property($basetable,$record_id,$property,$cv_name);
+   $props = tripal_core_get_property($basetable,$record_id,$property,$cv_name);
+   if(!is_array($props)) { 
+    $props = array($props); 
+   }   
    $rank = 0;
-   $exists = 0;
-   if(count($prop)>0){ 
+   if(count($props)>0){       
       if($update_if_present){
-         return tripal_core_update_property($basetable,$record_id,$property,$cv_name,$value) ;
+         return tripal_core_update_property($basetable, $record_id, $property, $cv_name, $value) ;
       } else {
          // iterate through the properties returned and check to see if the
          // property with this value already exists if not, get the largest rank
          // and insert the same property but with this new value
-         foreach($prop as $p){
+         foreach($props as $p){
             if($p->rank > $rank){
                $rank = $p->rank;
             }
             if(strcmp($p->value,$value)==0){
-               $exists = 1;
+               return TRUE;
             }
          }
          // now add 1 to the rank
@@ -1448,11 +1455,6 @@ function tripal_core_insert_property($basetable, $record_id, $property,
       }
    }
 
-   // if the property with this value exists then we return TRUE as if the
-   // insert was successful.
-   if($exists){
-      return TRUE;
-   }
    // get the foreign key for this property table
    $table_desc = module_invoke_all('chado_'.$basetable.'prop_schema');
    $fkcol = key($table_desc['foreign keys'][$basetable]['columns']);

+ 19 - 90
tripal_cv/tripal_cv.api.inc

@@ -159,94 +159,6 @@ function tripal_cv_get_cv_options() {
 
 }
 
-/**
- * To retrieve a chado controlled vocabulary term object
- *
- * @param $select_values
- *   An array meant to uniquely select a given controlled vocabulary term
- *
- * @return
- *   Chado controlled vocabulary term object
- *
- * The controlled vocabulary term is selected using tripal_core_chado select and as such the
- * $select_values array parameter meant to uniquely identify the controlled vocab term to be 
- * returned follows the same form as when using tripal_core_chado_select directly.
- *
- * Example Usage:
- * @code
-    $select_values = array(
-      'name' => 'synonym',
-      'cv_id' => array(
-        'name' => 'feature_property'
-      )
-    );
-    $cvterm_object = tripal_cv_get_cvterm($select_values);
- * @endcode
- *  The above code selects the synonym cvterm from the feature_proeprty cv and returns 
- *  the following object:
- * @code
-    $cvterm_object = stdClass Object ( 
-      [cvterm_id] => 2099
-      [name] => synonym
-      [definition] => Historic community symbol, may have originally been symbol []
-      [is_obsolete] => 0
-      [is_relationshiptype] => 1
-      [cv_cv_id] => 13
-      [cv_name] => feature_property
-      [cv_definition] => 
-      [dbreference_dbxref_id] => 2581
-      [dbreference_accession] => synonym
-      [dbreference_description] => 
-      [dbreference_version] => 
-      [dbreference_db_db_id] => 49
-      [dbreference_db_name] => SOFP
-      [dbreference_db_description] => 
-      [dbreference_db_urlprefix] => 
-      [dbreference_db_url] => 
-    ); 
- * @endcode
- *
- * @ingroup tripal_cv_api
- */
-function tripal_cv_get_cvterm ($select_values) {
-
-  $columns = array(
-    'cvterm_id', 
-    'cv_id', 
-    'name', 
-    'definition', 
-    'dbxref_id', 
-    'is_obsolete', 
-    'is_relationshiptype'
-  );
-  $results = tripal_core_chado_select('cvterm', $columns, $select_values);
-  if (sizeof($results) == 1) {
-    // Add cv
-    $cvterm = tripal_cv_add_cv_to_object(array('cv_id'=>$results[0]->cv_id),$results[0],array());
-    unset($cvterm->cv_id);
-    
-    // Add dbxref
-    $cvterm = tripal_db_add_dbxref_to_object(array('dbxref_id'=>$cvterm->dbxref_id),$cvterm,array());
-    unset($cvterm->dbxref_id);
-    
-    return $cvterm;
-  } elseif (empty($results)) {
-    watchdog('tripal_cv', 
-      'tripal_cv_get_cvterm: No cvterm matches criteria values:%values',
-      array('%values' => print_r($select_values, TRUE)),
-      WATCHDOG_WARNING
-    );
-    return FALSE;
-  } else {
-    watchdog('tripal_cv', 
-      'tripal_cv_get_cvterm: 2+ cvterms match criteria values:%values',
-      array('%values' => print_r($select_values, TRUE)),
-      WATCHDOG_WARNING
-    );
-  }
- 
-}
-
 /**
  * Retrieve a chado cvterm object with a given name
  *
@@ -345,6 +257,16 @@ function tripal_cv_chado_cvterm_schema() {
 }
 
 /**
+* Adds a controlled vocabular to the CV table of Chado.
+*
+* @param $name
+*   The name of the controlled vocabulary. These are typically all lower case
+*   with no special characters other than an undrescore (for spaces).
+* @param $comment
+*   A description or definition of the vocabulary.
+*
+* @return
+*   An object populated with fields from the newly added database.
 *
 * @ingroup tripal_cv_api
 */
@@ -405,13 +327,17 @@ function tripal_cv_add_cv($name,$comment){
 *   If this term is a relationship term then this value should be 1.
 * @param $update
 *   By default this is set to 1.  If the term exists it is automatically updated.
+* @param $dbname
+*   In some cases the database name will not be part of the $term['id'] and it
+*   needs to be explicitly set.  Use this argument only if the database name
+*   cannot be specififed in the term ID (e.g. <DB>:<ACCESSION>).
 *
 * @return
 *   A CVTerm object  
 *
 * @ingroup tripal_cv_api
 */
-function tripal_cv_add_cvterm($term,$defaultcv,$is_relationship = 0,$update = 1){
+function tripal_cv_add_cvterm($term,$defaultcv=NULL,$is_relationship = 0,$update = 1,$dbname=NULL){
 
    // get the term properties
    $id = $term['id'];
@@ -444,7 +370,10 @@ function tripal_cv_add_cvterm($term,$defaultcv,$is_relationship = 0,$update = 1)
                   WHERE DBX.accession = '%s' and DB.name = '%s'";  
 
    // get the accession and the database from the cvterm
-   if(preg_match('/^.+?:.*$/',$id)){
+   if($dbname){
+      $accession = $id;
+   }
+   elseif(preg_match('/^.+?:.*$/',$id)){
       $accession = preg_replace('/^.+?:(.*)$/','\1',$id);
       $dbname = preg_replace('/^(.+?):.*$/','\1',$id);
    } 

+ 41 - 5
tripal_db/tripal_db.api.inc

@@ -291,21 +291,57 @@ function tripal_db_chado_dbxref_schema() {
   return $description;
 }
 /**
+* Adds a new database to the Chado DB table and returns the DB object.
+*
+* @param $dbname
+*   The name of the database. This name is usually used as the prefix for
+*   CV term accessions
+* @param $description
+*   Optional. A description of the database.  By default no description is required.
+* @param $url
+*   Optional. The URL for the database
+* @param $urlprefix
+*   Optional. The URL that is to be used as a prefix when constructing a link to
+*   a database term
+* @param $update
+*   Optional. Set this to '1' to force an update of the database if it 
+*   already exists. The default is to not update. If the database exists
+*   then nothing is added.
+*
+* @return
+*   An object populated with fields from the newly added database.
 *
 * @ingroup tripal_db_api
 */
-function tripal_db_add_db($dbname){
+function tripal_db_add_db($dbname,$description='',$url='',$urlprefix='',$update=0){
+
 
+   $values = array(
+      'name' => $dbname,
+      'description' => $description,
+      'url' => $url,
+      'urlprefix' => $urlprefix
+   );
+      
    $db_sql = "SELECT * FROM {db} WHERE name ='%s'";
    $db = db_fetch_object(db_query($db_sql,$dbname));
    if(!$db){
-      if(!db_query("INSERT INTO {db} (name) VALUES ('%s')",$dbname)){
-         watchdog('tripal_cv', "Cannot create '$dbname' db in Chado.",NULL,WATCHDOG_WARNING);
+      if(!tripal_core_chado_insert('db',$values)){
+         watchdog('tripal_db', "Cannot create db '$dbname'.",NULL,WATCHDOG_WARNING);
+         return 0;
+      }      
+      $db = tripal_core_chado_select('db',array('*'),$values);
+   } 
+   elseif($update) {
+      $match = array('db_id' => $db->db_id);
+      if(!tripal_core_chado_update('db',$match,$values)){
+         watchdog('tripal_db', "Cannot update db '$dbname'.",NULL,WATCHDOG_WARNING);
          return 0;
       }      
-     $db = db_fetch_object(db_query($db_sql,$dbname));
+      $db = tripal_core_chado_select('db',array('*'),$values);
+   } else {
+      return $db;
    }
-   return $db;
 }
 /**
 *

+ 2 - 1
tripal_feature/tripal_feature.api.inc

@@ -560,7 +560,8 @@ function tripal_feature_get_property($feature_id,$property,$cv_name='tripal')
 function tripal_feature_insert_property($feature_id, $property, $value,
    $update_if_present = 0, $cv_name = 'tripal')
 {
-    return tripal_core_insert_property('feature',$feature_id,$property,$cv_name,$value,$update_if_present);
+    return tripal_core_insert_property('feature', $feature_id, $property,
+       $cv_name, $value, $update_if_present);
 }
 /**
  * Update a feature property using the property name. Only use this