Tripal
Public Member Functions | Protected Attributes | List of all members
ChadoSchema Class Reference

Public Member Functions

 __construct ($version=NULL, $schema_name=NULL)
 
 getVersion ()
 
 getSchemaName ()
 
 getTableNames ($include_custom=FALSE)
 
 getTableSchema ($table)
 
 getCustomTableSchema ($table)
 
 getBaseTables ()
 
 getCvtermMapping ($params)
 
 checkTableExists ($table)
 
 checkColumnExists ($table, $column)
 
 checkColumnType ($table, $column, $expected_type=NULL)
 
 checkSequenceExists ($table, $column)
 
 checkPrimaryKey ($table, $column=NULL)
 
 checkConstraintExists ($table, $constraint_name, $type)
 
 checkFKConstraintExists ($base_table, $base_column)
 
 checkIndexExists ($table, $name)
 

Protected Attributes

 $version = ''
 
 $schema_name = 'chado'
 

Detailed Description

Provides an application programming interface (API) for describing Chado tables.

If you need the Drupal-style array definition for any table, use the following:

$chado_schema = new \ChadoSchema();
$table_schema = $chado_schema->getTableSchema($table_name);

where the variable $table contains the name of the table you want to retireve. The getTableSchema method determines the appropriate version of Chado and uses the Drupal hook infrastructure to call the appropriate hook function to retrieve the table schema.

Additionally, here are some other examples of how to use this class:

// Retrieve the schema array for the organism table in chado 1.2
$chado_schema = new \ChadoSchema('1.2');
$table_schema = $chado_schema->getTableSchema('organism');
// Retrieve all chado tables.
$chado_schema = new \ChadoSchema();
$tables = $chado_schema->getTableNames();
$base_tables = $chado_schema->getbaseTables();
// Check the feature.type_id foreign key constraint
$chado_schema = new \ChadoSchema();
$exists = $chado_schema ->checkFKConstraintExists('feature','type_id');
// Check Sequence exists
$chado_schema = new \ChadoSchema();
$exists = $chado_schema->checkSequenceExists('organism','organism_id');
// Or just check the primary key directly
$compliant = $chado_schema->checkPrimaryKey('organism');

Constructor & Destructor Documentation

◆ __construct()

ChadoSchema::__construct (   $version = NULL,
  $schema_name = NULL 
)

The ChadoSchema constructor.

Parameters
string$versionThe current version for this site. E.g. "1.3". If a version is not provided, the version of the current database will be looked up.

Member Function Documentation

◆ checkConstraintExists()

ChadoSchema::checkConstraintExists (   $table,
  $constraint_name,
  $type 
)

Check that the constraint exists.

Parameters
$tableThe table the constraint applies to.
$constraint_nameThe name of the constraint you want to check.
$typeThe type of constraint. Should be one of "PRIMARY KEY", "UNIQUE", or "FOREIGN KEY".
Returns
TRUE if the constraint exists and false otherwise.

◆ checkFKConstraintExists()

ChadoSchema::checkFKConstraintExists (   $base_table,
  $base_column 
)

Check the foreign key constrain specified exists.

Parameters
$base_tableThe name of the table the foreign key resides in. E.g. 'feature' for the feature.type_id => cvterm.cvterm_id foreign key.
$base_columnThe name of the column that is a foreign key in. E.g. 'type_id' for the feature.type_id => cvterm.cvterm_id foreign key.
Returns
TRUE if the constraint exists and false otherwise.

◆ checkIndexExists()

ChadoSchema::checkIndexExists (   $table,
  $name 
)

A Chado-aware replacement for the db_index_exists() function.

Parameters
$tableThe table to be altered.
$nameThe name of the index.

◆ checkPrimaryKey()

ChadoSchema::checkPrimaryKey (   $table,
  $column = NULL 
)

Check that the primary key exists, has a sequence and a constraint.

Parameters
$tableThe table you want to check the primary key for.
$column(OPTIONAL) The name of the primary key column.
Returns
TRUE if the primary key meets all the requirements and false otherwise.

◆ checkTableExists()

ChadoSchema::checkTableExists (   $table)

Check that any given Chado table exists.

This function is necessary because Drupal's db_table_exists() function will not look in any other schema but the one where Drupal is installed

Parameters
$tableThe name of the chado table whose existence should be checked.
Returns
TRUE if the table exists in the chado schema and FALSE if it does not.

◆ getCustomTableSchema()

ChadoSchema::getCustomTableSchema (   $table)

Retrieves the schema array for the specified custom table.

Parameters
$tableThe name of the table to create.
Returns
A Drupal-style Schema API array definition of the table. Returns FALSE on failure.

◆ getCvtermMapping()

ChadoSchema::getCvtermMapping (   $params)

Get information about which Chado base table a cvterm is mapped to.

Vocbulary terms that represent content types in Tripal must be mapped to Chado tables. A cvterm can only be mapped to one base table in Chado. This function will return an object that contains the chado table and foreign key field to which the cvterm is mapped. The 'chado_table' property of the returned object contains the name of the table, and the 'chado_field' property contains the name of the foreign key field (e.g. type_id), and the 'cvterm' property contains a cvterm object.

@params An associative array that contains the following keys:

  • cvterm_id: the cvterm ID value for the term.
  • vocabulary: the short name for the vocabulary (e.g. SO, GO, PATO)
  • accession: the accession for the term.
  • bundle_id: the ID for the bundle to which a term is associated. The 'vocabulary' and 'accession' must be used together, the 'cvterm_id' can be used on it's own.
Returns
An object containing the chado_table and chado_field properties or NULL if if no mapping was found for the term.

◆ getSchemaName()

ChadoSchema::getSchemaName ( )

Retrieve the name of the PostgreSQL schema housing Chado.

Returns
The name of the schema.

◆ getTableNames()

ChadoSchema::getTableNames (   $include_custom = FALSE)

Retrieves the list of tables in the Chado schema. By default it only returns the default Chado tables, but can return custom tables added to the Chado schema if requested.

Parameters
$include_customOptional. Set as TRUE to include any custom tables created in the Chado schema. Custom tables are added to Chado using the tripal_chado_chado_create_table() function.
Returns
An associative array where the key and value pairs are the Chado table names.

◆ getTableSchema()

ChadoSchema::getTableSchema (   $table)

Retrieves the chado tables Schema API array.

Parameters
$tableThe name of the table to retrieve. The function will use the appopriate Tripal chado schema API hooks (e.g. v1.11 or v1.2).
Returns
A Drupal Schema API array defining the table.

◆ getVersion()

ChadoSchema::getVersion ( )

Returns the version number of the Chado this object references.

Returns
The version of Chado

The documentation for this class was generated from the following file: