function chado_get_dbxref

3.x tripal_chado.db.api.inc chado_get_dbxref($identifiers, $options = array())

Retrieves a chado database reference variable.

Example Usage:

  $identifiers = array(
    'accession' => 'synonym',
    'db_id' => array(
      'name' => 'SOFP'
    )
  );
  $dbxref_object = chado_get_dbxref($identifiers);

The above code selects the synonym database reference and returns the following object:

 $dbxref_object = stdClass Object (
    [dbxref_id] => 2581
    [accession] => synonym
    [description] =>
    [version] =>
    [db_db_id] => 49
    [db_name] => SOFP
    [db_description] =>
    [db_urlprefix] =>
    [db_url] =>
  );

Parameters

$identifier: An array apropriate for use with the chado_generate_var for uniquely identifying a dbxref record. Alternatively, there are also some specially handled keys. They are:

  • property: An array/object describing the property to select records for. It should at least have either a type_name (if unique across cvs) or type_id. Other supported keys include: cv_id/cv_name (of the type), value and rank.

$options: An array of options. Supported keys include:

  • Any keys supported by chado_generate_var(). See that function definition for additional details.

NOTE: the $identifier parameter can really be any array similar to $values passed into chado_select_record(). It should fully specify the dbxref record to be returned.

Return value

If unique values were passed in as an identifier then an object describing the dbxref will be returned (will be a chado variable from chado_generate_var()). Otherwise, FALSE will be returned.

Related topics

3 calls to chado_get_dbxref()
sbo__database_cross_reference_formatter::view in tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc
tripal_chado_field_storage_write in tripal_chado/includes/tripal_chado.field_storage.inc
Implements hook_field_storage_write().
tripal_get_dbxref in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
Retrieves a chado database reference variable.

File

tripal_chado/api/modules/tripal_chado.db.api.inc, line 214
Provides API functions specificially for managing external database reference records in Chado.

Code

function chado_get_dbxref($identifiers, $options = array()) {

  // Set Defaults.
  if (!isset($options['include_fk'])) {
    // Tells chado_generate_var not only expand the db.
    $options['include_fk'] = array('db_id' => TRUE);
  }

  // Error Checking of parameters.
  if (!is_array($identifiers)) {
    tripal_report_error('tripal_db_api', TRIPAL_ERROR, 
    "chado_get_dbxref: The identifier passed in is expected to be an array with the key
        matching a column name in the dbxref table (ie: dbxref_id or name). You passed in %identifier.", 
    array('%identifier' => print_r($identifiers, TRUE))
    );
  }
  elseif (empty($identifiers)) {
    tripal_report_error('tripal_db_api', TRIPAL_ERROR, 
    "chado_get_dbxref: You did not pass in anything to identify the dbxref you want. The identifier
        is expected to be an array with the key matching a column name in the dbxref table
        (ie: dbxref_id or name). You passed in %identifier.", 
    array('%identifier' => print_r($identifiers, TRUE))
    );
  }

  // If one of the identifiers is property then use chado_get_record_with_property().
  if (isset($identifiers['property'])) {
    $property = $identifiers['property'];
    unset($identifiers['property']);
    $dbxref = chado_get_record_with_property(
    array('table' => 'dbxref', 'base_records' => $identifiers), 
    array('type_name' => $property), 
    $options
    );
  }

  // Else we have a simple case and we can just use chado_generate_var to get 
  // the analysis.
  else {
    $dbxref = chado_generate_var('dbxref', $identifiers, $options);
  }

  // Ensure the dbxref is singular. If it's an array then it is not singular.
  if (is_array($dbxref)) {
    tripal_report_error('tripal_db_api', TRIPAL_ERROR, 
    "chado_get_dbxref: The identifiers you passed in were not unique. You passed in %identifier.", 
    array('%identifier' => print_r($identifiers, TRUE))
    );
  }

  // Report an error if $dbxref is FALSE since then chado_generate_var has 
  // failed.
  elseif ($dbxref === FALSE) {
    tripal_report_error(
    'tripal_db_api', 
    TRIPAL_ERROR, 
    "chado_get_dbxref: chado_generate_var() failed to return a dbxref based on the identifiers
        you passed in. You should check that your identifiers are correct, as well as, look
        for a chado_generate_var error for additional clues. You passed in %identifier.", 
    array(
      '%identifier' => print_r($identifiers, TRUE)
    )
    );
  }

  // Else, as far we know, everything is fine so give them their dbxref :)
  else {
    return $dbxref;
  }
}