function chado_add_semweb_table

3.x tripal_chado.semweb.api.inc chado_add_semweb_table($chado_table)

Adds a new Chado table to the semantic web support for Chado.

Newly added tables (i.e. custom tables) need to be integrated into the semantic web infrastructure. After a new table is created and added to the Chado schema, this function should be called to indicate that the table should be included in the semantic web. No associations are made for the columns. The associations should be added using the chado_associate_semweb_term() function.

If the table has already been added previously then this function does nothing. It will not overwrite existing assocations.

Temporary tables (e.g. Tripal tables that begin with 'tripal_' and end with '_temp', are not supported.

Parameters

$chado_table: The name of the Chado table.

Related topics

4 calls to chado_add_semweb_table()
chado_create_custom_table in tripal_chado/api/tripal_chado.custom_tables.api.inc
Add a new table to the Chado schema. This function is simply a wrapper for the db_create_table() function of Drupal, but ensures the table is created inside the Chado schema rather than the Drupal schema. If the table already exists then it will be…
chado_edit_custom_table in tripal_chado/api/tripal_chado.custom_tables.api.inc
Edits a custom table in the chado database. It supports using the Drupal Schema API array.
tripal_add_chado_semweb_table in tripal_chado/api/tripal_chado.DEPRECATED.api.inc
Adds a new Chado table to the semantic web support for Chado.
tripal_chado_populate_chado_semweb_table in tripal_chado/includes/tripal_chado.semweb.inc
Adds defaults to the chado_semweb table.

File

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

Code

function chado_add_semweb_table($chado_table) {

  // Don't include the tripal temp tables.
  if (preg_match('/tripal_.+_temp/', $chado_table)) {
    return;
  }

  // Get the table's schema and add all of it's fields if they aren't
  // already there.
  $schema = chado_get_schema($chado_table);
  foreach ($schema['fields'] as $chado_column => $details) {

    // If the record already exists don't overwrite it.
    $record = db_select('chado_semweb', 'CS')
      ->fields('CS', array('chado_semweb_id'))
      ->condition('CS.chado_table', $chado_table)
      ->condition('CS.chado_column', $chado_column)
      ->execute()
      ->fetchField();
    if (!$record) {
      $record = array(
        'chado_table' => $chado_table,
        'chado_column' => $chado_column,
      );
      drupal_write_record('chado_semweb', $record);
    }
  }
}