function chado_feature_add_synonyms

2.x tripal_feature.chado_node.inc chado_feature_add_synonyms($synonyms, $feature_id)
3.x tripal_feature.chado_node.inc chado_feature_add_synonyms($synonyms, $feature_id)
1.x tripal_feature.module chado_feature_add_synonyms($synonyms, $feature_id)

Related topics

2 calls to chado_feature_add_synonyms()
chado_feature_insert in tripal_feature/tripal_feature.module
When a new chado_feature node is created we also need to add information to our chado_feature table. This function is called on insert of a new node of type 'chado_feature' and inserts the necessary information.
chado_feature_update in tripal_feature/tripal_feature.module

File

tripal_feature/tripal_feature.module, line 624
@todo Add file header description

Code

function chado_feature_add_synonyms($synonyms, $feature_id) {

  // separate synomys by carriage returns
  $synonyms = preg_replace("/[\n\r]+/", " ", $synonyms);
  // split the synonyms into an array based on a space as the delimieter
  $syn_array = array();
  $syn_array = explode(" ", $synonyms);


  // remove any old synonyms
  $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
  if (!chado_query($feature_syn_dsql, $feature_id)) {
    $error .= "Could not remove synonyms from feature. ";
  }

  // return if we don't have any synonmys to add
  if (!$synonyms) {
    return;
  }
  // iterate through each synonym and add it to the database
  foreach ($syn_array as $syn) {
    // skip this item if it's empty
    if (!$syn) {
      break;
    }

    // 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.
    // It is possible for the accession number to be present and not the feature
    $synonym_sql = "SELECT synonym_id FROM {synonym} " .
      "WHERE name = '%s'";
    $synonym = db_fetch_object(chado_query($synonym_sql, $syn));
    if (!$synonym) {
      $synonym_isql = "INSERT INTO {synonym} (name,synonym_sgml,type_id) " .
        "VALUES ('%s','%s', " .
        "   (SELECT cvterm_id " .
        "    FROM {CVTerm} CVT " .
        "    INNER JOIN CV ON CVT.cv_id = CV.cv_id " .
        "    WHERE CV.name = 'feature_property' and CVT.name = 'synonym'))";
      if (!chado_query($synonym_isql, $syn, $syn)) {
        $error .= "Could not add synonym. ";
      }
      // now get the synonym we just added
      $synonym_sql = "SELECT synonym_id FROM {synonym} " .
        "WHERE name = '%s'";
      $synonym = db_fetch_object(chado_query($synonym_sql, $syn));
    }

    // now add in our new sysnonym
    $feature_syn_isql = "INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id) " .
      "VALUES (%d,%d,1)";
    if (!chado_query($feature_syn_isql, $synonym->synonym_id, $feature_id)) {
      $error .= "Could not add synonyms to feature. ";
    }
  }

  // return to the drupal database
  return $error;

}