Browse Source

Removed the old cvterm.php file as those API functions have been replaced. All call to those old functions have been removed

Stephen Ficklin 13 years ago
parent
commit
0b0d4e1f49

+ 1 - 1
extensions/tripal_search_unigene/tripal_search_unigene.install

@@ -35,7 +35,7 @@ function tripal_search_unigene_install(){
    							  ";
    							  ";
    
    
    $index = "feature_id, go_term, unigene, blast_value, kegg_value, interpro_value";
    $index = "feature_id, go_term, unigene, blast_value, kegg_value, interpro_value";
-   $singlet_type_id = tripal_get_cvterm_id('singlet_in_analysis');
+   $singlet_type_id = tripal_cv_get_cvterm_by_name('singlet_in_analysis');
    if ($singlet_type_id) {
    if ($singlet_type_id) {
    	$singlet_condition = " AND F.feature_id NOT IN (SELECT feature_id from feature
    	$singlet_condition = " AND F.feature_id NOT IN (SELECT feature_id from feature
    						   WHERE type_id = (select cvterm_id from cvterm where name = 'EST')
    						   WHERE type_id = (select cvterm_id from cvterm where name = 'EST')

+ 7 - 4
extensions/tripal_search_unigene/views_handler_filter_analysis_name.inc

@@ -1,10 +1,13 @@
 <?php
 <?php
 class views_handler_filter_analysis_name extends views_handler_filter_string {
 class views_handler_filter_analysis_name extends views_handler_filter_string {
 	function value_form(&$form, &$form_state) {
 	function value_form(&$form, &$form_state) {
-		$type_id = tripal_get_cvterm_id("analysis_type");
-		$sql = "SELECT name, A.analysis_id FROM {analysis} A INNER JOIN {analysisprop} AP ON A.analysis_id = AP.analysis_id WHERE type_id = $type_id AND value = 'tripal_analysis_unigene'";
+		$type_id = tripal_cv_get_cvterm_by_name("analysis_type");
+		$sql = "SELECT name, A.analysis_id 
+		        FROM {analysis} A 
+		           INNER JOIN {analysisprop} AP ON A.analysis_id = AP.analysis_id 
+		        WHERE type_id = %d AND value = 'tripal_analysis_unigene'";
 
 
-		$results = chado_query($sql);
+		$results = chado_query($sql,$typ_id->cvterm_id);
 		$analyses = array();
 		$analyses = array();
 		$block_ana = array();
 		$block_ana = array();
 		$counter = 0;
 		$counter = 0;
@@ -47,4 +50,4 @@ class views_handler_filter_analysis_name extends views_handler_filter_string {
 			'=' => t('Is equal to')
 			'=' => t('Is equal to')
 		);
 		);
 	}
 	}
-}
+}

+ 7 - 7
tripal_analysis/tripal_analysis.install

@@ -29,10 +29,10 @@ function tripal_analysis_install() {
 	}
 	}
 	tripal_db_set_active($previous_db);
 	tripal_db_set_active($previous_db);
 
 
-   tripal_add_cvterms('analysis_type','The type of analysis was performed. This value is automatically set by each Tripal Analysis module and should be equal to the module name (e.g. tripal_analysis_blast, tripal_analysis_go).');
-	tripal_add_cvterms('analysis_date','The date that an analysis was performed.');
-	tripal_add_cvterms('analysis_short_name','A computer legible (no spaces '.
-      'or special characters) abbreviation for the analysis.');
+   tripal_cv_add_cvterm(array('name' => 'analysis_type','def' => 'The type of analysis was performed. This value is automatically set by each Tripal Analysis module and should be equal to the module name (e.g. tripal_analysis_blast, tripal_analysis_go).'),'tripal',0,1,'tripal');
+	tripal_cv_add_cvterm(array('name' => 'analysis_date','def' => 'The date that an analysis was performed.'),'tripal',0,1,'tripal');
+	tripal_cv_add_cvterm(array('name' => 'analysis_short_name','def' => 'A computer legible (no spaces '.
+      'or special characters) abbreviation for the analysis.'),'tripal',0,1,'tripal');
 }
 }
 
 
 /*******************************************************************************
 /*******************************************************************************
@@ -131,10 +131,10 @@ function tripal_analysis_requirements($phase) {
  */
  */
 function tripal_analysis_update_6001(){
 function tripal_analysis_update_6001(){
    // we have some new cvterms to add
    // we have some new cvterms to add
-   tripal_add_cvterms('based_on_analysis','The analysis that this analysis was based on. For example, blast/kegg/interpro analyses are based on a unigene analysis. The unigene analysis_id should be stored in analysisprop as the rank using this cvterm. The name of said unigene analysis can be inserted as the value in analysisprop.');
-   tripal_add_cvterms('additional_files', 'Additional files for this analysis. Each file should be separated by a semi-colon and have this format: <file description>, <file path>;');
+   tripal_cv_add_cvterm(array('name' => 'based_on_analysis','def' => 'The analysis that this analysis was based on. For example, blast/kegg/interpro analyses are based on a unigene analysis. The unigene analysis_id should be stored in analysisprop as the rank using this cvterm. The name of said unigene analysis can be inserted as the value in analysisprop.'),'tripal',0,1,'tripal');
+   tripal_cv_add_cvterm(array('name' => 'additional_files', 'def' => 'Additional files for this analysis. Each file should be separated by a semi-colon and have this format: <file description>, <file path>;'),'tripal',0,1,'tripal');
    $ret = array(
    $ret = array(
       '#finished' => 1,
       '#finished' => 1,
    );   
    );   
    return $ret;
    return $ret;
-}
+}

+ 0 - 124
tripal_core/cvterms.php

@@ -1,124 +0,0 @@
-<?php
-
-/** 
- * @defgroup tripal_core_cv_api Core Module CV API
- * @{
- * For working with controlled vocabularies see the Controlled Vocabulary
- * API.  However, there are cases where a CV does not exist. For example in
- * some cases a module may want to support adding of properties (such as to
- * for an analysis) to a record but an organized CV does not exist.  The 
- * progammer may create their own ontology and populate it, or they may use
- * the basic CV interface provided by Tripal.  Tripal provides a CV named
- * 'Tripal' and modules may add terms to this CV to support the functionality
- * of their modules.  
- * @}
- * @ingroup tripal_api
- */
-
-/**
- * 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
- * @param $definition 
- *   The definition for the term
- * @param $cv_name 
- *   The name of the controlled vocabulary to which the term will be added.
- *   The default CV is 'tripal'.
- * @param $db_name 
- *   CV records also have a corresponding database reference.  This argument
- *   specifies the name of the database to which this term belongs. The default
- *   database name is 'tripal'.
- *
- * @ingroup tripal_core_cv_api
- */
-function tripal_add_cvterms ($name,$definition,$cv_name = 'tripal',$db_name='tripal'){
-   
-   
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = '$cv_name'"));
-   if (!$cv->cv_id) {
-      tripal_db_set_active($previous_db);
-      tripal_add_cv('tripal', 'Terms used by Tripal for modules to manage data such as that 
-                               stored in property tables like featureprop, analysisprop, etc');
-      tripal_db_set_active('chado');
-      $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = '$cv_name'"));
-   }
-   $db = db_fetch_object(db_query("SELECT * FROM {db} WHERE name = '$db_name'"));
-	if (!$db->db_id) {
-	   tripal_db_set_active($previous_db);
-	   tripal_add_db('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms', '', '');
-	   tripal_db_set_active('chado');
-	   $db = db_fetch_object(db_query("SELECT * FROM {db} WHERE name = '$db_name'"));
-	}
-
-	// check to see if the dbxref already exists if not then add it
-	$sql = "SELECT * FROM {dbxref} WHERE db_id = $db->db_id and accession = '$name'";
-	$dbxref = db_fetch_object(db_query($sql));
-	if(!$dbxref){
-	   db_query("INSERT INTO {dbxref} (db_id,accession) VALUES ($db->db_id,'$name')");
-		$dbxref = db_fetch_object(db_query($sql));
-	}
-
-   
-   // now add the cvterm only if it doesn't already exist
-	$sql = "SELECT * FROM {cvterm} ".
-	       "WHERE cv_id = $cv->cv_id and dbxref_id = $dbxref->dbxref_id and name = '$name'";
-	$cvterm = db_fetch_object(db_query($sql));
-	if(!$cvterm){
-      $result = db_query("INSERT INTO {cvterm} (cv_id,name,definition,dbxref_id) ".
-                         "VALUES ($cv->cv_id,'$name','$definition',$dbxref->dbxref_id)");
-	}
-   tripal_db_set_active($previous_db);  // now use drupal database	
-	
-   if(!$result){
-     // TODO -- ERROR HANDLING
-   }
-}
-/**
- * Add a database to the Chado 'db' table.
- * NOTE: This function is deprecated and may not be used in future releases of Tripal
- *  
- * @ingroup tripal_core_cv_api
- */
-function tripal_add_db($db_name,$description,$urlprefix,$url){
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-
-   // use this SQL statement to get the db_id for the database name
-   $id_sql = "SELECT db_id FROM {db} WHERE name = '%s'";
-
-   $db = db_fetch_object(db_query($id_sql,$db_name));
-
-   // if the database doesn't exist then let's add it.
-   if(!$db->db_id){
-      $sql = "
-         INSERT INTO {db} (name,description,urlprefix,url) VALUES 
-         ('%s','%s','%s','%s');
-      ";
-      db_query($sql,$db_name,$description,$urlprefix,$url);
-    
-      # now get the id for this new db entry
-      $db = db_fetch_object(db_query($id_sql,$db_name));
-   }
-   tripal_db_set_active($previous_db);  // now use drupal database	
-   return $db->db_id;
-}
-
-
-/**
- * Get cvterm_id for a tripal term by passing its name
- * NOTE: This function is deprecated and may not be used in future releases of Tripal
- *  
- * @ingroup tripal_core_cv_api
- */
-function tripal_get_cvterm_id ($cvterm){
-	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT
-         	    INNER JOIN cv ON cv.cv_id = CVT.cv_id 
-            	 WHERE CVT.name = '$cvterm' 
-                AND CV.name = 'tripal'";
-	return db_result(chado_query($sql));
-}
-

+ 0 - 1
tripal_core/tripal_core.module

@@ -2,7 +2,6 @@
 
 
 require_once "jobs.php";
 require_once "jobs.php";
 require_once "mviews.php";
 require_once "mviews.php";
-require_once "cvterms.php";
 require_once "chado_install.php";
 require_once "chado_install.php";
 require_once "tripal_core.api.inc";
 require_once "tripal_core.api.inc";
 
 

+ 46 - 17
tripal_cv/tripal_cv.api.inc

@@ -166,28 +166,46 @@ function tripal_cv_get_cv_options() {
  *   the cvterm.name
  *   the cvterm.name
  * @param $cv_id
  * @param $cv_id
  *   the cv_id of the term you are looking for
  *   the cv_id of the term you are looking for
+ * @param $cv_name
+ *   the name of the CV
  *
  *
  * @return 
  * @return 
  *   cvterm object
  *   cvterm object
  *
  *
  * @ingroup tripal_cv_api
  * @ingroup tripal_cv_api
  */
  */
-function tripal_cv_get_cvterm_by_name ($name, $cv_id=0) {
+function tripal_cv_get_cvterm_by_name ($name, $cv_id=0,$cv_name='tripal') {
 
 
-  if (!empty($cv_id)) {
-    $sql = "SELECT * FROM cvterm WHERE name='%s' AND cv_id=%d";
-    $previous_db = tripal_db_set_active('chado');
-    $r = db_fetch_object(db_query($sql, $name, $cv_id));
-    tripal_db_set_active($previous_db);
-  } else {
-    $sql = "SELECT * FROM cvterm WHERE name='%s'";
-    $previous_db = tripal_db_set_active('chado');
-    $r = db_fetch_object(db_query($sql, $name));
-    tripal_db_set_active($previous_db);
+  if ($cv_id) {
+    $values = array(
+       'name' => $name,
+       'cv_id' => $cv_id,
+    );
+    $r = tripal_core_chado_select('cvterm',array('*'),$values);
+  } 
+  elseif($cv_name){
+    $values = array(
+       'name' => $name,
+       'cv_id' => array(
+          'name' => $cv_name,
+       ),
+    );
+    $r = tripal_core_chado_select('cvterm',array('*'),$values);
+  }
+  else {
+    $values = array(
+       'name' => $name,
+    );
+    $r = tripal_core_chado_select('cvterm',array('*'),$values);
   }
   }
   
   
-  return $r;
-  
+  if(!$r){
+     return FALSE;
+  }
+  if(count($r) > 0){
+     return FALSE;
+  }
+  return $r[0];
 }
 }
 
 
 /**
 /**
@@ -319,10 +337,11 @@ function tripal_cv_add_cv($name,$comment){
 *   the database to which the cvterm belongs and the <ACCESSION> is the 
 *   the database to which the cvterm belongs and the <ACCESSION> is the 
 *   term's accession number in the database.
 *   term's accession number in the database.
 * @param $defaultcv
 * @param $defaultcv
-*   Optional. A CV object populated with the fields of the CV to which the term 
+*   Optional. The CV name to which the term 
 *   belongs.  If this arugment is null or not provided then the function tries
 *   belongs.  If this arugment is null or not provided then the function tries
 *   to find a record in the CV table with the same name provided in the 
 *   to find a record in the CV table with the same name provided in the 
-*   $term[namespace]. 
+*   $term[namespace].  If this field is provided then it overrides what the 
+*   value in $term[namespace] 
 * @param $is_relationship
 * @param $is_relationship
 *   If this term is a relationship term then this value should be 1.
 *   If this term is a relationship term then this value should be 1.
 * @param $update
 * @param $update
@@ -337,7 +356,7 @@ function tripal_cv_add_cv($name,$comment){
 *
 *
 * @ingroup tripal_cv_api
 * @ingroup tripal_cv_api
 */
 */
-function tripal_cv_add_cvterm($term,$defaultcv=NULL,$is_relationship = 0,$update = 1,$dbname=NULL){
+function tripal_cv_add_cvterm($term,$defaultcv='',$is_relationship = 0,$update = 1,$dbname=NULL){
 
 
    // get the term properties
    // get the term properties
    $id = $term['id'];
    $id = $term['id'];
@@ -348,8 +367,18 @@ function tripal_cv_add_cvterm($term,$defaultcv=NULL,$is_relationship = 0,$update
    if(isset($term['is_obsolete']) and  strcmp($term['is_obsolete'],'true')==0){
    if(isset($term['is_obsolete']) and  strcmp($term['is_obsolete'],'true')==0){
      $is_obsolete = 1;
      $is_obsolete = 1;
    }
    }
+   if(!$name and !$id){
+      watchdog('tripal_cv', "Cannot find cvterm without 'id' or 'name'",NULL,WATCHDOG_WARNING);
+      return 0;
+   }
+   if(!$id){
+      $id = $name;
+   }
+   if(!$name){
+      $name = $id;
+   }
    if(!$cvname){
    if(!$cvname){
-      $cvname = $defaultcv->name;
+      $cvname = $defaultcv;
    }
    }
    // make sure the CV name exists
    // make sure the CV name exists
    $cv = tripal_cv_add_cv($cvname,'');
    $cv = tripal_cv_add_cv($cvname,'');

+ 1 - 1
tripal_feature/gff_loader.php

@@ -865,7 +865,7 @@ function tripal_feature_load_gff3_alias($feature,$aliases){
          'definition' => array(''),
          'definition' => array(''),
          'is_obsolete' => array(0),
          'is_obsolete' => array(0),
       );
       );
-      $syntype = tripal_cv_add_cvterm($term,$syncv,0,1);
+      $syntype = tripal_cv_add_cvterm($term,$syncv->name,0,1);
       if(!$syntype){
       if(!$syntype){
          print("Cannot add synonym type: internal:$type");
          print("Cannot add synonym type: internal:$type");
          return 0;
          return 0;

+ 6 - 6
tripal_library/tripal_library.install

@@ -16,14 +16,14 @@ function tripal_library_install(){
    // Insert cvterm 'library_description' into cvterm table of chado
    // Insert cvterm 'library_description' into cvterm table of chado
    // database. This CV term is used to keep track of the library
    // database. This CV term is used to keep track of the library
    // description in the libraryprop table.
    // description in the libraryprop table.
-   tripal_add_cvterms('library_description','Description of a library');
+   tripal_cv_add_cvterm(array('name' => 'library_description','def' => 'Description of a library'),'tripal',0,1,'tripal');
    
    
    // Add CVTerms for the library types
    // Add CVTerms for the library types
-   tripal_add_cvterms('cdna_library','cDNA Library');
-   tripal_add_cvterms('bac_library','BAC Library');
-   tripal_add_cvterms('fosmid_library','FOSMID Library');
-   tripal_add_cvterms('cosmid_library','COSMID Library');
-   tripal_add_cvterms('yac_library','YAC Library');
+   tripal_cv_add_cvterm(array('name' => 'cdna_library','def' => 'cDNA Library'),'tripal',0,1,'tripal');
+   tripal_cv_add_cvterm(array('name' => 'bac_library','def' => 'BAC Library'),'tripal',0,1,'tripal');
+   tripal_cv_add_cvterm(array('name' => 'fosmid_library','def' => 'FOSMID Library'),'tripal',0,1,'tripal');
+   tripal_cv_add_cvterm(array('name' => 'cosmid_library','def' => 'COSMID Library'),'tripal',0,1,'tripal');
+   tripal_cv_add_cvterm(array('name' => 'yac_library','def' => 'YAC Library'),'tripal',0,1,'tripal');
 
 
    // Add the materialized view needed to count the features for the library
    // Add the materialized view needed to count the features for the library
    // Drop the MView table if it exists
    // Drop the MView table if it exists