function chado_insert_cv

3.x tripal_chado.cv.api.inc chado_insert_cv($name, $definition)

Adds a controlled vocabulary to the CV table of Chado.

Parameters

$name: The name of the controlled vocabulary. These are typically all lower case with no special characters other than an undrescore (for spaces).

$comment: A description or definition of the vocabulary.

Return value

An object populated with fields from the newly added database.

Related topics

35 calls to chado_insert_cv()
chado_insert_cvterm in tripal_chado/api/modules/tripal_chado.cv.api.inc
Add's a controlled vocabulary term to Chado.
OBOImporter::addCvtermProp in tripal_chado/includes/TripalImporter/OBOImporter.inc
Adds a property to a cvterm
OBOImporter::addSynonym in tripal_chado/includes/TripalImporter/OBOImporter.inc
Adds the synonyms to a term
OBOImporter::loadOBO_v1_2 in tripal_chado/includes/TripalImporter/OBOImporter.inc
Imports a given OBO file into Chado. This function is usually called by one of three wrapper functions: loadOBO_v1_2_id, loadOBO_v1_2_file or tirpal_cv_load_obo_v1_2_url. But, it can be called directly if the full path to an OBO file is available on…
OBOImporter::processTerm in tripal_chado/includes/TripalImporter/OBOImporter.inc
Uses the provided term array to add/update information to Chado about the term including the term, dbxref, synonyms, properties, and relationships.

... See full list

File

tripal_chado/api/modules/tripal_chado.cv.api.inc, line 844
Provides API functions specificially for managing controlled vocabulary records in Chado.

Code

function chado_insert_cv($name, $definition) {

  // Insert/update values.
  $ins_values = array(
    'name' => $name,
    'definition' => $definition
  );

  // See if the CV default exists already in the database.
  $sel_values = array('name' => $name);
  $results = chado_select_record('cv', array('*'), $sel_values);

  // If it does not exists then add it.
  if (count($results) == 0) {
    $success = chado_insert_record('cv', $ins_values);
    if (!$success) {
      tripal_report_error('tripal_chado', TRIPAL_WARNING, "Failed to create the CV record", NULL);
      return FALSE;
    }
    $results = chado_select_record('cv', array('*'), $sel_values);
  }
  // If it already exists then do an update.
  else {
    $success = chado_update_record('cv', $sel_values, $ins_values);
    if (!$success) {
      tripal_report_error('tripal_chado', TRIPAL_WARNING, "Failed to update the CV record", NULL);
      return FALSE;
    }
    $results = chado_select_record('cv', array('*'), $sel_values);
  }

  // Return the cv object.
  return $results[0];
}