function chado_get_base_tables

3.x tripal_chado.schema.api.inc chado_get_base_tables()

Returns all chado base tables.

Base tables are those that contain the primary record for a data type. For example, feature, organism, stock, are all base tables. Other tables include linker tables (which link two or more base tables), property tables, and relationship tables. These provide additional information about primary data records and are therefore not base tables. This function retreives only the list of tables that are considered 'base' tables.

Return value

An array of base table names.

Related topics

2 calls to chado_get_base_tables()
tripal_chado_field_storage_bundle_mapping_form in tripal_chado/includes/tripal_chado.field_storage.inc
Implements hook_field_storage_bundle_mapping_form().
tripal_chado_map_cvterms in tripal_chado/includes/tripal_chado.mapping.inc
This function populates the Tripal entity tables using existing data in the database.

File

tripal_chado/api/tripal_chado.schema.api.inc, line 587
Provides an application programming interface (API) for describing Chado tables.

Code

function chado_get_base_tables() {

  // Initialize the base tables with those tables that are missing a type.
  // Ideally they should have a type, but that's for a future version of Chado.
  $base_tables = array('organism', 'project', 'analysis', 'biomaterial', 'eimage');

  // We'll use the cvterm table to guide which tables are base tables. Typically
  // base tables (with a few exceptions) all have a type.  Iterate through the
  // referring tables.
  $schema = chado_get_schema('cvterm');
  $referring = $schema['referring_tables'];
  foreach ($referring as $tablename) {

    // Ignore the cvterm tables, relationships, chadoprop tables.
    if ($tablename == 'cvterm_dbxref' || $tablename == 'cvterm_relationship' || 
      $tablename == 'cvtermpath' || $tablename == 'cvtermprop' || $tablename == 'chadoprop' || 
      $tablename == 'cvtermsynonym' || preg_match('/_relationship$/', $tablename) || 
      preg_match('/_cvterm$/', $tablename) || 
      // Ignore prop tables
      preg_match('/prop$/', $tablename) || preg_match('/prop_.+$/', $tablename) || 
      // Ignore nd_tables
      preg_match('/^nd_/', $tablename)) {
      continue;
    }
    else {
      array_push($base_tables, $tablename);
    }
  }

  // Remove any linker tables that have snuck in.  Linker tables are those
  // whose foreign key constraints link to two or more base table.
  $final_list = array();
  foreach ($base_tables as $i => $tablename) {
    // The biomaterial table breaks our rule and seems to look like a linking
    // table, but we want to keep it as a base table.
    if ($tablename == 'biomaterial') {
      $final_list[] = $tablename;
      continue;
    }
    $num_links = 0;
    $schema = chado_get_schema($tablename);
    $fkeys = $schema['foreign keys'];
    foreach ($fkeys as $fkid => $details) {
      $fktable = $details['table'];
      if (in_array($fktable, $base_tables)) {
        $num_links++;
      }
    }
    if ($num_links < 2) {
      $final_list[] = $tablename;
    }
  }

  // Remove the phenotype table. It really shouldn't be a base table as
  // it is meant to store individual phenotype measurements.
  unset($final_list['phenotyp']);

  // Now add in the cvterm table to the list.
  $final_list[] = 'cvterm';

  // Sort the tables and return the list.
  sort($final_list);
  return $final_list;
}