function chado_get_semweb_column

3.x tripal_chado.semweb.api.inc chado_get_semweb_column($chado_table, $term)

Retreive the column name in a Chado table that matches a given term.

Parameters

$chado_table: The name of the Chado table.

$term: The term. This can be a term name or a unique identifer of the form {db}:{accession} or of the form {db}__{term_name}.

Return value

The name of the Chado column that matches the given term or FALSE if the term is not mapped to the Chado table.

Related topics

4 calls to chado_get_semweb_column()
ChadoField::query in tripal_chado/includes/TripalFields/ChadoField.inc
In addition to the rules to follow for the TripalField::query function these should also be followed for the ChadoField::query implementation.
ChadoField::queryOrder in tripal_chado/includes/TripalFields/ChadoField.inc
tripal_chado_field_storage_query in tripal_chado/includes/tripal_chado.field_storage.inc
Implements hook_field_storage_query().
tripal_get_chado_semweb_column in tripal_chado/api/tripal_chado.DEPRECATED.api.inc
Retreive the column name in a Chado table that matches a given term.

File

tripal_chado/api/tripal_chado.semweb.api.inc, line 249
Provides an application programming interface (API) for semantic web support.

Code

function chado_get_semweb_column($chado_table, $term) {
  $columns = db_select('chado_semweb', 'CS')
    ->fields('CS')
    ->condition('chado_table', $chado_table)
    ->execute();

  while ($column = $columns->fetchObject()) {
    $cvterm_id = $column->cvterm_id;

    if ($cvterm_id) {

      $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));

      $full_accession = strtolower($cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession);
      $full_accession = preg_replace('/ /', '_', $full_accession);
      $full_name_uscore = strtolower($cvterm->dbxref_id->db_id->name . '__' . $cvterm->name);
      $full_name_uscore = preg_replace('/ /', '_', $full_name_uscore);

      $term = preg_replace('/ /', '_', $term);
      $term = strtolower(preg_replace('/ /', '_', $term));

      // Does the term match identically?
      if ($term == $cvterm->name) {
        return $column->chado_column;
      }
      // Is the term a concatenation of the vocab and the accession?
      else if ($term == $full_accession) {
        return $column->chado_column;
      }
      // Is the term a concatenation of the vocab and the accession?
      else if ($term == $full_name_uscore) {
        return $column->chado_column;
      }
    }
  }
  return FALSE;
}