function tripal_cv_obo_add_synonyms

2.x tripal_cv.obo_loader.inc tripal_cv_obo_add_synonyms($term, $cvterm)
1.x obo_loader.inc tripal_cv_obo_add_synonyms($term, $cvterm)

Adds the synonyms to a term

Parameters

term: An array representing the cvterm. It must have a 'synonym' key/value pair.

cvterm: The database object of the cvterm to which the synonym will be added.

Related topics

1 call to tripal_cv_obo_add_synonyms()
tripal_cv_obo_process_term in tripal_cv/includes/tripal_cv.obo_loader.inc
Uses the provided term array to add/update information to Chado about the term including the term, dbxref, synonyms, properties, and relationships.

File

tripal_cv/includes/tripal_cv.obo_loader.inc, line 1042
Functions to aid in loading ontologies into the chado cv module

Code

function tripal_cv_obo_add_synonyms($term, $cvterm) {

  // make sure we have a 'synonym_type' vocabulary
  $syncv = tripal_insert_cv('synonym_type', 'A vocabulary added by the Tripal CV module OBO loader for storing synonym types.');

  // now add the synonyms
  if (array_key_exists('synonym', $term)) {
    foreach ($term['synonym'] as $synonym) {

      // separate out the synonym definition and the synonym type
      $def = preg_replace('/^\s*"(.*)"\s*.*$/', '\1', $synonym);
      // the scope will be 'EXACT', etc...
      $scope = drupal_strtolower(preg_replace('/^.*"\s+(.*?)\s+.*$/', '\1', $synonym));
      if (!$scope) { // if no scope then default to 'exact'
        $scope = 'exact';
      }

      // make sure the synonym type exists in the 'synonym_type' vocabulary
      $values = array(
        'name' => $scope,
        'cv_id' => array(
          'name' => 'synonym_type',
        ),
      );
      $syntype = tripal_get_cvterm($values);

      // if it doesn't exist then add it
      if (!$syntype) {
        // build a 'term' object so we can add the missing term
        $term = array(
          'name' => $scope,
          'id' => "internal:$scope",
          'definition' => '',
          'is_obsolete' => 0,
          'cv_name' => $syncv->name,
          'is_relationship' => FALSE
        );
        $syntype = tripal_insert_cvterm($term, array('update_existing' => TRUE));
        if (!$syntype) {
          tripal_cv_obo_quiterror("Cannot add synonym type: internal:$scope");
        }
      }

      // make sure the synonym doesn't already exists
      $values = array(
        'cvterm_id' => $cvterm->cvterm_id,
        'synonym' => $def
      );
      $results = chado_select_record('cvtermsynonym', array('*'), $values);
      if (count($results) == 0) {
        $values = array(
          'cvterm_id' => $cvterm->cvterm_id,
          'synonym' => $def,
          'type_id' => $syntype->cvterm_id
        );
        $options = array('return_record' => FALSE);
        $success = chado_insert_record('cvtermsynonym', $values, $options);
        if (!$success) {
          tripal_cv_obo_quiterror("Failed to insert the synonym for term: $name ($def)");
        }
      }

      // now add the dbxrefs for the synonym if we have a comma in the middle
      // of a description then this will cause problems when splitting os lets
      // just change it so it won't mess up our splitting and then set it back
      // later.
      /**
      $synonym = preg_replace('/(".*?),\s(.*?")/','$1,_$2',$synonym);
      $dbxrefs = preg_split("/, /",preg_replace('/^.*\[(.*?)\]$/','\1',$synonym));
      foreach ($dbxrefs as $dbxref) {
       $dbxref = preg_replace('/,_/',", ",$dbxref);
        if ($dbxref) {
          tripal_cv_obo_add_cvterm_dbxref($syn,$dbxref);
        }
      }
      */
    }
  }

  return TRUE;
}