function tripal_get_publication

2.x tripal_pub.api.inc tripal_get_publication($identifiers, $options = array())

Retrieves a chado publication array

Parameters

$identifier: An array used to uniquely identify a publication. This array has the same format as that used by the chado_generate_var(). The following keys can be useful for uniquely identifying a publication as they should be unique:

  • pub_id: the chado pub.pub_id primary key
  • nid: the drupal nid of the publication
  • uniquename: A value to matach with the pub.uniquename field

There are also some specially handled keys. They are:

  • property: An array describing the property to select records for. It should at least have either a 'type_name' key (if unique across cvs) or 'type_id' key. Other supported keys include: 'cv_id', 'cv_name' (of the type), 'value' and 'rank'
  • dbxref: The database cross reference accession. It should be in the form DB:ACCESSION, where DB is the database name and ACCESSION is the unique publication identifier (e.g. PMID:4382934)
  • dbxref_id: The dbxref.dbxref_id of the publication.

$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 pub record to be returned.

Return value

If a singe publication is retreived using the identifiers, then a publication array will be returned. The array is of the same format returned by the chado_generate_var() function. Otherwise, FALSE will be returned.

Related topics

3 calls to tripal_get_publication()
chado_get_publication in tripal_pub/api/tripal_pub.DEPRECATED.inc
chado_pub_validate_check_uniquename in tripal_pub/includes/tripal_pub.chado_node.inc
Validate the publication uniquename. To be called from hook_validate().
tripal_publication_exists in tripal_pub/api/tripal_pub.api.inc
The publication table of Chado only has a unique constraint for the uniquename of the publiation, but in reality a publication can be considered unique by a combination of the title, publication type, published year and series name (e.g. journal nameā€¦
1 string reference to 'tripal_get_publication'

File

tripal_pub/api/tripal_pub.api.inc, line 53
Provides an application programming interface (API) to manage chado publications

Code

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

  // Error Checking of parameters
  if (!is_array($identifiers)) {
    tripal_report_error('tripal_pub_api', TRIPAL_ERROR, 
    "chado_get_publication: The identifier passed in is expected to be an array with the key
       matching a column name in the pub table (ie: pub_id or name). You passed in %identifier.", 
    array('%identifier' => print_r($identifiers, TRUE))
    );
  }
  elseif (empty($identifiers)) {
    tripal_report_error('tripal_pub_api', TRIPAL_ERROR, 
    "chado_get_publication: You did not pass in anything to identify the publication you want. The identifier
       is expected to be an array with the key matching a column name in the pub table
       (ie: pub_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 (array_key_exists('property', $identifiers)) {
    $property = $identifiers['property'];
    unset($identifiers['property']);
    $pub = chado_get_record_with_property(
    array('table' => 'pub', 'base_records' => $identifiers), 
    array('type_name' => $property), 
    $options
    );
  }
  elseif (array_key_exists('dbxref', $identifiers)) {
    if (preg_match('/^(.*?):(.*?)$/', $identifiers['dbxref'], $matches)) {
      $dbname = $matches[1];
      $accession = $matches[2];

      // First make sure the dbxref is present.
      $values = array(
        'accession' => $accession,
        'db_id' => array(
          'name' => $dbname
        ),
      );

      $dbxref = chado_select_record('dbxref', array('dbxref_id'), $values);
      if (count($dbxref) == 0) {
        return FALSE;
      }
      $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), array('dbxref_id' => $dbxref[0]->dbxref_id));
      if (count($pub_dbxref) == 0) {
        return FALSE;
      }
      $pub = chado_generate_var('pub', array('pub_id' => $pub_dbxref[0]->pub_id), $options);
    }
    else {
      tripal_report_error('tripal_pub_api', TRIPAL_ERROR, 
      "chado_get_publication: The dbxref identifier is not correctly formatted.", 
      array('%identifier' => print_r($identifiers, TRUE))
      );
    }
  }
  elseif (array_key_exists('dbxref_id', $identifiers)) {
    // first get the pub_dbxref record
    $values = array('dbxref_id' => $identifiers['dbxref_id']);
    $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), $values);

    // now get the pub
    if (count($pub_dbxref) > 0) {
      $pub = chado_generate_var('pub', array('pub_id' => $pub_dbxref[0]->pub_id), $options);
    }
    else {
      return FALSE;
    }

  }
  // Else we have a simple case and we can just use chado_generate_var to get the pub
  else {
    // Try to get the pub
    $pub = chado_generate_var('pub', $identifiers, $options);
  }
  // Ensure the pub is singular. If it's an array then it is not singular
  if (is_array($pub)) {
    tripal_report_error('tripal_pub_api', TRIPAL_ERROR, 
    "chado_get_publication: The identifiers did not find a single unique record. Identifiers passed: %identifier.", 
    array('%identifier' => print_r($identifiers, TRUE))
    );
  }
  // Report an error if $pub is FALSE since then chado_generate_var has failed
  elseif ($pub === FALSE) {
    tripal_report_error('tripal_pub_api', TRIPAL_ERROR, 
    "chado_get_publication: Could not find a publication using the identifiers
       provided. Check that the identifiers are correct. Identifiers passed: %identifier.", 
    array('%identifier' => print_r($identifiers, TRUE))
    );
  }
  // Else, as far we know, everything is fine so give them their pub :)
  else {
    return $pub;
  }
}